Top Level Namespace

Defined Under Namespace

Modules: CocoaPodsMPaaS, CocoapodsMpaas, CocoapodsmPaaS, CocoapodsmPaaSHooks, LogTools, Pod Classes: BaselineTools, CheckUpdateTools, MPaaSCocoapodShare, MPaaSPodfile, PodfileTools

Instance Method Summary collapse

Instance Method Details

#add_framework_ref(parent_ref, path, xcproj, absolute_path) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 132

def add_framework_ref(parent_ref, path, xcproj, absolute_path)
  ref = parent_ref.new_reference(path)
  ref.set_source_tree("<group>")
  if absolute_path
    # ref添加后会自动使用相对路径,但我们不希望这样
    ref.path = path
  end
  return ref
end

#add_framework_search_path(path, target_name, xcproj) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 73

def add_framework_search_path(path, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    target.build_configuration_list.build_configurations.each do |config|
      LogTools.p "Add '#{path}' to 'Framework Search Paths' build settings of target '#{target}'."
      search_paths = config.build_settings["FRAMEWORK_SEARCH_PATHS"]
      if search_paths == nil
        config.build_settings["FRAMEWORK_SEARCH_PATHS"] = Array[path]
      elsif search_paths.is_a?(String)
        if search_paths != path
          config.build_settings["FRAMEWORK_SEARCH_PATHS"] = Array[search_paths, path]
        end
      elsif !search_paths.include?(path)
        search_paths << path
      end
    end
  }
end

#add_framework_to_build_phase(ref, target_name, xcproj) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 142

def add_framework_to_build_phase(ref, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    target.build_phases.each do |phase|
      if "#{phase}".include? "FrameworksBuild"
        LogTools.p "Add '#{File::basename(ref.path)}' to 'Link Binary With Libraries' build phase of target '#{target}'."
        phase.add_file_reference(ref, true)
        break
      end
    end
  }
end

#add_mpaas_references_headers_to_pch(pch_path, header_file_name) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/cocoapods-mPaaS/installNew.rb', line 198

def add_mpaas_references_headers_to_pch(pch_path, header_file_name)
  LogTools.p "Add MPaaS framework headers to '#{pch_path}'."
  trim_end_multiple_nextline(pch_path)
  io = File::open(pch_path).readlines
  override = File.new(pch_path, "w")
  hasIncludeOldHeader = false
  io.each do |line|
    #line.chomp!
    #判断是不是已经有了一个header
    if line.include?("mPaaS-Headers.h")
      hasIncludeOldHeader = true
      override.puts "#import \"#{header_file_name}\""
    else
      override.puts line
    end
  end
  #说明是第一次
  if !hasIncludeOldHeader
    override.puts "\n// MPAAS HEADERS BEGIN\n// This part is maintained by MPaaS plugin automatically. \n#ifdef __OBJC__\n\n"
    override.puts "#import \"#{header_file_name}\""
    override.puts "\n#endif\n// MPAAS HEADERS END"
  end
  override.close
end

#add_mpaas_references_to_target_headers(header_file_path, modules, terget_modules_ignore) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/cocoapods-mPaaS/installNew.rb', line 89

def add_mpaas_references_to_target_headers(header_file_path, modules, terget_modules_ignore)
  ignored_modules = Array["SecurityGuardSDK", "UTDID", "MPTianYan", "MPSyncService", "APProtocolBuffers", "APOpenSSL", "APSecurityUtility", "MPPerformance", "MPDataCenter", "MPDiagnosis", "AntLog", "mPaas", "MPPipeLine", "NebulaSDKPlugins"]
  LogTools.p "Add MPaaS framework headers terget_modules_ignore '#{terget_modules_ignore}'."
  LogTools.p "Add MPaaS framework headers to '#{header_file_path}'."
  trim_end_multiple_nextline(header_file_path)
  # s = File::open(header_file_path).read
  override = File.new(header_file_path, "w")
  baseline_matched = BaselineTools.getBaselineMatched(File.join(Dir::pwd, "Podfile"))
  # override.puts s
  override.puts "\n// MPAAS BEGIN\n// This part is maintained by MPaaS plugin automatically. Please don't modify.\n#ifdef __OBJC__\n\n"
  override.puts "#import <UIKit/UIKit.h>\n"
  hasNebulaBiz = false
  hasNebulaLogging = false
  hasAliUpgradeUI = false
  hasAliUpgradeCheckService = false
  hasAlipaySDK = false
  hasNebulaHeader = false
  modules.each do |m, v|
    if ignored_modules.include?(m)
      next
    end
    if MPaaSCocoapodShare.instance.igenore_headers.include?(m)
      next
    end

    if terget_modules_ignore.include?(m)
      next
    end

    if m == "APCrashReporter"
      override.puts "#import <#{m}/DFCrashReport.h>"
    elsif m == "APConfig"
      override.puts "#import <#{m}/APConfigService.h>"
    elsif m == "NebulamPaaSBiz"
      hasNebulaBiz = true
    elsif m == "NebulaLogging"
      hasNebulaLogging = true
    elsif m == "AliUpgradeUI"
      hasAliUpgradeUI = true
    elsif m == "AliUpgradeCheckService"
      hasAliUpgradeCheckService = true
    elsif m == "NebulaHeader"
      #不在添加NebulaHeader头文件
      hasNebulaHeader = (baseline_matched != "cp_change_15200851")
    elsif m == "MPNebulaAdapter"
      override.puts "#import <#{m}/MPNebulaAdapterInterface.h>"
    elsif m == "MPMgsAdapter"
      override.puts "#import <#{m}/MPRpcInterface.h>"
    elsif m == "MPConfigAdapter"
      override.puts "#import <MPConfigAdapter/MPConfigInterface.h>"
    elsif m == "MPDynamicAdapter"
      override.puts "#import <#{m}/MPDynamicInterface.h>"
    elsif m == "MPMssAdapter"
      override.puts "#import <#{m}/MPSyncInterface.h>"
    elsif m == "MPUTDIDAdapter"
      override.puts "#import <#{m}/MPUtdidInterface.h>"
    elsif m == "AliUpgradeCheckService_32"
      override.puts "#import <AliUpgradeCheckService/UpgradeCheckService.h>"
      override.puts "#import <AliUpgradeCheckService/MPCheckUpgradeInterface.h>"
    elsif m == "MPTinyAppAdapterInterface_60"
      override.puts "#import <MPNebulaAdapter/MPTinyAppAdapterInterface.h>"
    else
      override.puts "#import <#{m}/#{m}.h>"
      # 这里先恶心的适配下
      if m == "AlipaySDK"
        hasAlipaySDK = true
      end
    end
  end

  if hasNebulaBiz
    override.puts "#import <NebulamPaaSBiz/NebulamPaaSBiz.h>"
  end

  if hasNebulaLogging
    override.puts "#import <NebulaLogging/NebulaLogging.h>"
  end

  if hasAliUpgradeUI
    override.puts "#import <AliUpgradeUI/ASUpdateAlertManager.h>"
  end

  if hasAliUpgradeCheckService
    override.puts "#import <AliUpgradeCheckService/UpgradeCheckService.h>"
  end

  if hasAlipaySDK
    override.puts "#import <AlipaySDK/APayAuthInfo.h>"
  end

  # 为了放在最后
  if hasNebulaHeader
    override.puts "#import <NebulaHeader/NebulaHeader.h>"
  end

  override.puts "\n#endif\n// MPAAS END"
  override.close
