Class: Pod::Podfile

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/cocoapods-bb-PodAssistant/podfile.rb,
lib/cocoapods-bb-PodAssistant/babybus/stable/podfile-linkline.rb,
lib/cocoapods-bb-PodAssistant/babybus/linkline/targetdefinition-linkline.rb

Defined Under Namespace

Modules: DSL Classes: TargetDefinition

Instance Method Summary collapse

Methods included from DSL

#stable!

Instance Method Details

#combine_modules(source_module, target_module, target_name, current_member) ⇒ Object

整合两个配置



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 338

def combine_modules(source_module, target_module, target_name, current_member)

    if ( target_module == nil && source_module == nil ) && ( target_name == nil || target_name.length == nil )
        return nil
    end
    source_module_name_condition = ( source_module != nil && source_module[:name] == target_name )
    target_module_name_condition = ( target_module != nil && target_module[:name] == target_name )
    source_module_names_condition = ( source_module != nil && source_module[:names].include?(target_name) )
    target_module_names_condition = ( target_module != nil && target_module[:names].include?(target_name) )
# 符合名字都在两个配置里
    condition = ( source_module_name_condition && target_module_name_condition && source_module_names_condition && target_module_names_condition )
    the_module = target_module
    if condition
        the_module = target_module
    else
        if target_module_name_condition || target_module_names_condition
            the_module = target_module
        elsif source_module_name_condition || source_module_names_condition
            the_module = source_module
        end
    end
    returned_module = {}
    default_module_keys = default_module_keys()
    if default_module_keys
        default_module_keys.each do | key |
            returned_module[key] = value_from_module(returned_module, the_module, key)
        end
    end

    returned_module[:names] = []
    returned_module[:name] = target_name
    method = returned_module[:method]
    if method == nil
        method = DEFAULT
    end
    module_with_method(method, returned_module, current_member)
end

#default_module_keysObject

默认配置key



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 134

def default_module_keys
    return [
        :name,
        :names,
        :git,
        :git_format,
        :root_path,
        :path,
        :path_format,
        :branch,
        :tag,
        :version,
        :method,
        :inhibit_warnings,
        :configurations,
        :linkage,
        :linkages,
    ]
end

#generate_pod_module_dependency_run(pod_names = []) ⇒ Object

生成pod模块配置文件



52
53
54
55
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 52

def generate_pod_module_dependency_run(pod_names=[])
    source_manager = BB::SourceManager.new()
    source_manager.generate_pod_module_dependency(pod_names)
end

#module_for_name(name, module_list) ⇒ Object

从列表中搜索得到对应配置



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 116

def module_for_name(name, module_list)
    if module_list
        module_list.each do | m |
            if name == m[:name]
                return m
            else
                m[:names].each do | n |
                    if n == name
                        return m
                    end
                end
            end
        end
    end
    return nil
end

#module_with_method(method = DEFAULT, source_module, current_member) ⇒ Object

根据请求方式调整配置 如果明确指定了方法 则使用方法 否则 使用默认方法(如果本地存在对应的项目地址就请求,否则就请求git仓库,否则报错)



172
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
215
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
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
304
305
306
307
308
309
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
335
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 172

