require 'cocoapods' require_relative 'config' require 'singleton' require 'cocoapods-byte-csjm/gem_version' require 'yaml' require 'digest' require "thread" require_relative 'net' require 'xcodeproj' require 'json' require 'cocoapods/command/update' require 'time' require 'open3' module CSJMPlugin def CSJMPlugin.action() recoder= GM::Recorder.instance if recoder.is_load_plugin yield(recoder) if block_given? end end def CSJMPlugin.update puts "Checking for updates..." # output = system('gem update cocoapods-byte-csjm') command = 'gem install cocoapods-byte-csjm' stdout, stderr, status = Open3.capture3(command) if status.success? puts "cocoapods-byte-csjm update sucess" else puts "cocoapods-byte-csjm update fail message:#{stderr}" end end end module GM # lock文件读写 # class LockfileCSJM def initialize(hash) @internal_data = hash end # 读取lock文件 # @requrn lock的json内容 # @param 文件路径 def self.read_from_path(path) if File.exist?(path) return true, YAML.load_file(path) end return false, nil end # 写入lock文件 def write_to_disk(path) begin is_exist, existing = LockfileCSJM.read_from_path(path) return if existing == @internal_data rescue Exception end File.open(path, 'w+') do |f| YAML.dump(@internal_data,f) end end end # 记录CSJM 版本信息 # class GmInfo attr_accessor :name attr_accessor :version def initialize(name, version) @name = name @version = version end def to_hash hash = {} hash["NAME"] = @name hash["VERSION"] = @version hash end def self.from_hash(hash) GmInfo.new(hash["NAME"],hash["VERSION"]) end end # 媒体配置记录 # class Note attr_accessor :auto_load attr_accessor :auto_update attr_accessor :load_detect def get_update(update_value) value = '' case update_value when true value = GM::BuildConfig.update_value_last_version when false value = GM::BuildConfig.update_value_non when String value = update_value else raise ArgumentError, "CSJM error: `#{update_value.inspect}`, should be a boolean or string." end value end end class GlobalNote < Note attr_accessor :auto_load_whitelist def initialize(auto_load = true , auto_update = GM::BuildConfig.update_value_last_version, load_detect = true, auto_load_whitelist = []) @auto_load = auto_load @auto_update = get_update auto_update @load_detect = load_detect @auto_load_whitelist = auto_load_whitelist end def has_set_load?(adn_name) adn_name = Pod::Specification.root_name(adn_name) if @auto_load_whitelist.size == 0 || @auto_load_whitelist.include?(adn_name) return true end false end def to_hash hash = {} hash["AUTO_LOAD"] = @auto_load hash["AUTO_UPDATE"] = @auto_update hash["LOAD_DETECT"] = @load_detect hash["AUTO_LOAD_WHITELIST"] = @auto_load_whitelist hash end def self.from_hash(hash) global_note = GlobalNote.new() global_note.auto_load = hash["AUTO_LOAD"] if hash.has_key?("AUTO_LOAD") global_note.auto_update = hash["AUTO_UPDATE"] if hash.has_key?("AUTO_UPDATE") global_note.load_detect = hash["LOAD_DETECT"] if hash.has_key?("LOAD_DETECT") global_note.auto_load_whitelist = hash["AUTO_LOAD_WHITELIST"] if hash.has_key?("AUTO_LOAD_WHITELIST") global_note end end class AdnNote < Note attr_accessor :adn_name attr_accessor :adn_version attr_accessor :adapter_name attr_accessor :adapter_original_version ##加载的版本号 attr_accessor :adapter_expected_version ##期望加载的版本号 def initialize(adn_name, auto_load = false , auto_update = GM::BuildConfig.update_value_non, load_detect = false) @adn_name = adn_name @adapter_name = GM::Adn_Adapter.get_adapter adn_name @auto_load = auto_load @auto_update = get_update auto_update @load_detect = load_detect @adapter_original_version = "" @adapter_expected_version = "" end def to_hash hash = {} hash["ADN_NAME"] = @adn_name hash["ADN_VERSION"] = @adn_version hash["ADAPTER_NAME"] = @adapter_name hash["ADAPTER_ORIGINAL_VERSION"] = @adapter_original_version hash["ADAPTER_EXPECTED_VERSION"] = @adapter_expected_version hash["AUTO_LOAD"] = @auto_load hash["AUTO_UPDATE"] = @auto_update hash["LOAD_DETECT"] = @load_detect hash end def self.from_hash(hash) note = AdnNote.new(hash["ADN_NAME"],hash["AUTO_LOAD"],hash["AUTO_UPDATE"],hash["LOAD_DETECT"]) note.adn_name = hash["ADN_NAME"] note.adn_version = hash["ADN_VERSION"] note.adapter_name = hash["ADAPTER_NAME"] note.adapter_original_version = hash["ADAPTER_ORIGINAL_VERSION"] note.adapter_expected_version = hash["ADAPTER_EXPECTED_VERSION"] note end end # 对应cocoapods target # class Target attr_accessor :is_release_target attr_accessor :referenced_target attr_reader :label attr_accessor :gm_info attr_accessor :nots_info def initialize(label) @label = label.clone @is_release_target = false end def find_note(adn_name) @nots_info ||= {} global_note = GM::Recorder.instance.global_note 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) @nots_info[adn_name] = note unless @nots_info.has_key?(adn_name) note end def has_adn?(adn_name) GM::Adn_Adapter.is_adn?(adn_name) && @nots_info.has_key?(adn_name) end def is_adn_update_or_detect?(adn_name) result = is_adn_update?(adn_name) || is_adn_detect?(adn_name) result end def is_adn_update?(adn_name) 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) result end def is_adn_detect?(adn_name) has_adn?(adn_name) && @nots_info[adn_name].load_detect end def to_hash hash = {} hash["LABEL"] = @label hash["IS_RELEASE_TARGET"] = @is_release_target hash["GM_INFO"] = @gm_info.to_hash hash["NOTS_INFO"] = {} @nots_info.each {|key, value| hash["NOTS_INFO"][key] = value.to_hash } hash end def self.from_hash(hash) target = Target.new(hash["LABEL"]) target.is_release_target = true target.gm_info = GmInfo.from_hash hash["GM_INFO"] if hash.has_key?("GM_INFO") target.nots_info ||= {} hash["NOTS_INFO"].each do |name, note_info| target.nots_info[name] = AdnNote.from_hash note_info end target end end # 记录方 # class Recorder include Singleton attr_accessor :global_note attr_accessor :target_info attr_reader :is_load_plugin attr_reader :plugin_version attr_reader :lockfile_data def set_plugin_load(is_load) @is_load_plugin = is_load @plugin_version = CocoapodsByteCsjm::Version.version end def add_global_note(note) @global_note = note end def find_global_note(option, is_force_update = false) return @global_note if !is_force_update && @global_note != nil @global_note = GlobalNote.new(false, GM::BuildConfig.update_value_non, false) load_key = GM::BuildConfig.get_load_key update_key = GM::BuildConfig.get_update_key load_detect_key = GM::BuildConfig.get_load_detect_key auto_load_whitelist_key = GM::BuildConfig.get_load_whitelist_key case option when true, false @global_note = GM::GlobalNote.new(option,option,option,{}) when Hash load_value = option.has_key?(load_key) ? option[load_key] : true update_value = option.has_key?(update_key) ? option[update_key] : true detect_value = option.has_key?(load_detect_key) ? option[load_detect_key] : true auto_load_whitelist = option.has_key?(auto_load_whitelist_key)?option[auto_load_whitelist_key] : {} @global_note = GM::GlobalNote.new(load_value, update_value,detect_value,auto_load_whitelist) else raise ArgumentError, "CSJM error: `#{option.inspect}`, should be a boolean or hash." end @global_note end def get_global_note @global_note end def get_target(label) @target_info ||= {} @target_info[label] ||= Target.new(label) end def to_hash hash = {} hash["IS_LOAD_PLUGIN"] = @is_load_plugin hash["PLUGIN_VERSION"] = @plugin_version hash["GLOBAL_NOTE"] = @global_note.to_hash hash["TARGET_INFO"] = {} @target_info.each {|item, value| hash["TARGET_INFO"][item] = value.to_hash } checksum = Digest::SHA1.hexdigest(hash.inspect) checksum = checksum.encode('UTF-8') if checksum.respond_to?(:encode) hash["RECODER_CHECKSUM"] = checksum hash end end # 对应cocoapods 的Specification # class SpecificationInfo @@possibilities = {} def self.update(name = '', possibilities) if name.length > 0 @@possibilities[name] ||= [] @@possibilities[name] = @@possibilities[name] | possibilities end end def self.get_info() @@possibilities end def self.get_a_specfication(name, version) result = @@possibilities[name].find { |specification| specification.version.version == version } result end def self.get_specfication(info_list = []) ##请注意, 这里可能获取不到对应的Specfication 实例, 此时需要报错并提示媒体使用pod update result = info_list.map{|info| info['is_find'] = false adapter_name = GM::Adn_Adapter.get_adapter_from_adn_abbreviation info["adn_name"] @@possibilities[adapter_name].find { |specification| info['is_find'] = true if specification.version.version == info["adn_adapter_version"] specification.version.version == info["adn_adapter_version"] } }.flatten unfind_list = info_list.select{ |info| info['is_find'] == false } if unfind_list.size > 0 ins = get_info str = "adapters(" unfind_list.each {|item| str << GM::Adn_Adapter.get_adapter_from_adn_abbreviation(info["item"]) + "->" + item["adn_adapter_version"]+ " " } str << ")" raise "CSJM error: #{str} 版本未找到,请执行 `pod update --verbose`" end result end end # 版本处理 # class VersionAnalyzer def self.resolve_release_target(target, specs) is_exist, hash = GM::LockfileCSJM.read_from_path(File.expand_path("#{Pod::Config.instance.installation_root}/Podfile.csjm.lock")) if is_exist ## 校验lock文件有无改动 checksum = hash.delete("RECODER_CHECKSUM") verified_checksum = Digest::SHA1.hexdigest(hash.inspect).encode('UTF-8') if checksum.respond_to?(:encode) if verified_checksum != checksum raise "CSJM error: Podfile.csjm.lock 文件校验失败, 请检查该文件是否被改动, 尝试删掉该文件并执行 'pod install', 若你确认没有被修改,请联系技术支持" end ## 校验对应的target是否存在 if !hash["TARGET_INFO"].has_key?(target.gm_build_config.referenced_target) raise "CSJM error:#{target.gm_build_config.label} 设置了'is_release_target=true' 但是在 Podfile.csjm.lock文件中没有找到target的信息" end ## 校验gm版本是否符合 gm_spec = specs.find do |spec| GM::BuildConfig.mediation_name==spec.spec.name end if gm_spec.nil? raise "CSJM error:#{GM::BuildConfig.mediation_name} not found in #{target.label}" end referenced_target = GM::Target.from_hash hash["TARGET_INFO"][target.gm_build_config.referenced_target] if gm_spec.spec.version.version != referenced_target.gm_info.version raise "CSJM error:#{GM::BuildConfig.mediation_name} version has change(#{referenced_target.gm_info.version}->#{gm_spec.spec.version.version}),please check" end ## 替换各adapter的版本 referenced_target.nots_info.each do |adn_name, note| original_adapter_sp = specs.find{|spec| spec.spec.name == note.adapter_name } if original_adapter_sp.nil? raise "CSJM error:#{note.adapter_name} not found" end ##校验adn是否更换了版本 original_adn_sp = specs.find do |spec| spec.spec.name == note.adn_name end if original_adn_sp.spec.version.version != note.adn_version raise "CSJM error:#{note.adn_name} version has change(#{note.adn_version}->#{original_adapter_sp.spec.version.version}),please check" end if note.adapter_expected_version.length > 0 && original_adapter_sp.spec.version.version != note.adapter_expected_version title_options = { :verbose_prefix => '-> '.green } 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) replace_sp = GM::SpecificationInfo.get_a_specfication note.adapter_name, note.adapter_expected_version if replace_sp specs << Pod::Resolver::ResolverSpecification.new(replace_sp, original_adapter_sp.used_by_non_library_targets_only, replace_sp.spec_source) specs.delete original_adapter_sp end end end specs.sort_by!{|spec| spec.spec.name} else raise "CSJM error: #{File.expand_path("#{Pod::Config.instance.installation_root}/Podfile.csjm.lock")} not found, please check" end end def self.resolve_last(target, specs) gm_spec = nil adn_specs = specs.select do |spec| name = spec.spec.name if name == GM::BuildConfig.mediation_name gm_spec = spec target.gm_build_config.gm_info = GM::GmInfo.new(spec.spec.name, spec.spec.version.version) end if GM::Adn_Adapter.is_adapter?(name) adn_note = target.gm_build_config.find_note GM::Adn_Adapter.get_adn name adn_note.adapter_name = name adn_note.adapter_original_version = spec.spec.version.version elsif GM::Adn_Adapter.is_adn?(name) adn_note = target.gm_build_config.find_note name adn_note.adn_version = spec.spec.version.version end target.gm_build_config.is_adn_update?(name) ## 这里去掉不更新但版本校验功能 end raise "CSJM error: #{GM::BuildConfig.mediation_name} not found,please check" if gm_spec == nil adn_info_list = adn_specs.map{|adn_spec| adn_note = target.gm_build_config.find_note adn_spec.spec.name adn_note.adn_version = adn_spec.spec.version.version {"adn_name" => GM::Adn_Adapter.get_adn_abbreviation(adn_spec.spec.name),"adn_version" => adn_spec.spec.version.version} # {"adn_name" => "ks","adn_version" => adn_spec.spec.version.version} # {"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} } if gm_spec ## 网络请求 response_data = request_adapter gm_spec.spec.version.version, adn_info_list result = GM::SpecificationInfo.get_specfication response_data result.each{|item| original_sp = specs.find{|spec| spec.spec.name == item.name } adn_name = GM::Adn_Adapter.get_adn item.name adn_note = target.gm_build_config.find_note adn_name adn_note.adapter_expected_version = item.version.version if original_sp && original_sp.spec.version.version == item.version.version title_options = { :verbose_prefix => '-> '.green } 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) else if original_sp && original_sp.spec.version.version != item.version.version ## 更新到最新版本 或 最新稳定版本 if target.gm_build_config.is_adn_update?(adn_name) # puts '开始更新版本' title_options = { :verbose_prefix => '-> '.green } 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) specs << Pod::Resolver::ResolverSpecification.new(item, original_sp.used_by_non_library_targets_only, item.spec_source) specs.delete original_sp elsif target.gm_build_config.is_adn_detect?(adn_name) ##媒体关闭了自动更新,只选择检查版本是否适配 ## 版本校验功能暂时去掉 , 一期不上,后续具体看情况 # puts '开始校验版本' # if item.version.version != original_sp.spec.version.version # 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}" # end else # puts '什么也不做' end end end } specs.sort_by!{|spec| spec.spec.name} end def self.delete_invalid_adapters(target, specs) un_den_adn_list= GM::Adn_Adapter.get_all_adn - specs.map(&:spec).map(&:name).map do |item| GM::Adn_Adapter.is_adn?(item) ? Pod::Specification.root_name(item) : nil end.compact.uniq un_den_adapter_list = [] un_den_adapter_list = un_den_adn_list.map {|item| GM::Adn_Adapter.get_adapter item } specs.delete_if { |spec| hh = !GM::Recorder.instance.global_note.auto_load_whitelist.include?(Pod::Specification.root_name(spec.spec.name)) 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)) if result title_options = { :verbose_prefix => '-> '.red} Pod::UserInterface.titled_section("remove #{spec.spec.name}", title_options) end result } end def self.get_package_name project_path = Pod::Config.instance.project_root # pattern = File.join(project_path, '*.xcodeproj') # 匹配所有子目录下的 .xcodeproj 文件 # xcodeproj_path = Dir.glob(pattern).first xcodeprojs = project_path.children.select { |e| e.fnmatch('*.xcodeproj') } if xcodeprojs.size == 1 package_name_list = Array.new xcodeproj_path = xcodeprojs.first project = Xcodeproj::Project.open(xcodeproj_path) project.targets.map(&:build_configuration_list).map(&:build_configurations).each do |item| package_name_list << item[1].simple_attributes_hash['buildSettings']['PRODUCT_BUNDLE_IDENTIFIER'] end package_name_list.uniq else raise Informative, 'Could not automatically select an Xcode project. ' \ "Specify one in your Podfile like so:\n\n" \ " project 'path/to/Project.xcodeproj'\n" end end def self.request_adapter(m_version, adn_list) package_name = ['com.bytedance.gromore-inhouse'] ##get_package_name body = Hash["package_name"=>package_name, "mediation_version"=>m_version, "os_type"=>"ios", "list"=>adn_list] Pod::UserInterface.section '[DEBUG]CSJM plugin Network request data' do puts "请求信息:#{body}" end config_time_start = (Time.now.to_f * 1000).to_i data = GM::Network.request_adapter(body) config_time_end = (Time.now.to_f * 1000).to_i ## 埋点信息 push_track config_time_start ,config_time_end ,data,m_version if data["code"] == "PG0000" ## 请求adn数目和返回adapter 个数不一致时进行报错处理 result = data["data"] if result.size != adn_list.size unfind_adn_list = adn_list.map do |hash| if hash["adn_name"] != result.find { |h| h["adn_version"] == hash["adn_version"] }&.dig("adn_name") { "adn_name" => hash["adn_name"], "adn_version" => hash["adn_version"] } end end.compact raise "CSJM error:未查找到与#{JSON.generate(unfind_adn_list)}匹配的Adadpter,请更新SDK至合适版本,如有疑问请联系技术支持。" end return data["data"] else ##业务逻辑异常的提示 case data["code"] when "PG0201" raise "CSJM error: #{data["message"]}(应用ID:#{package_name}),请使用在平台注册的应用ID,如有疑问请联系技术支持。" when "21018" ,"PG21018" raise "CSJM error: #{data["message"]}(应用ID:#{package_name}),如有疑问请联系技术支持。" else raise "CSJM error: #{data["message"]}(应用ID:#{package_name}),如有疑问请联系技术支持。" end end end def self.push_track(config_start_time, config_end_time, response_data, m_version) config_duration = config_end_time - config_start_time package_name = get_package_name event_extra = Hash["package_ids"=>package_name, "mediation_version"=>m_version, "os"=>"ios", "config_time_start" => config_start_time,"config_time_end" => config_end_time,"config_duration"=>config_duration,"response"=>response_data, "plugin_version" => CocoapodsByteCsjm::Version.version] event_extra = event_extra.to_json stats_list = Array.new << Hash["conn_type" => 1, "event_id" => "3C0BA297-0C19-4F68-949A-3196B6F0B895", "timestamp" =>(Time.now.to_f * 1000).to_i ,"type" => "auto_tools", "event_extra" => event_extra] body = Hash["ts" =>Time.now.to_i, "stats_list" => stats_list] # Pod::UserInterface.section '[DEBUG]CSJM plugin Network request data' do # puts "埋点信息:#{body}" # end data = GM::Network.push_track(body) if data["code"] == "20000" ## 埋点成功. 目前什么也不做 else ## 埋点失败 end end def self.is_update?(value) is_auto_update?(value) || is_stable_update?(value) end def self.is_auto_update?(value) value == GM::BuildConfig.update_value_last_version end def self.is_stable_update?(value) value == GM::BuildConfig.update_value_last_stable_version end end end class Xcodeproj::Project::Object::XCBuildConfiguration attr_accessor :simple_attributes_hash end class Pod::Resolver alias_method :original_search_for, :search_for def search_for(dependency) possibilities = original_search_for(dependency) ##返回不可变数组 CSJMPlugin.action do |recoder| GM::SpecificationInfo.update dependency.name , possibilities end possibilities end alias_method :original_specifications_for_dependency, :specifications_for_dependency def specifications_for_dependency(dependency, additional_requirements = []) CSJMPlugin.action do |recoder| if additional_requirements.length > 0 && GM::Adn_Adapter.is_adapter?(dependency.name) additional_requirements = [] dependency = Pod::Dependency.new(dependency.name) end end original_specifications_for_dependency(dependency, additional_requirements) end end class Pod::Installer::Analyzer alias_method :original_resolve_dependencies, :resolve_dependencies def resolve_dependencies(locked_dependencies) resolver_specs_by_target = original_resolve_dependencies(locked_dependencies) CSJMPlugin.action do |recoder| resolver_specs_by_target.each do |target, specs| if specs.length > 0 Pod::UserInterface.section 'CSJM plugin remove invalid adapter dependencie from loaded dependencies ' do GM::VersionAnalyzer.delete_invalid_adapters target, specs end if GM::Recorder.instance.get_global_note.auto_load if target.gm_build_config.is_release_target Pod::UserInterface.section "CSJM plugin is detected that #{target.label} target is set to `gm_release_target!`, start configuration" do GM::VersionAnalyzer.resolve_release_target target, specs end else Pod::UserInterface.section 'CSJM plugin start update or detect dependencies ' do GM::VersionAnalyzer.resolve_last target, specs end Pod::UserInterface.section 'CSJM plugin write Podfile.csjm.lock' do write_lock_file recoder end end end end end resolver_specs_by_target end ## 写入lock文件 def write_lock_file(recoder) GM::LockfileCSJM.new(recoder.to_hash).write_to_disk(File.expand_path("#{Pod::Config.instance.installation_root}/Podfile.csjm.lock")) end end module Pod class Podfile module DSL def use_gm_adapter_update!(option = true) current_target_definition.use_gm_adapter_update!(option) end def gm_release_target!(option = true) current_target_definition.gm_release_target!(option) end alias_method :original_pod, :pod def pod(name = nil, *requirements) CSJMPlugin.action do |recoder| if recoder.get_global_note.auto_load unless current_target_definition.is_add_adapter_dependencys current_target_definition.is_add_adapter_dependencys = true Pod::UserInterface.section 'CSJM plugin start auto load dependencies ' do GM::Adn_Adapter.get_all_adapter.each {|item| 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 title_options = { :verbose_prefix => '-> '.green } Pod::UserInterface.titled_section("add #{item}", title_options) current_target_definition.store_pod(item,[String.new(">=0")] ) end } end end end end original_pod(name, *requirements) end alias_method :original_plugin, :plugin def plugin(name, options = {}) if name == 'cocoapods-byte-csjm' GM::Recorder.instance.set_plugin_load true CSJMPlugin.update end original_plugin(name, options) end end class TargetDefinition attr_reader :gm_release_target attr_accessor :is_add_adapter_dependencys attr_reader :global_gm_build_config attr_reader :gm_build_config def gm_release_target!(option = true) 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" case option when true name = String.new("T-") << label @gm_build_config = GM::Recorder.instance.get_target name @gm_build_config.is_release_target = option @gm_build_config.referenced_target = name when Hash @gm_build_config = GM::Recorder.instance.get_target String.new("T-") << label @gm_build_config.is_release_target = true @gm_build_config.referenced_target = String.new("T-") << option[:referenced] else raise ArgumentError, "CSJM error: `#{option.inspect}`, should be a true or a target name" end end def use_gm_adapter_update!(option) @global_gm_build_config = GM::Recorder.instance.find_global_note option end alias_method :original_parse_inhibit_warnings, :parse_inhibit_warnings def parse_inhibit_warnings(name, requirements) CSJMPlugin.action do |recoder| options = requirements.last || {} name = Specification.root_name(name) @gm_build_config = recoder.get_target String.new("T-") << label if GM::Adn_Adapter.is_adn?(name) load_key = GM::BuildConfig.get_load_key update_key = GM::BuildConfig.get_update_key load_detect_key = GM::BuildConfig.get_load_detect_key gm_note = @gm_build_config.find_note name GM::BuildConfig.get_all_config.each{|item| if options.is_a?(Hash) && options[item] != nil # gm_note.auto_load = options[item] if item == load_key ## adn维度 auto_load 失效 gm_note.load_detect = options[item] if item == load_detect_key gm_note.auto_update = adapter_update_config options[item] if item == update_key options.delete(item) requirements.pop if options.empty? end } end end original_parse_inhibit_warnings(name, requirements) end private def adapter_update_config(update_value) value = '' is_update = false case update_value when true value = GM::BuildConfig.update_value_last_version is_update = true when false value = GM::BuildConfig.update_value_non when String value = update_value is_update = true if update_value == GM::BuildConfig.update_value_last_version || update_value == GM::BuildConfig.update_value_non else raise ArgumentError, "CSJM error: `#{update_value.inspect}`, 应该设置为布尔值" end value end end end end