end

#add_mPaaS_repoObject



9
10
11
# File 'lib/cocoapods-mPaaS/installNew.rb', line 9

def add_mPaaS_repo
  system "pod repo add #{CocoapodsmPaaS::MPAAS_REPO_NAME} #{CocoapodsmPaaS::MPAAS_REPO_URL}"
end

#add_mPaaS_repo_with(repo_name, repo_url) ⇒ Object



13
14
15
# File 'lib/cocoapods-mPaaS/installNew.rb', line 13

def add_mPaaS_repo_with(repo_name, repo_url)
  system "pod repo add #{repo_name} #{repo_url}"
end

#add_non_source_file(parent_ref, path, xcproj) ⇒ Object



171
172
173
174
175
176
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 171

def add_non_source_file(parent_ref, path, xcproj)
  LogTools.v "Add file '#{File::basename(path)}' to project. path: #{path}"
  LogTools.v "Add file 1'#{parent_ref} , #{parent_ref.class}' to project. path: #{path}"

  return parent_ref.new_reference(path)
end

#add_pch_file(project_directory, target_name, xcproj, pch_array) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 276

def add_pch_file(project_directory, target_name, xcproj, pch_array)
  # pch文件与Info.plist放到同一个目录
  do_with_target(target_name, xcproj) { |target|
    target.build_configuration_list.build_configurations.each do |config|
      info_plist_path = config.build_settings["INFOPLIST_FILE"]
      if info_plist_path == nil
        next
      else
        pch_file_path = "#{File::dirname(info_plist_path)}/#{target_name}-Prefix.pch"
        config.build_settings["GCC_PRECOMPILE_PREFIX_HEADER"] = "YES"
        config.build_settings["GCC_PREFIX_HEADER"] = pch_file_path
        if File::exist?("#{project_directory}/#{pch_file_path}")
          next
        end

        author = get_current_user
        time_str = Time.new.strftime("%Y/%m/%d")
        pch_file = File.new("#{project_directory}/#{pch_file_path}", "w")
        pch_file.puts "//"
        pch_file.puts "//  #{target_name}-Prefix.pch"
        pch_file.puts "//  #{target_name}"
        pch_file.puts "//"
        pch_file.puts "//  Created by #{author} on #{time_str}."
        pch_file.puts ""
        pch_file.close

        if !pch_array.include?(pch_file_path)
          pch_array << pch_file_path
        end
      end
    end
  }
end

#add_resource_ref(parent_ref, path, xcproj) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 213

def add_resource_ref(parent_ref, path, xcproj)
  ref = nil
  if File::directory?(path)
    basename = File::basename(path)
    if basename =~ /\w+\.bundle/
      LogTools.p "Add '#{basename}' to project."
      ref = parent_ref.new_bundle(File::basename(path, ".bundle"))
      ref.set_source_tree("<group>")
    end
  else
    ref = add_non_source_file(parent_ref, File::basename(path), xcproj)
  end
  return ref
end

#add_resource_to_build_phase(ref, target_name, xcproj) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 228

def add_resource_to_build_phase(ref, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    target.build_phases.each do |phase|
      if "#{phase}".include? "ResourcesBuild"
        LogTools.p "Add '#{File::basename(ref.path)}' to 'Copy Bundle Resources' build phase of target '#{target}'."
        phase.add_file_reference(ref, true)
        break
      end
    end
  }
end

#add_script_build_phase(name, script, target_name, xcproj) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 46

def add_script_build_phase(name, script, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    LogTools.p "Add '#{name}' to build phase of target '#{target}'."
    phase = target.new_shell_script_build_phase(name)
    phase.shell_script = script
    phase.show_env_vars_in_log = "0"
    target.build_phases.delete(phase)
    target.build_phases.insert(0, phase)
  }
end

