cocoapods-bb-PodAssistant 0.1.5

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 (33) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +48 -0
  4. data/lib/cocoapods-bb-PodAssistant/babybus/business/babybus_install_environment.rb +129 -0
  5. data/lib/cocoapods-bb-PodAssistant/babybus/helpers/babybus_info_plist_helper.rb +92 -0
  6. data/lib/cocoapods-bb-PodAssistant/babybus/installer/post_install_hooks.rb +111 -0
  7. data/lib/cocoapods-bb-PodAssistant/command/PodAssistant.rb +44 -0
  8. data/lib/cocoapods-bb-PodAssistant/command/linkline/linkline.rb +68 -0
  9. data/lib/cocoapods-bb-PodAssistant/command/linkline/target-linkline.rb +9 -0
  10. data/lib/cocoapods-bb-PodAssistant/command/linkline/targetValidator-linkline.rb +25 -0
  11. data/lib/cocoapods-bb-PodAssistant/command/linkline/targetdefinition-linkline.rb +37 -0
  12. data/lib/cocoapods-bb-PodAssistant/command/stable/podfile-linkline.rb +9 -0
  13. data/lib/cocoapods-bb-PodAssistant/command/stable/stable.rb +168 -0
  14. data/lib/cocoapods-bb-PodAssistant/command.rb +9 -0
  15. data/lib/cocoapods-bb-PodAssistant/config/cache_path.rb +16 -0
  16. data/lib/cocoapods-bb-PodAssistant/config/source_manager.rb +389 -0
  17. data/lib/cocoapods-bb-PodAssistant/config/stable_source.rb +7 -0
  18. data/lib/cocoapods-bb-PodAssistant/config/stable_specs.rb +27 -0
  19. data/lib/cocoapods-bb-PodAssistant/gem_version.rb +3 -0
  20. data/lib/cocoapods-bb-PodAssistant/helpers/git_cmd_helper.rb +73 -0
  21. data/lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb +246 -0
  22. data/lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb +128 -0
  23. data/lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb +36 -0
  24. data/lib/cocoapods-bb-PodAssistant/helpers/stable_manager_helper.rb +85 -0
  25. data/lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb +72 -0
  26. data/lib/cocoapods-bb-PodAssistant/helpers.rb +6 -0
  27. data/lib/cocoapods-bb-PodAssistant/podfile.rb +392 -0
  28. data/lib/cocoapods-bb-PodAssistant/source_provider_hook.rb +335 -0
  29. data/lib/cocoapods-bb-PodAssistant.rb +1 -0
  30. data/lib/cocoapods_plugin.rb +9 -0
  31. data/spec/command/PodAssistant_spec.rb +12 -0
  32. data/spec/spec_helper.rb +50 -0
  33. metadata +132 -0
