Class: Luna::Binary::Uploader::SingleUploader
- Inherits:
-
Object
- Object
- Luna::Binary::Uploader::SingleUploader
- Defined in:
- lib/luna/binary/uploader.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#binaryPath ⇒ Object
readonly
Returns the value of attribute binaryPath.
-
#gitNode ⇒ Object
readonly
Returns the value of attribute gitNode.
-
#gitUrl ⇒ Object
readonly
‘2.git地址 3.git节点 5.二进制缓存地址.
-
#local_path ⇒ Object
Returns the value of attribute local_path.
-
#podspecName ⇒ Object
readonly
Returns the value of attribute podspecName.
-
#rootName ⇒ Object
readonly
Returns the value of attribute rootName.
-
#specification ⇒ Object
Returns the value of attribute specification.
Instance Method Summary collapse
- #binary_json_dir ⇒ Object
- #binary_source ⇒ Object
- #clearTempFile ⇒ Object
- #command(c) ⇒ Object
- #copyDependcyFramework(path, moduleName) ⇒ Object
- #createFrameworkSpec ⇒ Object
- #createSpec(spec) ⇒ Object
- #download_git ⇒ Object
- #filename ⇒ Object
- #findBundle ⇒ Object
- #findFramework ⇒ Object
-
#initialize(podspecName, gitUrl, gitNode, binaryPath) ⇒ SingleUploader
constructor
A new instance of SingleUploader.
- #isHasFrameworkInService ⇒ Object
- #isHasSpecInRepo ⇒ Object
- #isLocalHasFramework ⇒ Object
- #isLocalHasPodSpec ⇒ Object
- #moduleDirPath ⇒ Object
- #moduleFrameworkName ⇒ Object
- #printPreUploadCommand ⇒ Object
- #push ⇒ Object
- #pushRepo ⇒ Object
- #refresh_specification_work ⇒ Object
- #repoPath ⇒ Object
- #source_files(suffix) ⇒ Object
- #specificationWork ⇒ Object
- #upload ⇒ Object
- #uploadFramework ⇒ Object
- #validate! ⇒ Object
- #write_spec_file(specification) ⇒ Object
Constructor Details
#initialize(podspecName, gitUrl, gitNode, binaryPath) ⇒ SingleUploader
Returns a new instance of SingleUploader.
23 24 25 26 27 28 29 30 |
# File 'lib/luna/binary/uploader.rb', line 23 def initialize(podspecName, gitUrl, gitNode, binaryPath) @podspecName = podspecName @gitUrl = gitUrl @gitNode = gitNode @binaryPath = binaryPath @rootName = Common.instance.tempLunaUploaderPath + "/temp/#{podspecName}/" validate! end |
Instance Attribute Details
#binaryPath ⇒ Object (readonly)
Returns the value of attribute binaryPath.
17 18 19 |
# File 'lib/luna/binary/uploader.rb', line 17 def binaryPath @binaryPath end |
#gitNode ⇒ Object (readonly)
Returns the value of attribute gitNode.
16 17 18 |
# File 'lib/luna/binary/uploader.rb', line 16 def gitNode @gitNode end |
#gitUrl ⇒ Object (readonly)
‘2.git地址 3.git节点 5.二进制缓存地址
15 16 17 |
# File 'lib/luna/binary/uploader.rb', line 15 def gitUrl @gitUrl end |
#local_path ⇒ Object
Returns the value of attribute local_path.
21 22 23 |
# File 'lib/luna/binary/uploader.rb', line 21 def local_path @local_path end |
#podspecName ⇒ Object (readonly)
Returns the value of attribute podspecName.
19 20 21 |
# File 'lib/luna/binary/uploader.rb', line 19 def podspecName @podspecName end |
#rootName ⇒ Object (readonly)
Returns the value of attribute rootName.
18 19 20 |
# File 'lib/luna/binary/uploader.rb', line 18 def rootName @rootName end |
#specification ⇒ Object
Returns the value of attribute specification.
20 21 22 |
# File 'lib/luna/binary/uploader.rb', line 20 def specification @specification end |
Instance Method Details
#binary_json_dir ⇒ Object
357 358 359 |
# File 'lib/luna/binary/uploader.rb', line 357 def binary_json_dir frameworkPath = rootName + "bin-json" end |
#binary_source ⇒ Object
324 325 326 |
# File 'lib/luna/binary/uploader.rb', line 324 def binary_source { http: format(Common.instance.binary_download_url, specification.root.name, specification.version), type: Common.instance.download_file_type } end |
#clearTempFile ⇒ Object
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/luna/binary/uploader.rb', line 413 def clearTempFile p rootName begin Common.instance.deleteDirectory("#{rootName}bin-json") rescue => exception ensure begin Common.instance.deleteDirectory("#{rootName}#{podspecName}.zip") rescue => exception ensure begin Common.instance.deleteDirectory("#{rootName}#{podspecName}") rescue => exception ensure end end end end |
#command(c) ⇒ Object
106 107 108 |
# File 'lib/luna/binary/uploader.rb', line 106 def command(c) return Common.instance.command(c) end |
#copyDependcyFramework(path, moduleName) ⇒ Object
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/luna/binary/uploader.rb', line 305 def copyDependcyFramework(path, moduleName) frameworkPath = rootName + '/**/' + path p "copyDependcyFramework " + frameworkPath frameworkpaths = Dir.glob(frameworkPath) if frameworkpaths.length command = "mkdir -p #{rootName}#{moduleName}/depencyFrameworks;" system command; p command; end frameworkDepencyFrameworks = [] frameworkpaths.each { |item| system "cp -r #{item} #{rootName}#{moduleName}/depencyFrameworks" p "cp -r #{item} #{rootName}#{moduleName}/depencyFrameworks" p "#{moduleName}/depencyFrameworks/#{File.basename(item)}" frameworkDepencyFrameworks = frameworkDepencyFrameworks + ["#{moduleName}/depencyFrameworks/#{File.basename(item)}"] } return frameworkDepencyFrameworks end |
#createFrameworkSpec ⇒ Object
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 |
# File 'lib/luna/binary/uploader.rb', line 182 def createFrameworkSpec @spec = specification.dup moduleName = specification.root.name # Source Location @spec.source = binary_source # Source Code @spec.source_files = source_files("/Headers/**/*") @spec.public_header_files = source_files("/Headers/**/*") findFramework bundlePaths = findBundle spec_hash = @spec.to_hash framework_contents = [moduleFrameworkName] puts "framework_contents : #{framework_contents}" subspecsMapper = { 'vendored_frameworks' => framework_contents } spec_hash['vendored_frameworks'] = framework_contents libA_contents = [] if spec_hash["vendored_library"] != nil libA_contents = libA_contents + copyDependcyFramework(spec_hash["vendored_library"], moduleName) end if spec_hash["vendored_libraries"] != nil if spec_hash["vendored_libraries"].respond_to?(:each) spec_hash["vendored_libraries"].each { |framework| libA_contents = libA_contents + copyDependcyFramework(framework, moduleName) } else libA_contents = libA_contents + copyDependcyFramework(spec_hash["vendored_libraries"], moduleName) end end if libA_contents.length > 0 spec_hash['vendored_libraries'] = libA_contents subspecsMapper['vendored_libraries'] = libA_contents else spec_hash.delete('vendored_libraries') end spec_hash.delete('resource_bundles') spec_hash.delete('resources') spec_hash.delete('resource_bundle') spec_hash.delete('resource') if bundlePaths.length > 0 spec_hash['resources'] = ["#{moduleName}/#{specification.root.name}.bundle"] subspecsMapper['resources'] = ["#{moduleName}/#{specification.root.name}.bundle"] end spec_hash.delete('exclude_files') spec_hash.delete('private_header_files') spec_hash.delete('preserve_paths') spec_hash.delete('pod_target_xcconfig') platforms = spec_hash['platforms'] selected_platforms = platforms.select { |k, _v| platforms.include?(k) } spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms if spec_hash['subspecs'] != nil tempSpec = [] spec_hash['subspecs'].each { |item| mapper = item.to_hash mapper.delete('private_header_files') mapper.delete('exclude_files') mapper.delete('pod_target_xcconfig') mapper["name"] = item["name"] mapper["source_files"] = source_files("/Headers/**/*") mapper["public_header_files"] = source_files("/Headers/**/*") framework_contents = [moduleFrameworkName] libA_contents = [] if mapper["vendored_framework"] != nil framework_contents = framework_contents + copyDependcyFramework(mapper["vendored_framework"], moduleName) end if mapper["vendored_frameworks"] != nil if mapper["vendored_frameworks"].respond_to?(:each) mapper["vendored_frameworks"].each { |framework| framework_contents = framework_contents + copyDependcyFramework(framework, moduleName) } else framework_contents = framework_contents + copyDependcyFramework(mapper["vendored_frameworks"], moduleName) end end if mapper["vendored_library"] != nil libA_contents = libA_contents + copyDependcyFramework(mapper["vendored_library"], moduleName) end if mapper["vendored_libraries"] != nil if mapper["vendored_libraries"].respond_to?(:each) mapper["vendored_libraries"].each { |framework| libA_contents = libA_contents + copyDependcyFramework(framework, moduleName) } else libA_contents = libA_contents + copyDependcyFramework(mapper["vendored_libraries"], moduleName) end end if framework_contents.length > 0 mapper["vendored_frameworks"] = framework_contents end if libA_contents.length > 0 mapper["vendored_libraries"] = libA_contents end if subspecsMapper["resources"] != nil mapper["resources"] = subspecsMapper["resources"] end tempSpec << mapper } spec_hash["subspecs"] = tempSpec end @spec1 = Pod::Specification.from_hash(spec_hash) @spec1 end |
#createSpec(spec) ⇒ Object
348 349 350 351 352 353 354 355 |
# File 'lib/luna/binary/uploader.rb', line 348 def createSpec(spec) Pod::UI. '生成二进制 podspec 内容: ' spec.to_pretty_json.split("\n").each do |text| Pod::UI. text end spec end |
#download_git ⇒ Object
102 103 104 |
# File 'lib/luna/binary/uploader.rb', line 102 def download_git command("git clone #{gitUrl} #{@rootName}temp; cd #{@rootName}temp; git fetch --all;git stash; git checkout #{gitNode};") if gitUrl && gitUrl.length > 0 end |
#filename ⇒ Object
361 362 363 |
# File 'lib/luna/binary/uploader.rb', line 361 def filename @filename ||= "#{binary_json_dir}/#{specification.root.name}.podspec.json" end |
#findBundle ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/luna/binary/uploader.rb', line 170 def findBundle bundlePaths = Dir.glob("#{binaryPath}/**/#{specification.root.name}.bundle") if bundlePaths.length > 1 # raise "findBundle:#{bundlePaths},不知道取哪个" puts "findBundle:#{bundlePaths},不知道取哪个,做合并" end bundlePaths.each { |item| system "cp -r #{item} #{moduleDirPath}" } return bundlePaths end |
#findFramework ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/luna/binary/uploader.rb', line 151 def findFramework frameworkPaths = Dir.glob("#{binaryPath}/**/#{specification.root.name.sub('-', '_')}.framework") if frameworkPaths.length > 1 raise "findFramework:#{frameworkPaths},不知道取哪个" end if frameworkPaths.length == 0 raise "findFramework:#{frameworkPaths},没有" end frameworkPaths.each { |item| command = "mkdir -p #{moduleDirPath}; cp -r #{item} #{moduleDirPath}" system command p command } return frameworkPaths end |
#isHasFrameworkInService ⇒ Object
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/luna/binary/uploader.rb', line 387 def isHasFrameworkInService command = "curl #{format(Common.instance.binary_download_url, specification.root.name, specification.version).sub("#{Common.instance.download_file_type}","")}" p command result = %x(#{command}) resultHash = JSON.parse(result) isHasFrameWork = false if resultHash[specification.root.name] != nil p "版本号#{resultHash[specification.root.name]}" resultHash[specification.root.name].each { |item| if item == specification.version.version isHasFrameWork = true end } end return isHasFrameWork end |
#isHasSpecInRepo ⇒ Object
370 371 372 373 374 375 376 |
# File 'lib/luna/binary/uploader.rb', line 370 def isHasSpecInRepo moduleName = specification.root.name tag = specification.version p "#{repoPath}/#{moduleName}/#{tag}/*.podspec.json" paths = Dir.glob("#{repoPath}/#{moduleName}/#{tag}/**/*.podspec.json") return paths.length != 0 end |
#isLocalHasFramework ⇒ Object
138 139 140 |
# File 'lib/luna/binary/uploader.rb', line 138 def isLocalHasFramework return Dir.glob("#{rootName}#{moduleFrameworkName}").length > 0 end |
#isLocalHasPodSpec ⇒ Object
142 143 144 |
# File 'lib/luna/binary/uploader.rb', line 142 def isLocalHasPodSpec return Dir.glob("#{filename}").length > 0 end |
#moduleDirPath ⇒ Object
134 135 136 |
# File 'lib/luna/binary/uploader.rb', line 134 def moduleDirPath return rootName + (specification.root.name) end |
#moduleFrameworkName ⇒ Object
146 147 148 149 |
# File 'lib/luna/binary/uploader.rb', line 146 def moduleFrameworkName moduleName = specification.root.name return "#{moduleName}/#{moduleName.sub('-', '_')}.framework" end |
#printPreUploadCommand ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/luna/binary/uploader.rb', line 119 def printPreUploadCommand if isLocalHasFramework && isLocalHasPodSpec if local_path puts "lbu single #{podspecName} #{local_path} #{binaryPath}".green elsif gitUrl && gitUrl.length == 0 puts "lbu single #{podspecName} #{specification.version} #{binaryPath}" .green else puts "lbu single #{podspecName} #{gitUrl} #{gitNode} #{binaryPath}".green end else raise "#{specification.name} #{specification.version} repo或framework缺失" end end |
#push ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/luna/binary/uploader.rb', line 110 def push if isLocalHasFramework && isLocalHasPodSpec pushRepo uploadFramework else raise "#{specification.name} #{specification.version} repo或framework缺失" end end |
#pushRepo ⇒ Object
378 379 380 381 382 383 384 385 |
# File 'lib/luna/binary/uploader.rb', line 378 def pushRepo moduleName = specification.root.name tag = specification.version targetDirname = "#{repoPath}/#{moduleName}/#{tag}" command = "cd #{repoPath};git stash;git checkout master;git pull origin master; mkdir -p #{targetDirname}; cp -r #{filename} #{targetDirname};cd #{repoPath};git add .; git commit -m 'MOD::#{moduleName}-#{tag} by LBU';git push -f origin master;" p command system command end |
#refresh_specification_work ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/luna/binary/uploader.rb', line 85 def refresh_specification_work begin clearTempFile rescue => exception ensure download_git if isHasSpecInRepo == true && isHasFrameworkInService == true @spec = createFrameworkSpec write_spec_file(@spec) else raise "repo or 二进制服务 不存在 #{specification.name} #{specification.version}" end end end |
#repoPath ⇒ Object
366 367 368 |
# File 'lib/luna/binary/uploader.rb', line 366 def repoPath return Common.instance.repoPath end |
#source_files(suffix) ⇒ Object
328 329 330 331 |
# File 'lib/luna/binary/uploader.rb', line 328 def source_files(suffix) moduleName = specification.root.name ["#{moduleName}/#{moduleName.sub('-', '_')}.framework" + suffix] end |
#specificationWork ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/luna/binary/uploader.rb', line 68 def specificationWork begin clearTempFile rescue => exception ensure download_git if isHasSpecInRepo == false && isHasFrameworkInService == false @spec = createFrameworkSpec write_spec_file(@spec) else raise "已存在repo or 二进制服务 #{specification.name} #{specification.version}" end end end |
#upload ⇒ Object
39 40 41 42 |
# File 'lib/luna/binary/uploader.rb', line 39 def upload specificationWork push end |
#uploadFramework ⇒ Object
404 405 406 407 408 409 410 411 |
# File 'lib/luna/binary/uploader.rb', line 404 def uploadFramework zipCommand = "cd #{rootName};zip -r #{specification.root.name}.zip #{specification.root.name}" p zipCommand system zipCommand command = "cd #{rootName};curl #{Common.instance.binary_upload_url} -F \"name=#{specification.root.name}\" -F \"version=#{specification.version}\" -F \"annotate=#{specification.root.name}_#{specification.version}_log\" -F \"file=@#{specification.root.name}.zip\"" p command system command end |
#validate! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/luna/binary/uploader.rb', line 32 def validate! raise '缺少gitUrl参数' unless gitUrl raise '缺少gitNode参数' unless gitNode raise '缺少binaryPath参数' unless binaryPath raise '缺少podspecName参数' unless podspecName end |
#write_spec_file(specification) ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/luna/binary/uploader.rb', line 333 def write_spec_file(specification) file = filename createSpec unless specification FileUtils.mkdir_p(binary_json_dir) unless File.exist?(binary_json_dir) FileUtils.rm_rf(file) if File.exist?(file) File.open(file, 'w+') do |f| # f.write("# MARK: converted automatically by plugin cocoapods-imy-bin @slj \r\n") f.write(specification.to_pretty_json) end @filename = file end |