cocoapods-coding-ar 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf872b5c897ddf20af800867f15ac7a5a59ad619ae1401c240ba206e78dca246
4
+ data.tar.gz: ca2a107a93b8cbb0e804fd0081374e77b6b6880e435622d14cb1a2a58dfc9b7b
5
+ SHA512:
6
+ metadata.gz: 0e1c6b6063c7ea645550d93f067fa3f1c7d925041e6d989564b7fe2697715619c150de54e83a459478fa613fc589ca33c33c86f1f0241ac61b6a6b44dfb2f637
7
+ data.tar.gz: 664d96ff0c96b47e47f736e58714bbf709ed8465e9e1a75d4f1e4189a8534d45d564ad95921d64a490a7ba6df1c4e7e14fdf6027109a7b52383e7e9f20571bbc
@@ -0,0 +1,3 @@
1
+ module CocoapodsCodingAr
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,69 @@
1
+ require 'coding_ar_source'
2
+ require 'coding_ar_command'
3
+ require 'coding_ar_util'
4
+
5
+ module Pod
6
+ module Downloader
7
+ class Http
8
+ def self.options
9
+ [:type, :flatten, :sha1, :sha256, :indexDownload]
10
+ end
11
+
12
+ alias_method :orig_download_file, :download_file
13
+ alias_method :orig_should_flatten?, :should_flatten?
14
+
15
+ def download_file(full_filename)
16
+ CodingArUtil.download(url, full_filename)
17
+ end
18
+
19
+ def should_flatten?
20
+ if options.key?(:indexDownload)
21
+ true
22
+ else
23
+ orig_should_flatten?
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ module Pod
31
+ class Source
32
+ class Manager
33
+ alias_method :orig_source_from_path, :source_from_path
34
+ alias_method :orig_create_source_with_url, :create_source_with_url
35
+
36
+ def source_from_path(path)
37
+ @sources_by_path ||= Hash.new do |hash, key|
38
+ hash[key] = case
39
+ when key.basename.to_s == Pod::TrunkSource::TRUNK_REPO_NAME
40
+ TrunkSource.new(key)
41
+ when (key + '.url').exist?
42
+ CDNSource.new(key)
43
+ when (key + '.coding_ar_url').exist?
44
+ CodingArSource.new(key)
45
+ else
46
+ Source.new(key)
47
+ end
48
+ end
49
+
50
+ @sources_by_path[path]
51
+ end
52
+
53
+ def create_source_with_url(url)
54
+ require 'coding_ar_util'
55
+
56
+ name = name_for_url(url)
57
+ if CodingArUtil.coding_ar_service?(url)
58
+ Command::Repo::AddCodingAr.parse([name, url]).run
59
+ else
60
+ orig_create_source_with_url(url)
61
+ end
62
+
63
+ source = source_with_url(url)
64
+ raise "Unable to create a source with URL #{url}" unless source
65
+ source
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,179 @@
1
+ module Pod
2
+ class Command
3
+ class Repo < Command
4
+ class AddCodingAr < Repo
5
+ self.summary = 'Add a CODING-AR-backed repo'
6
+ self.description = <<-DESC
7
+ Adds the remote named `NAME` to the local spec-repos directory at `#{Config.instance.repos_dir}`.
8
+ DESC
9
+
10
+ def initialize(argv)
11
+ @name, @url = argv.shift_argument, argv.shift_argument
12
+ super
13
+ end
14
+
15
+ def validate!
16
+ super
17
+ unless @name && @url
18
+ help! 'This command requires both a repo name and a url.'
19
+ end
20
+ end
21
+
22
+ def run
23
+ require 'coding_ar_util'
24
+
25
+ UI.section("Adding CODING-AR-backed repository `#@url` into local spec repo `#@name`") do
26
+ if !CodingArUtil.coding_ar_service?(@url)
27
+ raise Informative, "`#@url` seems not to be a CODING-AR-backed repository."
28
+ end
29
+
30
+ raise Informative, "Local spec repo #@name (in #{dir}) already exists." if File.exists?(dir)
31
+
32
+ FileUtils.mkdir_p dir
33
+
34
+ begin
35
+ url_path = create_coding_ar_url_file dir
36
+ rescue => e
37
+ raise Informative, "Cannot create file '#{url_path}' because : #{e.message}."
38
+ end
39
+ end
40
+ end
41
+
42
+ def create_coding_ar_url_file(repo_dir)
43
+ url_path = File.join(repo_dir, ".coding_ar_url")
44
+ url_file = File.new(url_path, "wb")
45
+ url_file << @url
46
+ url_file.close
47
+ url_path
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ module Pod
55
+ class Command
56
+ class Repo < Command
57
+ class PushCodingAr < Repo
58
+ extend Executable
59
+ executable :tar
60
+
61
+ self.summary = 'Push a pod to CODING-AR.'
62
+ self.description = <<-DESC
63
+ Push a pod include its spec to a CODINF-AR repo.
64
+ DESC
65
+
66
+ self.arguments = [
67
+ CLAide::Argument.new('REPO', true),
68
+ CLAide::Argument.new('NAME.podspec', true)
69
+ ]
70
+
71
+ def initialize(argv)
72
+ @repo = argv.shift_argument
73
+ @podspec = argv.shift_argument
74
+ super
75
+ end
76
+
77
+ def validate!
78
+ super
79
+ super
80
+ unless @repo && @podspec
81
+ help! 'This command requires both a repo and a podspec.'
82
+ end
83
+ end
84
+
85
+ def run
86
+ FileUtils.mkdir_p tmp_dir
87
+ begin
88
+ UI.section("Pushing pod `#{spec.name} #{spec.version.to_s}`` to CODING-AR repo `#@repo`") do
89
+ pod_tar_gz_path = create_pod_tar_gz
90
+ podspec_json_path = create_spec_json
91
+
92
+ post_pod_with_spec(pod_tar_gz_path, podspec_json_path)
93
+ end
94
+ UI.puts "Successfully push pod `#{spec.name} #{spec.version.to_s}`` to CODING-AR repo `#@repo`".green
95
+ ensure
96
+ FileUtils.rm_rf tmp_dir
97
+ end
98
+ end
99
+
100
+ def create_pod_tar_gz
101
+ require 'digest/sha1'
102
+
103
+ pod_dir = File.join(tmp_dir, "pod")
104
+ FileUtils.mkdir_p(pod_dir)
105
+
106
+ pod_root = File.dirname Pathname(@podspec).realpath
107
+ path_list = Pod::Sandbox::PathList.new(pod_root)
108
+
109
+ file_accessors ||= spec.available_platforms.flat_map do |platform|
110
+ Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
111
+ end
112
+
113
+ Pod::Sandbox::FileAccessor.all_files(file_accessors).each do |source|
114
+ target = File.join(pod_dir, Pathname(source).relative_path_from(pod_root))
115
+ FileUtils.mkdir_p(File.dirname(target))
116
+ FileUtils.copy_file(source, target)
117
+ end
118
+
119
+ tar_gz_path = File.join(tmp_dir, "#{spec.name}-#{spec.version}.tar.gz")
120
+
121
+ Dir.chdir(pod_dir) { tar!('-czf', tar_gz_path, '.') }
122
+
123
+ tar_gz_path
124
+ end
125
+
126
+ def create_spec_json
127
+ require 'json'
128
+
129
+ FileUtils.mkdir_p(tmp_dir)
130
+ podspec_json_path = File.join(tmp_dir, "#{spec.name}.podspec.json")
131
+ podspec_json = File.new(podspec_json_path, "wb")
132
+ podspec_json.puts(spec.to_pretty_json)
133
+ podspec_json.close
134
+ podspec_json_path
135
+ end
136
+
137
+ def post_pod_with_spec(pod_path, spec_path)
138
+ require 'json'
139
+
140
+ request_body = {
141
+ 'pod' => file_push_profile(pod_path),
142
+ 'spec' => file_push_profile(spec_path)
143
+ }
144
+ request_body_json_path = File.join(tmp_dir, "request_body.json")
145
+ request_body_json = File.new(request_body_json_path, "wb")
146
+ request_body_json.puts(request_body.to_json)
147
+ request_body_json.close
148
+
149
+ require 'coding_ar_util'
150
+ CodingArUtil.push_pod(coding_ar_repo_url, request_body_json_path)
151
+ end
152
+
153
+ def spec
154
+ spec_file = Pathname(@podspec)
155
+ spec = Pod::Specification.from_file(spec_file)
156
+ end
157
+
158
+ def tmp_dir
159
+ File.join(Config.instance.repos_dir, @repo, '.tmp', spec.name, spec.version.to_s)
160
+ end
161
+
162
+ def coding_ar_repo_url
163
+ File.read File.join(Config.instance.repos_dir, @repo, ".coding_ar_url")
164
+ end
165
+
166
+ def file_push_profile(path)
167
+ require 'digest/sha1'
168
+
169
+ content = File.read(path)
170
+ {
171
+ 'size' => File.lstat(path).size,
172
+ 'base64_content' => Base64.strict_encode64(content),
173
+ 'sha1_digest' => Digest::SHA1.hexdigest(content)
174
+ }
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,126 @@
1
+ module Pod
2
+ class CodingArSource < Source
3
+ def initialize(repo)
4
+ super(repo)
5
+ end
6
+
7
+ def name
8
+ repo.basename.to_s
9
+ end
10
+
11
+ def url
12
+ @url ||= File.read(repo.join('.coding_ar_url')).chomp.chomp('/')
13
+ end
14
+
15
+ def type
16
+ 'CODING-AR'
17
+ end
18
+
19
+ def specs_dir
20
+ repo
21
+ end
22
+
23
+ def pod_path(name)
24
+ specs_dir.join(name)
25
+ end
26
+
27
+ def pods
28
+ raise Informative, "Can't retrieve all the pods for a CODING-AR-backed source."
29
+ end
30
+
31
+ def versions(name)
32
+ eturn nil unless specs_dir
33
+ raise ArgumentError, 'No name' unless name
34
+
35
+ list_version(name).map do |v|
36
+ Version.new(v)
37
+ end.compact.sort.reverse
38
+ end
39
+
40
+ def specification_path(name, version)
41
+ raise ArgumentError, 'No name' unless name
42
+ raise ArgumentError, 'No version' unless version
43
+ unless versions(name).include?(Version.new(version))
44
+ raise StandardError, "Unable to find the specification #{name} " \
45
+ "(#{version}) in the #{self.name} source."
46
+ end
47
+
48
+ spec_url = "#{url}/Specs/#{name}/#{version.to_s}/#{name}.podspec.json"
49
+ spec_path = File.join(specs_dir, name, version.to_s, "#{name}.podspec.json")
50
+ FileUtils.mkdir_p File.dirname(spec_path)
51
+ require 'coding_ar_util'
52
+ CodingArUtil.download(spec_url, spec_path)
53
+
54
+ spec_path
55
+ end
56
+
57
+ def all_specs
58
+ raise Informative, "Can't retrieve all the specs for a CODING-AR-backed source."
59
+ end
60
+
61
+ def pod_sets
62
+ raise Informative, "Can't retrieve all the pod sets for a CODING-AR-backed source."
63
+ end
64
+
65
+ def search(query)
66
+ unless specs_dir
67
+ raise Informative, "Unable to find a source named: `#{name}`"
68
+ end
69
+ if query.is_a?(Dependency)
70
+ query = query.root_name
71
+ end
72
+
73
+ if list_version(query).length > 0
74
+ set = set(query)
75
+ set if set.specification_name == query
76
+ end
77
+ end
78
+
79
+ def search_by_name(query, full_text_search = false)
80
+ raise Informative, "Can't search a CODING-AR-backed source by name."
81
+ end
82
+
83
+ def update(_show_output)
84
+ require 'json'
85
+ require 'coding_ar_util'
86
+
87
+ changed_spec_paths = []
88
+ UI.puts "Updating CODING-AR-backed repo #{name}".yellow if _show_output
89
+ Pathname.glob(repo.join('**/*/*.json')).map do |f|
90
+ origin_content = File.read(f)
91
+ spec = JSON.parse origin_content
92
+ spec_url = "#{url}/Specs/#{spec['name']}/#{spec['version']}/#{spec['name']}.podspec.json"
93
+ UI.puts "- Fetch #{spec_url}" if _show_output
94
+ FileUtils.mkdir_p File.dirname(f)
95
+ CodingArUtil.download(spec_url, f)
96
+ latest_content = File.read(f)
97
+ FileUtils.rm_rf(File.dirname(f)) if latest_content.to_s.start_with?('Pod not found')
98
+ JSON.parse latest_content
99
+ changed_spec_paths.push(f) if origin_content != latest_content
100
+ end
101
+ UI.puts "Successfully update CODING-AR-backed repo #{name}".green if _show_output
102
+
103
+ []
104
+ end
105
+
106
+ def updateable?
107
+ true
108
+ end
109
+
110
+ def git?
111
+ false
112
+ end
113
+
114
+ def indexable?
115
+ false
116
+ end
117
+
118
+ private
119
+
120
+ def list_version(pod)
121
+ require 'coding_ar_util'
122
+ CodingArUtil.get_json("#{url}/pods/#{pod}")
123
+ end
124
+
125
+ end
126
+ end
@@ -0,0 +1,98 @@
1
+ require 'json'
2
+ require 'typhoeus'
3
+ require 'netrc'
4
+ require 'cocoapods_coding_ar'
5
+
6
+ module Pod
7
+ class CodingArUtil
8
+ CODING_AR_NETRC_PATH_ENV = 'COCOAPODS_CODING_AR_NETRC_PATH'
9
+ JSON_CONTENT_TYPE = 'application/json; charset=utf-8'
10
+ USER_AGENT = "cocoapods-coding-ar/#{CocoapodsCodingAr::VERSION}"
11
+
12
+ def self.coding_ar_service?(url)
13
+ request = Typhoeus::Request.new(
14
+ url,
15
+ :method => :get,
16
+ :headers => {
17
+ 'User-Agent' => USER_AGENT,
18
+ },
19
+ )
20
+ request.run
21
+
22
+ begin
23
+ resp = JSON.parse(request.response.body)
24
+ resp['service'] == 'CODING-AR'
25
+ rescue
26
+ return false
27
+ end
28
+ end
29
+
30
+ def self.push_pod(url, body_path)
31
+ request = Typhoeus::Request.new(
32
+ url,
33
+ :method => :post,
34
+ :netrc => :optional,
35
+ :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path,
36
+ :headers => {
37
+ 'Content-Type' => JSON_CONTENT_TYPE,
38
+ 'User-Agent' => USER_AGENT,
39
+ },
40
+ :body => File.read(body_path),
41
+ )
42
+ request.run
43
+
44
+ if request.response.code == 0
45
+ raise "fail to push pod: #{request.response.return_message}"
46
+ elsif request.response.code != 200
47
+ raise "fail to push pod: #{request.response.body}"
48
+ end
49
+ end
50
+
51
+ def self.get_json(url)
52
+ request = Typhoeus::Request.new(
53
+ url,
54
+ :method => :get,
55
+ :netrc => :optional,
56
+ :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path,
57
+ :followlocation => true,
58
+ :headers => {
59
+ 'User-Agent' => USER_AGENT,
60
+ },
61
+ )
62
+ request.run
63
+
64
+ if request.response.code == 0
65
+ raise "fail to request #{url}: #{request.response.return_message}"
66
+ elsif request.response.code != 200
67
+ raise "fail to request #{url}: #{request.response.body}"
68
+ else
69
+ JSON.parse(request.response.body)
70
+ end
71
+ end
72
+
73
+ def self.download(url, path)
74
+ request = Typhoeus::Request.new(
75
+ url,
76
+ :method => :get,
77
+ :netrc => :optional,
78
+ :netrc_file => ENV[CODING_AR_NETRC_PATH_ENV] || Netrc.default_path,
79
+ :followlocation => true,
80
+ :headers => {
81
+ 'User-Agent' => USER_AGENT,
82
+ },
83
+ )
84
+ request.run
85
+
86
+ if request.response.code == 0
87
+ raise "fail to request #{url}: #{request.response.return_message}"
88
+ elsif request.response.code != 200
89
+ raise "fail to request #{url}: #{request.response.body}"
90
+ else
91
+ file = File.new(path, 'wb')
92
+ file << request.response.body
93
+ file.close
94
+ end
95
+ end
96
+
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-coding-ar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - huangmingxin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-31 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: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: CODING-AR-backed repo support for Cocoapods
42
+ email:
43
+ - huangmingxin@coding.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods_coding_ar.rb
49
+ - lib/cocoapods_plugin.rb
50
+ - lib/coding_ar_command.rb
51
+ - lib/coding_ar_source.rb
52
+ - lib/coding_ar_util.rb
53
+ homepage: https://coding-public.coding.net/p/cocoapods-coding-ar
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.0.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: CODING-AR-backed repo support for Cocoapods
76
+ test_files: []