@@ -0,0 +1,392 @@
1
+ require 'cocoapods/podfile'
2
+ require 'cocoapods-core/podfile/dsl'
3
+ require 'uri'
4
+ require 'cocoapods-bb-PodAssistant'
5
+ require 'cocoapods-bb-PodAssistant/helpers/pod_module_helper'
6
+ require 'cocoapods-bb-PodAssistant/helpers/stable_manager_helper'
7
+
8
+ # 参数
9
+ # :name, :names,
10
+ # :git, :git_format,
11
+ # :root_path, :path, :path_format,
12
+ # :branch, :tag, :version,
13
+ # :method,
14
+
15
+ # 使用说明
16
+ # 如果有method 则使用method对应的方式请求模块
17
+ # 如果配置中数据匹配对应method失败 则使用默认规则
18
+ # method { (必选参数), [ 可选参数 ] }
19
+ # DEFAULT LOCAL
20
+ # LOCAL { ( (:name || :names),), [:path, :root_path, :path_format] }
21
+ # REMOTE_GIT { ( (:name || :names), :git), [:git_format] }
22
+ # REMOTE_VERSION { ( (:name || :names), :git), [:version] }
23
+ # REMOTE_BRANCH { ( (:name || :names), :git), [:branch='master'] }
24
+ # REMOTE_TAG { ( (:name || :names), :git, :tag), [] }
25
+
26
+ # 默认规则
27
+ # 如果配置中有git地址, 优先使用git地址,
28
+ # 如果git地址不存在, 则根据名字判断本地模块目录(当前用户模块根目录地址+模块名字)是否存在,
29
+ # 如果本地模块根目录存在, 则LOCAL(pod 'name' :path => 'path')
30
+ # 如果本地模块根目录不存在 则REMOTE_VERSION(pod 'name' || pod 'name' 'version')
31
+ # DEFAULT LOCAL
32
+ # LOCAL ( pod 'name' :path => 'path' )
33
+ # REMOTE_GIT ( pod 'name' :git => 'git' :branch => 'master' )
34
+ # REMOTE_VERSION ( pod 'name' || pod 'name' 'version')
35
+ # REMOTE_BRANCH ( pod 'name' :git => 'git' :branch => 'branch' )
36
+ # REMOTE_TAG ( pod 'name' :git => 'git' :tag => 'tag' )
37
+
38
+ # method
39
+ DEFAULT = 0
40
+ LOCAL = 1
41
+ REMOTE_GIT = 2
42
+ REMOTE_VERSION = 3
43
+ REMOTE_BRANCH = 4
44
+ REMOTE_TAG = 5
45
+
46
+ module Pod
47
+ class Podfile
48
+ # @!group DSL support
49
+ include Pod::Podfile::DSL
50
+
51
+ # pod组件合并操作
52
+ def pod_module_run(pod_modules, member_modules = {}, member_configs = [], ignore_local_stable = false)
53
+ # Pod::UI.puts "Pod Module:#{pod_modules}"
54
+ time1 = Time.new
55
+ puts "[PodAssistant]pod组件组装开始操作时间:#{time1}".green
56
+ source = BB::PodModule.new(pod_modules, member_modules, member_configs, ignore_local_stable)
57
+ pod_box_module_run(source)
58
+ time2 = Time.new
59
+ puts "[PodAssistant]pod组件组装结束时间:#{time2}".green
60
+ # 获取时间差
61
+ time = time2 - time1
62
+ puts "pod组件组装操作耗时:#{time.to_s.send(:red)}秒".green
63
+ end
64
+ # 更新项目lock
65
+ def update_product_stable_lock(installer)
66
+ BB::StableManager.updateProductStableLock(installer.pod_targets)
67
+ end
68
+ # 更新公共lock
69
+ def update_common_stable_lock(installer)
70
+ BB::StableManager.updateCommonStableLock(installer.pod_targets)
71
+ end
72
+ # 更新业务公共lock
73
+ def update_business_stable_lock(businessSpecName, pod_targets)
74
+ BB::StableManager.updateBusinessStableLock(businessSpecName, pod_targets)
75
+ end
76
+
77
+ # 从列表中搜索得到对应配置
78
+ def module_for_name(name, module_list)
79
+ if module_list
80
+ module_list.each do | m |
81
+ if name == m[:name]
82
+ return m
83
+ else
84
+ m[:names].each do | n |
85
+ if n == name
86
+ return m
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ return nil
93
+ end
94
+
95
+ # 默认配置key
96
+ def default_module_keys
97
+ return [
98
+ :name,
99
+ :names,
100
+ :git,
101
+ :git_format,
102
+ :root_path,
103
+ :path,
104
+ :path_format,
105
+ :branch,
106
+ :tag,
107
+ :version,
108
+ :method,
109
+ :inhibit_warnings,
110
+ :configurations,
111
+ :linkage,
112
+ :linkages,
113
+ ]
114
+ end
115
+
116
+ # 获取需要的对应key的值
117
+ def value_from_module(source_module, target_module, key)
118
+
119
+ if target_module == nil || source_module == nil || key == nil || key.length == nil
120
+ return nil
121
+ end
122
+
123
+ source_value = source_module[key]
124
+ target_value = target_module[key]
125
+ if target_value == nil
126
+ return source_value
127
+ else
128
+ return target_value
129
+ end
130
+
131
+ end
132
+
133
+ # 根据请求方式调整配置 如果明确指定了方法 则使用方法 否则 使用默认方法(如果本地存在对应的项目地址就请求,否则就请求git仓库,否则报错)
134
+ def module_with_method(method=DEFAULT, source_module, current_member)
135
+
136
+ if source_module == nil
137
+ return nil
138
+ end
139
+
140
+ if method == nil
141
+ method = DEFAULT
142
+ end
143
+
144
+ name = source_module[:name]
145
+ git_name = name
146
+ if name != nil && name.split("/") != nil && name.split("/").length > 0
147
+ git_name = name.split("/")[0]
148
+ end
149
+
150
+ name_condition = (name != nil && name.length > 0)
151
+ if name_condition == false
152
+ return nil
153
+ end
154
+
155
+ git = source_module[:git]
156
+ git_condition = (source_module[:git] != nil && source_module[:git].length > 0)
157
+ git_format_condition = (source_module[:git_format] != nil && source_module[:git_format].length > 0)
158
+ if git_condition
159
+ git = git
160
+ elsif git_format_condition
161
+ git = source_module[:git_format].gsub(/\#\{git_name\}/, "\#\{git_name\}" => git_name)
162
+ else
163
+ git = nil
164
+ end
165
+
166
+ path = source_module[:path]
167
+ root_path_condition = (source_module[:root_path] != nil && source_module[:root_path].length > 0)
168
+ path_condition = (path != nil && path.length > 0)
169
+ path_format_condition = (source_module[:path_format] != nil && source_module[:path_format].length > 0)
170
+ if path_condition
171
+ path = path
172
+ elsif path_format_condition
173
+ path = source_module[:path_format].gsub(/\#\{git_name\}/, "\#\{git_name\}" => git_name)
174
+ elsif root_path_condition
175
+ path = File.join(source_module[:root_path], git_name)
176
+ else
177
+ path = nil
178
+ if current_member[:force_local] == true
179
+ if current_member[:pathes]
180
+ current_member[:pathes].each do | p |
181
+ if File.exist?(File.join(p, git_name))
182
+ path = File.join(p, git_name)
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+
189
+ branch = source_module[:branch]
190
+ branch_condition = (branch != nil && branch.length > 0)
191
+ tag = source_module[:tag]
192
+ tag_condition = (tag != nil && tag.length > 0)
193
+ version = source_module[:version]
194
+ version_condition = (version != nil && version.length > 0)
195
+ target_method = DEFAULT
196
+ if path != nil && path.length > 0
197
+ if File.exist?(path)
198
+ target_method = LOCAL
199
+ else
200
+ target_method = REMOTE_VERSION
201
+ end
202
+ elsif git != nil && git.length > 0
203
+ if branch_condition
204
+ target_method = REMOTE_BRANCH
205
+ elsif tag_condition
206
+ target_method = REMOTE_TAG
207
+ else
208
+ target_method = REMOTE_GIT
209
+ end
210
+ elsif version_condition
211
+ target_method = REMOTE_VERSION
212
+ else
213
+ if path == nil || path.length == 0
214
+ if current_member[:pathes]
215
+ current_member[:pathes].each do | p |
216
+ if File.exist?(File.join(p, git_name))
217
+ path = File.join(p, git_name)
218
+ end
219
+ end
220
+ end
221
+ end
222
+
223
+ if path != nil && path.length > 0
224
+ target_method = LOCAL
225
+ else
226
+ target_method = REMOTE_VERSION
227
+ end
228
+ end
229
+
230
+ inhibit_warnings_variable = source_module[:inhibit_warnings]
231
+ if inhibit_warnings_variable == nil
232
+ inhibit_warnings_variable = true
233
+ end
234
+
235
+ configurations = source_module[:configurations]
236
+ if configurations == nil
237
+ configurations = []
238
+ end
239
+
240
+ # linkline 插件参数获取,兼容没有插件情况 nil => nil
241
+ linkage = source_module[:linkage]
242
+ linkages = source_module[:linkages]
243
+ linkageKey = :linkage if linkage.to_s.length > 0
244
+ linkagesKey = :linkages if linkages.to_s.length > 0
245
+
246
+ case method
247
+ when DEFAULT
248
+ # 根据参数判断method
249
+ if target_method != DEFAULT
250
+ module_with_method(target_method, source_module, current_member)
251
+ else
252
+ module_with_method(LOCAL, source_module, current_member)
253
+ end
254
+ when LOCAL
255
+ if ( path != nil && path.length > 0 )
256
+ if File.exist?(path)
257
+ pod "#{name}", :path => "#{path}", :inhibit_warnings => inhibit_warnings_variable , :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
258
+ end
259
+ else
260
+ module_with_method(REMOTE_VERSION, source_module, current_member)
261
+ end
262
+ when REMOTE_GIT
263
+ if ( git != nil && git.length > 0 )
264
+ pod "#{name}", :git => "#{git}", :branch => 'master', :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
265
+ else
266
+ module_with_method(LOCAL, source_module, current_member)
267
+ end
268
+ when REMOTE_VERSION
269
+ if ( version != nil && version.length > 0 )
270
+ pod "#{name}", "#{version}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
271
+ else
272
+ pod "#{name}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
273
+ end
274
+ when REMOTE_BRANCH
275
+ if ( git != nil && git.length > 0 )
276
+ if ( branch != nil && branch.length > 0 )
277
+ pod "#{name}", :git => "#{git}", :branch => "#{branch}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
278
+ else
279
+ pod "#{name}", :git => "#{git}", :branch => "master", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
280
+ end
281
+ else
282
+ module_with_method(LOCAL, source_module, current_member)
283
+ end
284
+ when REMOTE_TAG
285
+ if ( git != nil && git.length > 0 )
286
+ if ( tag != nil && tag.length > 0 )
287
+ pod "#{name}", :git => "#{git}", :tag => "#{tag}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
288
+ else
289
+ pod "#{name}", :git => "#{git}", :branch => "master", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
290
+ end
291
+ else
292
+ module_with_method(LOCAL, source_module, current_member)
293
+ end
294
+ else
295
+ module_with_method(LOCAL, source_module, current_member)
296
+ end
297
+ end
298
+
299
+ # 整合两个配置
300
+ def combine_modules(source_module, target_module, target_name, current_member)
301
+
302
+ if ( target_module == nil && source_module == nil ) && ( target_name == nil || target_name.length == nil )
303
+ return nil
304
+ end
305
+ source_module_name_condition = ( source_module != nil && source_module[:name] == target_name )
306
+ target_module_name_condition = ( target_module != nil && target_module[:name] == target_name )
307
+ source_module_names_condition = ( source_module != nil && source_module[:names].include?(target_name) )
308
+ target_module_names_condition = ( target_module != nil && target_module[:names].include?(target_name) )
309
+ # 符合名字都在两个配置里
310
+ condition = ( source_module_name_condition && target_module_name_condition && source_module_names_condition && target_module_names_condition )
311
+ the_module = target_module
312
+ if condition
313
+ the_module = target_module
314
+ else
315
+ if target_module_name_condition || target_module_names_condition
316
+ the_module = target_module
317
+ elsif source_module_name_condition || source_module_names_condition
318
+ the_module = source_module
319
+ end
320
+ end
321
+ returned_module = {}
322
+ default_module_keys = default_module_keys()
323
+ if default_module_keys
324
+ default_module_keys.each do | key |
325
+ returned_module[key] = value_from_module(returned_module, the_module, key)
326
+ end
327
+ end
328
+
329
+ returned_module[:names] = []
330
+ returned_module[:name] = target_name
331
+ method = returned_module[:method]
332
+ if method == nil
333
+ method = DEFAULT
334
+ end
335
+ module_with_method(method, returned_module, current_member)
336
+ end
337
+
338
+ def pod_box_module_run(pod_module)
339
+ @run_modules = []
340
+ # 获取当前成员信息
341
+ @current_member = pod_module.current_member
342
+ # 获取成员信息对应的配置列表
343
+ @current_member_modules = pod_module.current_member_modules
344
+ # 获取全部需要执行的模块
345
+ # pod member_modules
346
+ if pod_module && pod_module.current_member_modules
347
+ pod_module.current_member_modules.each do | m |
348
+ name = m[:name]
349
+ if name == nil || name.length == 0
350
+ if m[:names]
351
+ m[:names].each do | n |
352
+ name = n
353
+ source_module = m
354
+ target_module = m
355
+ combine_modules(source_module, target_module, name, @current_member)
356
+ end
357
+ end
358
+ else
359
+ source_module = m
360
+ target_module = m
361
+ combine_modules(source_module, target_module, name, @current_member)
362
+ end
363
+ end
364
+ end
365
+
366
+ # pod global_modules
367
+ if pod_module && pod_module.current_all_modules
368
+ pod_module.current_all_modules.each do | m |
369
+ name = m[:name]
370
+ if name == nil || name.length == 0
371
+ if m[:names]
372
+ m[:names].each do | n |
373
+ name = n
374
+ source_module = m
375
+ target_module = module_for_name(name, @current_member_modules)
376
+ if target_module == nil
377
+ combine_modules(source_module, target_module, name, @current_member)
378
+ end
379
+ end
380
+ end
381
+ else
382
+ source_module = m
383
+ target_module = module_for_name(name, @current_member_modules)
384
+ if target_module == nil
385
+ combine_modules(source_module, target_module, name, @current_member)
386
+ end
387
+ end
388
+ end
389
+ end
390
+ end
391
+ end
392
+ end