cocoapods-byte-csjm 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 557aba2b4be3b65803702667f275d8e26d58a9b649731570920cb10a2a3283d0
4
+ data.tar.gz: 38fb1f7a1fb6e6ba068c9b6ebac4238f6261ac39829f6a67bfda43f6014067aa
5
+ SHA512:
6
+ metadata.gz: da1aeb813ffa790f061b05f34804bf12b3d5c292e6b31bd9bdfbbd023d523f66cb1c3805cdc28f51fc5343c2d4383c02582c022ed5cc651c5c72aba56f397b93
7
+ data.tar.gz: 855c37ba8174dc683bc872cbff1d75ec5105f3e5e7c209904ba5c60a19a7109a63bb9eb8fff27c1d1281bc466fca716694a8d595f9a0bbd8f2ffe5eb45337f2d
@@ -0,0 +1,126 @@
1
+ module GM
2
+
3
+ class BuildConfig
4
+
5
+ def self.get_load_key
6
+ :gm_auto_load
7
+ end
8
+
9
+ def self.get_update_key
10
+ :gm_auto_update
11
+ end
12
+
13
+ def self.get_load_detect_key
14
+ :gm_load_detect
15
+ end
16
+
17
+ def self.get_load_whitelist_key
18
+ :auto_load_whitelist
19
+ end
20
+
21
+ def self.update_value_last_version
22
+ return "last" ## 最新版本
23
+ end
24
+
25
+ def self.update_value_last_stable_version
26
+ return "last_stable" ## 最新稳定版本
27
+ end
28
+
29
+ def self.update_value_non
30
+ return "not_update" ## 不自动更新
31
+ end
32
+
33
+ def self.mediation_name
34
+ return "Ads-Fusion-CN-Beta/CSJMediation"
35
+ end
36
+
37
+ def self.get_all_config
38
+ [BuildConfig.get_update_key,BuildConfig.get_load_key,BuildConfig.get_load_detect_key]
39
+ end
40
+ end
41
+
42
+ class Adn_Adapter
43
+ ADNADAPTER = Hash[
44
+ # 'Ads-CN' => 'ABUAdCsjAdapter',
45
+ 'UnityAds' => 'CSJMUnityAdapter',
46
+ 'Google-Mobile-Ads-SDK'=> 'CSJMAdmobAdapter',
47
+ 'BaiduMobAdSDK'=> 'CSJMBaiduAdapter',
48
+ 'GDTMobSDK'=> 'CSJMGdtAdapter',
49
+ 'SigmobAd-iOS'=> 'CSJMSigmobAdapter',
50
+ 'KSAdSDK'=> 'CSJMKsAdapter',
51
+ 'KlevinAdSDK'=> 'CSJMKlevinAdapter',
52
+ 'MintegralAdSDK'=> 'CSJMMintegralAdapter',
53
+ ].freeze
54
+
55
+ SERVERMAPADAPTER = Hash[
56
+ 'unity' => 'CSJMUnityAdapter',
57
+ 'admob'=> 'CSJMAdmobAdapter',
58
+ 'baidu'=> 'CSJMBaiduAdapter',
59
+ 'gdt'=> 'CSJMGdtAdapter',
60
+ 'sigmob'=> 'CSJMSigmobAdapter',
61
+ 'ks'=> 'CSJMKsAdapter',
62
+ 'klevin'=> 'CSJMKlevinAdapter',
63
+ 'mtg'=> 'CSJMMintegralAdapter',
64
+ ].freeze
65
+
66
+ SERVERMAPADN = Hash[
67
+ 'UnityAds' => 'unity',
68
+ 'Google-Mobile-Ads-SDK'=> 'admob',
69
+ 'BaiduMobAdSDK'=> 'baidu',
70
+ 'GDTMobSDK'=> 'gdt',
71
+ 'SigmobAd-iOS'=> 'sigmob',
72
+ 'KSAdSDK'=> 'ks',
73
+ 'KlevinAdSDK'=> 'klevin',
74
+ 'MintegralAdSDK'=> 'mtg',
75
+ ].freeze
76
+
77
+ def self.get_adn_abbreviation(name)
78
+ SERVERMAPADN[name]
79
+ end
80
+
81
+ def self.get_adapter_from_adn_abbreviation(name)
82
+ SERVERMAPADAPTER[name]
83
+ end
84
+
85
+ def self.is_adn?(name)
86
+ ADNADAPTER.has_key?(name)
87
+ end
88
+
89
+ def self.is_adapter?(name)
90
+ ADNADAPTER.has_value?(name)
91
+ end
92
+
93
+ def self.get_adapter(name)
94
+ adapter = ''
95
+ if is_adn?(name)
96
+ adapter = ADNADAPTER[name]
97
+ end
98
+ adapter
99
+ end
100
+
101
+ def self.get_adn(name)
102
+ adn_name = ''
103
+ if is_adapter?(name)
104
+ ## .index 在调试时候会报错
105
+ ADNADAPTER.select{ |key, value|
106
+ if value == name
107
+ adn_name = key
108
+ break
109
+ end
110
+ true
111
+ }
112
+ end
113
+ adn_name
114
+ end
115
+
116
+ def self.get_all_adapter
117
+ ADNADAPTER.values
118
+ end
119
+
120
+ def self.get_all_adn
121
+ ADNADAPTER.keys
122
+ end
123
+ end
124
+
125
+
126
+ end
@@ -0,0 +1 @@
1
+ ## CSJ相关的功能将在这里收敛
@@ -0,0 +1,8 @@
1
+ module CocoapodsByteCsjm
2
+ VERSION = "0.0.3"
3
+ class Version
4
+ def self.version
5
+ VERSION
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,753 @@
1
+ require 'cocoapods'
2
+ require_relative 'config'
3
+ require 'singleton'
4
+ require 'cocoapods-byte-csjm/gem_version'
5
+ require 'yaml'
6
+ require 'digest'
7
+ require "thread"
8
+ require_relative 'net'
9
+ require 'xcodeproj'
10
+ require 'json'
11
+
12
+
13
+ module CSJMPlugin
14
+ def CSJMPlugin.action()
15
+ recoder= GM::Recorder.instance
16
+ if recoder.is_load_plugin
17
+ yield(recoder) if block_given?
18
+ end
19
+ end
20
+ end
21
+
22
+ module GM
23
+ # lock文件读写
24
+ #
25
+ class LockfileCSJM
26
+ def initialize(hash)
27
+ @internal_data = hash
28
+ end
29
+ # 读取lock文件
30
+ # @requrn lock的json内容
31
+ # @param 文件路径
32
+ def self.read_from_path(path)
33
+ if File.exist?(path)
34
+ return true, YAML.load_file(path)
35
+ end
36
+ return false, nil
37
+ end
38
+ # 写入lock文件
39
+ def write_to_disk(path)
40
+ begin
41
+ is_exist, existing = LockfileCSJM.read_from_path(path)
42
+ return if existing == @internal_data
43
+ rescue Exception
44
+ end
45
+ File.open(path, 'w+') do |f|
46
+ YAML.dump(@internal_data,f)
47
+ end
48
+ end
49
+ end
50
+
51
+ # 记录CSJM 版本信息
52
+ #
53
+ class GmInfo
54
+ attr_accessor :name
55
+ attr_accessor :version
56
+ def initialize(name, version)
57
+ @name = name
58
+ @version = version
59
+ end
60
+ def to_hash
61
+ hash = {}
62
+ hash["NAME"] = @name
63
+ hash["VERSION"] = @version
64
+ hash
65
+ end
66
+ def self.from_hash(hash)
67
+ GmInfo.new(hash["NAME"],hash["VERSION"])
68
+ end
69
+ end
70
+
71
+ # 媒体配置记录
72
+ #
73
+ class Note
74
+ attr_accessor :auto_load
75
+ attr_accessor :auto_update
76
+ attr_accessor :load_detect
77
+ def get_update(update_value)
78
+ value = ''
79
+ case update_value
80
+ when true
81
+ value = GM::BuildConfig.update_value_last_version
82
+ when false
83
+ value = GM::BuildConfig.update_value_non
84
+ when String
85
+ value = update_value
86
+ else
87
+ raise ArgumentError, "CSJM error: `#{update_value.inspect}`, should be a boolean or string."
88
+ end
89
+ value
90
+ end
91
+ end
92
+
93
+ class GlobalNote < Note
94
+ attr_accessor :auto_load_whitelist
95
+ def initialize(auto_load = true , auto_update = GM::BuildConfig.update_value_last_version, load_detect = true, auto_load_whitelist = [])
96
+ @auto_load = auto_load
97
+ @auto_update = get_update auto_update
98
+ @load_detect = load_detect
99
+ @auto_load_whitelist = auto_load_whitelist
100
+ end
101
+
102
+ def has_set_load?(adn_name)
103
+ adn_name = Pod::Specification.root_name(adn_name)
104
+ if @auto_load_whitelist.size == 0 || @auto_load_whitelist.include?(adn_name)
105
+ return true
106
+ end
107
+ false
108
+ end
109
+
110
+ def to_hash
111
+ hash = {}
112
+ hash["AUTO_LOAD"] = @auto_load
113
+ hash["AUTO_UPDATE"] = @auto_update
114
+ hash["LOAD_DETECT"] = @load_detect
115
+ hash["AUTO_LOAD_WHITELIST"] = @auto_load_whitelist
116
+ hash
117
+ end
118
+
119
+ def self.from_hash(hash)
120
+ global_note = GlobalNote.new()
121
+ global_note.auto_load = hash["AUTO_LOAD"] if hash.has_key?("AUTO_LOAD")
122
+ global_note.auto_update = hash["AUTO_UPDATE"] if hash.has_key?("AUTO_UPDATE")
123
+ global_note.load_detect = hash["LOAD_DETECT"] if hash.has_key?("LOAD_DETECT")
124
+ global_note.auto_load_whitelist = hash["AUTO_LOAD_WHITELIST"] if hash.has_key?("AUTO_LOAD_WHITELIST")
125
+ global_note
126
+ end
127
+ end
128
+
129
+ class AdnNote < Note
130
+
131
+ attr_accessor :adn_name
132
+ attr_accessor :adn_version
133
+ attr_accessor :adapter_name
134
+ attr_accessor :adapter_original_version ##加载的版本号
135
+ attr_accessor :adapter_expected_version ##期望加载的版本号
136
+
137
+ def initialize(adn_name, auto_load = false , auto_update = GM::BuildConfig.update_value_non, load_detect = false)
138
+ @adn_name = adn_name
139
+ @adapter_name = GM::Adn_Adapter.get_adapter adn_name
140
+ @auto_load = auto_load
141
+ @auto_update = get_update auto_update
142
+ @load_detect = load_detect
143
+ @adapter_original_version = ""
144
+ @adapter_expected_version = ""
145
+ end
146
+
147
+ def to_hash
148
+ hash = {}
149
+ hash["ADN_NAME"] = @adn_name
150
+ hash["ADN_VERSION"] = @adn_version
151
+ hash["ADAPTER_NAME"] = @adapter_name
152
+ hash["ADAPTER_ORIGINAL_VERSION"] = @adapter_original_version
153
+ hash["ADAPTER_EXPECTED_VERSION"] = @adapter_expected_version
154
+ hash["AUTO_LOAD"] = @auto_load
155
+ hash["AUTO_UPDATE"] = @auto_update
156
+ hash["LOAD_DETECT"] = @load_detect
157
+ hash
158
+ end
159
+
160
+ def self.from_hash(hash)
161
+ note = AdnNote.new(hash["ADN_NAME"],hash["AUTO_LOAD"],hash["AUTO_UPDATE"],hash["LOAD_DETECT"])
162
+ note.adn_name = hash["ADN_NAME"]
163
+ note.adn_version = hash["ADN_VERSION"]
164
+ note.adapter_name = hash["ADAPTER_NAME"]
165
+ note.adapter_original_version = hash["ADAPTER_ORIGINAL_VERSION"]
166
+ note.adapter_expected_version = hash["ADAPTER_EXPECTED_VERSION"]
167
+ note
168
+ end
169
+
170
+ end
171
+
172
+ # 对应cocoapods target
173
+ #
174
+ class Target
175
+
176
+ attr_accessor :is_release_target
177
+ attr_accessor :referenced_target
178
+ attr_reader :label
179
+ attr_accessor :gm_info
180
+ attr_accessor :nots_info
181
+
182
+ def initialize(label)
183
+ @label = label.clone
184
+ @is_release_target = false
185
+ end
186
+
187
+ def find_note(adn_name)
188
+ @nots_info ||= {}
189
+ global_note = GM::Recorder.instance.global_note
190
+ note = (@nots_info.has_key?(adn_name) && @nots_info[adn_name]) || AdnNote.new(adn_name, global_note.auto_load, global_note.auto_update, global_note.load_detect)
191
+ @nots_info[adn_name] = note unless @nots_info.has_key?(adn_name)
192
+ note
193
+ end
194
+
195
+ def has_adn?(adn_name)
196
+ GM::Adn_Adapter.is_adn?(adn_name) && @nots_info.has_key?(adn_name)
197
+ end
198
+
199
+ def is_adn_update_or_detect?(adn_name)
200
+ result = is_adn_update?(adn_name) || is_adn_detect?(adn_name)
201
+ result
202
+ end
203
+
204
+ def is_adn_update?(adn_name)
205
+ result = has_adn?(adn_name) && @nots_info[adn_name].auto_update != GM::BuildConfig.update_value_non && GM::Recorder.instance.global_note.has_set_load?(adn_name)
206
+ result
207
+ end
208
+
209
+ def is_adn_detect?(adn_name)
210
+ has_adn?(adn_name) && @nots_info[adn_name].load_detect
211
+ end
212
+
213
+ def to_hash
214
+ hash = {}
215
+ hash["LABEL"] = @label
216
+ hash["IS_RELEASE_TARGET"] = @is_release_target
217
+ hash["GM_INFO"] = @gm_info.to_hash
218
+ hash["NOTS_INFO"] = {}
219
+ @nots_info.each {|key, value|
220
+ hash["NOTS_INFO"][key] = value.to_hash
221
+ }
222
+ hash
223
+ end
224
+
225
+ def self.from_hash(hash)
226
+ target = Target.new(hash["LABEL"])
227
+ target.is_release_target = true
228
+ target.gm_info = GmInfo.from_hash hash["GM_INFO"] if hash.has_key?("GM_INFO")
229
+ target.nots_info ||= {}
230
+ hash["NOTS_INFO"].each do |name, note_info|
231
+ target.nots_info[name] = AdnNote.from_hash note_info
232
+ end
233
+ target
234
+ end
235
+
236
+ end
237
+
238
+ # 记录方
239
+ #
240
+ class Recorder
241
+
242
+ include Singleton
243
+ attr_accessor :global_note
244
+ attr_accessor :target_info
245
+ attr_reader :is_load_plugin
246
+ attr_reader :plugin_version
247
+ attr_reader :lockfile_data
248
+ def set_plugin_load(is_load)
249
+ @is_load_plugin = is_load
250
+ @plugin_version = CocoapodsByteCsjm::Version.version
251
+ end
252
+
253
+ def add_global_note(note)
254
+ @global_note = note
255
+ end
256
+
257
+ def find_global_note(option, is_force_update = false)
258
+
259
+ return @global_note if !is_force_update && @global_note != nil
260
+ @global_note = GlobalNote.new(false, GM::BuildConfig.update_value_non, false)
261
+ load_key = GM::BuildConfig.get_load_key
262
+ update_key = GM::BuildConfig.get_update_key
263
+ load_detect_key = GM::BuildConfig.get_load_detect_key
264
+ auto_load_whitelist_key = GM::BuildConfig.get_load_whitelist_key
265
+ case option
266
+ when true, false
267
+ @global_note = GM::GlobalNote.new(option,option,option,{})
268
+ when Hash
269
+ load_value = option.has_key?(load_key) ? option[load_key] : true
270
+ update_value = option.has_key?(update_key) ? option[update_key] : true
271
+ detect_value = option.has_key?(load_detect_key) ? option[load_detect_key] : true
272
+ auto_load_whitelist = option.has_key?(auto_load_whitelist_key)?option[auto_load_whitelist_key] : {}
273
+ @global_note = GM::GlobalNote.new(load_value, update_value,detect_value,auto_load_whitelist)
274
+ else
275
+ raise ArgumentError, "CSJM error: `#{option.inspect}`, should be a boolean or hash."
276
+ end
277
+ @global_note
278
+ end
279
+
280
+ def get_global_note
281
+ @global_note
282
+ end
283
+
284
+ def get_target(label)
285
+ @target_info ||= {}
286
+ @target_info[label] ||= Target.new(label)
287
+ end
288
+
289
+ def to_hash
290
+ hash = {}
291
+ hash["IS_LOAD_PLUGIN"] = @is_load_plugin
292
+ hash["PLUGIN_VERSION"] = @plugin_version
293
+ hash["GLOBAL_NOTE"] = @global_note.to_hash
294
+ hash["TARGET_INFO"] = {}
295
+ @target_info.each {|item, value|
296
+ hash["TARGET_INFO"][item] = value.to_hash
297
+ }
298
+ checksum = Digest::SHA1.hexdigest(hash.inspect)
299
+ checksum = checksum.encode('UTF-8') if checksum.respond_to?(:encode)
300
+ hash["RECODER_CHECKSUM"] = checksum
301
+ hash
302
+ end
303
+ end
304
+
305
+ # 对应cocoapods 的Specification
306
+ #
307
+ class SpecificationInfo
308
+ @@possibilities = {}
309
+ def self.update(name = '', possibilities)
310
+ if name.length > 0
311
+ @@possibilities[name] ||= []
312
+ @@possibilities[name] = @@possibilities[name] | possibilities
313
+ end
314
+ end
315
+
316
+ def self.get_info()
317
+ @@possibilities
318
+ end
319
+
320
+ def self.get_a_specfication(name, version)
321
+ result = @@possibilities[name].find { |specification|
322
+ specification.version.version == version
323
+ }
324
+ result
325
+ end
326
+
327
+ def self.get_specfication(info_list = [])
328
+
329
+ ##请注意, 这里可能获取不到对应的Specfication 实例, 此时需要报错并提示媒体使用pod update
330
+ result = info_list.map{|info|
331
+ info['is_find'] = false
332
+ adapter_name = GM::Adn_Adapter.get_adapter_from_adn_abbreviation info["adn_name"]
333
+ @@possibilities[adapter_name].find { |specification|
334
+ info['is_find'] = true if specification.version.version == info["adn_adapter_version"]
335
+ specification.version.version == info["adn_adapter_version"]
336
+ }
337
+ }.flatten
338
+ unfind_list = info_list.select{ |info|
339
+ info['is_find'] == false
340
+ }
341
+ if unfind_list.size > 0
342
+ ins = get_info
343
+ str = "adapters("
344
+ unfind_list.each {|item|
345
+ str << GM::Adn_Adapter.get_adapter_from_adn_abbreviation(info["item"]) + "->" + item["adn_adapter_version"]+ " "
346
+ }
347
+ str << ")"
348
+ raise "CSJM error: #{str} 版本未找到,请执行 `pod update --verbose`"
349
+ end
350
+ result
351
+ end
352
+ end
353
+
354
+ # 版本处理
355
+ #
356
+ class VersionAnalyzer
357
+
358
+ def self.resolve_release_target(target, specs)
359
+
360
+ is_exist, hash = GM::LockfileCSJM.read_from_path(File.expand_path("#{Pod::Config.instance.installation_root}/Podfile.csjm.lock"))
361
+ if is_exist
362
+ ## 校验lock文件有无改动
363
+ checksum = hash.delete("RECODER_CHECKSUM")
364
+ verified_checksum = Digest::SHA1.hexdigest(hash.inspect).encode('UTF-8') if checksum.respond_to?(:encode)
365
+ if verified_checksum != checksum
366
+ raise "CSJM error: Podfile.csjm.lock 文件校验失败, 请检查该文件是否被改动, 尝试删掉该文件并执行 'pod install', 若你确认没有被修改,请联系技术支持"
367
+ end
368
+ ## 校验对应的target是否存在
369
+ if !hash["TARGET_INFO"].has_key?(target.gm_build_config.referenced_target)
370
+ raise "CSJM error:#{target.gm_build_config.label} 设置了'is_release_target=true' 但是在 Podfile.csjm.lock文件中没有找到target的信息"
371
+ end
372
+
373
+ ## 校验gm版本是否符合
374
+ gm_spec = specs.find do |spec|
375
+ GM::BuildConfig.mediation_name==spec.spec.name
376
+ end
377
+ if gm_spec.nil?
378
+ raise "CSJM error:#{GM::BuildConfig.mediation_name} not found in #{target.label}"
379
+ end
380
+ referenced_target = GM::Target.from_hash hash["TARGET_INFO"][target.gm_build_config.referenced_target]
381
+ if gm_spec.spec.version.version != referenced_target.gm_info.version
382
+ raise "CSJM error:#{GM::BuildConfig.mediation_name} version has change(#{referenced_target.gm_info.version}->#{gm_spec.spec.version.version}),please check"
383
+ end
384
+ ## 替换各adapter的版本
385
+ referenced_target.nots_info.each do |adn_name, note|
386
+
387
+ original_adapter_sp = specs.find{|spec|
388
+ spec.spec.name == note.adapter_name
389
+ }
390
+ if original_adapter_sp.nil?
391
+ raise "CSJM error:#{note.adapter_name} not found"
392
+ end
393
+ ##校验adn是否更换了版本
394
+ original_adn_sp = specs.find do |spec|
395
+ spec.spec.name == note.adn_name
396
+ end
397
+ if original_adn_sp.spec.version.version != note.adn_version
398
+ raise "CSJM error:#{note.adn_name} version has change(#{note.adn_version}->#{original_adapter_sp.spec.version.version}),please check"
399
+ end
400
+ if note.adapter_expected_version.length > 0 && original_adapter_sp.spec.version.version != note.adapter_expected_version
401
+ title_options = { :verbose_prefix => '-> '.green }
402
+ Pod::UserInterface.titled_section("#{note.adn_name} will change adapter version , the current adapter(#{note.adapter_name}) version will change from #{original_adapter_sp.spec.version.version} to #{note.adapter_expected_version}", title_options)
403
+ replace_sp = GM::SpecificationInfo.get_a_specfication note.adapter_name, note.adapter_expected_version
404
+ if replace_sp
405
+ specs << Pod::Resolver::ResolverSpecification.new(replace_sp, original_adapter_sp.used_by_non_library_targets_only, replace_sp.spec_source)
406
+ specs.delete original_adapter_sp
407
+ end
408
+ end
409
+ end
410
+ specs.sort_by!{|spec| spec.spec.name}
411
+ else
412
+ raise "CSJM error: #{File.expand_path("#{Pod::Config.instance.installation_root}/Podfile.csjm.lock")} not found, please check"
413
+ end
414
+ end
415
+
416
+ def self.resolve_last(target, specs)
417
+
418
+ gm_spec = nil
419
+ adn_specs = specs.select do |spec|
420
+ name = spec.spec.name
421
+ if name == GM::BuildConfig.mediation_name
422
+ gm_spec = spec
423
+
424
+ target.gm_build_config.gm_info = GM::GmInfo.new(spec.spec.name, spec.spec.version.version)
425
+ end
426
+ if GM::Adn_Adapter.is_adapter?(name)
427
+ adn_note = target.gm_build_config.find_note GM::Adn_Adapter.get_adn name
428
+ adn_note.adapter_name = name
429
+ adn_note.adapter_original_version = spec.spec.version.version
430
+ elsif GM::Adn_Adapter.is_adn?(name)
431
+ adn_note = target.gm_build_config.find_note name
432
+ adn_note.adn_version = spec.spec.version.version
433
+ end
434
+ target.gm_build_config.is_adn_update?(name) ## 这里去掉不更新但版本校验功能
435
+ end
436
+ raise "CSJM error: #{GM::BuildConfig.mediation_name} not found,please check" if gm_spec == nil
437
+ adn_info_list = adn_specs.map{|adn_spec|
438
+ adn_note = target.gm_build_config.find_note adn_spec.spec.name
439
+ adn_note.adn_version = adn_spec.spec.version.version
440
+ {"adn_name" => GM::Adn_Adapter.get_adn_abbreviation(adn_spec.spec.name),"adn_version" => adn_spec.spec.version.version}
441
+ # {"adn_name" => "ks","adn_version" => adn_spec.spec.version.version}
442
+ # {"adn_name" => adn_spec.spec.name,"adn_version" => adn_spec.spec.version.version, "auto_update" => adn_note.auto_update, "load_detect" => adn_note.load_detect, "adapter_name" => adn_note.adapter_name, "adapter_version" => adn_note.adapter_original_version}
443
+ } if gm_spec
444
+ ## 网络请求
445
+ response_data = request_adapter gm_spec.spec.version.version, adn_info_list
446
+
447
+ result = GM::SpecificationInfo.get_specfication response_data
448
+ result.each{|item|
449
+
450
+ original_sp = specs.find{|spec|
451
+ spec.spec.name == item.name
452
+ }
453
+ adn_name = GM::Adn_Adapter.get_adn item.name
454
+ adn_note = target.gm_build_config.find_note adn_name
455
+ adn_note.adapter_expected_version = item.version.version
456
+ if original_sp && original_sp.spec.version.version == item.version.version
457
+ title_options = { :verbose_prefix => '-> '.green }
458
+ Pod::UserInterface.titled_section("#{adn_name} has set version update or check, the current adapter(#{item.name}) version(#{item.version.version}) is as expected", title_options)
459
+ else
460
+
461
+ if original_sp && original_sp.spec.version.version != item.version.version ## 更新到最新版本 或 最新稳定版本
462
+ if target.gm_build_config.is_adn_update?(adn_name)
463
+ # puts '开始更新版本'
464
+ title_options = { :verbose_prefix => '-> '.green }
465
+ Pod::UserInterface.titled_section("#{adn_name} will change adapter version , the current adapter(#{item.name}) version will change from #{original_sp.spec.version.version} to #{item.version.version}", title_options)
466
+ specs << Pod::Resolver::ResolverSpecification.new(item, original_sp.used_by_non_library_targets_only, item.spec_source)
467
+ specs.delete original_sp
468
+ elsif target.gm_build_config.is_adn_detect?(adn_name) ##媒体关闭了自动更新,只选择检查版本是否适配
469
+ ## 版本校验功能暂时去掉 , 一期不上,后续具体看情况
470
+ # puts '开始校验版本'
471
+ # if item.version.version != original_sp.spec.version.version
472
+ # raise "CSJM error:#{adn_name} has set the version check of the adapter(#{item.name}), current version does not match. please change your version. The current version is #{original_sp.spec.version.version} but the expected version is #{item.version.version}"
473
+ # end
474
+ else
475
+ # puts '什么也不做'
476
+ end
477
+ end
478
+ end
479
+ }
480
+ specs.sort_by!{|spec| spec.spec.name}
481
+ end
482
+
483
+ def self.delete_invalid_adapters(target, specs)
484
+ un_den_adn_list= GM::Adn_Adapter.get_all_adn - specs.map(&:spec).map(&:name).map do |item|
485
+ GM::Adn_Adapter.is_adn?(item) ? Pod::Specification.root_name(item) : nil
486
+ end.compact.uniq
487
+ un_den_adapter_list = []
488
+ un_den_adapter_list = un_den_adn_list.map {|item|
489
+ GM::Adn_Adapter.get_adapter item
490
+ }
491
+ specs.delete_if { |spec|
492
+ hh = !GM::Recorder.instance.global_note.auto_load_whitelist.include?(Pod::Specification.root_name(spec.spec.name))
493
+ result = un_den_adapter_list.include?(Pod::Specification.root_name(spec.spec.name)) && !GM::Recorder.instance.global_note.auto_load_whitelist.include?(Pod::Specification.root_name(spec.spec.name))
494
+ if result
495
+ title_options = { :verbose_prefix => '-> '.red}
496
+ Pod::UserInterface.titled_section("remove #{spec.spec.name}", title_options)
497
+ end
498
+ result
499
+ }
500
+ end
501
+
502
+ def self.get_package_name
503
+ project_path = Pod::Config.instance.project_root
504
+ # pattern = File.join(project_path, '*.xcodeproj') # 匹配所有子目录下的 .xcodeproj 文件
505
+ # xcodeproj_path = Dir.glob(pattern).first
506
+ xcodeprojs = project_path.children.select { |e| e.fnmatch('*.xcodeproj') }
507
+ if xcodeprojs.size == 1
508
+ package_name_list = Array.new
509
+ xcodeproj_path = xcodeprojs.first
510
+ project = Xcodeproj::Project.open(xcodeproj_path)
511
+ project.targets.map(&:build_configuration_list).map(&:build_configurations).each do |item|
512
+ package_name_list << item[1].simple_attributes_hash['buildSettings']['PRODUCT_BUNDLE_IDENTIFIER']
513
+ end
514
+ package_name_list.uniq
515
+ else
516
+ raise Informative, 'Could not automatically select an Xcode project. ' \
517
+ "Specify one in your Podfile like so:\n\n" \
518
+ " project 'path/to/Project.xcodeproj'\n"
519
+ end
520
+ end
521
+
522
+ def self.request_adapter(m_version, adn_list)
523
+
524
+ package_name = get_package_name
525
+ body = Hash["package_name"=>package_name, "mediation_version"=>m_version, "os_type"=>"ios", "list"=>adn_list]
526
+ Pod::UserInterface.section '[DEBUG]CSJM plugin Network request data' do
527
+ puts "请求信息:#{body}"
528
+ end
529
+ data = GM::Network.request_adapter(body)
530
+ if data["code"] == "PG0000"
531
+ ## 请求adn数目和返回adapter 个数不一致时进行报错处理
532
+ result = data["data"]
533
+ if result.size != adn_list.size
534
+ unfind_adn_list = adn_list.map do |hash|
535
+ if hash["adn_name"] != result.find { |h| h["adn_version"] == hash["adn_version"] }&.dig("adn_name")
536
+ { "adn_name" => hash["adn_name"], "adn_version" => hash["adn_version"] }
537
+ end
538
+ end.compact
539
+ raise "CSJM error:未查找到与#{JSON.generate(unfind_adn_list)}匹配的Adadpter,请更新SDK至合适版本,如有疑问请联系技术支持。"
540
+ end
541
+ return data["data"]
542
+ else
543
+ ##业务逻辑异常的提示
544
+ case data["code"]
545
+ when "PG0201"
546
+ raise "CSJM error: #{data["message"]}(应用ID:#{package_name}),请使用在平台注册的应用ID,如有疑问请联系技术支持。"
547
+ when "21018" ,"PG21018"
548
+ raise "CSJM error: #{data["message"]}(应用ID:#{package_name}),如有疑问请联系技术支持。"
549
+ else
550
+ raise "CSJM error: #{data["message"]}(应用ID:#{package_name}),如有疑问请联系技术支持。"
551
+ end
552
+ end
553
+ end
554
+
555
+ def self.is_update?(value)
556
+ is_auto_update?(value) || is_stable_update?(value)
557
+ end
558
+
559
+ def self.is_auto_update?(value)
560
+ value == GM::BuildConfig.update_value_last_version
561
+ end
562
+
563
+ def self.is_stable_update?(value)
564
+ value == GM::BuildConfig.update_value_last_stable_version
565
+ end
566
+ end
567
+ end
568
+
569
+ class Xcodeproj::Project::Object::XCBuildConfiguration
570
+ attr_accessor :simple_attributes_hash
571
+ end
572
+
573
+ class Pod::Resolver
574
+
575
+ alias_method :original_search_for, :search_for
576
+ def search_for(dependency)
577
+ possibilities = original_search_for(dependency) ##返回不可变数组
578
+ CSJMPlugin.action do |recoder|
579
+ GM::SpecificationInfo.update dependency.name , possibilities
580
+ end
581
+ possibilities
582
+ end
583
+
584
+ alias_method :original_specifications_for_dependency, :specifications_for_dependency
585
+ def specifications_for_dependency(dependency, additional_requirements = [])
586
+ CSJMPlugin.action do |recoder|
587
+ if additional_requirements.length > 0 && GM::Adn_Adapter.is_adapter?(dependency.name)
588
+ additional_requirements = []
589
+ dependency = Pod::Dependency.new(dependency.name)
590
+ end
591
+ end
592
+ original_specifications_for_dependency(dependency, additional_requirements)
593
+ end
594
+ end
595
+
596
+ class Pod::Installer::Analyzer
597
+
598
+ alias_method :original_resolve_dependencies, :resolve_dependencies
599
+ def resolve_dependencies(locked_dependencies)
600
+ resolver_specs_by_target = original_resolve_dependencies(locked_dependencies)
601
+ CSJMPlugin.action do |recoder|
602
+ resolver_specs_by_target.each do |target, specs|
603
+ if specs.length > 0
604
+ Pod::UserInterface.section 'CSJM plugin remove invalid adapter dependencie from loaded dependencies ' do
605
+ GM::VersionAnalyzer.delete_invalid_adapters target, specs
606
+ end if GM::Recorder.instance.get_global_note.auto_load
607
+
608
+ if target.gm_build_config.is_release_target
609
+ Pod::UserInterface.section "CSJM plugin is detected that #{target.label} target is set to `gm_release_target!`, start configuration" do
610
+ GM::VersionAnalyzer.resolve_release_target target, specs
611
+ end
612
+ else
613
+ Pod::UserInterface.section 'CSJM plugin start update or detect dependencies ' do
614
+ GM::VersionAnalyzer.resolve_last target, specs
615
+ end
616
+ Pod::UserInterface.section 'CSJM plugin write Podfile.csjm.lock' do
617
+ write_lock_file recoder
618
+ end
619
+ end
620
+ end
621
+ end
622
+ end
623
+ resolver_specs_by_target
624
+ end
625
+
626
+ ## 写入lock文件
627
+ def write_lock_file(recoder)
628
+ GM::LockfileCSJM.new(recoder.to_hash).write_to_disk(File.expand_path("#{Pod::Config.instance.installation_root}/Podfile.csjm.lock"))
629
+ end
630
+ end
631
+
632
+ module Pod
633
+ class Podfile
634
+
635
+ module DSL
636
+ def use_gm_adapter_update!(option = true)
637
+ current_target_definition.use_gm_adapter_update!(option)
638
+ end
639
+
640
+ def gm_release_target!(option = true)
641
+ current_target_definition.gm_release_target!(option)
642
+ end
643
+
644
+ alias_method :original_pod, :pod
645
+ def pod(name = nil, *requirements)
646
+ CSJMPlugin.action do |recoder|
647
+ if recoder.get_global_note.auto_load
648
+ unless current_target_definition.is_add_adapter_dependencys
649
+ current_target_definition.is_add_adapter_dependencys = true
650
+ Pod::UserInterface.section 'CSJM plugin start auto load dependencies ' do
651
+ GM::Adn_Adapter.get_all_adapter.each {|item|
652
+ if GM::Recorder.instance.global_note.auto_load_whitelist.include?(GM::Adn_Adapter.get_adn item) || GM::Recorder.instance.global_note.auto_load_whitelist.size==0
653
+ title_options = { :verbose_prefix => '-> '.green }
654
+ Pod::UserInterface.titled_section("add #{item}", title_options)
655
+ current_target_definition.store_pod(item,[String.new(">=0")] )
656
+ end
657
+ }
658
+ end
659
+ end
660
+ end
661
+
662
+ end
663
+ original_pod(name, *requirements)
664
+ end
665
+
666
+ alias_method :original_plugin, :plugin
667
+ def plugin(name, options = {})
668
+ GM::Recorder.instance.set_plugin_load true if name == 'cocoapods-byte-csjm'
669
+ original_plugin(name, options)
670
+ end
671
+ end
672
+
673
+ class TargetDefinition
674
+
675
+ attr_reader :gm_release_target
676
+ attr_accessor :is_add_adapter_dependencys
677
+ attr_reader :global_gm_build_config
678
+ attr_reader :gm_build_config
679
+
680
+
681
+ def gm_release_target!(option = true)
682
+
683
+ raise ArgumentError, "CSJM error: The `gm_release_target!` configuration item needs to be set in a specific target, do not set it globally" if @label == "Pods"
684
+ case option
685
+ when true
686
+ name = String.new("T-") << label
687
+ @gm_build_config = GM::Recorder.instance.get_target name
688
+ @gm_build_config.is_release_target = option
689
+ @gm_build_config.referenced_target = name
690
+ when Hash
691
+ @gm_build_config = GM::Recorder.instance.get_target String.new("T-") << label
692
+ @gm_build_config.is_release_target = true
693
+ @gm_build_config.referenced_target = String.new("T-") << option[:referenced]
694
+ else
695
+ raise ArgumentError, "CSJM error: `#{option.inspect}`, should be a true or a target name"
696
+ end
697
+ end
698
+
699
+ def use_gm_adapter_update!(option)
700
+ @global_gm_build_config = GM::Recorder.instance.find_global_note option
701
+
702
+
703
+ end
704
+
705
+
706
+ alias_method :original_parse_inhibit_warnings, :parse_inhibit_warnings
707
+ def parse_inhibit_warnings(name, requirements)
708
+
709
+ CSJMPlugin.action do |recoder|
710
+ options = requirements.last || {}
711
+ name = Specification.root_name(name)
712
+ @gm_build_config = recoder.get_target String.new("T-") << label
713
+ if GM::Adn_Adapter.is_adn?(name)
714
+ load_key = GM::BuildConfig.get_load_key
715
+ update_key = GM::BuildConfig.get_update_key
716
+ load_detect_key = GM::BuildConfig.get_load_detect_key
717
+
718
+ gm_note = @gm_build_config.find_note name
719
+ GM::BuildConfig.get_all_config.each{|item|
720
+ if options.is_a?(Hash) && options[item] != nil
721
+ # gm_note.auto_load = options[item] if item == load_key ## adn维度 auto_load 失效
722
+ gm_note.load_detect = options[item] if item == load_detect_key
723
+ gm_note.auto_update = adapter_update_config options[item] if item == update_key
724
+ options.delete(item)
725
+ requirements.pop if options.empty?
726
+ end
727
+ }
728
+ end
729
+ end
730
+ original_parse_inhibit_warnings(name, requirements)
731
+ end
732
+
733
+ private
734
+ def adapter_update_config(update_value)
735
+ value = ''
736
+ is_update = false
737
+ case update_value
738
+ when true
739
+ value = GM::BuildConfig.update_value_last_version
740
+ is_update = true
741
+ when false
742
+ value = GM::BuildConfig.update_value_non
743
+ when String
744
+ value = update_value
745
+ is_update = true if update_value == GM::BuildConfig.update_value_last_version || update_value == GM::BuildConfig.update_value_non
746
+ else
747
+ raise ArgumentError, "CSJM error: `#{update_value.inspect}`, 应该设置为布尔值"
748
+ end
749
+ value
750
+ end
751
+ end
752
+ end
753
+ end
@@ -0,0 +1,35 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'json'
5
+
6
+ module GM
7
+ # 网络请求
8
+ class Network
9
+ ## post请求
10
+ def Network.post (url,body)
11
+ # puts "start net request:#{body}"
12
+ uri = URI.parse(url)
13
+ https = Net::HTTP.new(uri.host,uri.port)
14
+ https.use_ssl = true
15
+ request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
16
+ request["x-tt-env"] = "boe_csj_sdk"
17
+ request["Cookie"]="__union_admin_sess_cookie=232301_noduimkpdwrbyrkr1qih; _ssa_userphone=; _ssa_username=zhangtianhao.1230"
18
+ request.body = body.to_json
19
+ res = https.request(request)
20
+ if res.code == "200"
21
+ data = JSON.parse(res.body)
22
+ # puts "finish net request:#{data}"
23
+ return data
24
+ else
25
+ ## 网络请求异常的提示
26
+ puts "请求失败 : Response code = #{res.code}, message = #{res.message}"
27
+ end
28
+ nil
29
+ end
30
+
31
+ def Network.request_adapter(body)
32
+ data = post("https://www.csjplatform.com/union_pangle/api/sdk_adapter/query",body)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-byte-csjm/gem_version'
@@ -0,0 +1 @@
1
+ require 'cocoapods-byte-csjm/gm'
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-byte-csjm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - zhangtianhao.1230@bytedance.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-byte-csjm.
42
+ email:
43
+ - zhangtianhao.1230@bytedance.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-byte-csjm.rb
49
+ - lib/cocoapods-byte-csjm/config.rb
50
+ - lib/cocoapods-byte-csjm/csj.rb
51
+ - lib/cocoapods-byte-csjm/gem_version.rb
52
+ - lib/cocoapods-byte-csjm/gm.rb
53
+ - lib/cocoapods-byte-csjm/net.rb
54
+ - lib/cocoapods_plugin.rb
55
+ homepage: https://github.com/EXAMPLE/cocoapods-byte-csjm
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.2.3
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: A longer description of cocoapods-byte-csjm.
78
+ test_files: []