Class: Pod::Podfile

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/cocoapods-bb-PodAssistant/podfile.rb,
lib/cocoapods-bb-PodAssistant/command/stable/podfile-linkline.rb,
lib/cocoapods-bb-PodAssistant/command/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

整合两个配置



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
336
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 300

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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 96

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

#module_for_name(name, module_list) ⇒ Object

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



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

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仓库,否则报错)



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
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
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 134

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_box_module_run(pod_module) ⇒ 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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 338

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_local_stable = false, skip_stable_check = false) ⇒ Object

pod组件合并操作



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 52

def pod_module_run(pod_modules, member_modules = {}, member_configs = [], ignore_local_stable = false, skip_stable_check = false)
    # 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, ignore_local_stable, skip_stable_check)
    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(businessSpecName, pod_targets) ⇒ Object

更新业务公共lock



73
74
75
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 73

def update_business_stable_lock(businessSpecName, pod_targets)
    BB::StableManager.updateBusinessStableLock(businessSpecName, pod_targets)
end

#update_common_stable_lock(installer) ⇒ Object

更新公共lock



69
70
71
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 69

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

#update_product_stable_lock(installer) ⇒ Object

更新项目lock



65
66
67
# File 'lib/cocoapods-bb-PodAssistant/podfile.rb', line 65

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

#value_from_module(source_module, target_module, key) ⇒ Object

获取需要的对应key的值



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

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