cocoapods-mPaaS 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cocoapods-mPaaS/baselineTools.rb +493 -0
  3. data/lib/cocoapods-mPaaS/checkUpdateTools.rb +42 -0
  4. data/lib/cocoapods-mPaaS/cocoapods_hook.rb +929 -0
  5. data/lib/cocoapods-mPaaS/command/mPaaS.rb +44 -0
  6. data/lib/cocoapods-mPaaS/command/mpaas/dev.rb +17 -0
  7. data/lib/cocoapods-mPaaS/command/mpaas/info.rb +170 -0
  8. data/lib/cocoapods-mPaaS/command/mpaas/init.rb +112 -0
  9. data/lib/cocoapods-mPaaS/command/mpaas/local_command.rb +49 -0
  10. data/lib/cocoapods-mPaaS/command/mpaas/open.rb +17 -0
  11. data/lib/cocoapods-mPaaS/command/mpaas/update.rb +223 -0
  12. data/lib/cocoapods-mPaaS/command/mpaas/version.rb +32 -0
  13. data/lib/cocoapods-mPaaS/command.rb +1 -0
  14. data/lib/cocoapods-mPaaS/dsl.rb +498 -0
  15. data/lib/cocoapods-mPaaS/gem_version.rb +5 -0
  16. data/lib/cocoapods-mPaaS/installNew.rb +303 -0
  17. data/lib/cocoapods-mPaaS/locales/en.yml +140 -0
  18. data/lib/cocoapods-mPaaS/locales/zh-Hans.yml +144 -0
  19. data/lib/cocoapods-mPaaS/localization.rb +238 -0
  20. data/lib/cocoapods-mPaaS/logTools.rb +67 -0
  21. data/lib/cocoapods-mPaaS/mPaaSPodfile.rb +117 -0
  22. data/lib/cocoapods-mPaaS/module_config.rb +298 -0
  23. data/lib/cocoapods-mPaaS/podfileTools.rb +48 -0
  24. data/lib/cocoapods-mPaaS/post_install_hook_processor.rb +61 -0
  25. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/DemoViewController.h +13 -0
  26. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/DemoViewController.m +43 -0
  27. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/Contents.json +6 -0
  28. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery.imageset/Contents.json +22 -0
  29. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery.imageset/TabBar_Discovery@2x.png +0 -0
  30. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery.imageset/TabBar_Discovery@3x.png +0 -0
  31. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery_Sel.imageset/Contents.json +22 -0
  32. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery_Sel.imageset/TabBar_Discovery_Sel@2x.png +0 -0
  33. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Discovery_Sel.imageset/TabBar_Discovery_Sel@3x.png +0 -0
  34. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends.imageset/Contents.json +22 -0
  35. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends.imageset/TabBar_Friends@2x.png +0 -0
  36. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends.imageset/TabBar_Friends@3x.png +0 -0
  37. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends_Sel.imageset/Contents.json +22 -0
  38. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends_Sel.imageset/TabBar_Friends_Sel@2x.png +0 -0
  39. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_Friends_Sel.imageset/TabBar_Friends_Sel@3x.png +0 -0
  40. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar.imageset/Contents.json +22 -0
  41. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar.imageset/icon30-line@2x.png +0 -0
  42. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar.imageset/icon30-line@3x.png +0 -0
  43. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar_Sel.imageset/Contents.json +22 -0
  44. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar_Sel.imageset/icon30@2x.png +0 -0
  45. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_HomeBar_Sel.imageset/icon30@3x.png +0 -0
  46. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService.imageset/Contents.json +22 -0
  47. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService.imageset/TabBar_PublicService@2x.png +0 -0
  48. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService.imageset/TabBar_PublicService@3x.png +0 -0
  49. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService_Sel.imageset/Contents.json +22 -0
  50. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService_Sel.imageset/TabBar_PublicService_Sel@2x.png +0 -0
  51. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/Images_mPaaS.xcassets/TabBar_PublicService_Sel.imageset/TabBar_PublicService_Sel@3x.png +0 -0
  52. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPAppDelegate.h +10 -0
  53. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPAppDelegate.m +43 -0
  54. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerController.h +8 -0
  55. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerController.m +135 -0
  56. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLauncherAppDelegate.h +10 -0
  57. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLauncherAppDelegate.m +43 -0
  58. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLeftView.h +16 -0
  59. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerLeftView.m +86 -0
  60. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerMainViewController.h +21 -0
  61. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPDrawerMainViewController.m +104 -0
  62. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPLauncherAppDelegate.h +10 -0
  63. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPLauncherAppDelegate.m +91 -0
  64. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationController.h +8 -0
  65. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationController.m +25 -0
  66. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationLauncherAppDelegate.h +10 -0
  67. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPNavigationLauncherAppDelegate.m +43 -0
  68. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPTabBarController.h +8 -0
  69. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPTabBarController.m +27 -0
  70. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPViewController.h +8 -0
  71. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MPViewController.m +19 -0
  72. data/lib/cocoapods-mPaaS/templates/APMobileFramework/AutoConfig/MobileRuntime.plist +26 -0
  73. data/lib/cocoapods-mPaaS/write_info_list_mPaaSApp.rb +125 -0
  74. data/lib/cocoapods-mPaaS/xcode_helper.rb +334 -0
  75. data/lib/cocoapods-mPaaS.rb +41 -0
  76. data/lib/cocoapods_plugin.rb +15 -0
  77. metadata +160 -0
