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.二进制缓存地址.
-
#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
- #copyDependcyFramework(path, moduleName) ⇒ Object
- #createFrameworkSpec ⇒ Object
- #createSpec(spec) ⇒ 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
- #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.
22 23 24 25 26 27 28 29 |
# File 'lib/luna/binary/uploader.rb', line 22 def initialize(podspecName, gitUrl, gitNode, binaryPath) @podspecName = podspecName @gitUrl = gitUrl @gitNode = gitNode @binaryPath = binaryPath @rootName = Luna::Binary::Common.instance.tempLunaUploaderPath + "/#{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 |
#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
326 327 328 |
# File 'lib/luna/binary/uploader.rb', line 326 def binary_json_dir frameworkPath = rootName + "bin-json" end |
#binary_source ⇒ Object
293 294 295 |
# File 'lib/luna/binary/uploader.rb', line 293 def binary_source { http: format(CBin.config.binary_download_url, specification.root.name, specification.version), type: CBin.config.download_file_type } end |
#clearTempFile ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/luna/binary/uploader.rb', line 382 def clearTempFile p rootName begin Luna::Binary::Common.instance.deleteDirectory("#{rootName}bin-json") rescue => exception ensure begin Luna::Binary::Common.instance.deleteDirectory("#{rootName}#{podspecName}.zip") rescue => exception ensure begin Luna::Binary::Common.instance.deleteDirectory("#{rootName}#{podspecName}") rescue => exception ensure end end end end |
#copyDependcyFramework(path, moduleName) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/luna/binary/uploader.rb', line 274 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
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 |
# File 'lib/luna/binary/uploader.rb', line 151 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
317 318 319 320 321 322 323 324 |
# File 'lib/luna/binary/uploader.rb', line 317 def createSpec(spec) Pod::UI. '生成二进制 podspec 内容: ' spec.to_pretty_json.split("\n").each do |text| Pod::UI. text end spec end |
#filename ⇒ Object
330 331 332 |
# File 'lib/luna/binary/uploader.rb', line 330 def filename @filename ||= "#{binary_json_dir}/#{specification.root.name}.podspec.json" end |
#findBundle ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/luna/binary/uploader.rb', line 139 def findBundle bundlePaths = Dir.glob("#{binaryPath}/**/#{specification.root.name}.bundle") if bundlePaths.length > 1 # raise "findBundle:#{bundlePaths},不知道取哪个" Pod::UserInterface.puts "findBundle:#{bundlePaths},不知道取哪个,做合并" end bundlePaths.each { |item| system "cp -r #{item} #{moduleDirPath}" } return bundlePaths end |
#findFramework ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/luna/binary/uploader.rb', line 120 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
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/luna/binary/uploader.rb', line 356 def isHasFrameworkInService command = "curl #{format(CBin.config.binary_download_url, specification.root.name, specification.version).sub("#{CBin.config.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
339 340 341 342 343 344 345 |
# File 'lib/luna/binary/uploader.rb', line 339 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
107 108 109 |
# File 'lib/luna/binary/uploader.rb', line 107 def isLocalHasFramework return Dir.glob("#{rootName}#{moduleFrameworkName}").length > 0 end |
#isLocalHasPodSpec ⇒ Object
111 112 113 |
# File 'lib/luna/binary/uploader.rb', line 111 def isLocalHasPodSpec return Dir.glob("#{filename}").length > 0 end |
#moduleDirPath ⇒ Object
103 104 105 |
# File 'lib/luna/binary/uploader.rb', line 103 def moduleDirPath return rootName + (specification.root.name) end |
#moduleFrameworkName ⇒ Object
115 116 117 118 |
# File 'lib/luna/binary/uploader.rb', line 115 def moduleFrameworkName moduleName = specification.root.name return "#{moduleName}/#{moduleName.sub('-', '_')}.framework" end |
#printPreUploadCommand ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/luna/binary/uploader.rb', line 90 def printPreUploadCommand if isLocalHasFramework && isLocalHasPodSpec if gitUrl && gitUrl.length == 0 Pod::UserInterface.puts "lbu single #{podspecName} #{specification.version} #{binaryPath}" else Pod::UserInterface.puts "lbu single #{podspecName} #{gitUrl} #{gitNode} #{binaryPath}" end else raise "#{specification.name} #{specification.version} repo或framework缺失" end end |
#push ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/luna/binary/uploader.rb', line 81 def push if isLocalHasFramework && isLocalHasPodSpec pushRepo uploadFramework else raise "#{specification.name} #{specification.version} repo或framework缺失" end end |
#pushRepo ⇒ Object
347 348 349 350 351 352 353 354 |
# File 'lib/luna/binary/uploader.rb', line 347 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 |
#repoPath ⇒ Object
335 336 337 |
# File 'lib/luna/binary/uploader.rb', line 335 def repoPath return Luna::Binary::Common.instance.repoPath end |
#source_files(suffix) ⇒ Object
297 298 299 300 |
# File 'lib/luna/binary/uploader.rb', line 297 def source_files(suffix) moduleName = specification.root.name ["#{moduleName}/#{moduleName.sub('-', '_')}.framework" + suffix] end |
#specificationWork ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/luna/binary/uploader.rb', line 60 def specificationWork begin clearTempFile rescue => exception ensure if gitUrl && gitUrl.length > 0 command = "git clone #{gitUrl} #{@rootName}temp; cd #{@rootName}temp; git fetch --all;git stash; git checkout #{gitNode};" p command result = system command end if isHasSpecInRepo == false && isHasFrameworkInService == false @spec = createFrameworkSpec write_spec_file(@spec) else raise "已存在repo or 二进制服务 #{specification.name} #{specification.version}" end end end |
#upload ⇒ Object
38 39 40 41 |
# File 'lib/luna/binary/uploader.rb', line 38 def upload specificationWork push end |
#uploadFramework ⇒ Object
373 374 375 376 377 378 379 380 |
# File 'lib/luna/binary/uploader.rb', line 373 def uploadFramework zipCommand = "cd #{rootName};zip -r #{specification.root.name}.zip #{specification.root.name}" p zipCommand system zipCommand command = "cd #{rootName};curl #{CBin.config.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
31 32 33 34 35 36 |
# File 'lib/luna/binary/uploader.rb', line 31 def validate! raise '缺少gitUrl参数' unless gitUrl raise '缺少gitNode参数' unless gitNode raise '缺少binaryPath参数' unless binaryPath raise '缺少podspecName参数' unless podspecName end |
#write_spec_file(specification) ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/luna/binary/uploader.rb', line 302 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 |