def module_with_method(method=DEFAULT, source_module, current_member)

    if source_module == nil
        return nil
    end

    if method == nil
        method = DEFAULT
    end

    name = source_module[:name]
    git_name = name
    if name != nil && name.split("/") != nil && name.split("/").length > 0
        git_name = name.split("/")[0]
    end

    name_condition = (name != nil && name.length > 0)
    if name_condition == false
        return nil
    end

    git = source_module[:git]
    git_condition = (source_module[:git] != nil && source_module[:git].length > 0)
    git_format_condition = (source_module[:git_format] != nil && source_module[:git_format].length > 0)
    if git_condition
        git = git
    elsif git_format_condition
        git = source_module[:git_format].gsub(/\#\{git_name\}/, "\#\{git_name\}" => git_name)
    else
        git = nil
    end

    path = source_module[:path]
    root_path_condition = (source_module[:root_path] != nil && source_module[:root_path].length > 0)
    path_condition = (path != nil && path.length > 0)
    path_format_condition = (source_module[:path_format] != nil && source_module[:path_format].length > 0)
    if path_condition
        path = path
    elsif path_format_condition
        path = source_module[:path_format].gsub(/\#\{git_name\}/, "\#\{git_name\}" => git_name)
    elsif root_path_condition
        path = File.join(source_module[:root_path], git_name)
    else
        path = nil
        if current_member[:force_local] == true
            if current_member[:pathes]
                current_member[:pathes].each do | p |
                    if File.exist?(File.join(p, git_name))
                        path = File.join(p, git_name)
                    end
                end
            end
        end
    end

    branch = source_module[:branch]
    branch_condition = (branch != nil && branch.length > 0)
    tag = source_module[:tag]
    tag_condition = (tag != nil && tag.length > 0)
    version = source_module[:version]
    version_condition = (version != nil && version.length > 0)
    target_method = DEFAULT
    if path != nil && path.length > 0
        if File.exist?(path)
            target_method = LOCAL
        else
            target_method = REMOTE_VERSION
        end
    elsif git != nil && git.length > 0
        if branch_condition
            target_method = REMOTE_BRANCH
        elsif tag_condition
            target_method = REMOTE_TAG
        else
            target_method = REMOTE_GIT
        end
    elsif version_condition
        target_method = REMOTE_VERSION
    else
        if path == nil || path.length == 0
            if current_member[:pathes]
                current_member[:pathes].each do | p |
                    if File.exist?(File.join(p, git_name))
                        path = File.join(p, git_name)
                    end
                end
            end
        end

        if path != nil && path.length > 0
            target_method = LOCAL
        else
            target_method = REMOTE_VERSION
        end
    end

    inhibit_warnings_variable = source_module[:inhibit_warnings]
    if inhibit_warnings_variable == nil
        inhibit_warnings_variable = true
    end

    configurations = source_module[:configurations]
    if configurations == nil
        configurations = []
    end
    
    # linkline 插件参数获取,兼容没有插件情况 nil => nil
    linkage = source_module[:linkage]
    linkages = source_module[:linkages]
    linkageKey = :linkage if linkage.to_s.length > 0
    linkagesKey = :linkages if linkages.to_s.length > 0

    case method
    when DEFAULT
        # 根据参数判断method
        if target_method != DEFAULT
            module_with_method(target_method, source_module, current_member)
        else
            module_with_method(LOCAL, source_module, current_member)
        end
    when LOCAL
        if ( path != nil && path.length > 0 )
            if File.exist?(path)
                pod "#{name}", :path => "#{path}", :inhibit_warnings => inhibit_warnings_variable , :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
            end
        else
            module_with_method(REMOTE_VERSION, source_module, current_member)
        end
    when REMOTE_GIT
        if ( git != nil && git.length > 0 )
            pod "#{name}", :git => "#{git}", :branch => 'master', :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
        else
            module_with_method(LOCAL, source_module, current_member)
        end
    when REMOTE_VERSION
        if ( version != nil && version.length > 0 )
            pod "#{name}", "#{version}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
        else
            pod "#{name}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
        end
    when REMOTE_BRANCH
        if ( git != nil && git.length > 0 )
            if ( branch != nil && branch.length > 0 )
                pod "#{name}", :git => "#{git}", :branch => "#{branch}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
            else
                pod "#{name}", :git => "#{git}", :branch => "master", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
            end
        else
            module_with_method(LOCAL, source_module, current_member)
        end
    when REMOTE_TAG
        if ( git != nil && git.length > 0 )
            if ( tag != nil && tag.length > 0 )
                pod "#{name}", :git => "#{git}", :tag => "#{tag}", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
            else
                pod "#{name}", :git => "#{git}", :branch => "master", :inhibit_warnings => inhibit_warnings_variable, :configurations => configurations, linkagesKey => linkages, linkageKey => linkage
            end
        else
            module_with_method(LOCAL, source_module, current_member)
        end
    else
        module_with_method(LOCAL, source_module, current_member)
    end
end

#pod_assistant_pathObject

pod助手ruby文件路径



107
108
109
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 107

def pod_assistant_path()
    return BB::StableManager.pod_assistant_path
end

#pod_assistant_robot_pathObject

pod助手机器人ruby文件路径



111
112
113
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 111

def pod_assistant_robot_path()
    return BB::StableManager.pod_assistant_robot_path
end

#pod_box_module_run(pod_module) ⇒ Object



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 376

def pod_box_module_run(pod_module)
    @run_modules = []
    # 获取当前成员信息
    @current_member = pod_module.current_member
    # 获取成员信息对应的配置列表
    @current_member_modules = pod_module.current_member_modules
    # 获取全部需要执行的模块
    # pod member_modules
    if pod_module && pod_module.current_member_modules
        pod_module.current_member_modules.each do | m |
            name = m[:name]
            if name == nil || name.length == 0
                if m[:names]
                    m[:names].each do | n |
                        name = n
                        source_module = m
                        target_module = m
                        combine_modules(source_module, target_module, name, @current_member)
                    end
                end
            else
                source_module = m
                target_module = m
                combine_modules(source_module, target_module, name, @current_member)
            end
        end
    end

    # pod global_modules
    if pod_module && pod_module.current_all_modules
        pod_module.current_all_modules.each do | m |
            name = m[:name]
            if name == nil || name.length == 0
                if m[:names]
                    m[:names].each do | n |
                        name = n
                        source_module = m
                        target_module = module_for_name(name, @current_member_modules)
                        if target_module == nil
                            combine_modules(source_module, target_module, name, @current_member)
                        end
                    end
                end
            else
                source_module = m
                target_module = module_for_name(name, @current_member_modules)
                if target_module == nil
                    combine_modules(source_module, target_module, name, @current_member)
                end
            end
        end
    end
end

#pod_module_run(pod_modules, member_modules = {}, member_configs = [], ignore_dependencies_pod_names = []) ⇒ Object

pod组件合并操作(单组件) 参数说明 all_modules 业务使用组件 member_modules 项目成员模块,一般用于切本地开发使用 member_configs 项目成员工程配置 ignore_dependencies_pod_names 过滤组件,不受stable版本控制



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 81

def pod_module_run(pod_modules, member_modules = {}, member_configs = [], ignore_dependencies_pod_names=[])
    # Pod::UI.puts "Pod Module:#{pod_modules}"
    time1 = Time.new
    puts "[PodAssistant]pod组件组装开始操作时间:#{time1}".green
    source = BB::PodModule.new(pod_modules, member_modules, member_configs, true, true, ignore_dependencies_pod_names)
    pod_box_module_run(source)
    time2 = Time.new
    puts "[PodAssistant]pod组件组装结束时间:#{time2}".green
     # 获取时间差
    time = time2 - time1
    puts "pod组件组装操作耗时:#{time.to_s.send(:red)}".green
end

#project_pod_module_run(pod_modules, member_modules = {}, member_configs = [], skip_stable_check = false, ignore_dependencies_pod_names = []) ⇒ Object

pod组件合并操作(项目) 参数说明 all_modules 业务使用组件 member_modules 项目成员模块,一般用于切本地开发使用 member_configs 项目成员工程配置 skip_stable_check 是否跳过stable检测,true 采用标准pod合并操作 ignore_dependencies_pod_names 过滤组件,不受stable版本控制



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 63

def project_pod_module_run(pod_modules, member_modules = {}, member_configs = [], skip_stable_check = false, ignore_dependencies_pod_names=[])
    # Pod::UI.puts "Pod Module:#{pod_modules}"
    time1 = Time.new
    puts "[PodAssistant]项目pod组件组装开始操作时间:#{time1}".green
    source = BB::PodModule.new(pod_modules, member_modules, member_configs, false, skip_stable_check, ignore_dependencies_pod_names)
    pod_box_module_run(source)
    time2 = Time.new
    puts "[PodAssistant]项目pod组件组装结束时间:#{time2}".green
     # 获取时间差
    time = time2 - time1
    puts "项目pod组件组装操作耗时:#{time.to_s.send(:red)}".green
end

#update_business_stable_lock(installer) ⇒ Object

更新业务公共lock



102
103
104
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 102

def update_business_stable_lock(installer)
    BB::StableManager.updateBusinessStableLock(installer.pod_targets)
end

#update_common_stable_lock(installer) ⇒ Object

更新公共lock



98
99
100
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 98

def update_common_stable_lock(installer)
    BB::StableManager.updateCommonStableLock(installer.pod_targets)
end

#update_product_stable_lock(installer) ⇒ Object

更新项目lock



94
95
96
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 94

def update_product_stable_lock(installer)
    BB::StableManager.updateProductStableLock(installer.pod_targets)
end

#value_from_module(source_module, target_module, key) ⇒ Object

获取需要的对应key的值



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

def value_from_module(source_module, target_module, key)

    if target_module == nil || source_module == nil || key == nil || key.length == nil
        return nil
    end

    source_value = source_module[key]
    target_value = target_module[key]
    if target_value == nil
        return source_value
    else
        return target_value
    end

end