#add_source_file(parent_ref, path, target_name, xcproj) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 178

def add_source_file(parent_ref, path, target_name, xcproj)
  LogTools.v "Add source file '#{File::basename(path)}' to project."
  ref = parent_ref.new_reference(path)
  do_with_target(target_name, xcproj) { |target|
    target.build_phases.each do |phase|
      if "#{phase}".include? "SourcesBuild"
        LogTools.p "Add '#{File::basename(path)}' to 'Compile Sources' build phase of target '#{target}'."
        phase.add_file_reference(ref, true)
        break
      end
    end
  }
  return ref
end

#append_array_to_file(file_path, array, delimiter = "\n") ⇒ Object

将数组中的元素追加到文件中



292
293
294
295
296
297
298
# File 'lib/cocoapods-mPaaS/module_config.rb', line 292

def append_array_to_file(file_path, array, delimiter="\n")
  # 打开文件,以追加模式写入
  File.open(file_path, 'a') do |file|
    # 将数组中的元素用指定分隔符连接成一个字符串
    file.puts array.join(delimiter)
  end
end


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 310

def check_other_link_flags(target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    def_flags = Array["-ObjC", "-lz", "-lsqlite3", "-lxml2", "-lc++", "-lbz2"]

    target.build_configuration_list.build_configurations.each do |config|
      flags = config.build_settings["OTHER_LDFLAGS"]
      if flags == nil
        flags = def_flags
      else
        if flags.is_a?(String) # 有可能是string
          flags = Array[flags]
        end

        flags.each do |f|
          def_flags.delete(f) # 已经有的删除
        end
        def_flags.each do |f|
          flags << f
        end
      end
      LogTools.p "Modify 'Other Linker Flags' of target '#{target}'."
      config.build_settings["OTHER_LDFLAGS"] = flags
    end
  }
end

#delete_source_file(parent_ref, path, target_name, xcproj) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 198

def delete_source_file(parent_ref, path, target_name, xcproj)
  LogTools.p "Delete source file '#{File::basename(path)}' to project."
  ref = parent_ref.new_reference(path)
  do_with_target(target_name, xcproj) { |target|
    target.build_phases.each do |phase|
      if "#{phase}".include? "SourcesBuild"
        LogTools.p "Delete '#{File::basename(path)}' to 'Compile Sources' build phase of target '#{target}'."
        phase.remove_file_reference(ref)
        break
      end
    end
  }
  return ref
end

#do_with_target(name, xcproj) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 23

def do_with_target(name, xcproj)
  xcproj.targets.each do |target|
    if target.name == name
      yield(target)
      break
    end
  end
end

#execute_mainusecrashreporting_action(action, resources_path, working_path, ref, target, xcproj) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/cocoapods-mPaaS/module_config.rb', line 216

