cocoapods-marstransfer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 256a7ca5134e098c1c77db9a5be7750a4ea44c79471437353bdf4c6fdc6b9625
4
+ data.tar.gz: cd425dd10753162c10b7f10c5c2940d2bae790fda1b51fdd818f0693f1ec87f7
5
+ SHA512:
6
+ metadata.gz: 52853a2414e07cb82cf08a2d2b0ee48e36e3505cb49554eef98e2eaf61bc7f480a907741bbb5ac4d55d78b46d404e309d0bf99512a193a8dcae93264b2ef4c7d
7
+ data.tar.gz: db3255b267476b39aa6293d67f018b409ef394d0a4f51fc1ce0688393e987056c90bf1c14fb26ed700aed5a1a7593959648387e231058c803104c90415549a08
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ ruby/*
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cocoapods-marstransfer.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'cocoapods'
8
+ gem 'mocha'
9
+ gem 'bacon'
10
+ gem 'mocha-on-bacon'
11
+ gem 'prettybacon'
12
+ gem 'json_pure'
13
+ gem 'rubyzip', '>= 1.0.0'
14
+ gem 'open-uri'
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2021 shangguanchengyang.1 <shangguanchengyang.1@bytedance.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # cocoapods-marstransfer
2
+
3
+ A description of cocoapods-marstransfer.
4
+
5
+ ## Installation
6
+
7
+ $ gem install cocoapods-marstransfer
8
+
9
+ ## Usage
10
+
11
+ $ pod spec marstransfer POD_NAME
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ def specs(dir)
4
+ FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
5
+ end
6
+
7
+ desc 'Runs all the specs'
8
+ task :specs do
9
+ sh "bundle exec bacon #{specs('**')}"
10
+ end
11
+
12
+ task :default => :specs
13
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cocoapods-marstransfer/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cocoapods-marstransfer'
8
+ spec.version = CocoapodsMarstransfer::VERSION
9
+ spec.authors = ['shangguanchengyang.1']
10
+ spec.email = ['shangguanchengyang.1@bytedance.com']
11
+ spec.description = %q{A short description of cocoapods-marstransfer.}
12
+ spec.summary = %q{A longer description of cocoapods-marstransfer.}
13
+ spec.homepage = 'https://github.com/EXAMPLE/cocoapods-marstransfer'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+
24
+ end
@@ -0,0 +1,89 @@
1
+ require 'fileutils'
2
+
3
+ module Pod
4
+ class Command
5
+ # This is an example of a cocoapods plugin adding a top-level subcommand
6
+ # to the 'pod' command.
7
+ #
8
+ # You can also create subcommands of existing or new commands. Say you
9
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
10
+ # (e.g. `pod list deprecated`), there are a few things that would need
11
+ # to change.
12
+ #
13
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
14
+ # the class to exist in the the Pod::Command::List namespace
15
+ # - change this class to extend from `List` instead of `Command`. This
16
+ # tells the plugin system that it is a subcommand of `list`.
17
+ # - edit `lib/cocoapods_plugins.rb` to require this file
18
+ #
19
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
20
+ # in the `plugins.json` file, once your plugin is released.
21
+ #
22
+ class Marstransfer < Command
23
+ self.summary = 'Short description of cocoapods-marstransfer.'
24
+
25
+ self.description = <<-DESC
26
+ Longer description of cocoapods-marstransfer.
27
+ DESC
28
+
29
+ self.arguments = [
30
+ CLAide::Argument.new('POD_LOCKFILE', true),
31
+ ]
32
+
33
+ def self.options
34
+ options = [
35
+ ['--pod_repo=pod_repo', 'the repo name of local cocoapods source'],
36
+ ['--tos_domain=tos_domain', 'the domain from tos service'],
37
+ ['--tos_key=tos_key', 'the key from tos service'],
38
+ ['--tos_bucket=tos_bucket', 'the bucket from tos service'],
39
+ ]
40
+ end
41
+
42
+ def initialize(argv)
43
+ @lockfile = argv.shift_argument
44
+ @pod_repo = argv.option('pod_repo', '')
45
+ @tos_domain = argv.option('tos_domain', '')
46
+ @tos_key = argv.option('tos_key', '')
47
+ @tos_bucket = argv.option('tos_bucket', '')
48
+
49
+ super
50
+ end
51
+
52
+ def validate!
53
+ super
54
+ help! 'A lockfile is required.' unless @lockfile
55
+ end
56
+
57
+ def run
58
+ temp_dir = ""
59
+ Dir.mktmpdir("marstransfer") do |dir|
60
+ puts "[MARS] working dir: #{dir}"
61
+ lockfile = Pod::Lockfile.from_file(Pathname.new(@lockfile))
62
+ pod_names = lockfile.pod_names
63
+ pods_by_spec_repo = lockfile.pods_by_spec_repo
64
+ trunk_pods = pods_by_spec_repo["trunk"]
65
+ Dir.chdir(dir) do
66
+ make_working_dir
67
+ if trunk_pods.length > 0
68
+ pod_specs = trunk_pods.map do |pod|
69
+ transfer = Transfer.new(lockfile,@pod_repo,@tos_key,@tos_domain,@tos_bucket)
70
+ if @tos_domain.include?("byted.org")
71
+ transfer.transfer_pod_tos(pod)
72
+ else
73
+ transfer.transfer_pod(pod)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ temp_dir = dir
79
+ end
80
+ FileUtils.rm_rf(temp_dir)
81
+ end
82
+
83
+ def make_working_dir
84
+ Dir.mkdir 'source' unless Dir.exist?('source')
85
+ Dir.mkdir 'podspec' unless Dir.exist?('podspec')
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-marstransfer/command/marstransfer'
@@ -0,0 +1,3 @@
1
+ module CocoapodsMarstransfer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,147 @@
1
+ require 'digest/md5'
2
+ require 'json/pure'
3
+ require 'zip'
4
+ require 'open-uri'
5
+ require 'net/http'
6
+
7
+ module Pod
8
+ class Transfer
9
+ def initialize(lockfile,pod_repo,tos_key,tos_domain,tos_bucket)
10
+ @lockfile = lockfile
11
+ @tos_key = tos_key
12
+ @tos_domain = tos_domain
13
+ @pod_repo = pod_repo
14
+ @tos_bucket = tos_bucket
15
+ end
16
+
17
+
18
+ def transfer_pod(pod)
19
+ puts "[MARS] =========== Start Transfer #{pod} =============="
20
+ version = @lockfile.version(pod)
21
+ checksum = @lockfile.checksum(pod)
22
+ md5 = Digest::MD5.hexdigest(pod)
23
+ pod_spec_url = "https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/#{md5[0,1]}/#{md5[1,1]}/#{md5[2,1]}/#{pod}/#{version}/#{pod}.podspec.json"
24
+ puts "[MARS] send podspec request:#{pod_spec_url}"
25
+ uri = URI(pod_spec_url)
26
+ response = Net::HTTP.get(uri)
27
+ json = JSON.parse(response)
28
+ source = json["source"]
29
+ source_url = source["git"] unless !source.has_key?("git")
30
+ source_tag = source["tag"] unless !source.has_key?("tag")
31
+ response_code = ""
32
+ zip_url = ""
33
+ if !source_url.nil? && !source_tag.nil?
34
+ Dir.chdir("source") do
35
+ cmd = "git clone #{source_url} #{pod} --branch #{source_tag} --config advice.detachedHead=false"
36
+ puts "[MARS] clone repo :#{source_url}"
37
+ system(cmd)
38
+
39
+ archive_zip_path = "#{pod}.zip"
40
+ archive_directory_path = "#{pod}"
41
+ Zip::File.open( archive_zip_path, Zip::File::CREATE ) do |zip_file|
42
+ Dir[ File.join( archive_directory_path, "**", "**" ) ].each do |file|
43
+ zip_file.add( file.sub( "#{ archive_directory_path }/", "" ), file )
44
+ end
45
+ end
46
+
47
+ url = "http://#{@tos_domain}/open_oss/upload_file"
48
+ uri = URI(url)
49
+ req = Net::HTTP::Post.new(uri)
50
+ req['Host'] = uri.hostname
51
+ # req['User-Agent'] = "tos-sdk-go"
52
+ req['Content-Type'] = "multipart/form-data"
53
+ req['Content-Length'] = File.size(archive_zip_path)
54
+ # puts "filesize:#{File.size(archive_zip_path)}"
55
+ form_data = [['file', File.open(archive_zip_path)],['file_path',@tos_bucket],['token',@tos_key]] # or File.open() in case of local file
56
+ req.set_form(form_data, 'multipart/form-data')
57
+ response = Net::HTTP.start(uri.hostname, uri.port) do |http|
58
+ http.request(req)
59
+ end
60
+ puts "[MARS] Upload file to TOS: Sending PUT #{url} with key #{@tos_key} bucket #{@tos_bucket}"
61
+ puts "[MARS] Response #{response.code} #{response.message}"
62
+ # puts "Headers: #{response.to_hash.inspect}"
63
+ data = JSON.parse(response.body)
64
+ puts "[MARS] Response #{response.body}"
65
+ response_code = response.code
66
+ zip_url = data["data"][0]
67
+ end
68
+
69
+ if response_code == "200"
70
+ puts "[MARS] Upload Success: url #{zip_url}"
71
+ json["source"] = {"http" => zip_url}
72
+ pod_spec_url = Dir.pwd + "/podspec/" + "#{pod}.podspec.json"
73
+ File.open(pod_spec_url, 'w') { |file|
74
+ file.write(JSON.pretty_generate(json))
75
+ }
76
+ ctr = "pod repo push #{@pod_repo} #{pod_spec_url} --skip-tests --skip-import-validation --allow-warnings"
77
+ puts "[MARS] push podspec #{pod_spec_url} to #{@pod_repo}"
78
+ system(ctr)
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ def transfer_pod_tos(pod)
85
+ puts "[MARS] =========== Start Transfer #{pod} =============="
86
+ version = @lockfile.version(pod)
87
+ checksum = @lockfile.checksum(pod)
88
+ md5 = Digest::MD5.hexdigest(pod)
89
+ pod_spec_url = "https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/#{md5[0,1]}/#{md5[1,1]}/#{md5[2,1]}/#{pod}/#{version}/#{pod}.podspec.json"
90
+ puts "[MARS] send podspec request:#{pod_spec_url}"
91
+ uri = URI(pod_spec_url)
92
+ response = Net::HTTP.get(uri)
93
+ json = JSON.parse(response)
94
+ source = json["source"]
95
+ source_url = source["git"] unless !source.has_key?("git")
96
+ source_tag = source["tag"] unless !source.has_key?("tag")
97
+ response_code = ""
98
+ if !source_url.nil? && !source_tag.nil?
99
+ Dir.chdir("source") do
100
+ cmd = "git clone #{source_url} #{pod} --branch #{source_tag} --config advice.detachedHead=false"
101
+ puts "[MARS] clone repo :#{source_url}"
102
+ system(cmd)
103
+
104
+ archive_zip_path = "#{pod}.zip"
105
+ archive_directory_path = "#{pod}"
106
+ Zip::File.open( archive_zip_path, Zip::File::CREATE ) do |zip_file|
107
+ Dir[ File.join( archive_directory_path, "**", "**" ) ].each do |file|
108
+ zip_file.add( file.sub( "#{ archive_directory_path }/", "" ), file )
109
+ end
110
+ end
111
+
112
+ url = "http://#{@tos_bucket}.#{@tos_domain}/#{@tos_bucket}/#{pod}/#{version}/#{pod}.zip"
113
+ uri = URI(url)
114
+ req = Net::HTTP::Put.new(uri)
115
+ req['Host'] = uri.hostname
116
+ req['User-Agent'] = "tos-sdk-go"
117
+ req['X-Tos-Access'] = @tos_key
118
+ req['Content-Length'] = File.size(archive_zip_path)
119
+ # puts "filesize:#{File.size(archive_zip_path)}"
120
+ req.body_stream = File.open(archive_zip_path)
121
+ response = Net::HTTP.start(uri.hostname, uri.port) do |http|
122
+ http.request(req)
123
+ end
124
+ puts "[MARS] Upload file to TOS: Sending PUT #{url} with #{@tos_key}"
125
+ puts "[MARS] Response #{response.code} #{response.message}"
126
+ # puts "Headers: #{response.to_hash.inspect}"
127
+ response_code = response.code
128
+ end
129
+
130
+ if response_code == "200"
131
+ zip_url = "http://#{@tos_bucket}.#{@tos_domain}/#{@tos_bucket}/#{pod}/#{version}/#{pod}.zip"
132
+ puts "[MARS] Upload Success: url #{zip_url}"
133
+ json["source"] = {"http" => zip_url}
134
+ pod_spec_url = Dir.pwd + "/podspec/" + "#{pod}.podspec.json"
135
+ File.open(pod_spec_url, 'w') { |file|
136
+ file.write(JSON.pretty_generate(json))
137
+ }
138
+ ctr = "pod repo push #{@pod_repo} #{pod_spec_url} --skip-tests --skip-import-validation --allow-warnings --silent"
139
+ puts "[MARS] push podspec #{pod_spec_url} to #{@pod_repo}"
140
+ system(ctr)
141
+ end
142
+
143
+ end
144
+ end
145
+ end
146
+ # module_function :transfer_pod
147
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-marstransfer/gem_version'
@@ -0,0 +1,2 @@
1
+ require 'cocoapods-marstransfer/command'
2
+ require 'cocoapods-marstransfer/transfer'
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Marstransfer do
5
+ describe 'CLAide' do
6
+ it 'registers it self' do
7
+ Command.parse(%w{ marstransfer }).should.be.instance_of Command::Marstransfer
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,50 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'bacon'
8
+ require 'mocha-on-bacon'
9
+ require 'pretty_bacon'
10
+ require 'pathname'
11
+ require 'cocoapods'
12
+
13
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
14
+
15
+ require 'cocoapods_plugin'
16
+
17
+ #-----------------------------------------------------------------------------#
18
+
19
+ module Pod
20
+
21
+ # Disable the wrapping so the output is deterministic in the tests.
22
+ #
23
+ UI.disable_wrap = true
24
+
25
+ # Redirects the messages to an internal store.
26
+ #
27
+ module UI
28
+ @output = ''
29
+ @warnings = ''
30
+
31
+ class << self
32
+ attr_accessor :output
33
+ attr_accessor :warnings
34
+
35
+ def puts(message = '')
36
+ @output << "#{message}\n"
37
+ end
38
+
39
+ def warn(message = '', actions = [])
40
+ @warnings << "#{message}\n"
41
+ end
42
+
43
+ def print(message)
44
+ @output << message
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ #-----------------------------------------------------------------------------#
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-marstransfer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shangguanchengyang.1
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-26 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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-marstransfer.
42
+ email:
43
+ - shangguanchengyang.1@bytedance.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - cocoapods-marstransfer.gemspec
54
+ - lib/cocoapods-marstransfer.rb
55
+ - lib/cocoapods-marstransfer/command.rb
56
+ - lib/cocoapods-marstransfer/command/marstransfer.rb
57
+ - lib/cocoapods-marstransfer/gem_version.rb
58
+ - lib/cocoapods-marstransfer/transfer.rb
59
+ - lib/cocoapods_plugin.rb
60
+ - spec/command/marstransfer_spec.rb
61
+ - spec/spec_helper.rb
62
+ homepage: https://github.com/EXAMPLE/cocoapods-marstransfer
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.0.9
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A longer description of cocoapods-marstransfer.
85
+ test_files:
86
+ - spec/command/marstransfer_spec.rb
87
+ - spec/spec_helper.rb