lg_pod_plugin 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,287 @@
1
+ require 'uri'
2
+ require_relative 'request'
3
+ require_relative 'l_util'
4
+ require_relative 'l_config'
5
+ require_relative 'podspec'
6
+ require_relative 'gitlab_api'
7
+
8
+ module LgPodPlugin
9
+
10
+ class GitLabArchive
11
+ REQUIRED_ATTRS ||= %i[git tag name commit branch].freeze
12
+ attr_accessor(*REQUIRED_ATTRS)
13
+
14
+ def initialize(name, git, branch, tag, commit)
15
+ self.git = git ||= LRequest.shared.request_params[:git]
16
+ self.tag = tag ||= LRequest.shared.request_params[:tag]
17
+ self.name = name ||= LRequest.shared.request_params[:name]
18
+ self.commit = commit ||= LRequest.shared.request_params[:commit]
19
+ self.branch = branch ||= LRequest.shared.request_params[:branch]
20
+ end
21
+
22
+ # 下载某个文件zip格式
23
+ def gitlab_download_file_by_name(path, filename, temp_name, project_name)
24
+ host = LRequest.shared.config.host
25
+ project = LRequest.shared.config.project
26
+ unless host
27
+ http = Ping.new(project.web_url)
28
+ host = http.uri.scheme + "://" + http.uri.hostname
29
+ end
30
+ if self.git && self.tag
31
+ sha = self.tag
32
+ elsif self.git && self.branch
33
+ sha = self.branch
34
+ elsif self.git && self.commit
35
+ sha = self.commit
36
+ end
37
+ token = LRequest.shared.config.access_token
38
+ begin
39
+ encode_fiename = LUtils.url_encode(filename)
40
+ download_url = host + "/api/v4/projects/" + "#{project.id}" + "/repository/archive.zip#{"\\?"}" + "path#{"\\="}#{encode_fiename}#{"\\&"}sha#{"\\="}#{sha}"
41
+ rescue => exception
42
+ return nil
43
+ end
44
+ LUtils.download_gitlab_zip_file(download_url, token, temp_name)
45
+ return nil unless File.exist?(temp_name)
46
+ return nil unless (result = LUtils.unzip_file(temp_name, "./"))
47
+ temp_zip_folder = nil
48
+ path.each_child do |f|
49
+ ftype = File::ftype(f)
50
+ next unless ftype == "directory"
51
+ next unless f.to_path.include?("#{filename}") || f.to_path.include?("#{project_name}")
52
+ temp_zip_folder = f
53
+ break
54
+ end
55
+ return nil unless temp_zip_folder && temp_zip_folder.exist?
56
+ begin
57
+ FileUtils.chdir(temp_zip_folder)
58
+ temp_zip_folder.each_child do |f|
59
+ ftype = File::ftype(f)
60
+ FileUtils.mv(f, path)
61
+ end
62
+ FileUtils.chdir(path)
63
+ FileUtils.rm_rf(temp_zip_folder)
64
+ FileUtils.rm_rf("./#{temp_name}")
65
+ return path
66
+ rescue => exception
67
+ pp exception
68
+ return path
69
+ end
70
+ end
71
+
72
+ # 从 GitLab下载 zip包
73
+ # 根据branch 下载 zip 包
74
+ def gitlab_download_branch_zip(root_path, temp_name)
75
+ project_path = root_path.join(self.name)
76
+ unless project_path.exist?
77
+ project_path.mkdir
78
+ FileUtils.chdir(project_path)
79
+ end
80
+ branch = self.branch ||= "master"
81
+ token = LRequest.shared.config.access_token
82
+ base_url = LRequest.shared.config.project.web_url
83
+ project_name = LRequest.shared.config.project.path
84
+ podspec_name = self.name + ".podspec"
85
+ LgPodPlugin.log_blue "开始下载 => #{base_url}"
86
+ self.gitlab_download_file_by_name(project_path, podspec_name,"#{podspec_name}.zip", project_name)
87
+ podspec_path = project_path.join(podspec_name)
88
+ return nil unless File.exist?(podspec_path)
89
+ begin
90
+ need_download_files = PodSpec.form_file(podspec_path).source_files
91
+ rescue
92
+ need_download_files = Set[]
93
+ end
94
+ unless !need_download_files.empty?
95
+ FileUtils.chdir(root_path)
96
+ file_name = "#{temp_name}.zip"
97
+ download_url = LUtils.get_gitlab_download_url(base_url, branch, nil, nil, project_name)
98
+ raise "download_url不存在" unless download_url
99
+ # LgPodPlugin.log_blue "开始下载 => #{download_url}"
100
+ LUtils.download_gitlab_zip_file(download_url, token, file_name)
101
+ raise "下载zip包失败, 尝试git clone #{self.git}" unless File.exist?(file_name)
102
+ # 解压文件
103
+ result = LUtils.unzip_file(root_path.join(file_name).to_path, "./")
104
+ new_file_name = "#{project_name}-#{branch}"
105
+ raise "解压文件失败, #{new_file_name}不存在" unless result && File.exist?(new_file_name)
106
+ return root_path.join(new_file_name)
107
+ end
108
+ need_download_files.each do |file|
109
+ next if project_path.join(file).exist?
110
+ self.gitlab_download_file_by_name(project_path, file,"#{file}.zip", project_name)
111
+ end
112
+ return project_path
113
+ end
114
+
115
+ # 通过tag下载zip包
116
+ def gitlab_download_tag_zip(root_path, temp_name)
117
+ project_path = root_path.join(self.name)
118
+ unless project_path.exist?
119
+ project_path.mkdir
120
+ FileUtils.chdir(project_path)
121
+ end
122
+ token = LRequest.shared.config.access_token
123
+ base_url = LRequest.shared.config.project.web_url
124
+ project_name = LRequest.shared.config.project.path
125
+ podspec_name = self.name + ".podspec"
126
+ LgPodPlugin.log_blue "开始下载 => #{base_url}"
127
+ self.gitlab_download_file_by_name(project_path, podspec_name,"#{podspec_name}.zip", project_name)
128
+ podspec_path = project_path.join(podspec_name)
129
+ return nil unless File.exist?(podspec_path)
130
+ begin
131
+ need_download_files = PodSpec.form_file(podspec_path).source_files
132
+ rescue
133
+ need_download_files = Set[]
134
+ end
135
+ unless !need_download_files.empty?
136
+ tag = self.tag
137
+ FileUtils.chdir(root_path)
138
+ file_name = "#{temp_name}.zip"
139
+ download_url = LUtils.get_gitlab_download_url(base_url, nil, tag, nil, project_name)
140
+ raise "download_url不存在" unless download_url
141
+ LUtils.download_gitlab_zip_file(download_url, token, file_name)
142
+ raise "下载zip包失败, 尝试git clone #{self.git}" unless File.exist?(file_name)
143
+ # 解压文件
144
+ result = LUtils.unzip_file(root_path.join(file_name).to_path, "./")
145
+ new_file_name = "#{project_name}-#{tag}"
146
+ raise "解压文件失败, #{new_file_name}不存在" unless result && File.exist?(new_file_name)
147
+ return root_path.join(new_file_name)
148
+ end
149
+ need_download_files.each do |file|
150
+ self.gitlab_download_file_by_name(project_path, file,"#{file}.zip", project_name)
151
+ end
152
+ return project_path
153
+ end
154
+
155
+ # 通过 commit 下载zip包
156
+ def gitlab_download_commit_zip(root_path, temp_name)
157
+ project_path = root_path.join(self.name)
158
+ unless project_path.exist?
159
+ project_path.mkdir
160
+ FileUtils.chdir(project_path)
161
+ end
162
+ token = LRequest.shared.config.access_token
163
+ base_url = LRequest.shared.config.project.web_url
164
+ project_name = LRequest.shared.config.project.path
165
+ podspec_name = self.name + ".podspec"
166
+ LgPodPlugin.log_blue "开始下载 => #{base_url}"
167
+ self.gitlab_download_file_by_name(project_path, podspec_name,"#{podspec_name}.zip", project_name)
168
+ podspec_path = project_path.join(podspec_name)
169
+ return nil unless File.exist?(podspec_path)
170
+ begin
171
+ need_download_files = PodSpec.form_file(podspec_path).source_files
172
+ rescue
173
+ need_download_files = Set[]
174
+ end
175
+ unless !need_download_files.empty?
176
+ FileUtils.chdir(root_path)
177
+ file_name = "#{temp_name}.zip"
178
+ download_url = LUtils.get_gitlab_download_url(base_url, nil, nil, self.commit, project_name)
179
+ raise "download_url不存在" unless download_url
180
+ # LgPodPlugin.log_blue "开始下载 => #{download_url}"
181
+ LUtils.download_gitlab_zip_file(download_url, token, file_name)
182
+ raise "下载zip包失败, 尝试git clone #{self.git}" unless File.exist?(file_name)
183
+ # 解压文件
184
+ result = LUtils.unzip_file(root_path.join(file_name).to_path, "./")
185
+ new_file_name = "#{project_name}-#{self.commit}"
186
+ raise "解压文件失败, #{new_file_name}不存在" unless result && File.exist?(new_file_name)
187
+ return root_path.join(new_file_name)
188
+ end
189
+ need_download_files.each do |file|
190
+ self.gitlab_download_file_by_name(project_path, file,"#{file}.zip", project_name)
191
+ end
192
+ return project_path
193
+ end
194
+
195
+ # 从 Github下载 zip 包
196
+ # 根据branch 下载 zip 包
197
+ def github_download_branch_zip(path, temp_name)
198
+ file_name = "#{temp_name}.zip"
199
+ branch = self.branch ||= "master"
200
+ if self.git.include?(".git")
201
+ base_url = self.git[0...self.git.length - 4]
202
+ else
203
+ base_url = self.git
204
+ end
205
+ origin_url = base_url + "/archive/#{branch}.zip"
206
+ project_name = base_url.split("/").last if base_url
207
+ download_url = "https://gh.api.99988866.xyz/#{origin_url}"
208
+ LgPodPlugin.log_blue "开始下载 => #{download_url}"
209
+ LUtils.download_github_zip_file(download_url, file_name)
210
+ unless File.exist?(file_name)
211
+ LgPodPlugin.log_red("下载zip包失败, 尝试git clone #{self.git}")
212
+ return self.git_clone_by_branch(path, temp_name)
213
+ end
214
+ # 解压文件
215
+ result = LUtils.unzip_file(path.join(file_name).to_path, "./")
216
+ new_file_name = "#{project_name}-#{branch}"
217
+ unless result && File.exist?(new_file_name)
218
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
219
+ return self.git_clone_by_branch(path, temp_name)
220
+ end
221
+ path.join(new_file_name)
222
+ end
223
+
224
+ # 通过tag下载zip包
225
+ def github_download_tag_zip(path, temp_name)
226
+ file_name = "#{temp_name}.zip"
227
+ if self.git.include?(".git")
228
+ base_url = self.git[0...self.git.length - 4]
229
+ else
230
+ base_url = self.git
231
+ end
232
+ project_name = base_url.split("/").last if base_url
233
+ origin_url = base_url + "/archive/refs/tags/#{self.tag}.zip"
234
+ download_url = "https://gh.api.99988866.xyz/#{origin_url}"
235
+ # 下载文件
236
+ LgPodPlugin.log_blue "开始下载 => #{download_url}"
237
+ LUtils.download_github_zip_file(download_url, file_name)
238
+ unless File.exist?(file_name)
239
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
240
+ return self.git_clone_by_tag(path, temp_name)
241
+ end
242
+ # 解压文件
243
+ result = LUtils.unzip_file(path.join(file_name).to_path, "./")
244
+ if self.tag.include?("v") && self.tag[0...1] == "v"
245
+ this_tag = self.tag[1...self.tag.length]
246
+ else
247
+ this_tag = self.tag
248
+ end
249
+ new_file_name = "#{project_name}-#{this_tag}"
250
+ unless result && File.exist?(new_file_name)
251
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
252
+ return self.git_clone_by_tag(path, temp_name)
253
+ end
254
+ path.join(new_file_name)
255
+ end
256
+
257
+ # 通过 commit 下载zip包
258
+ def github_download_commit_zip(path, temp_name)
259
+ file_name = "#{temp_name}.zip"
260
+ if self.git.include?(".git")
261
+ base_url = self.git[0...self.git.length - 4]
262
+ else
263
+ base_url = self.git
264
+ end
265
+ project_name = base_url.split("/").last if base_url
266
+ origin_url = base_url + "/archive/#{self.commit}.zip"
267
+ download_url = "https://gh.api.99988866.xyz/#{origin_url}"
268
+ # 下载文件
269
+ LgPodPlugin.log_blue "开始下载 => #{download_url}"
270
+ LUtils.download_github_zip_file(download_url, file_name)
271
+ unless File.exist?(file_name)
272
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
273
+ return self.git_clone_by_commit(path, temp_name)
274
+ end
275
+ # 解压文件
276
+ result = LUtils.unzip_file(path.join(file_name).to_path, "./")
277
+ new_file_name = "#{project_name}-#{self.commit}"
278
+ unless result && File.exist?(new_file_name)
279
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
280
+ return self.git_clone_by_commit(path, temp_name)
281
+ end
282
+ path.join(new_file_name)
283
+ end
284
+
285
+ end
286
+
287
+ end
@@ -0,0 +1,181 @@
1
+ require 'pp'
2
+ require 'git'
3
+ require_relative 'l_config'
4
+ require_relative 'l_util'
5
+ require_relative 'request'
6
+ require_relative 'l_cache'
7
+ require_relative 'net-ping'
8
+ require_relative 'database'
9
+ require_relative 'gitlab_archive'
10
+
11
+ module LgPodPlugin
12
+
13
+ class LGitUtil
14
+
15
+ REQUIRED_ATTRS ||= %i[git tag path name commit branch].freeze
16
+ attr_accessor(*REQUIRED_ATTRS)
17
+
18
+ def initialize(name, options = {})
19
+ self.name = name
20
+ self.git = options[:git]
21
+ self.tag = options[:tag]
22
+ self.path = options[:path]
23
+ self.branch = options[:branch]
24
+ self.commit = options[:commit]
25
+ end
26
+
27
+ def git_clone_by_branch(path, temp_name)
28
+ if self.git && self.branch
29
+ LgPodPlugin.log_blue "git clone --template= --single-branch --depth 1 -b #{self.branch} #{self.git}"
30
+ system("git clone --template= --single-branch --depth 1 -b #{self.branch} #{self.git} #{temp_name}")
31
+ else
32
+ LgPodPlugin.log_blue "git clone --template= --single-branch --depth 1 #{self.git}"
33
+ system("git clone --template= --single-branch --depth 1 #{self.git} #{temp_name}")
34
+ end
35
+ path.join(temp_name)
36
+ end
37
+
38
+ def git_clone_by_tag(path, temp_name)
39
+ LgPodPlugin.log_blue "git clone --template= --single-branch --depth 1 -b #{self.tag} #{self.git}"
40
+ system("git clone --template= --single-branch --depth 1 -b #{self.tag} #{self.git} #{temp_name}")
41
+ path.join(temp_name)
42
+ end
43
+
44
+ # git clone commit
45
+ def git_clone_by_commit(path, temp_name)
46
+ Git.init(temp_name)
47
+ FileUtils.chdir(temp_name)
48
+ LgPodPlugin.log_blue "git clone #{self.git}"
49
+ system("git remote add origin #{self.git}")
50
+ system("git fetch origin #{self.commit}")
51
+ system("git reset --hard FETCH_HEAD")
52
+ path.join(temp_name)
53
+ end
54
+
55
+ # clone 代码仓库
56
+ def git_clone_repository(path)
57
+ FileUtils.chdir(path)
58
+ temp_name = "lg_temp_pod"
59
+ git_archive = GitLabArchive.new(self.name, self.git, self.branch, self.tag, self.commit)
60
+ if self.git && self.tag
61
+ begin
62
+ if LUtils.is_use_gitlab_archive_file(self.git)
63
+ return git_archive.gitlab_download_tag_zip(path, temp_name)
64
+ elsif self.git.include?("https://github.com")
65
+ return git_archive.github_download_tag_zip path, temp_name
66
+ else
67
+ return self.git_clone_by_tag(path, temp_name)
68
+ end
69
+ rescue
70
+ return self.git_clone_by_tag(path, temp_name)
71
+ end
72
+ elsif self.git && self.branch
73
+ begin
74
+ if LUtils.is_use_gitlab_archive_file(self.git)
75
+ return git_archive.gitlab_download_branch_zip(path, temp_name)
76
+ elsif self.git.include?("https://github.com")
77
+ return git_archive.github_download_branch_zip path, temp_name
78
+ else
79
+ return self.git_clone_by_branch(path, temp_name)
80
+ end
81
+ rescue
82
+ return self.git_clone_by_branch(path, temp_name)
83
+ end
84
+ elsif self.git && self.commit
85
+ if LUtils.is_use_gitlab_archive_file(self.git)
86
+ return git_archive.gitlab_download_commit_zip(path, temp_name)
87
+ elsif self.git.include?("https://github.com")
88
+ return git_archive.github_download_commit_zip path, temp_name
89
+ else
90
+ return self.git_clone_by_commit(path, temp_name)
91
+ end
92
+ elsif self.git
93
+ if LUtils.is_use_gitlab_archive_file(self.git)
94
+ return git_archive.gitlab_download_branch_zip(path, temp_name)
95
+ elsif self.git.include?("https://github.com")
96
+ return git_archive.github_download_branch_zip path, temp_name
97
+ else
98
+ return self.git_clone_by_branch(path, temp_name)
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+ # git 预下载
105
+ def pre_download_git_repository
106
+ temp_path = LFileManager.download_director.join("temp")
107
+ if temp_path.exist?
108
+ FileUtils.rm_rf(temp_path)
109
+ end
110
+ lg_pod_path = LRequest.shared.cache.cache_root
111
+ unless lg_pod_path.exist?
112
+ lg_pod_path.mkdir(0700)
113
+ end
114
+ get_temp_folder = git_clone_repository(lg_pod_path)
115
+ #下载 git 仓库失败
116
+ unless get_temp_folder && get_temp_folder.exist?
117
+ return nil
118
+ end
119
+ if LRequest.shared.single_git
120
+ LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, { :git => self.git })
121
+ end
122
+ LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, LRequest.shared.get_cache_key_params)
123
+ FileUtils.chdir(LFileManager.download_director)
124
+ FileUtils.rm_rf(lg_pod_path)
125
+ end
126
+
127
+ # 获取最新的一条 commit 信息
128
+ def self.git_ls_remote_refs(name,git, branch, tag, commit)
129
+ ip = LRequest.shared.net_ping.ip
130
+ network_ok = LRequest.shared.net_ping.network_ok
131
+ return [nil, nil] unless (ip && network_ok)
132
+ if branch
133
+ LgPodPlugin.log_blue "git ls-remote --refs #{git} #{branch}"
134
+ result = %x(timeout 5 git ls-remote --refs #{git} #{branch})
135
+ unless result && result != ""
136
+ id = LPodLatestRefs.get_pod_id(name, git, branch, tag)
137
+ pod_info = LSqliteDb.shared.query_pod_refs(id)
138
+ new_commit = pod_info.commit if pod_info
139
+ return [branch, new_commit]
140
+ end
141
+ new_commit = LUtils.commit_from_ls_remote(result, branch)
142
+ if new_commit
143
+ LSqliteDb.shared.insert_pod_refs(name, git, branch, tag, new_commit)
144
+ end
145
+ return [branch, new_commit]
146
+ elsif tag
147
+ LgPodPlugin.log_blue "git ls-remote --tags #{git}"
148
+ result = %x(timeout 5 git ls-remote --tags #{git})
149
+ unless result && result != ""
150
+ id = LPodLatestRefs.get_pod_id(name, git, branch, tag)
151
+ pod_info = LSqliteDb.shared.query_pod_refs(id)
152
+ new_commit = pod_info.commit if pod_info
153
+ return [nil, new_commit]
154
+ end
155
+ new_commit = LUtils.commit_from_ls_remote(result, tag)
156
+ if new_commit
157
+ LSqliteDb.shared.insert_pod_refs(name, git, branch, tag, new_commit)
158
+ end
159
+ return [nil, new_commit]
160
+ elsif commit
161
+ return nil, commit
162
+ else
163
+ LgPodPlugin.log_blue "git ls-remote --refs #{git}"
164
+ result = %x(timeout 5 git ls-remote -- #{git})
165
+ unless result && result != ""
166
+ id = LPodLatestRefs.get_pod_id(name, git, branch, tag)
167
+ pod_info = LSqliteDb.shared.query_pod_refs(id)
168
+ new_commit = pod_info.commit if pod_info
169
+ return [nil, new_commit]
170
+ end
171
+ new_commit = LUtils.commit_from_ls_remote(result, "HEAD")
172
+ if new_commit
173
+ LSqliteDb.shared.insert_pod_refs(name, git, branch, tag, new_commit)
174
+ end
175
+ return nil, new_commit
176
+ end
177
+ end
178
+
179
+ end
180
+
181
+ end
@@ -4,14 +4,14 @@ require 'cgi'
4
4
  require 'cocoapods'
5
5
  require_relative 'request'
6
6
  require_relative 'database'
7
- require_relative 'git_util'
8
- require_relative 'downloader.rb'
7
+ require_relative 'downloader'
9
8
  require 'cocoapods-core/podfile'
9
+ require_relative 'gitlab_download'
10
10
  require 'cocoapods-core/podfile/target_definition'
11
+
11
12
  module LgPodPlugin
12
13
 
13
14
  class Installer
14
-
15
15
  REQUIRED_ATTRS ||= %i[name version options target real_name workspace].freeze
16
16
  attr_accessor(*REQUIRED_ATTRS)
17
17
 
@@ -29,16 +29,20 @@ module LgPodPlugin
29
29
  self.target = profile.send(:current_target_definition)
30
30
  unless requirements && requirements.is_a?(Hash)
31
31
  LRequest.shared.libs.delete(name)
32
+ LRequest.shared.libs.delete(self.real_name)
32
33
  LgPodPlugin.log_red "pod `#{name}`, 缺少必要的 [git|commit|tag|branch] 参数"
33
34
  return
34
35
  end
35
- hash_map = requirements
36
- hash_map.delete(:path)
37
- git = hash_map[:git]
36
+ git = requirements[:git]
37
+ tag = requirements[:tag]
38
+ commit = requirements[:commit]
39
+ branch = requirements[:branch]
40
+ hash_map = Hash.new
41
+ hash_map[:git] = git if git
42
+ hash_map[:tag] = tag if tag
43
+ hash_map[:commit] = commit if commit
44
+ hash_map[:branch] = branch if branch
38
45
  if git
39
- tag = hash_map[:tag]
40
- branch = hash_map[:branch]
41
- commit = hash_map[:commit]
42
46
  if tag
43
47
  hash_map.delete(:branch)
44
48
  hash_map.delete(:commit)
@@ -56,15 +60,22 @@ module LgPodPlugin
56
60
  end
57
61
  self.options = hash_map
58
62
  LRequest.shared.setup_pod_info(self.name, self.workspace, hash_map)
63
+ LRequest.shared.downloader.real_name = self.real_name
59
64
  self.install_remote_pod(name, hash_map)
60
65
  end
61
66
 
62
67
  public
63
68
  def install_remote_pod(name, options = {})
64
- if options[:git]
65
- LRequest.shared.downloader.pre_download_pod
69
+ git = options[:git]
70
+ if git
71
+ if LRequest.shared.net_ping && LRequest.shared.net_ping.ip && LRequest.shared.net_ping.network_ok
72
+ LRequest.shared.downloader.pre_download_pod
73
+ else
74
+ LgPodPlugin.log_red "请求#{git} 超时, 下载失败!"
75
+ end
66
76
  else
67
77
  LRequest.shared.libs.delete(name)
78
+ LRequest.shared.libs.delete(self.real_name)
68
79
  LgPodPlugin.log_red "pod `#{name}`, 缺少必要的 [git|commit|tag|branch] 参数"
69
80
  end
70
81
  end
@@ -77,11 +88,10 @@ module LgPodPlugin
77
88
  if update
78
89
  if libs.empty?
79
90
  LgPodPlugin.log_red "no external pod update, you can use `pod update` to update --all pods"
80
- # LgPodPlugin.log_green "bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} "
81
- # system("bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} ")
91
+ system("bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} ")
82
92
  else
83
93
  pod_names = libs.join(" ")
84
- LgPodPlugin.log_green libs.join("\n")
94
+ LgPodPlugin.log_green libs.join("\n")
85
95
  LgPodPlugin.log_green "bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} "
86
96
  system("bundle exec arch -x86_64 pod update #{pod_names} #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} ")
87
97
  end
@@ -100,21 +110,28 @@ module LgPodPlugin
100
110
  LgPodPlugin.log_red "no such file `Podfile`"
101
111
  return
102
112
  end
113
+ LRequest.shared.is_update = (command == "update")
103
114
  podfile = Pod::Podfile.from_file(podfile_path)
104
- # LgPodPlugin.log_red "podfile => #{podfile} podfile_path => #{podfile_path}"
105
115
  target = podfile.send(:current_target_definition)
106
- children = target.children
116
+ release_pods = []
107
117
  install_hash_map = {}
118
+ children = target.children
108
119
  children.each do |s|
109
120
  internal_hash = s.send(:internal_hash)
121
+ next unless internal_hash.is_a?(Hash)
110
122
  dependencies = internal_hash["dependencies"]
111
- next unless dependencies
123
+ next unless dependencies.is_a?(Array)
112
124
  dependencies.each { |e|
113
125
  next unless e.is_a?(Hash)
114
126
  next if (key = e.keys.first) == nil
115
127
  next if (val = e[key].last) == nil
116
- next unless val.is_a?(Hash)
117
- install_hash_map[key] = val
128
+ if val.is_a?(Hash)
129
+ next unless val[:path] == nil
130
+ next unless val[:podspec] == nil
131
+ install_hash_map[key] = val
132
+ else
133
+ release_pods.append(key)
134
+ end
118
135
  }
119
136
  end
120
137
  LRequest.shared.libs = install_hash_map
@@ -126,7 +143,7 @@ module LgPodPlugin
126
143
  LgPodPlugin.log_red "开始安装pod"
127
144
  #切换工作目录到当前工程下, 开始执行pod install
128
145
  FileUtils.chdir(podfile_path.dirname)
129
- libs = LRequest.shared.libs.keys ||= []
146
+ libs = LRequest.shared.libs.keys.empty? ? release_pods : LRequest.shared.libs.keys
130
147
  # 执行pod install/ update 方法入口
131
148
  update_pod = (command == "update")
132
149
  run_pod_install(update_pod, libs, options)
@@ -16,8 +16,8 @@ module LgPodPlugin
16
16
  end
17
17
 
18
18
  #判断缓存是否存在且有效命中缓存
19
- def find_pod_cache(name)
20
- hash_map = LRequest.shared.get_cache_key_params
19
+ def find_pod_cache(name, options)
20
+ hash_map = Hash.new.merge!(options)
21
21
  request = LCache.download_request(name, hash_map)
22
22
  destination = LCache.path_for_pod(request, {})
23
23
  cache_pod_spec = LCache.path_for_spec(request, {})
@@ -134,7 +134,9 @@ module LgPodPlugin
134
134
  def self.write_spec(spec, path)
135
135
  path.dirname.mkpath
136
136
  Pod::Downloader::Cache.write_lock(path) do
137
- path.open('w') { |f| f.write spec.to_pretty_json }
137
+ path.open('w') { |f|
138
+ f.write spec.to_pretty_json
139
+ }
138
140
  end
139
141
  end
140
142