Class: BB::SourceManager
- Inherits:
-
Object
- Object
- BB::SourceManager
- Defined in:
- lib/cocoapods-bb-PodAssistant/config/source_manager.rb
Instance Method Summary collapse
-
#business_stable_yaml ⇒ Object
业务源路径(远端).
-
#compare_specs(local_specs, common_specs) ⇒ Object
compare specs 参数1:本地,参数2:远端.
-
#fetch_local_stable_datas ⇒ Object
产品线本地lock数据.
-
#fetch_origin_stable_datas ⇒ Object
远端公共lock数据.
- #generate_localStable ⇒ Object
-
#initialize(businessSpecName = nil) ⇒ SourceManager
constructor
A new instance of SourceManager.
-
#local_stable_yaml ⇒ Object
本地源路径.
-
#merge_stable_data ⇒ Object
合并stable数据.
-
#public_stable_yaml ⇒ Object
公共源路径(远端).
- #showMergeLog(added, updated, rollbacked, deleted) ⇒ Object
-
#update_localstable_datas(stable_lock) ⇒ Object
更新本地lock数据.
-
#versionGreat(tag1, tag2) ⇒ Object
compare tags (>).
-
#versionGreatOrEqual(tag1, tag2) ⇒ Object
Help ######################################## compare tags (>=).
Constructor Details
#initialize(businessSpecName = nil) ⇒ SourceManager
Returns a new instance of SourceManager.
9 10 11 12 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 9 def initialize(businessSpecName = nil) @businessSpecName = businessSpecName @stableMgr = BB::StableManager.new() end |
Instance Method Details
#business_stable_yaml ⇒ Object
业务源路径(远端)
20 21 22 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 20 def business_stable_yaml return @stableMgr.business_stable_yaml(@businessSpecName) end |
#compare_specs(local_specs, common_specs) ⇒ Object
compare specs 参数1:本地,参数2:远端
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 119 def compare_specs(local_specs, common_specs) added_projects = [] updated_projects = [] rollbacked_projects = [] deleted_projects = [] new_specs = local_specs listdata = common_specs[YAML_CONFIG_LIST_KEY] removedata = common_specs[YAML_CONFIG_REMOVE_KEY] dependenciesdata = common_specs[YAML_CONFIG_DEPENDENCIES_KEY] # puts "local_specs:#{local_specs}".send(:green) # puts "common_specs:#{common_specs}".send(:green) # step.1 匹配组件版本信息 listdata.each do |name, version| name = name.to_s local_version = local_specs[name] if local_version.nil? # 本地不存在这个数据 elsif local_version != version # puts "merge name:#{name} local_version:#{local_version} route_version:#{version}".red # 版本不一致 if (version.is_a? String) && (local_version.is_a? String) end if versionGreat(version, local_version) updated_projects << "【#{name}】 (#{local_version}) -> (#{version.to_s.send(:yellow)})" else rollbacked_projects << "【#{name}】 (#{version.to_s.send(:red)}) <- (#{local_version})" end new_specs[name] = version end end # step.2 匹配组件新增 dependenciesdata.each do |name, array| name = name.to_s version = listdata[name] unless version puts "公共库缺少[#{name}]版本依赖 cls:#{listdata.class} listdata:#{listdata}".send(:red) exit end local_exist_ver = new_specs[name] if local_exist_ver.nil? new_specs[name] = version added_projects << "【#{name}】 (#{version.to_s.send(:green)})" end if array.is_a?(Array) array.each do |name| name = name.to_s local_exist_ver = new_specs[name] if local_exist_ver.nil? new_specs[name] = version added_projects << "【#{name}】 (#{version.to_s.send(:green)})" end end end end # step.3 匹配组件移除 removedata.each do |name| name = name.to_s # local_exist_ver = new_specs[name] version = listdata[name] if version deleted_projects << "【#{name}】 (#{"delete".send(:red)}) <- (#{version})" end new_specs.delete(name) end showMergeLog(added_projects, updated_projects, rollbacked_projects, deleted_projects) # puts "new_specs:#{new_specs}".send(:red) return new_specs end |
#fetch_local_stable_datas ⇒ Object
产品线本地lock数据
30 31 32 33 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 30 def fetch_local_stable_datas localSpec = BB::StableSpecs.new() return localSpec.readData(local_stable_yaml) end |
#fetch_origin_stable_datas ⇒ Object
远端公共lock数据
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 36 def fetch_origin_stable_datas # 策略:公共数据包含通用数据 + 业务线数据 pubSpec = BB::StableSpecs.new() common_data = pubSpec.readData(public_stable_yaml) # 业务线数据 business_config_file = business_stable_yaml if business_config_file if File.exist?(business_config_file) busimessSpec = BB::StableSpecs.new() busimess_data = busimessSpec.readData(business_config_file) else puts "业务线公共配置文件#{business_config_file}不存在,请确认!!!". send(:yellow) exit end end if busimess_data # 数据合并操作(策略:业务线公共盖通用数据,理论不存在该情况) newData = common_data listdata = newData[YAML_CONFIG_LIST_KEY] removedata = newData[YAML_CONFIG_REMOVE_KEY] dependenciesdata = newData[YAML_CONFIG_DEPENDENCIES_KEY] busimess_data.each do | key, val| if key == YAML_CONFIG_LIST_KEY if val.is_a?(Hash) val.each do |list_name,list_ver| listdata[list_name] = list_ver end end elsif key == YAML_CONFIG_REMOVE_KEY if val.is_a?(Array) val.each do |remove_name| removedata.push(remove_name) end end elsif key == YAML_CONFIG_DEPENDENCIES_KEY if val.is_a?(Hash) val.each do |dependencies_name,dependencies_val| dependenciesdata[dependencies_name] = dependencies_val end end end end return newData end return common_data end |
#generate_localStable ⇒ Object
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 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 218 def generate_localStable podfile_lock = File.join(Pathname.pwd,"Podfile.lock") raise "podfile.lock,不存在,请先pod install/update" unless File.exist?(podfile_lock) lockfile ||= Pod::Lockfile.from_file(Pathname.new(podfile_lock)) local_specs = {} # step.1 获取分支指向信息 dependencies = lockfile.dependencies dependencies.each do | dependency | if dependency.external_source.is_a? Hash name = dependency.name external_source = dependency.external_source podCoreName = name.include?('/') ? name.split('/').first.strip : name # checkout_options = lockfile.checkout_options_for_pod_named(podCoreName) # if checkout_options.is_a? Hash # commit = checkout_options[:commit] # external_source[:commit] = commit # puts "name:#{podCoreName} checkout_options:#{checkout_options} commit:#{commit}" # end if podCoreName != name local_specs[podCoreName] = external_source subPodName = name.include?('/') ? name.split('/').last.strip : name if subPodName != "Core" # 过滤core数据 local_specs[name] = external_source Pod::UI.puts "[分支] #{name} => (#{external_source})" end else local_specs[name] = external_source Pod::UI.puts "[分支] #{name} => (#{external_source})" end end end # step.2 获取pods标签信息,如果存在分支优先使用分支信息 lockfile.pod_names.each do |pod_name| version = lockfile.version(pod_name) podCoreName = pod_name.include?('/') ? pod_name.split('/').first.strip : pod_name if local_specs.has_key?(podCoreName) if podCoreName != pod_name subPodName = pod_name.include?('/') ? pod_name.split('/').last.strip : pod_name if subPodName != "Core" # 过滤core数据 # Pod::UI.puts "step.2 #{pod_name} => (#{local_specs[podCoreName]})" local_specs[pod_name] = local_specs[podCoreName] end end else ver = version.to_s local_specs[pod_name] = ver Pod::UI.puts "[标签] #{pod_name} => (#{ver})" end end # Pod::UI.puts "yml配置数据:#{local_specs}" if local_specs.length > 0 update_localstable_datas(local_specs) Pod::UI.puts "Generating yml配置文件=> #{local_stable_yaml} 更新成功".green end end |
#local_stable_yaml ⇒ Object
本地源路径
25 26 27 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 25 def local_stable_yaml return @stableMgr.local_stable_yaml end |
#merge_stable_data ⇒ Object
合并stable数据
90 91 92 93 94 95 96 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 90 def merge_stable_data() #4、show origin_stable_lock diff with local_stable_lock new_stable_spec = compare_specs(fetch_local_stable_datas, fetch_origin_stable_datas) #5、rewirte local_stable_lock with origin_stable_lock update_localstable_datas(new_stable_spec) end |
#public_stable_yaml ⇒ Object
公共源路径(远端)
15 16 17 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 15 def public_stable_yaml return @stableMgr.public_stable_yaml end |
#showMergeLog(added, updated, rollbacked, deleted) ⇒ Object
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 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 190 def showMergeLog(added, updated, rollbacked, deleted) #31m: 红色 32m:绿色 33m:黄色 34m:蓝色 #puts "\e[34m#{string}\e[0m" if added.any? puts "新增了以下项目:".send(:green) puts added.join("\n") end if updated.any? puts "更新了以下项目:". send(:yellow) puts updated.join("\n") end if rollbacked.any? puts "回滚了以下项目:".send(:red) puts rollbacked.join("\n") end if deleted.any? puts "移除了以下项目:".send(:red) puts deleted.join("\n") end unless added.any? || updated.any? || added.any? || deleted.any? puts "已经是最新版本数据".send(:green) end end |
#update_localstable_datas(stable_lock) ⇒ Object
更新本地lock数据
84 85 86 87 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 84 def update_localstable_datas(stable_lock) localSpec = BB::StableSpecs.new() localSpec.writeData(local_stable_yaml, stable_lock) end |
#versionGreat(tag1, tag2) ⇒ Object
compare tags (>)
110 111 112 113 114 115 116 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 110 def versionGreat(tag1, tag2) result = versionGreatOrEqual(tag1,tag2) if result == true && tag1 == tag2 return false end return result end |
#versionGreatOrEqual(tag1, tag2) ⇒ Object
Help ######################################## compare tags (>=)
100 101 102 103 104 105 106 107 |
# File 'lib/cocoapods-bb-PodAssistant/config/source_manager.rb', line 100 def versionGreatOrEqual(tag1, tag2) if (tag1.is_a? String) && (tag2.is_a? String) && tag1.to_i >= tag2.to_i return true else return false end return true end |