def execute_mainusecrashreporting_action(action, resources_path, working_path, ref, target, xcproj)
  if is_target_executable(target, xcproj)
    # 需要到工程的Target对应的目录里找使用的main.m文件
    target_path = File::dirname(working_path)
    targets_path = File::dirname(target_path)
    mpaas_path = File::dirname(targets_path)
    project_path = File::dirname(mpaas_path)

    target_path = "#{project_path}/#{target}"
    LogTools.v_green "execute_mainusecrashreporting_action"
    crash_enable_line = "    [MPAnalysisHelper enableCrashReporterService]; // USE MPAAS CRASH REPORTER"
    if File::exist?(target_path)
      main_path = find_file_recursively("main.m", target_path)
      if main_path != nil
        lines = IO.readlines(main_path)
        override = File.new(main_path, "w")
        in_function = false
        lines.each do |l|
          if l =~ /\s*int\s+main\s*\(\s*int\s+argc\s*,\s*char\s*\*\s*argv\s*\[\s*\]\s*\).*/
            override.puts l
            if l =~ /.*\{\s*/
              override.puts "#{crash_enable_line}"
            else
              in_function = true
            end
          else
            if in_function
              override.puts l
              override.puts "#{crash_enable_line}"
              in_function = false
            else
              #做判断是否是"    enableCrashReporterService // USE MPAAS CRASH REPORTER"
              if !(l =~ /.*enableCrashReporterService.*/)
                override.puts l
              end
            end
          end
        end
        override.close
      end
    end
  end
end

#execute_mainuseframework_action(action, resources_path, working_path, ref, target, xcproj) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/cocoapods-mPaaS/module_config.rb', line 173

def execute_mainuseframework_action(action, resources_path, working_path, ref, target, xcproj)
  # LogTools.p "B"
  if is_target_executable(target, xcproj)
    # 需要到工程的Target对应的目录里找使用的main.m文件
    target_path = File::dirname(working_path)
    targets_path = File::dirname(target_path)
    mpaas_path = File::dirname(targets_path)
    project_path = File::dirname(mpaas_path)

    target_path = "#{project_path}/#{target}"
    # LogTools.p "B: #{target_path}"
    if File::exist?(target_path)
      main_path = find_file_recursively("main.m", target_path)
      if main_path != nil
        lines = IO.readlines(main_path)

        # 先判断下是否已经改过,避免重复,todo 效率
        hasAdd = false
        lines.each do |l|
          if l.include?("DFApplication") || l.include?("DFClientDelegate")
            hasAdd = true
          end
        end

        unless hasAdd
          override = File.new(main_path, "w")

          lines.each do |l|
            if l =~ /\s*return\s+UIApplicationMain\s*\(.+/
              override.puts "//#{l}"	# 把原来的注释掉并写入文件
              override.puts "        return UIApplicationMain(argc, argv, @\"DFApplication\", @\"DFClientDelegate\"); // NOW USE MPAAS FRAMEWORK"
            else
              override.puts l
            end
          end

          override.close
        end
      end
    end
  end
end

#execute_microapplication_action(action, resources_path, working_path, ref, target, xcproj) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/cocoapods-mPaaS/module_config.rb', line 147

def execute_microapplication_action(action, resources_path, working_path, ref, target, xcproj)
  # 找该target对应的MobileRuntime.plist,只有编译为可执行文件时才做这个action
  if is_target_executable(target, xcproj)
    parent_path = File::dirname(working_path)
    plist_path = "#{parent_path}/MPMobileFramework/MobileRuntime.plist"
    # LogTools.p "A: #{plist_path}"
    if File::exist?(plist_path)
      params = action["params"]
      name = params["name"]
      delegate = params["delegate"]
      description = params["description"]

      # 在MobileRuntime.plist里添加应用
      LogTools.p "Write micro-application '#{name}' into 'MobileRuntime.plist'."
      system "/usr/libexec/PlistBuddy -c \"Add :Applications:0:name string \\\"#{name}\\\"\" \"#{plist_path}\""
      system "/usr/libexec/PlistBuddy -c \"Add :Applications:0:delegate string \\\"#{delegate}\\\"\" \"#{plist_path}\""
      system "/usr/libexec/PlistBuddy -c \"Add :Applications:0:description string \\\"#{description}\\\"\" \"#{plist_path}\""

      if params["set_launcher"]
        LogTools.p "Set micro-application '#{name}' as Launcher."
        system "/usr/libexec/PlistBuddy -c \"Set :Launcher \\\"#{name}\\\"\" \"#{plist_path}\""
      end
    end
  end
end

#execute_module_action(action, resources_path, working_path, ref, target, xcproj) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/cocoapods-mPaaS/module_config.rb', line 260

def execute_module_action(action, resources_path, working_path, ref, target, xcproj)
  if action["type"] == nil
    LogTools.p_red "Invalid action with content '#{action}'."
  end

  if action["type"] == "source"
    execute_source_action(action, resources_path, working_path, ref, target, xcproj)
  elsif action["type"] == "resource"
    execute_resource_action(action, resources_path, working_path, ref, target, xcproj)
  elsif action["type"] == "micro_application"
    execute_microapplication_action(action, resources_path, working_path, ref, target, xcproj)
  elsif action["type"] == "main_use_framework"
    execute_mainuseframework_action(action, resources_path, working_path, ref, target, xcproj)
    # elsif action["type"] == "main_use_crashreporting"
    # execute_mainusecrashreporting_action(action, resources_path, working_path, ref, target, xcproj)
  end
end

#execute_resource_action(action, resources_path, working_path, ref, target, xcproj) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/cocoapods-mPaaS/module_config.rb', line 128

def execute_resource_action(action, resources_path, working_path, ref, target, xcproj)
  if action["files"]
    action["files"].each do |f|
      original_path = "#{resources_path}/#{f}"
      working_file_path = "#{working_path}/#{f}"
      # LogTools.p "#{working_path}"
      if File::exist?(original_path)
        if !(File::exist?(working_file_path))
          FileUtils.cp_r original_path, working_path
          res_ref = add_resource_ref(ref, f, xcproj)
          add_resource_to_build_phase(res_ref, target, xcproj)
        end
      else
        LogTools.p_red "Required file '#{original_path}' missing."
      end
    end
  end
end

#execute_source_action(action, resources_path, working_path, ref, target, xcproj) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cocoapods-mPaaS/module_config.rb', line 106

def execute_source_action(action, resources_path, working_path, ref, target, xcproj)
  if action["files"]
    action["files"].each do |f|
      original_path = "#{resources_path}/#{f}"
      working_file_path = "#{working_path}/#{f}"
      # LogTools.p "#{working_path}"
      if (File::exist?(original_path))
        if !(File::exist?(working_file_path))
          FileUtils.cp_r original_path, working_path
          if is_source_file(f)
            add_source_file(ref, f, target, xcproj)
          else
            add_non_source_file(ref, f, xcproj)
          end
        end
      else
        LogTools.p_red "Required file '#{original_path}' missing."
      end
    end
  end
end

#extract_unique_module_names(file_path) ⇒ Object

读取文件中的模块名,并返回一个集合



279
280
281
282
283
284
285
286
287
288
289
# File 'lib/cocoapods-mPaaS/module_config.rb', line 279

def extract_unique_module_names(file_path)
  module_names = Set.new
  File.foreach(file_path) do |line|
    # 去除注释和行首尾空白
    module_name = line.gsub(/#.*$/, '').strip
    # 如果模块名非空,则添加到集合中
    module_names << module_name unless module_name.empty?
  end

  return module_names
end

#find_config_file(project_dir) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cocoapods-mPaaS/installNew.rb', line 60

def find_config_file(project_dir)
  meta_file_path = ""
  Dir::foreach(project_dir) do |file_name|
    # 693B055141932-default-iOS.config
    # tempArray = file_name.split(".")
    # 改为字符串正则匹配
    # if tempArray.size > 0 && tempArray[1] == "config"
    if (file_name.include?(".config") && file_name.downcase.include?("-ios")) || file_name == "meta.config" # 兼容下多target的情况
      meta_file_name = file_name
      meta_file_path = File.join(project_dir, file_name)
      break
    end
  end
  return meta_file_path
end

#find_file_recursively(file, path) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cocoapods-mPaaS/module_config.rb', line 88

def find_file_recursively(file, path)
  entries = Dir::entries(path)
  entries.each do |entry|
    if entry[0] != "."
      filePath = path + "/" + entry
      if File::directory?(filePath)
        result = find_file_recursively file, filePath
        if result != nil
          return result
        end
      elsif entry == file
        return filePath
      end
    end
  end
  return nil
end

#find_pch_file(target_name, xcproj) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 261

def find_pch_file(target_name, xcproj)
  result = Array[]
  do_with_target(target_name, xcproj) { |target|
    target.build_configuration_list.build_configurations.each do |config|
      pch = config.build_settings["GCC_PREFIX_HEADER"]
      if pch != nil and pch != ""
        if !result.include?(pch)
          result << pch
        end
      end
    end
  }
  return result
end

#find_target(name, xcproj) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 14

def find_target(name, xcproj)
  xcproj.targets.each do |target|
    if target.name == name
      return target
    end
  end
  return nil
end

#generate_module_config_source(config, target) ⇒ Object

从原始配置中生成为模块配置的.m和.h



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cocoapods-mPaaS/module_config.rb', line 15

def generate_module_config_source(config, target)
  result = Hash[]

  class_name = config["class"]
  header = config["header"]
  author = get_current_user
  time_str = Time.new.strftime("%Y/%m/%d")

  result["source_file"] = "#{class_name}+#{target}.m"
  result["header_file"] = "#{class_name}+#{target}.h"

  # .m 文件
  m_source = ""
  puts_line_to_string(m_source, "//")
  puts_line_to_string(m_source, "//  #{result["source_file"]}")
  puts_line_to_string(m_source, "//  #{target}")
  puts_line_to_string(m_source, "//")
  puts_line_to_string(m_source, "//  Created by #{author} on #{time_str}. All rights reserved.")
  puts_line_to_string(m_source, "//")
  puts_line_to_string(m_source, "")
  puts_line_to_string(m_source, "#import \"#{result["header_file"]}\"")
  puts_line_to_string(m_source, "")
  puts_line_to_string(m_source, "#pragma clang diagnostic push")
  puts_line_to_string(m_source, "#pragma clang diagnostic ignored \"-Wobjc-protocol-method-implementation\"")
  puts_line_to_string(m_source, "")
  puts_line_to_string(m_source, "@implementation #{class_name} (#{target})")
  puts_line_to_string(m_source, "")

  # 添加方法实现
  if config["methods"] != nil
    config["methods"].each do |m|
      puts_line_to_string(m_source, m)
    end
  end

  puts_line_to_string(m_source, "@end")
  puts_line_to_string(m_source, "")
  puts_line_to_string(m_source, "#pragma clang diagnostic pop")
  puts_line_to_string(m_source, "")

  result["source"] = m_source

  # .h 文件
  h_source = ""
  puts_line_to_string(h_source, "//")
  puts_line_to_string(h_source, "//  #{result["header_file"]}")
  puts_line_to_string(h_source, "//  #{target}")
  puts_line_to_string(h_source, "//")
  puts_line_to_string(h_source, "//  Created by #{author} on #{time_str}. All rights reserved.")
  puts_line_to_string(h_source, "//")
  puts_line_to_string(h_source, "")
  puts_line_to_string(h_source, "#import #{header}")
  puts_line_to_string(h_source, "")
  puts_line_to_string(h_source, "@interface #{class_name} (#{target})")
  puts_line_to_string(h_source, "")
  puts_line_to_string(h_source, "@end")
  puts_line_to_string(h_source, "")

  result["header"] = h_source

  return result
end

#get_current_userObject



6
7
8
9
10
11
12
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 6

def get_current_user()
  author = `whoami`
  if author[author.length - 1] == "\n"
    author.chop!
  end
  return author
end

#get_module_versions_from_colon_array(modules) ⇒ Object

从‘Module:1.0.0’这种数组,解析出需要的模块的版本,放在字典中



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cocoapods-mPaaS/installNew.rb', line 77

def get_module_versions_from_colon_array(modules)
  pretty = Hash[]
  modules.each do |m|
    if m =~ /\w+:.+/
      name = m.sub(/:.+/, "")
      version = m.sub(/\w+:/, "")
      pretty[name] = version
    end
  end
  return pretty
end

#get_mPaaS_lib_namesObject

todo 改读取基线文件判断



29
30
31
32
# File 'lib/cocoapods-mPaaS/installNew.rb', line 29

def get_mPaaS_lib_names
  names = ["APLog", "APRemoteLogging", "MPAnalysis", "MPDataCenter", "mPaas", "MPPushSDK", "APMobileNetwork", "APProtocolBuffers", "APOpenSSL", "SecurityGuardSDK", "APSecurityUtility", "AutoTracker", "MPPerformance", "TianYan", "APCrashReporter"]
  return names
end

#is_source_file(path) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/cocoapods-mPaaS/module_config.rb', line 78

def is_source_file(path)
  path = File::basename(path)
  parts = path.split(".")
  ext = parts.last
  if ext != nil
    return (ext == "m") || (ext == "mm") || (ext == "c") || (ext == "cpp") || (ext == "swift")
  end
  return false
end

#is_target_executable(name, xcproj) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 32

def is_target_executable(name, xcproj)
  target = find_target(name, xcproj)
  if target != nil
    target.build_configuration_list.build_configurations.each do |config|
      mach_o = config.build_settings["MACH_O_TYPE"]
      if mach_o == nil || mach_o == "mh_execute"
        return true
      end
      break
    end
  end
  return false
end

#mPaaS_lib_has_adapter?(pods_path, libName) ⇒ Boolean

Returns:

  • (Boolean)


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/cocoapods-mPaaS/installNew.rb', line 223

def mPaaS_lib_has_adapter?(pods_path, libName)
  # 这里的几个判断直接返回 true 了,不兼容32以下老基线了
  if libName == "APRemoteLogging"
    return true
    # return Dir.entries(pods_path).include?("MPMasAdapter")
  elsif libName == "MPAnalysis"
    return true
    # return Dir.entries(pods_path).include?("MPMasAdapter")
  elsif libName == "APMobileNetwork"
    return true
    # return Dir.entries(pods_path).include?("MPMgsAdapter")
  elsif libName == "APLongLinkService"
    return true
    # return Dir.entries(pods_path).include?("MPMssAdapter")
  elsif libName == "MPDiagnosis"
    return true
    # 因为诊断是强依赖 sync 的,所以这里偷懒用 MPMssAdapter 来判断,todo 判断版本号
    # return Dir.entries(pods_path).include?("MPMssAdapter")
  elsif libName == "MPHotpatchSDK"
    return true
    # return Dir.entries(pods_path).include?("MPDynamicAdapter")
  elsif libName == "NebulaHeader"
    return Dir.entries(pods_path).include?("Nebula") # Nebula NBInsideAccountAdaptor
  else
    return false
  end
end

#mPaaS_pod_deprecated(name, *version) ⇒ Object

todo 配置化



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/cocoapods-mPaaS/installNew.rb', line 252

def mPaaS_pod_deprecated(name, *version)
  LogTools.v "mPaaS_pod : #{name} / #{version}"

  if name.casecmp("mPaaS_Log") == 0
    if version && !version.empty?
      if version[0] == "1.0.0"
        pod "APLog", "3.0.2.181018154912"
        pod "APRemoteLogging", "1.0.0.181024160529"
        pod "MPAnalysis", "1.1.0.20170806"
        pod "MPDataCenter", "10.1.12.1.20181226"
        pod "mPaas", "10.1.25.20180822"
      end
    end
  elsif name.casecmp("mPaaS_Push") == 0
    if version && !version.empty?
      if version[0] == "1.0.0"
        pod "MPPushSDK", "1.0.0.20180304"
        pod "APMobileNetwork", "10.1.18.20180302"
        pod "APProtocolBuffers", "3.0.0.20170628"
        pod "APOpenSSL", "10.1.18.20180227"
        pod "SecurityGuardSDK", "6.3.85.20170814"
        pod "APSecurityUtility", "1.2.0.20170320"
        pod "APRemoteLogging", "1.0.0.181024160529"
        pod "APLog", "3.0.2.181018154912"
        pod "MPAnalysis", "1.1.0.20170806"
        pod "MPDataCenter", "10.1.12.1.20181226"
        pod "mPaas", "10.1.25.20180822"
      end
    end
  elsif name.casecmp("mPaaS_AutoTracker") == 0
    if version && !version.empty?
      if version[0] == "1.0.0"
        pod "AutoTracker", "3.0.0.20170628"
      end
    end
  elsif name.casecmp("mPaaS_Performance") == 0
    if version && !version.empty?
      if version[0] == "1.0.0"
        pod "MPPerformance", "3.0.4.20171205"
        pod "TianYan", "3.0.2.20171113"
      end
    end
  elsif name.casecmp("mPaaS_Crash") == 0
    if version && !version.empty?
      if version[0] == "1.0.0"
        pod "APCrashReporter", "10.1.18.20180228"
      end
    end
  else
    LogTools.p_red "No mPaaS_pod found !!! Check name in Podfile"
  end
end

#mPaaS_repo_exist?Boolean

判断 mPaaS repo 是否已经存在

Returns:

  • (Boolean)


4
5
6
7
# File 'lib/cocoapods-mPaaS/installNew.rb', line 4

def mPaaS_repo_exist?
  repo_name = `pod repo list | awk '{print $1}' | grep -w #{CocoapodsmPaaS::MPAAS_REPO_NAME}`
  repo_name.include?(CocoapodsmPaaS::MPAAS_REPO_NAME)
end

#mPaaS_repo_exist_by_name?(repo_name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/cocoapods-mPaaS/installNew.rb', line 17

def mPaaS_repo_exist_by_name?(repo_name)
  result = `pod repo list | awk '{print $1}' | grep -w #{repo_name}`
  result.include?(repo_name)
end

#puts_line_to_string(s, line) ⇒ Object



9
10
11
12
# File 'lib/cocoapods-mPaaS/module_config.rb', line 9

def puts_line_to_string(s, line)
  s.concat(line)
  s.concat("\n")
end

#remove_framework(name, target_name, xcproj) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 154

def remove_framework(name, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    target.build_phases.each do |phase|
      if "#{phase}".include? "FrameworksBuild"
        refs = phase.files_references
        refs.each do |r|
          if r.name == name || (File::basename(r.path) == name)
            LogTools.p "Remove '#{name}' from 'Link Binary With Libraries' build phase of target '#{target}'."
            phase.remove_file_reference(r)
          end
        end
        break
      end
    end
  }
end

#remove_framework_search_path(path, target_name, xcproj) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 113

def remove_framework_search_path(path, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    target.build_configuration_list.build_configurations.each do |config|
      search_paths = config.build_settings["FRAMEWORK_SEARCH_PATHS"]
      if search_paths != nil
        LogTools.p "Remove '#{path}' from 'Framework Search Paths' build settings of target '#{target}'."
        if search_paths.is_a?(String)
          if search_paths.include?(path)
            config.build_settings["FRAMEWORK_SEARCH_PATHS"] = Array[]
          end
        else
          config.build_settings["FRAMEWORK_SEARCH_PATHS"].delete(path)
          config.build_settings["FRAMEWORK_SEARCH_PATHS"].delete("#{path}/**")
        end
      end
    end
  }
end

#remove_framework_search_path_general(path, target_name, xcproj) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 91

def remove_framework_search_path_general(path, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    target.build_configuration_list.build_configurations.each do |config|
      search_paths = config.build_settings["FRAMEWORK_SEARCH_PATHS"]
      if search_paths != nil
        LogTools.p "Remove '#{path}' from 'Framework Search Paths' build settings of target '#{target}'."
        if search_paths.is_a?(String)
          if search_paths.include?(path)
            config.build_settings["FRAMEWORK_SEARCH_PATHS"] = Array[]
          end
        else
          config.build_settings["FRAMEWORK_SEARCH_PATHS"].delete_if { |item|
            item.include? path
          }
          # config.build_settings['FRAMEWORK_SEARCH_PATHS'].delete(path)
          # config.build_settings['FRAMEWORK_SEARCH_PATHS'].delete("#{path}/**")
        end
      end
    end
  }
end

#remove_from_project(ref) ⇒ Object



193
194
195
196
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 193

def remove_from_project(ref)
  LogTools.p "remove_from_project #{ref}"
  return ref.remove_from_project
end

#remove_resource(name, target_name, xcproj) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 240

def remove_resource(name, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    target.build_phases.each do |phase|
      if "#{phase}".include? "ResourcesBuild"
        refs = phase.files_references
        refs.each do |r|
          if r && r.path != nil
            # LogTools.p_red r.path
            basename = File::basename(r.path)
            if basename == name
              LogTools.p "Remove '#{name}' from 'Copy Bundle Resources' build phase of target '#{target}'."
              phase.remove_file_reference(r)
            end
          end
        end
        break
      end
    end
  }
end

#remove_script_build_phase(name, target_name, xcproj) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cocoapods-mPaaS/xcode_helper.rb', line 57

def remove_script_build_phase(name, target_name, xcproj)
  do_with_target(target_name, xcproj) { |target|
    deleted = Array[]
    target.build_phases.each do |phase|
      if "#{phase}".downcase == name.downcase
        deleted << phase
      end
    end

    deleted.each do |phase|
      LogTools.p "Remove '#{phase}' from build phase of target '#{target}'."
      target.build_phases.delete(phase)
    end
  }
end

#repo_name_from_url(url) ⇒ Object



22
23
24
25
26
# File 'lib/cocoapods-mPaaS/installNew.rb', line 22

def repo_name_from_url(url)
  uri = url.gsub(/\.git$/, '')
  parts = uri.split(/[\/:]/).last(2)
  parts.join("-").downcase
end

#runWriteInfoList(arr, pods_path) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cocoapods-mPaaS/write_info_list_mPaaSApp.rb', line 1

def runWriteInfoList(arr, pods_path)
  if arr.length > 18
    project_path = arr[0]
    target_name = arr[1]
    productIdKey = arr[2]
    productIdValue = arr[3]
    productVersionKey = arr[4]
    productVersionValue = arr[5]
    mpaasProperties = arr[6]
    workspaceIdKey = arr[7]
    workspaceIdValue = arr[8]
    appIdKey = arr[9]
    appIdValue = arr[10]
    mpaasGatewayKey = arr[11]
    mpaasGatewayValue = arr[12]
    platformKey = "Platform"
    platformValue = "IOS"
    bundleIdValue = arr[13]
    mPaaSInternal = arr[14]
    syncPortKey = arr[15]
    syncPortValue = arr[16]
    syncServerKey = arr[17]
    syncServerValue = arr[18]
    # workspaceIdKey = arr[6]
    # workspaceIdValue = arr[7]
    # appIdKey = arr[8]
    # appIdValue = arr[9]

    appTransportSecurityKey = "NSAppTransportSecurity"
    appTransportSecurityValue = "NSAllowsArbitraryLoads"

    xcproj = Xcodeproj::Project.open(project_path)
    if xcproj == nil
      LogTools.p_red "Cannot find open project '#{project_path}'."
      exit 1
    end

    target = find_target(target_name, xcproj)
    if target == nil
      LogTools.p_red "Cannot find target '#{target_name}'."
      exit 1
    end

    plist_files = Array[]
    target.build_configuration_list.build_configurations.each do |config|
      if !plist_files.include?(config.build_settings["INFOPLIST_FILE"])
        plist_files << config.build_settings["INFOPLIST_FILE"]
      end
    end

    plist_files.each do |f|
      path = File::dirname(project_path) + "/#{f}"

      # 默认不输出原始产生的日志
      nolog = " 2> /dev/null"
      if LogTools.verbose?
        # 不屏蔽原始日志
        nolog = ""
      end

      # 10.1.32适配 如果有埋点或者rpc不添加且删除
      if mPaaS_lib_has_adapter?(pods_path, "APRemoteLogging") || mPaaS_lib_has_adapter?(pods_path, "APMobileNetwork")
        system "/usr/libexec/PlistBuddy -c \"Delete :\'#{productIdKey}\'\" \"#{path}\"" + nolog
        LogTools.v "Delete '#{productIdKey}' of value '#{productIdValue}' into '#{path}'."
      else
        # 注释历史逻辑,不兼容了
        # system "/usr/libexec/PlistBuddy -c \"Add :\'#{productIdKey}\' string #{productIdValue}\" \"#{path}\"" + nolog
        # LogTools.v "Write '#{productIdKey}' of value '#{productIdValue}' into '#{path}'."
      end

      system "/usr/libexec/PlistBuddy -c \"Add :\'#{productVersionKey}\' string #{productVersionValue}\" \"#{path}\"" + nolog
      LogTools.v "Write '#{productVersionKey}' of value '#{productVersionValue}' into '#{path}'."
      # system "/usr/libexec/PlistBuddy -c \"Add :\'#{workspaceIdKey}\' string #{workspaceIdValue}\" \"#{path}\""
      #  LogTools.v "Write '#{workspaceIdKey}' of value '#{workspaceIdValue}' into '#{path}'."
      # system "/usr/libexec/PlistBuddy -c \"Add :\'#{appIdKey}\' string #{appIdValue}\" \"#{path}\""
      #  LogTools.v "Write '#{appIdKey}' of value '#{appIdValue}' into '#{path}'."

      # 先添加key值
      system "/usr/libexec/PlistBuddy -c 'Add :\'#{appTransportSecurityKey}\' dict' \"#{path}\"" + nolog
      # 添加value值,
      system "/usr/libexec/PlistBuddy -c 'Add :\'#{appTransportSecurityKey}\':\'#{appTransportSecurityValue}\' bool true' \"#{path}\"" + nolog

      # 10.1.32适配 如果有rpc不添加且删除
      if mPaaS_lib_has_adapter?(pods_path, "APMobileNetwork")
        system "/usr/libexec/PlistBuddy -c \"Delete :\'#{mpaasProperties}\'\" \"#{path}\"" + nolog
        LogTools.v "Delete '#{mpaasProperties}' into '#{path}'."
      else
        # 注释历史逻辑,不兼容了
        # # 先添加key值:mpaas
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mpaasProperties}\' dict' \"#{path}\"" + nolog
        # # 添加字典value:WorkspaceId和UniformGateway
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mpaasProperties}\':\'#{workspaceIdKey}\' string #{workspaceIdValue}' \"#{path}\"" + nolog
        # LogTools.v "Write '#{workspaceIdKey}' of value '#{workspaceIdValue}' into '#{path}'."
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mpaasProperties}\':\'#{mpaasGatewayKey}\' string #{mpaasGatewayValue}' \"#{path}\"" + nolog
        # LogTools.v "Write '#{mpaasGatewayKey}' of value '#{mpaasGatewayValue}' into '#{path}'."
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mpaasProperties}\':\'#{appIdKey}\' string #{appIdValue}' \"#{path}\"" + nolog
        # LogTools.v "Write '#{appIdKey}' of value '#{appIdValue}' into '#{path}'."
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mpaasProperties}\':\'#{platformKey}\' string #{platformValue}' \"#{path}\"" + nolog
        # LogTools.v "Write '#{platformKey}' of value '#{platformValue}' into '#{path}'."
      end

      # 10.1.32适配 如果有sync不添加且删除
      if mPaaS_lib_has_adapter?(pods_path, "APLongLinkService")
        system "/usr/libexec/PlistBuddy -c \"Delete :\'#{mPaaSInternal}\'\" \"#{path}\"" + nolog
        LogTools.v "Delete '#{mPaaSInternal}' into '#{path}'."
      else
        # 注释历史逻辑,不兼容了
        # # 先添加key值:mPaaSInternal
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mPaaSInternal}\' dict' \"#{path}\"" + nolog
        # # 添加字典value:WorkspaceId和UniformGateway
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mPaaSInternal}\':\'#{syncPortKey}\' string #{syncPortValue}' \"#{path}\"" + nolog
        # LogTools.v "Write '#{syncPortKey}' of value '#{syncPortValue}' into '#{path}'."
        # system "/usr/libexec/PlistBuddy -c 'Add :\'#{mPaaSInternal}\':\'#{syncServerKey}\' string #{syncServerValue}' \"#{path}\"" + nolog
        # LogTools.v "Write '#{syncServerKey}' of value '#{syncServerValue}' into '#{path}'."
      end

      #修改Bundle Id
      system "/usr/libexec/PlistBuddy -c 'Set :CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER)' \"#{path}\"" + nolog
      LogTools.v "Write Bundle Identifier of value $(PRODUCT_BUNDLE_IDENTIFIER) into '#{path}'."
    end
  end