@@ -0,0 +1,929 @@
1
+ require "cocoapods-mPaaS/module_config"
2
+ require "cocoapods-mPaaS/write_info_list_mPaaSApp"
3
+ require "cocoapods-mPaaS/baselineTools"
4
+ require "cocoapods-mPaaS/checkUpdateTools"
5
+ require "cocoapods-mPaaS/podfileTools"
6
+ require 'cocoapods-mPaaS/localization'
7
+ require 'cocoapods-mPaaS/post_install_hook_processor'
8
+ require "shellwords"
9
+ require "uri"
10
+ module CocoapodsmPaaSHooks
11
+
12
+ Pod::HooksManager.register("cocoapods-mPaaS", :pre_install) do |context, options|
13
+ @currentset_default_baseline = context.podfile.default_baseline
14
+ @is_local_mode = context.podfile.local_component_json_path || context.podfile.local_content_json_path
15
+ custom_repo_url = context.podfile.mpaas_repo_url
16
+
17
+ # 默认打开
18
+ check_repo = true
19
+ if options["check_repo"] != nil
20
+ check_repo = options["check_repo"]
21
+ end
22
+ if check_repo && !@is_local_mode
23
+ LogTools.p "--------------------------------mPaaS start--------------------------------------------"
24
+ LogTools.p_green Pod::MPAAS::Localization.t('mpaas.hooks.check_repo_exists')
25
+
26
+ repo_name = custom_repo_url ? repo_name_from_url(custom_repo_url) : CocoapodsmPaaS::MPAAS_REPO_NAME
27
+ repo_url = custom_repo_url || CocoapodsmPaaS::MPAAS_REPO_URL
28
+
29
+ unless mPaaS_repo_exist_by_name?(repo_name)
30
+ LogTools.p Pod::MPAAS::Localization.t('mpaas.hooks.add_repo')
31
+ add_mPaaS_repo_with(repo_name, repo_url)
32
+ else
33
+ LogTools.p "repo name : #{repo_name}"
34
+ end
35
+ LogTools.p "--------------------------------mPaaS end----------------------------------------------"
36
+ elsif @is_local_mode
37
+ LogTools.p "--------------------------------mPaaS start--------------------------------------------"
38
+ LogTools.p_green "Local mode: skip repo check"
39
+ LogTools.p "--------------------------------mPaaS end----------------------------------------------"
40
+ end
41
+ end
42
+
43
+ Pod::HooksManager.register("cocoapods-mPaaS", :post_install) do |context, options|
44
+ LogTools.p "--------------------------------mPaaS start--------------------------------------------"
45
+ # LogTools.p_red "post_install_context : #{context}"
46
+ if options["exclude_simulator_arm64"]
47
+ hook_processor = CocoaPodsMPaaS::PostInstallHookProcessor.new(context)
48
+ hook_processor.apply_excluded_archs_to_pods_project
49
+ hook_processor.apply_excluded_archs_to_user_project_targets
50
+ end
51
+
52
+ startTime_post_install = Time.new
53
+ LogTools.p "plugin options : #{options}"
54
+ # 这里认为所有 UmbrellaTargetDescription 的 user_project 都一样 ?
55
+ project = context.umbrella_targets[0].user_project
56
+ project_path = context.umbrella_targets[0].user_project_path
57
+ project_dir = File::dirname(project_path)
58
+ LogTools.v "tt project.path : #{project.path}"
59
+
60
+ pod_project = context.pods_project
61
+ pods_path = context.sandbox_root
62
+ LogTools.v "tt pods_path : #{pods_path}"
63
+
64
+ # 存放 Podfile 解析后有依赖过mPaaS库的 target 与依赖的 pod
65
+ targets_mPaaS_hash = {}
66
+
67
+ # 存放 Podfile 解析后的所有 target 与依赖的 pod,上报日志埋点用,暂时未筛选 mPaaS 库, todo
68
+ targets_libs_for_log_hash = {}
69
+
70
+ mPaaS_lib_names = BaselineTools.getmPaaSlibs
71
+ sourceUrl = URI.parse(CocoapodsmPaaS::MPAAS_REPO_URL)
72
+ sourceUrlPath = sourceUrl.host + sourceUrl.path
73
+ if sourceUrlPath.end_with?(".git")
74
+ sourceUrlPath = sourceUrlPath.chomp(".git")
75
+ end
76
+
77
+ context.instance_variables.each do |var|
78
+ value = context.instance_variable_get(var)
79
+ #puts "-------------context--------#{var}: #{value}"
80
+ end
81
+
82
+ context.umbrella_targets.each do |umbrellaTargetDescription|
83
+ umbrellaTargetDescription.instance_variables.each do |var|
84
+ value = umbrellaTargetDescription.instance_variable_get(var)
85
+ #puts "-------------umbrellaTargetDescription--------#{var}: #{value}"
86
+ end
87
+ specs = umbrellaTargetDescription.specs
88
+
89
+ # 这里认为 user_targets 一定有值,且对应 specs
90
+ target1 = umbrellaTargetDescription.user_targets[0].name
91
+ if specs
92
+ specs_strings = []
93
+ hasmPaaSlib = MPaaSCocoapodShare.instance.usedMpaasTarget.include?(target1)
94
+ unuseMpaaSTarget = MPaaSCocoapodShare.instance.unuseMpaasTarget.include?(target1)
95
+ if unuseMpaaSTarget
96
+ hasmPaaSlib = false
97
+ end
98
+ # 恶心的处理下容器和小程序不能并存的问题
99
+ hasMPNebulaSDKPlugins = false
100
+ hasNebulaSDKPlugins = false
101
+
102
+ specs.each do |specification|
103
+ specs_strings << specification.name
104
+ if hasmPaaSlib == false && unuseMpaaSTarget == false
105
+ begin
106
+ if specification.spec_sourcee.url.include?(sourceUrlPath)
107
+ hasmPaaSlib = true
108
+ end
109
+ rescue => e
110
+ if mPaaS_lib_names.include?(specification.name)
111
+ hasmPaaSlib = true
112
+ end
113
+ end
114
+ end
115
+
116
+ if specification.name == "MPNebulaSDKPlugins"
117
+ hasMPNebulaSDKPlugins = true
118
+ end
119
+
120
+ if specification.name == "NebulaSDKPlugins"
121
+ hasNebulaSDKPlugins = true
122
+ end
123
+ end
124
+
125
+ if hasMPNebulaSDKPlugins && hasNebulaSDKPlugins
126
+ info = Pod::MPAAS::Localization.t('mpaas.hooks.mp_nebula_conflict')
127
+ raise Pod::Informative, info
128
+ end
129
+
130
+ show_all_specs = options["show_all_specs"]
131
+ if show_all_specs
132
+ LogTools.p_green "------------------------copy start-------------------------------"
133
+ reach_index = 0
134
+ specs.each do |specification|
135
+ line = '"' + specification.name.to_s + '": "' + specification.version.to_s + '"'
136
+ unless reach_index == (specs.size - 1)
137
+ line += ','
138
+ end
139
+ reach_index += 1
140
+
141
+ LogTools.p_red line
142
+ end
143
+ LogTools.p_green "------------------------copy end----------------------------------"
144
+ end
145
+
146
+ baseline_to_be_checked = options["check_baseline"]
147
+ if baseline_to_be_checked
148
+ specs.each do |specification|
149
+ unless BaselineTools.checkBaseline?(baseline_to_be_checked, specification.name.to_s, specification.version.to_s)
150
+ info = Pod::MPAAS::Localization.t('mpaas.hooks.not_found_in_baseline', name: specification.name.to_s, version: specification.version.to_s, baseline_to_be_checked: baseline_to_be_checked)
151
+ raise Pod::Informative, info
152
+ end
153
+ end
154
+ end
155
+
156
+ # 埋点统计用
157
+ if CocoapodsmPaaS::REPORT_LOG
158
+ reach_index = 0
159
+ sdks = ""
160
+ specs.each do |specification|
161
+ sdks += (specification.name.to_s + "_" + specification.version.to_s)
162
+ unless reach_index == (specs.size - 1)
163
+ sdks += "|"
164
+ end
165
+ reach_index += 1
166
+ end
167
+
168
+ target_hash = targets_libs_for_log_hash[target1]
169
+ unless target_hash
170
+ target_hash = {}
171
+ end
172
+
173
+ target_hash["sdks"] = sdks
174
+ targets_libs_for_log_hash[target1] = target_hash
175
+ end
176
+
177
+ # 保存每个target的所有依赖关系
178
+ if hasmPaaSlib
179
+ targets_mPaaS_hash[target1] = specs_strings
180
+ else
181
+ LogTools.v_red "#{target1} has no mPaaS libs"
182
+ end
183
+
184
+ else
185
+ LogTools.v_red "specs == nil"
186
+ end
187
+ end
188
+
189
+ # 在这里兼容处理下 plugin 的 options
190
+ plugin_targets = options["targets"]
191
+ if plugin_targets
192
+ plugin_targets.each do |plugin_target|
193
+ # 这里直接设置申明的target依赖mPaaS所有的库
194
+ targets_mPaaS_hash[plugin_target] = mPaaS_lib_names
195
+ end
196
+ end
197
+
198
+ LogTools.v "targets_mPaaS_hash : #{targets_mPaaS_hash}"
199
+ targets_mPaaS_hash_keys = targets_mPaaS_hash.keys
200
+
201
+ # 这里还是拿 project.targets
202
+ project.targets.each do |eachTarget|
203
+
204
+ if options["only_frameworks"]
205
+ LogTools.p_yellow "only add mPaaS frameworks, no need to do more ..."
206
+ break
207
+ end
208
+
209
+ LogTools.p_green Pod::MPAAS::Localization.t('mpaas.hooks.start_processing_target', target_name: eachTarget.name)
210
+
211
+ unless targets_mPaaS_hash_keys.include?(eachTarget.name)
212
+ LogTools.p_red "#{eachTarget.name} has no mPaaS libs, no need to do add Category .."
213
+ next
214
+ end
215
+
216
+ # 当前 target 所依赖的 mPaaS 库
217
+ current_mPaaS_libs = targets_mPaaS_hash[eachTarget.name]
218
+
219
+ mpaas_ref = project["MPaaS"]
220
+ if mpaas_ref == nil
221
+ mpaas_ref = project.new_group("MPaaS", "MPaaS")
222
+ end
223
+ LogTools.v "mpaas_ref : #{mpaas_ref}"
224
+
225
+ targets_directory_ref = mpaas_ref["Targets"]
226
+ if targets_directory_ref == nil
227
+ targets_directory_ref = mpaas_ref.new_group("Targets", "Targets")
228
+ end
229
+ LogTools.v "targets_directory_ref : #{targets_directory_ref}"
230
+
231
+ sub_target_dir = "#{project_dir}/MPaaS/Targets/#{eachTarget.name}"
232
+ LogTools.v "sub_target_dir : #{sub_target_dir}"
233
+ safe_create_directory_tt(sub_target_dir)
234
+
235
+ sub_target_directory_ref = targets_directory_ref[eachTarget.name]
236
+ if sub_target_directory_ref == nil
237
+ sub_target_directory_ref = targets_directory_ref.new_group(eachTarget.name, eachTarget.name)
238
+ end
239
+ LogTools.v "sub_target_directory_ref : #{sub_target_directory_ref}"
240
+
241
+ # 存放需要添加头文件的模块
242
+ modules = []
243
+ # 存放需要添加配置类的模块
244
+ config_hash = {}
245
+
246
+ ## 读取配置文件
247
+ ## 10.1.20 逻辑 meta.config
248
+ # 查找json文件
249
+ config_file_name = "meta.config"
250
+
251
+ # 取每个target目录下
252
+ meta_file_path = File.join(sub_target_dir, config_file_name)
253
+ meta_file_path_old = File.join(project_dir, config_file_name)
254
+ need_add_meta_file_if_needed = false
255
+
256
+ # 如果 meta.config 不存在,就是第一次安装,查找原始config文件
257
+ unless File::exist?(meta_file_path)
258
+ meta_file_path_original = find_config_file(project_dir)
259
+
260
+ unless File::exist?(meta_file_path_original)
261
+ info = Pod::MPAAS::Localization.t('mpaas.hooks.no_config_file_found')
262
+ raise Pod::Informative, info
263
+ end
264
+
265
+ # 改名
266
+ File::rename(meta_file_path_original, meta_file_path_old)
267
+
268
+ # 再复制到每个target下面
269
+ FileUtils::cp_r(meta_file_path_old, sub_target_dir)
270
+
271
+ need_add_meta_file_if_needed = true
272
+ end
273
+
274
+ meta_hash = JSON.parse(File.read(meta_file_path))
275
+ meta_file_name = File::basename(meta_file_path)
276
+
277
+ # 处理历史不兼容多target的情况
278
+ if need_add_meta_file_if_needed && sub_target_directory_ref[meta_file_name]
279
+ # 先移除资源
280
+ remove_resource(meta_file_name, eachTarget.name, project)
281
+
282
+ ref = sub_target_directory_ref[meta_file_name]
283
+ ref.remove_from_project
284
+ end
285
+
286
+ # 配置文件工程里面也添加一下
287
+ unless sub_target_directory_ref[meta_file_name]
288
+ ref = add_non_source_file(sub_target_directory_ref, meta_file_path, project) # File::basename(meta_file_path)
289
+ # resource 要加一下
290
+ add_resource_to_build_phase(ref, eachTarget.name, project)
291
+ else
292
+ LogTools.p "#{meta_file_name} file already exist in project, no need to add again"
293
+ end
294
+
295
+ ## 处理加密图片相关
296
+ # 生成无线保镖图片
297
+ yw_jpg_name = "yw_1222.jpg"
298
+ yw_jpg_path = File.join(sub_target_dir, yw_jpg_name)
299
+ addtarget_yw_jpg_path = yw_jpg_path
300
+ yw_jpg_path = Shellwords.escape(yw_jpg_path)
301
+ run_base64_command = nil
302
+ guard_image_version = nil
303
+ guard_image_version = options["guard_image_version"]
304
+ #如果配置了guard_image_version字段,根据guard_image_version生成图片
305
+ #如果配置了guard_image_version字段,10.2.3版本的生成v6其他生成v5
306
+ LogTools.p_green "currentset_default_baseline #{@currentset_default_baseline}"
307
+ if guard_image_version == nil
308
+ if @currentset_default_baseline == "10.2.3"
309
+ if meta_hash["v6Base64Code"].nil? || meta_hash["v6Base64Code"].empty?
310
+ LogTools.p_green "!!!!!!!!!!!!!!!!!!!!meta.config hasn't v6Base64Code, cannot generate v6 guard image"
311
+ else
312
+ run_base64_command = "base64 -D -o " + yw_jpg_path + " <<< " + meta_hash["v6Base64Code"]
313
+ end
314
+ else
315
+ if meta_hash["base64Code"].nil? || meta_hash["base64Code"].empty?
316
+ LogTools.p_green "!!!!!!!!!!!!!!!!!!!!meta.config hasn't base64Code, cannot generate yw_1222 image"
317
+ else
318
+ run_base64_command = "base64 -D -o " + yw_jpg_path + " <<< " + meta_hash["base64Code"]
319
+ end
320
+ end
321
+ elsif guard_image_version == 6
322
+ if meta_hash["v6Base64Code"].nil? || meta_hash["v6Base64Code"].empty?
323
+ LogTools.p_green "!!!!!!!!!!!!!!!!!!!!meta.config hasn't v6Base64Code, cannot generate v6 guard image"
324
+ else
325
+ run_base64_command = "base64 -D -o " + yw_jpg_path + " <<< " + meta_hash["v6Base64Code"]
326
+ end
327
+ else
328
+ if meta_hash["base64Code"].nil? || meta_hash["base64Code"].empty?
329
+ LogTools.p_green "!!!!!!!!!!!!!!!!!!!!meta.config hasn't base64Code, cannot generate yw_1222 image"
330
+ else
331
+ run_base64_command = "base64 -D -o " + yw_jpg_path + " <<< " + meta_hash["base64Code"]
332
+ end
333
+ end
334
+
335
+
336
+ if run_base64_command
337
+ LogTools.p_green "yw_jpg_path #{yw_jpg_path}"
338
+
339
+ system run_base64_command
340
+ # 再添加到工程
341
+ unless sub_target_directory_ref[yw_jpg_name]
342
+ ref = add_non_source_file(sub_target_directory_ref, addtarget_yw_jpg_path, project) # File::basename(meta_file_path)
343
+ add_resource_to_build_phase(ref, eachTarget.name, project) # resource 要加一下
344
+ else
345
+ LogTools.p "yw_1222.jpg file already exist in project, no need to add again"
346
+ end
347
+ end
348
+
349
+ # 生成蓝盾图片
350
+ antguardStr = meta_hash["absBase64Code"]
351
+ if antguardStr && !antguardStr.empty?
352
+ antguard_jpg_name = "abs_1222.jpg"
353
+ antguard_jpg_path = File.join(sub_target_dir, antguard_jpg_name)
354
+ addTarget_antguard_jpg_path = antguard_jpg_path
355
+ antguard_jpg_path = Shellwords.escape(antguard_jpg_path)
356
+
357
+ run_antguard_base64_command = "base64 -D -o " + antguard_jpg_path + " <<< " + antguardStr
358
+
359
+ system run_antguard_base64_command
360
+ # 再添加到工程
361
+ unless sub_target_directory_ref[antguard_jpg_name]
362
+ ref = add_non_source_file(sub_target_directory_ref, addTarget_antguard_jpg_path, project) # File::basename(meta_file_path)
363
+ add_resource_to_build_phase(ref, eachTarget.name, project) # resource 要加一下
364
+ else
365
+ LogTools.p "abs_1222.jpg file already exist in project, no need to add again"
366
+ end
367
+ end
368
+
369
+ # 刷改 PRODUCT_BUNDLE_IDENTIFIER
370
+ eachTarget.build_configuration_list.build_configurations.each do |config|
371
+ config.build_settings["PRODUCT_BUNDLE_IDENTIFIER"] = meta_hash["bundleId"]
372
+ LogTools.v_green config.build_settings.to_s
373
+ end
374
+
375
+ # info.plist 中也先加一下
376
+ # 先复用原插件中独立脚本,人肉拼参数
377
+ write_infoPlist_array = [project.path.to_s, eachTarget.name, "Product ID", meta_hash["appKey"] + "-" + meta_hash["workspaceId"], "Product Version", "1.0.0.0", "mPaaS", "WorkspaceId", meta_hash["workspaceId"], "AppId", meta_hash["appId"], "UniformGateway", meta_hash["mpaasapi"], meta_hash["bundleId"], "mPaaSInternal", "SyncPort", meta_hash["syncport"], "SyncServer", meta_hash["syncserver"]]
378
+
379
+ LogTools.p "write info.plist ..."
380
+ startTime_infoPlist = Time.new
381
+ runWriteInfoList(write_infoPlist_array, pods_path)
382
+ LogTools.p "write info.plist end (cost " + "%.3f" % (Time.new.to_f - startTime_infoPlist.to_f) + "s)"
383
+ # system run_wirte_infoPlist_command
384
+
385
+ # 处理下上报埋点 读取 meta.config
386
+ if CocoapodsmPaaS::REPORT_LOG
387
+ target_hash = targets_libs_for_log_hash[eachTarget.name]
388
+ unless target_hash
389
+ target_hash = {}
390
+ end
391
+
392
+ target_hash["bundleId"] = meta_hash["bundleId"]
393
+ target_hash["appId"] = meta_hash["appId"]
394
+ targets_libs_for_log_hash[eachTarget.name] = target_hash
395
+ end
396
+
397
+ # Find.find(pods_path) do |path|
398
+ # if File::basename(path) == "APLog" && File::directory?(path)
399
+
400
+ # 遍历 pod install 后的 pods 文件夹,判断已添加的库
401
+
402
+ Dir::foreach(pods_path) do |dir_name|
403
+ if dir_name == "APRemoteLogging" && current_mPaaS_libs.include?("APRemoteLogging")
404
+ logGwString = ""
405
+ unless meta_hash["logGW"]
406
+ LogTools.v_red "config have not logGW"
407
+ else
408
+ logGwString = meta_hash["logGW"]
409
+ end
410
+
411
+ LogTools.v_green "It has #{dir_name}, need add files by code"
412
+
413
+ # 标识头文件
414
+ modules << "#{dir_name}:1.0.0"
415
+
416
+ # 添加内容
417
+ logServerURL = logGwString + "/loggw/logUpload.do"
418
+ platformID = meta_hash["appKey"] + "-" + meta_hash["workspaceId"]
419
+ config_json = '{"methods": ["- (NSString*)logServerURL\n{\n return @\"' + logServerURL + '\";\n}\n", "- (NSArray*)defaultUploadLogTypes\n{\n return @[@(APLogTypeBehavior), @(APLogTypeCrash), @(APLogTypeAuto), @(APLogTypeMonitor), @(APLogTypeKeyBizTrace), @(APLogTypePerformance)];\n}\n", "- (NSString *)platformID\n{\n return @\"' + platformID + '\";\n}\n"], "class": "APLogAdditions", "actions": [], "header": "<APRemoteLogging\/APLogAddions.h>"}'
420
+ config = JSON.parse(config_json)
421
+ config_hash[dir_name] = config
422
+
423
+ # 10.1.20 兼容处理 加个判断有 MPMasAdapter 的时候再处理
424
+ if Dir.entries(pods_path).include?("MPMasAdapter")
425
+ config_json1 = '{"methods":[],"class":"MPAnalysisInterface","actions":[],"header":"<MPAnalysis\/MPAnalysisInterface.h>"}'
426
+ config1 = JSON.parse(config_json1)
427
+ config_hash["MPAnalysis"] = config1
428
+ end
429
+
430
+ elsif dir_name == "APLog" && current_mPaaS_libs.include?("APLog")
431
+ LogTools.v_green "It has #{dir_name}, need add files by code"
432
+
433
+ # 标识头文件
434
+ modules << "#{dir_name}:1.0.0"
435
+
436
+ # 添加系统库 (先放这里)
437
+ eachTarget.add_system_framework("CoreTelephony")
438
+ eachTarget.add_system_framework("SystemConfiguration")
439
+ elsif dir_name == "mPaas" && current_mPaaS_libs.include?("mPaas")
440
+ LogTools.v_green "It has #{dir_name}, need add files by code"
441
+
442
+ # 标识头文件
443
+ modules << "#{dir_name}:1.0.0"
444
+
445
+ # 添加内容
446
+ config_json = '{"actions":[],"methods":["- (BOOL)enableSettingService\n{\n return NO;\n}\n","- (NSString *)userId\n{\n return nil;\n}\n"],"class":"MPaaSInterface","header":"<mPaas\/MPaaSInterface.h>","resources_path":"\/Users\/Shared\/.mpaaskit_sdk\/mPaas\/10.1.25\/mPaas.framework\/AutoConfig"}'
447
+ config = JSON.parse(config_json)
448
+ config_hash[dir_name] = config
449
+ elsif dir_name == "MPAnalysis" && current_mPaaS_libs.include?("MPAnalysis")
450
+ LogTools.v_green "It has #{dir_name}, need add files by code"
451
+
452
+ # 标识头文件
453
+ modules << "#{dir_name}:1.0.0"
454
+
455
+ # 添加内容
456
+ config_json = '{"methods":[],"class":"MPAnalysisInterface","actions":[],"header":"<MPAnalysis\/MPAnalysisInterface.h>"}'
457
+ config = JSON.parse(config_json)
458
+ config_hash[dir_name] = config
459
+ elsif dir_name == "APMobileNetwork" && current_mPaaS_libs.include?("APMobileNetwork")
460
+ LogTools.v_green "It has #{dir_name}, need add files by code"
461
+
462
+ # 标识头文件
463
+ modules << "#{dir_name}:1.0.0"
464
+
465
+ # 添加内容
466
+ gatewayURL = meta_hash["rpcGW"]
467
+ signKeyForRequest = meta_hash["appKey"]
468
+ productId = meta_hash["appId"]
469
+
470
+ config_json = '{"methods":["- (NSString*)gatewayURL\n{\n return @\"' + gatewayURL + '\";\n}\n","- (NSString*)signKeyForRequest:(NSURLRequest*)request\n{\n return @\"' + signKeyForRequest + '\";\n}\n","- (NSString *)productId\n{\n return @\"' + productId + '\";\n}\n","- (NSString*)commonInterceptorClassName\n{\n return @\"DTRpcCommonInterceptor\";\n}\n"],"class":"DTRpcInterface","actions":[],"header":"<APMobileNetwork\/DTRpcInterface.h>"}'
471
+ config = JSON.parse(config_json)
472
+ config_hash[dir_name] = config
473
+ elsif dir_name == "AutoTracker" && current_mPaaS_libs.include?("AutoTracker")
474
+ LogTools.v_green "It has #{dir_name}, need add files by code"
475
+
476
+ # 标识头文件
477
+ modules << "#{dir_name}:1.0.0"
478
+ elsif dir_name == "TianYan" && current_mPaaS_libs.include?("TianYan")
479
+ LogTools.v_green "It has #{dir_name}, need add files by code"
480
+
481
+ # 标识头文件
482
+ modules << "#{dir_name}:1.0.0"
483
+
484
+ # 添加系统库 (先放这里)
485
+ eachTarget.add_system_framework("WebKit")
486
+ eachTarget.add_system_framework("CoreMotion")
487
+ elsif dir_name == "APCrashReporter" && current_mPaaS_libs.include?("APCrashReporter")
488
+ LogTools.v_green "It has #{dir_name}, need add files by code"
489
+
490
+ # 标识头文件
491
+ modules << "#{dir_name}:1.0.0"
492
+
493
+ # 需要单独修改一下 main.m 文件
494
+ execute_mainusecrashreporting_action("", "", sub_target_dir, "", eachTarget.name, project)
495
+ elsif dir_name == "NebulaSDK" && current_mPaaS_libs.include?("NebulaSDK")
496
+ LogTools.v_green "It has #{dir_name}, need add files by code"
497
+
498
+ # 标识头文件
499
+ modules << "#{dir_name}:1.0.0"
500
+ elsif dir_name == "NebulaAppManager" && current_mPaaS_libs.include?("NebulaAppManager")
501
+ LogTools.v_green "It has #{dir_name}, need add files by code"
502
+
503
+ # 标识头文件
504
+ modules << "#{dir_name}:1.0.0"
505
+ elsif dir_name == "NebulaPoseidon" && current_mPaaS_libs.include?("NebulaPoseidon")
506
+ LogTools.v_green "It has #{dir_name}, need add files by code"
507
+
508
+ # 标识头文件
509
+ modules << "#{dir_name}:1.0.0"
510
+ elsif dir_name == "APLongLinkService" && current_mPaaS_libs.include?("APLongLinkService")
511
+ LogTools.v_green "It has #{dir_name}, need add files by code"
512
+
513
+ # 标识头文件
514
+ modules << "#{dir_name}:1.0.0"
515
+
516
+ # 添加内容
517
+ appId = meta_hash["appId"]
518
+ workspaceId = meta_hash["workspaceId"]
519
+ syncport = ""
520
+ unless meta_hash["syncport"]
521
+ LogTools.v_red "config have not syncport"
522
+ else
523
+ syncport = meta_hash["syncport"]
524
+ end
525
+ syncserver = ""
526
+ unless meta_hash["syncserver"]
527
+ LogTools.v_red "config have not syncport"
528
+ else
529
+ syncserver = meta_hash["syncserver"]
530
+ end
531
+
532
+ # 这个category 32以上就不生成了,这里兼容下历史代码吧
533
+ syncport = '' unless syncport
534
+ syncserver = '' unless syncserver
535
+
536
+ config_json = '{"methods":["- (NSString*)appId\n{\n return @\"' + appId + '\";\n}\n","- (NSString*)platform\n{\n return @\"IOS\";\n}\n","- (NSString*)workspaceId\n{\n return @\"' + workspaceId + '\";\n}\n","- (int)syncPort\n{\n return ' + syncport + ';\n}\n","- (NSString*)syncServer\n{\n return @\"' + syncserver + '\";\n}\n"],"class":"DTSyncInterface","actions":[],"header":"<APLongLinkService\/DTSyncInterface.h>"}'
537
+ config = JSON.parse(config_json)
538
+ config_hash[dir_name] = config
539
+
540
+ eachTarget.add_system_framework("MessageUI")
541
+ elsif dir_name == "MPHotpatchSDK" && current_mPaaS_libs.include?("MPHotpatchSDK")
542
+ LogTools.v_green "It has #{dir_name}, need add files by code"
543
+
544
+ # 标识头文件
545
+ modules << "#{dir_name}:1.0.0"
546
+
547
+ # 添加内容
548
+ appKey = meta_hash["appKey"]
549
+
550
+ config_json = '{"methods":["- (NSString*)AESEncryptionKeyName\n{\n return @\"' + appKey + '\";\n}\n","#ifdef MPNebulaHandler\n- (id<NebulaHandler>)getNebulaHandler\n{\n NARequestManager *handle = [NARequestManager sharedInctance];\n return handle;\n}\n#endif\n"],"class":"DynamicReleaseInterface","actions":[],"header":"<MPHotpatchSDK\/MPHotpatchSDK.h>"}'
551
+ config = JSON.parse(config_json)
552
+ config_hash[dir_name] = config
553
+ elsif dir_name == "NebulamPaaSBiz" && current_mPaaS_libs.include?("NebulamPaaSBiz")
554
+ LogTools.v_green "It has #{dir_name}, need add files by code"
555
+
556
+ # 标识头文件
557
+ modules << "#{dir_name}:1.0.0"
558
+ elsif dir_name == "APCommonUI" && current_mPaaS_libs.include?("APCommonUI")
559
+ LogTools.v_green "It has #{dir_name}, need add files by code"
560
+
561
+ # 标识头文件
562
+ modules << "#{dir_name}:1.0.0"
563
+ elsif dir_name == "APMobileFramework" && current_mPaaS_libs.include?("APMobileFramework")
564
+ LogTools.v_green "It has #{dir_name}, need add files by code"
565
+
566
+ # 标识头文件
567
+ modules << "#{dir_name}:1.0.0"
568
+
569
+ config_json = '{"actions":[{"type":"resource","files":["MobileRuntime.plist", "Images_mPaaS.xcassets"]},{"type":"source","files":["MPLauncherAppDelegate.h","MPLauncherAppDelegate.m","MPTabBarController.h","MPTabBarController.m","DemoViewController.h","DemoViewController.m"]},{"type":"micro_application","params":{"delegate":"MPLauncherAppDelegate","set_launcher":true,"description":"Launcher","name":"Launcher"}},{"type":"main_use_framework"}],"methods":["- (BOOL)shouldLogReportActive\n{\n return YES;\n}\n","- (NSTimeInterval)logReportActiveMinInterval\n{\n return 0;\n}\n","- (BOOL)shouldLogStartupConsumption\n{\n return YES;\n}\n","- (BOOL)shouldAutoactivateBandageKit\n{\n return YES;\n}\n","- (BOOL)shouldAutoactivateShareKit\n{\n return YES;\n}\n","- (DTNavigationBarBackTextStyle)navigationBarBackTextStyle\n{\n return DTNavigationBarBackTextStyleAlipay;\n}\n"],"class":"DTFrameworkInterface","header":"<APMobileFramework\/DTFrameworkInterface.h>"}'
570
+ config = JSON.parse(config_json)
571
+ config["resources_path"] = File.join(CocoapodsmPaaS::MPAAS_TEMPLATES_PATH, "APMobileFramework", "AutoConfig")
572
+ config_hash[dir_name] = config
573
+ elsif dir_name == "NebulaLogging" && current_mPaaS_libs.include?("NebulaLogging")
574
+ LogTools.v_green "It has #{dir_name}, need add files by code"
575
+
576
+ # 标识头文件
577
+ modules << "#{dir_name}:1.0.0"
578
+ elsif dir_name == "TBScanSDK" && current_mPaaS_libs.include?("TBScanSDK")
579
+ LogTools.v_green "It has #{dir_name}, need add files by code"
580
+
581
+ # 标识头文件
582
+ modules << "#{dir_name}:1.0.0"
583
+ elsif dir_name == "TBDecodeSDK" && current_mPaaS_libs.include?("TBDecodeSDK")
584
+ LogTools.v_green "It has #{dir_name}, need add files by code"
585
+
586
+ # 标识头文件
587
+ modules << "#{dir_name}:1.0.0"
588
+ elsif dir_name == "MPUpgradeCheckService" && current_mPaaS_libs.include?("MPUpgradeCheckService")
589
+ LogTools.v_green "It has #{dir_name}, need add files by code"
590
+
591
+ # 这里偷懒,放在一起处理
592
+ # 标识头文件
593
+ modules << "AliUpgradeUI:1.0.0"
594
+ modules << "AliUpgradeCheckService:1.0.0"
595
+ modules << "AliUpgradeSDK:1.0.0"
596
+ elsif dir_name == "APConfig" && current_mPaaS_libs.include?("APConfig")
597
+ LogTools.v_green "It has #{dir_name}, need add files by code"
598
+
599
+ # 标识头文件
600
+ modules << "#{dir_name}:1.0.0"
601
+ elsif dir_name == "MPShareKit" && current_mPaaS_libs.include?("MPShareKit")
602
+ LogTools.v_green "It has #{dir_name}, need add files by code"
603
+
604
+ # 标识头文件
605
+ modules << "#{dir_name}:1.0.0"
606
+ elsif dir_name == "MPDiagnosis" && current_mPaaS_libs.include?("MPDiagnosis")
607
+ LogTools.v_green "It has #{dir_name}, need add files by code"
608
+
609
+ # 标识头文件
610
+ # modules << "#{dir_name}:1.0.0"
611
+
612
+ # 添加内容
613
+ config_json = '{"methods":["- (NSString*)uploadLogUrl\n{\n return @\"https:\/\/cn-hangzhou-mas-log.cloud.alipay.com\/loggw\/extLog.do\";\n}\n","- (NSString*)uploadStatusUrl\n{\n return @\"https:\/\/cn-hangzhou-mas-log.cloud.alipay.com\/loggw\/report_diangosis_upload_status.htm\";\n}\n","- (NSString*)currentUserId\n{\n return @\"\";\n}\n","- (BOOL)isLogFormatAssertCheck\n{\n return NO;\n}\n","- (BOOL)isCloseLogEncrypt\n{\n return NO;\n}\n"],"class":"APLogUser","actions":[],"header":"<MPDiagnosis\/MPDiagnosis.h>"}'
614
+ config = JSON.parse(config_json)
615
+ config_hash[dir_name] = config
616
+ elsif dir_name == "MPBadgeService" && current_mPaaS_libs.include?("MPBadgeService")
617
+ LogTools.v_green "It has #{dir_name}, need add files by code"
618
+
619
+ # 标识头文件
620
+ modules << "#{dir_name}:1.0.0"
621
+ elsif dir_name == "AlipaySDK" && current_mPaaS_libs.include?("AlipaySDK")
622
+ LogTools.v_green "It has #{dir_name}, need add files by code"
623
+
624
+ # 标识头文件
625
+ modules << "#{dir_name}:1.0.0"
626
+ elsif dir_name == "MPPinyinSearch" && current_mPaaS_libs.include?("MPPinyinSearch")
627
+ LogTools.v_green "It has #{dir_name}, need add files by code"
628
+
629
+ # 标识头文件
630
+ modules << "#{dir_name}:1.0.0"
631
+ elsif dir_name == "AMapFoundationKit" && current_mPaaS_libs.include?("AMapFoundationKit")
632
+ LogTools.v_green "It has #{dir_name}, need add files by code"
633
+
634
+ # 标识头文件
635
+ modules << "#{dir_name}:1.0.0"
636
+ elsif dir_name == "APMobileLBS" && current_mPaaS_libs.include?("APMobileLBS")
637
+ LogTools.v_green "It has #{dir_name}, need add files by code"
638
+
639
+ # 标识头文件
640
+ modules << "#{dir_name}:1.0.0"
641
+ elsif dir_name == "MAMapKit" && current_mPaaS_libs.include?("MAMapKit")
642
+ LogTools.v_green "It has #{dir_name}, need add files by code"
643
+
644
+ # 标识头文件
645
+ modules << "#{dir_name}:1.0.0"
646
+ elsif dir_name == "APMap" && current_mPaaS_libs.include?("APMap")
647
+ LogTools.v_green "It has #{dir_name}, need add files by code"
648
+
649
+ # 标识头文件
650
+ modules << "#{dir_name}:1.0.0"
651
+ elsif dir_name == "NebulaHeader" && current_mPaaS_libs.include?("NebulaHeader")
652
+ LogTools.v_green "It has #{dir_name}, need add files by code"
653
+
654
+ # 10.1.60 适配下账户通了
655
+ unless mPaaS_lib_has_adapter?(pods_path, dir_name)
656
+ # 标识头文件
657
+ modules << "#{dir_name}:1.0.0"
658
+ end
659
+
660
+
661
+ # 10.1.60 这段注释掉,据说32下也不用,待验证打脸
662
+ # elsif dir_name == "SocketCraft" && current_mPaaS_libs.include?("SocketCraft")
663
+ # LogTools.v_green "It has #{dir_name}, need add files by code"
664
+
665
+ # # 标识头文件
666
+ # modules << "#{dir_name}:1.0.0"
667
+
668
+ # 10.1.60 添加
669
+ elsif dir_name == "Nebula" && current_mPaaS_libs.include?("Nebula")
670
+ LogTools.v_green "It has #{dir_name}, need add files by code"
671
+
672
+ # 标识头文件
673
+ modules << "#{dir_name}:1.0.0"
674
+
675
+ elsif dir_name == "MPNebulaAdapter" && current_mPaaS_libs.include?("MPNebulaAdapter")
676
+ LogTools.v_green "It has #{dir_name}, need add files by code"
677
+
678
+ # 标识头文件
679
+ modules << "#{dir_name}:1.0.0"
680
+
681
+ # 10.1.60 写死适配
682
+ if File::exist?(File.join(pods_path, dir_name, dir_name + ".framework", "Headers", "MPTinyAppAdapterInterface.h"))
683
+ modules << "MPTinyAppAdapterInterface_60:1.0.0"
684
+ end
685
+ elsif dir_name == "MPMgsAdapter" && current_mPaaS_libs.include?("MPMgsAdapter")
686
+ LogTools.v_green "It has #{dir_name}, need add files by code"
687
+
688
+ # 标识头文件
689
+ modules << "#{dir_name}:1.0.0"
690
+ elsif dir_name == "MPConfigAdapter" && current_mPaaS_libs.include?("MPConfigAdapter")
691
+ LogTools.v_green "It has #{dir_name}, need add files by code"
692
+
693
+ # 标识头文件
694
+ modules << "#{dir_name}:1.0.0"
695
+ elsif dir_name == "MPDynamicAdapter" && current_mPaaS_libs.include?("MPDynamicAdapter")
696
+ LogTools.v_green "It has #{dir_name}, need add files by code"
697
+
698
+ # 标识头文件
699
+ modules << "#{dir_name}:1.0.0"
700
+ elsif dir_name == "MPMasAdapter" && current_mPaaS_libs.include?("MPMasAdapter")
701
+ LogTools.v_green "It has #{dir_name}, need add files by code"
702
+
703
+ # 标识头文件
704
+ modules << "#{dir_name}:1.0.0"
705
+ elsif dir_name == "MPMssAdapter" && current_mPaaS_libs.include?("MPMssAdapter")
706
+ LogTools.v_green "It has #{dir_name}, need add files by code"
707
+
708
+ # 标识头文件
709
+ modules << "#{dir_name}:1.0.0"
710
+ elsif dir_name == "MPUTDIDAdapter" && current_mPaaS_libs.include?("MPUTDIDAdapter")
711
+ LogTools.v_green "It has #{dir_name}, need add files by code"
712
+
713
+ # 标识头文件
714
+ modules << "#{dir_name}:1.0.0"
715
+ elsif dir_name == "MPPushSDK" && current_mPaaS_libs.include?("MPPushSDK")
716
+ LogTools.v_green "It has #{dir_name}, need add files by code"
717
+
718
+ # 标识头文件
719
+ modules << "#{dir_name}:1.0.0"
720
+ elsif dir_name == "AliUpgradeCheckService" && current_mPaaS_libs.include?("AliUpgradeCheckService")
721
+ LogTools.v_green "It has #{dir_name}, need add files by code"
722
+
723
+ # 标识头文件
724
+ modules << "AliUpgradeCheckService_32:1.0.0"
725
+ end
726
+ end
727
+
728
+ # 兼容 10.1.20 处理
729
+ # config_hash.each do |key, value|
730
+ # # 如果存在 APRemoteLogging
731
+ # if key == "APRemoteLogging"
732
+ # # 添加内容
733
+ # config_json = '{"methods":[],"class":"MPAnalysisInterface","actions":[],"header":"<MPAnalysis\/MPAnalysisInterface.h>"}'
734
+ # config = JSON.parse(config_json)
735
+ # config_hash[dir_name] = config
736
+ # end
737
+ # end
738
+
739
+ #每个target都有一个头文件保存所有头文件,用户可以将这个文件加到pch中
740
+ mpaas_header_file_path = "#{sub_target_dir}/#{eachTarget.name}-mPaaS-Headers.h"
741
+ LogTools.v "mpaas_header_file_path : #{mpaas_header_file_path}"
742
+
743
+ if !File::exist?(mpaas_header_file_path)
744
+ mpaas_header_file = safe_create_file(mpaas_header_file_path)
745
+ # 如果还没加过头文件,要加一下
746
+ add_non_source_file(sub_target_directory_ref, mpaas_header_file_path, project)
747
+ end
748
+
749
+ # arg_modules = "APLog:3.0.1,APRemoteLogging:10.1.18"
750
+ # modules = arg_modules.split(",")
751
+
752
+ module_hash = get_module_versions_from_colon_array(modules)
753
+ LogTools.p "modules to pe process : #{module_hash.keys}"
754
+ LogTools.v "module_hash : #{module_hash}"
755
+
756
+ add_mpaas_references_to_target_headers(mpaas_header_file_path, module_hash, MPaaSCocoapodShare.instance.targetmap_igenore_headers[eachTarget.name]) # module_properties
757
+
758
+ # 处理pch文件,自动引用上添加的frameworks
759
+ pch_files = find_pch_file(eachTarget.name, project)
760
+ if pch_files.size == 0
761
+ # 添加一个pch文件
762
+ add_pch_file(project_dir, eachTarget.name, project, pch_files)
763
+ end
764
+ if pch_files.size > 0
765
+ pch_files.each do |f|
766
+ if File::exist?("#{project_dir}/#{f}")
767
+ # pch文件实际放在target目录下,但是加到mPaas/Supporting Files/target下面
768
+ add_mpaas_references_headers_to_pch("#{project_dir}/#{f}", "#{eachTarget.name}-mPaaS-Headers.h")
769
+ #add_mpaas_references_to_pch("#{proj_directory}/#{f}", target_modules, module_properties)
770
+
771
+ # 如果还没加过pch,要加一下
772
+ added = false
773
+ sub_target_directory_ref.children.each do |r|
774
+ if "#{r}".include?(File::basename(f))
775
+ added = true
776
+ end
777
+ end
778
+ if !added
779
+ add_non_source_file(sub_target_directory_ref, "../../../#{f}", project) # pch文件并不在support下面
780
+ end
781
+ else
782
+ LogTools.v_red "[WARNING] Prefix header file '#{project_dir}/#{f}' does not exist. But it is set as prefix header file in target build settings. Please fix your project."
783
+ end
784
+ end
785
+ else
786
+ LogTools.v_red "Cannot find prefix header in target '#{eachTarget.name}' of project. You should add MPaaS framework headers by yourself."
787
+ end
788
+
789
+ LogTools.p "Add category files if needed ..."
790
+ startTime_config_hash = Time.new
791
+ addedModules = Set.new
792
+ record_modules_path = File.join(sub_target_dir, "added_modules.mpaas")
793
+ if options["auto_gen_first_add"]
794
+ if File::exist?(record_modules_path)
795
+ addedModules = extract_unique_module_names(record_modules_path)
796
+ LogTools.v "addedModules : #{addedModules}"
797
+ else
798
+ write_file_to_path(record_modules_path, "#This file specifically handles the scenario where the auto_gen_first_add parameter within the Podfile mpaas plugin is set to true. Its purpose is to determine whether the current module is being added to the project for the very first time.")
799
+ end
800
+ end
801
+ newAddedModelNames = Array.new
802
+ LogTools.v "config_hash : #{config_hash}"
803
+ # 遍历要生成的代码
804
+ config_hash.each do |dir_name, config|
805
+ # 创建模板category的文件夹
806
+ # module_dir = File.join(project_dir, "MPaaS", "Targets", eachTarget, dir_name)
807
+ if !addedModules.include?(dir_name)
808
+ newAddedModelNames.push(dir_name)
809
+ else
810
+ next
811
+ end
812
+ module_dir = "#{project_dir}/MPaaS/Targets/#{eachTarget.name}/#{dir_name}"
813
+ module_directory_ref = sub_target_directory_ref[dir_name]
814
+
815
+ # 兼容 10.1.20 众多adapter
816
+ if mPaaS_lib_has_adapter?(pods_path, dir_name)
817
+ # 就不添加 category 了,并且删除旧版本存在的 category
818
+
819
+ dict = generate_module_config_source(config, eachTarget.name)
820
+ if File::exist?("#{module_dir}/#{dict["source_file"]}")
821
+ m_path = write_file_to_path("#{module_dir}/#{dict["source_file"]}", dict["source"])
822
+ delete_source_file(module_directory_ref, File::basename(m_path), eachTarget.name, project)
823
+ end
824
+
825
+ # 删除 group
826
+ if module_directory_ref
827
+ remove_from_project(module_directory_ref)
828
+ end
829
+
830
+ # 删除真实文件
831
+ safe_delete_directory_tt(module_dir)
832
+ elsif options["ignore_framework_for_portal"] && dir_name == "APMobileFramework"
833
+ LogTools.p_red Pod::MPAAS::Localization.t('mpaas.hooks.no_framework_modules_added')
834
+ else
835
+ safe_create_directory_tt(module_dir)
836
+
837
+ if module_directory_ref == nil
838
+ module_directory_ref = sub_target_directory_ref.new_group(dir_name, dir_name)
839
+ end
840
+
841
+ # 创建配置代码文件,并添加到工程里
842
+ if config["class"] and config["class"].length > 0
843
+ dict = generate_module_config_source(config, eachTarget.name)
844
+
845
+ if !(File::exist?("#{module_dir}/#{dict["header_file"]}"))
846
+ h_path = write_file_to_path("#{module_dir}/#{dict["header_file"]}", dict["header"])
847
+ add_non_source_file(module_directory_ref, File::basename(h_path), project)
848
+ end
849
+
850
+ if !(File::exist?("#{module_dir}/#{dict["source_file"]}"))
851
+ m_path = write_file_to_path("#{module_dir}/#{dict["source_file"]}", dict["source"])
852
+ add_source_file(module_directory_ref, File::basename(m_path), eachTarget.name, project)
853
+ end
854
+ end
855
+
856
+ # 执行actions
857
+ if config["actions"]
858
+ config["actions"].each do |act|
859
+ execute_module_action(act, config["resources_path"], module_dir, module_directory_ref, eachTarget.name, project)
860
+ end
861
+ end
862
+ end
863
+
864
+ end
865
+ LogTools.v "newAddedModelNames : #{newAddedModelNames}"
866
+ unless newAddedModelNames.empty?
867
+ if File::exist?(record_modules_path) && options["auto_gen_first_add"]
868
+ append_array_to_file(record_modules_path, newAddedModelNames)
869
+ end
870
+ LogTools.p "Add category files end (cost " + "%.3f" % (Time.new.to_f - startTime_config_hash.to_f) + "s)"
871
+ else
872
+ LogTools.p "Add category files end (cost " + "%.3f" % (Time.new.to_f - startTime_config_hash.to_f) + "s), but no new added modules."
873
+ end
874
+
875
+ #todo 在循环内调不会有问题 ?
876
+ project.save
877
+ end
878
+
879
+ # 上报埋点
880
+ if CocoapodsmPaaS::REPORT_LOG
881
+ # LogTools.p_red Pod::MPAAS::Localization.t('mpaas.hooks.report_buried_points')
882
+ # 默认不输出原始产生的日志
883
+ nolog = " 2> /dev/null"
884
+ if LogTools.verbose?
885
+ # 不屏蔽原始日志
886
+ nolog = ""
887
+ end
888
+
889
+ targets_libs_for_log_hash.each do |target_name, target_hash|
890
+ logger_dir_path = File.join(CocoapodsmPaaS::MPAAS_LOCAL_PATH, "bin", "CLLogger")
891
+
892
+ baseline_matched = BaselineTools.getBaselineMatched(File.join(Dir::pwd, "Podfile"))
893
+ version_code = BaselineTools.getVersionCodeInLocalByBaseline(baseline_matched)
894
+
895
+ s = {}
896
+ s["pkgId"] = target_hash["bundleId"]
897
+ s["appId"] = target_hash["appId"]
898
+ s["baseline"] = baseline_matched
899
+ s["version_code"] = version_code
900
+ s["updatetime"] = Time.new.to_i
901
+ s["type"] = "2"
902
+ s["sdks"] = target_hash["sdks"]
903
+
904
+ s1 = s.to_json
905
+ s1.gsub!(":", "=")
906
+ s1.gsub!(",", "^")
907
+ s1.gsub!("{", "")
908
+ s1.gsub!("}", "")
909
+
910
+ system "#{logger_dir_path} -t 0 -s #{s1}" + nolog
911
+
912
+ LogTools.v "log version_code : #{version_code}"
913
+ end
914
+ end
915
+
916
+ # 回写 version_code 到 podfile 里面
917
+ PodfileTools.writeVersionCode(File.join(Dir::pwd, "Podfile"))
918
+
919
+ # 检查更新,本地模式下跳过在线检查
920
+ if !@is_local_mode && (options["check_new"].nil? || options["check_new"])
921
+ CheckUpdateTools.checkNew(BaselineTools.getBaselineMatched(File.join(Dir::pwd, "Podfile")))
922
+ end
923
+
924
+ LogTools.p "(mPaaS cost " + "%.3f" % (Time.new.to_f - startTime_post_install.to_f) + "s)"
925
+ LogTools.p "--------------------------------mPaaS end----------------------------------------------"
926
+ end
927
+
928
+
929
+ end