end

#safe_create_directory_tt(path) ⇒ Object

判断是否存在,并返回path



35
36
37
38
39
40
41
# File 'lib/cocoapods-mPaaS/installNew.rb', line 35

def safe_create_directory_tt(path)
  if !File::exist?(path)
    LogTools.p "Create directory '#{path}'."
    FileUtils::mkdir_p(path)
  end
  return path
end

#safe_create_file(path) ⇒ Object

判断是否存在,并返回path



52
53
54
55
56
57
58
# File 'lib/cocoapods-mPaaS/installNew.rb', line 52

def safe_create_file(path)
  if !File::exist?(path)
    LogTools.p "Create file '#{path}'."
    File.new(path, "w")
  end
  return path
end

#safe_delete_directory_tt(path) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/cocoapods-mPaaS/installNew.rb', line 43

def safe_delete_directory_tt(path)
  if File::exist?(path)
    LogTools.p "Delete directory '#{path}'."
    FileUtils::rm_r(path)
  end
  return path
end

#trim_end_multiple_nextline(path) ⇒ Object



188
189
190
191
192
193
194
195
196
# File 'lib/cocoapods-mPaaS/installNew.rb', line 188

def trim_end_multiple_nextline(path)
  s = File::open(path).read
  while s[s.length - 1] == "\n"
    s.chop!
  end
  override = File.new(path, "w")
  override.puts s
  override.close
end

#write_file_to_path(path, content) ⇒ Object

并返回path



2
3
4
5
6
7
# File 'lib/cocoapods-mPaaS/module_config.rb', line 2

def write_file_to_path(path, content)
  file = File.new(path, "w")
  file.puts content
  file.close
  return path
end