lg_pod_plugin 1.0.8 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/bin/lg +5 -0
  3. data/lib/command/cache.rb +22 -18
  4. data/lib/command/command.rb +27 -35
  5. data/lib/command/install.rb +52 -0
  6. data/lib/command/update.rb +39 -0
  7. data/lib/lg_pod_plugin/downloader.rb +12 -17
  8. data/lib/lg_pod_plugin/git_util.rb +150 -106
  9. data/lib/lg_pod_plugin/install.rb +74 -88
  10. data/lib/lg_pod_plugin/l_cache.rb +11 -77
  11. data/lib/lg_pod_plugin/l_util.rb +6 -2
  12. data/lib/lg_pod_plugin/request.rb +90 -82
  13. data/lib/lg_pod_plugin/version.rb +1 -1
  14. data/lib/lg_pod_plugin.rb +9 -5
  15. metadata +57 -118
  16. data/lib/git/author.rb +0 -14
  17. data/lib/git/base/factory.rb +0 -101
  18. data/lib/git/base.rb +0 -670
  19. data/lib/git/branch.rb +0 -126
  20. data/lib/git/branches.rb +0 -71
  21. data/lib/git/config.rb +0 -22
  22. data/lib/git/diff.rb +0 -155
  23. data/lib/git/encoding_utils.rb +0 -33
  24. data/lib/git/escaped_path.rb +0 -77
  25. data/lib/git/index.rb +0 -5
  26. data/lib/git/lib.rb +0 -1215
  27. data/lib/git/log.rb +0 -135
  28. data/lib/git/object.rb +0 -312
  29. data/lib/git/path.rb +0 -31
  30. data/lib/git/remote.rb +0 -36
  31. data/lib/git/repository.rb +0 -6
  32. data/lib/git/stash.rb +0 -27
  33. data/lib/git/stashes.rb +0 -55
  34. data/lib/git/status.rb +0 -199
  35. data/lib/git/url.rb +0 -127
  36. data/lib/git/version.rb +0 -5
  37. data/lib/git/working_directory.rb +0 -4
  38. data/lib/git/worktree.rb +0 -38
  39. data/lib/git/worktrees.rb +0 -47
  40. data/lib/git.rb +0 -326
  41. data/lib/rchardet/big5freq.rb +0 -927
  42. data/lib/rchardet/big5prober.rb +0 -42
  43. data/lib/rchardet/chardistribution.rb +0 -250
  44. data/lib/rchardet/charsetgroupprober.rb +0 -110
  45. data/lib/rchardet/charsetprober.rb +0 -70
  46. data/lib/rchardet/codingstatemachine.rb +0 -67
  47. data/lib/rchardet/constants.rb +0 -42
  48. data/lib/rchardet/escprober.rb +0 -90
  49. data/lib/rchardet/escsm.rb +0 -245
  50. data/lib/rchardet/eucjpprober.rb +0 -88
  51. data/lib/rchardet/euckrfreq.rb +0 -597
  52. data/lib/rchardet/euckrprober.rb +0 -42
  53. data/lib/rchardet/euctwfreq.rb +0 -431
  54. data/lib/rchardet/euctwprober.rb +0 -42
  55. data/lib/rchardet/gb18030freq.rb +0 -474
  56. data/lib/rchardet/gb18030prober.rb +0 -42
  57. data/lib/rchardet/hebrewprober.rb +0 -289
  58. data/lib/rchardet/jisfreq.rb +0 -571
  59. data/lib/rchardet/jpcntx.rb +0 -229
  60. data/lib/rchardet/langbulgarianmodel.rb +0 -229
  61. data/lib/rchardet/langcyrillicmodel.rb +0 -330
  62. data/lib/rchardet/langgreekmodel.rb +0 -227
  63. data/lib/rchardet/langhebrewmodel.rb +0 -202
  64. data/lib/rchardet/langhungarianmodel.rb +0 -226
  65. data/lib/rchardet/langthaimodel.rb +0 -201
  66. data/lib/rchardet/latin1prober.rb +0 -147
  67. data/lib/rchardet/mbcharsetprober.rb +0 -89
  68. data/lib/rchardet/mbcsgroupprober.rb +0 -47
  69. data/lib/rchardet/mbcssm.rb +0 -542
  70. data/lib/rchardet/sbcharsetprober.rb +0 -122
  71. data/lib/rchardet/sbcsgroupprober.rb +0 -58
  72. data/lib/rchardet/sjisprober.rb +0 -88
  73. data/lib/rchardet/universaldetector.rb +0 -179
  74. data/lib/rchardet/utf8prober.rb +0 -87
  75. data/lib/rchardet/version.rb +0 -3
  76. data/lib/rchardet.rb +0 -67
  77. data/lib/zip/central_directory.rb +0 -212
  78. data/lib/zip/compressor.rb +0 -9
  79. data/lib/zip/constants.rb +0 -115
  80. data/lib/zip/crypto/decrypted_io.rb +0 -40
  81. data/lib/zip/crypto/encryption.rb +0 -11
  82. data/lib/zip/crypto/null_encryption.rb +0 -43
  83. data/lib/zip/crypto/traditional_encryption.rb +0 -99
  84. data/lib/zip/decompressor.rb +0 -31
  85. data/lib/zip/deflater.rb +0 -34
  86. data/lib/zip/dos_time.rb +0 -53
  87. data/lib/zip/entry.rb +0 -719
  88. data/lib/zip/entry_set.rb +0 -88
  89. data/lib/zip/errors.rb +0 -19
  90. data/lib/zip/extra_field/generic.rb +0 -44
  91. data/lib/zip/extra_field/ntfs.rb +0 -94
  92. data/lib/zip/extra_field/old_unix.rb +0 -46
  93. data/lib/zip/extra_field/universal_time.rb +0 -77
  94. data/lib/zip/extra_field/unix.rb +0 -39
  95. data/lib/zip/extra_field/zip64.rb +0 -70
  96. data/lib/zip/extra_field/zip64_placeholder.rb +0 -15
  97. data/lib/zip/extra_field.rb +0 -103
  98. data/lib/zip/file.rb +0 -468
  99. data/lib/zip/filesystem.rb +0 -643
  100. data/lib/zip/inflater.rb +0 -54
  101. data/lib/zip/input_stream.rb +0 -180
  102. data/lib/zip/ioextras/abstract_input_stream.rb +0 -122
  103. data/lib/zip/ioextras/abstract_output_stream.rb +0 -43
  104. data/lib/zip/ioextras.rb +0 -36
  105. data/lib/zip/null_compressor.rb +0 -15
  106. data/lib/zip/null_decompressor.rb +0 -19
  107. data/lib/zip/null_input_stream.rb +0 -10
  108. data/lib/zip/output_stream.rb +0 -198
  109. data/lib/zip/pass_thru_compressor.rb +0 -23
  110. data/lib/zip/pass_thru_decompressor.rb +0 -31
  111. data/lib/zip/streamable_directory.rb +0 -15
  112. data/lib/zip/streamable_stream.rb +0 -52
  113. data/lib/zip/version.rb +0 -3
  114. data/lib/zip.rb +0 -72
@@ -6,7 +6,8 @@ require_relative 'request'
6
6
  require_relative 'database'
7
7
  require_relative 'git_util'
8
8
  require_relative 'downloader.rb'
9
-
9
+ require 'cocoapods-core/podfile'
10
+ require 'cocoapods-core/podfile/target_definition'
10
11
  module LgPodPlugin
11
12
 
12
13
  class Installer
@@ -14,7 +15,10 @@ module LgPodPlugin
14
15
  REQUIRED_ATTRS ||= %i[name version options target real_name workspace].freeze
15
16
  attr_accessor(*REQUIRED_ATTRS)
16
17
 
17
- def initialize(profile, name, *requirements)
18
+ def initialize(profile, name, requirements)
19
+ unless name
20
+ raise StandardError, 'A dependency requires a name.'
21
+ end
18
22
  if name.include?("/")
19
23
  self.name = name.split("/").first
20
24
  else
@@ -23,26 +27,15 @@ module LgPodPlugin
23
27
  self.real_name = name
24
28
  self.workspace = profile.send(:defined_in_file).dirname
25
29
  self.target = profile.send(:current_target_definition)
26
-
27
- unless requirements && !requirements.empty?
28
- LRequest.shared.setup_pod_info(self.name, self.workspace, nil)
29
- self.lg_pod(self.real_name, requirements)
30
+ unless requirements && requirements.is_a?(Hash)
31
+ LRequest.shared.libs.delete(name)
32
+ LgPodPlugin.log_red "pod `#{name}`, 缺少必要的 [git|commit|tag|branch] 参数"
30
33
  return
31
34
  end
32
-
33
- first = requirements[0].first
34
- if "#{first.class}" == "String"
35
- self.version = first
36
- elsif "#{first.class}" == "Hash"
37
- self.options = first
38
- end
39
- hash_map = nil
40
- last = requirements[0].last
41
- if "#{last.class}" == "Hash"
42
- hash_map = last
43
- end
35
+ hash_map = requirements
36
+ hash_map.delete(:path)
44
37
  git = hash_map[:git]
45
- if hash_map && git
38
+ if git
46
39
  tag = hash_map[:tag]
47
40
  branch = hash_map[:branch]
48
41
  commit = hash_map[:commit]
@@ -55,95 +48,88 @@ module LgPodPlugin
55
48
  elsif branch
56
49
  hash_map.delete(:tag)
57
50
  hash_map.delete(:commit)
51
+ else
52
+ hash_map.delete(:tag)
53
+ hash_map.delete(:branch)
54
+ hash_map.delete(:commit)
58
55
  end
59
56
  end
60
57
  self.options = hash_map
61
58
  LRequest.shared.setup_pod_info(self.name, self.workspace, hash_map)
62
- self.lg_pod(name, requirements)
59
+ self.install_remote_pod(name, hash_map)
63
60
  end
64
61
 
65
62
  public
66
- def lg_pod(name, *requirements)
67
- unless name
68
- raise StandardError, 'A dependency requires a name.'
69
- end
70
-
71
- # 根据pod name安装, pod 'AFNetworking'
72
- unless requirements
73
- self.target.store_pod(self.real_name)
74
- return
75
- end
76
- # 根据name, version 安装, pod 'AFNetworking', "1.0.1"
77
- if self.version && !self.options
78
- self.target.store_pod(self.real_name, self.version)
79
- return
80
- end
81
- # 根据name, version 安装, pod 'AFNetworking', "1.0.1", :configurations => ["Debug"]
82
- if self.version && self.options
83
- hash_map = self.options
84
- # hash_map.delete(:cache)
85
- self.target.store_pod(self.real_name, self.version, hash_map)
86
- return
87
- end
88
-
89
- hash_map = self.options
90
- unless hash_map.is_a?(Hash)
91
- self.target.store_pod(self.real_name)
92
- return
93
- end
94
-
95
- path = hash_map[:path]
96
- if path
97
- self.install_local_pod(name, path, options)
63
+ def install_remote_pod(name, options = {})
64
+ if options[:git]
65
+ LRequest.shared.downloader.pre_download_pod
98
66
  else
99
- hash_map.delete(:path)
100
- self.install_remote_pod(name, hash_map)
67
+ LRequest.shared.libs.delete(name)
68
+ LgPodPlugin.log_red "pod `#{name}`, 缺少必要的 [git|commit|tag|branch] 参数"
101
69
  end
102
-
103
70
  end
104
71
 
105
72
  public
106
- def install_remote_pod(name, options = {})
107
- git = options[:git]
108
- if git
109
- LRequest.shared.downloader.pre_download_pod
110
- self.target.store_pod(self.real_name, options)
73
+ # 执行pod install/update命令
74
+ def self.run_pod_install(update, libs, options = {})
75
+ verbose = options[:verbose]
76
+ repo_update = options[:repo_update]
77
+ if update
78
+ if libs.empty?
79
+ 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" : ""} ")
82
+ else
83
+ pod_names = libs.join(" ")
84
+ LgPodPlugin.log_green libs.join("\n")
85
+ LgPodPlugin.log_green "bundle exec arch -x86_64 pod update #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} "
86
+ system("bundle exec arch -x86_64 pod update #{pod_names} #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""} ")
87
+ end
111
88
  else
112
- LgPodPlugin.log_red "pod `#{name}` 的参数 path, git , tag , commit不正确"
89
+ LgPodPlugin.log_green "bundle exec arch -x86_64 pod install #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""}"
90
+ system("bundle exec arch -x86_64 pod install #{repo_update ? "--repo-update" : "--no-repo-update"} #{verbose ? "--verbose" : ""}")
113
91
  end
114
92
  end
115
93
 
116
- public
117
- #安装本地pod
118
- def install_local_pod(name, relative_path, options = {})
119
- hash_map = options
120
- absolute_path = Pathname.new(relative_path).expand_path(self.workspace)
121
-
122
- unless absolute_path.exist?
123
- hash_map.delete(:path)
124
- self.install_remote_pod(name, hash_map)
94
+ #执行lg install/update命令
95
+ def self.run(command, options = {})
96
+ work_space = Pathname(Dir.pwd)
97
+ LgPodPlugin.log_green "当前工作目录 #{work_space}"
98
+ podfile_path = work_space.join("Podfile")
99
+ unless podfile_path.exist?
100
+ LgPodPlugin.log_red "no such file `Podfile`"
125
101
  return
126
102
  end
127
-
128
- if Dir.glob(File.expand_path(".git", absolute_path)).empty?
129
- hash_map.delete(:path)
130
- self.install_remote_pod(name, hash_map)
131
- return
103
+ podfile = Pod::Podfile.from_file(podfile_path)
104
+ # LgPodPlugin.log_red "podfile => #{podfile} podfile_path => #{podfile_path}"
105
+ target = podfile.send(:current_target_definition)
106
+ children = target.children
107
+ install_hash_map = {}
108
+ children.each do |s|
109
+ internal_hash = s.send(:internal_hash)
110
+ dependencies = internal_hash["dependencies"]
111
+ next unless dependencies
112
+ dependencies.each { |e|
113
+ next unless e.is_a?(Hash)
114
+ next if (key = e.keys.first) == nil
115
+ next if (val = e[key].last) == nil
116
+ next unless val.is_a?(Hash)
117
+ install_hash_map[key] = val
118
+ }
132
119
  end
133
-
134
- if Dir.glob(File.expand_path("#{name}.podspec", absolute_path)).empty?
135
- hash_map.delete(:path)
136
- self.install_remote_pod(name, hash_map)
137
- return
120
+ LRequest.shared.libs = install_hash_map
121
+ LgPodPlugin.log_red "预下载Pod"
122
+ install_hash_map.each do |key, val|
123
+ Installer.new(podfile, key, val)
138
124
  end
139
- # LRequest.shared.git_util.git_local_pod_check(absolute_path)
140
- hash_map.delete(:tag)
141
- hash_map.delete(:git)
142
- # hash_map.delete(:cache)
143
- hash_map.delete(:commit)
144
- hash_map.delete(:branch)
145
- # 安装本地私有组件库
146
- self.target.store_pod(self.real_name, hash_map)
125
+
126
+ LgPodPlugin.log_red "开始安装pod"
127
+ #切换工作目录到当前工程下, 开始执行pod install
128
+ FileUtils.chdir(podfile_path.dirname)
129
+ libs = LRequest.shared.libs.keys ||= []
130
+ # 执行pod install/ update 方法入口
131
+ update_pod = (command == "update")
132
+ run_pod_install(update_pod, libs, options)
147
133
  end
148
134
 
149
135
  end
@@ -6,16 +6,6 @@ require 'cocoapods/downloader/request'
6
6
 
7
7
  module LgPodPlugin
8
8
 
9
- class LCachePodInfo
10
- REQUIRED_ATTRS ||= %i[sha tag name path branch timestamp].freeze
11
- attr_accessor(*REQUIRED_ATTRS)
12
-
13
- def initialize
14
- super
15
- end
16
-
17
- end
18
-
19
9
  class LCache
20
10
  REQUIRED_ATTRS ||= %i[workspace cache_root].freeze
21
11
  attr_accessor(*REQUIRED_ATTRS)
@@ -24,44 +14,15 @@ module LgPodPlugin
24
14
  self.workspace = workspace
25
15
  self.cache_root = LFileManager.cache_workspace(self.workspace)
26
16
  end
27
-
28
- #根据git branch commit 返回请求参数用来获取缓存 path
29
- def get_request_params(git, branch, tag, commit)
30
- options = { :git => git }
31
- if git && tag
32
- options[:tag] = tag
33
- options[:commit] = commit
34
- elsif git && branch
35
- if commit
36
- options[:commit] = commit
37
- else
38
- new_commit_id = LGitUtil.git_ls_remote_refs(git, branch, nil, commit)
39
- options[:commit] = new_commit_id
40
- end
41
- elsif git && commit
42
- options[:commit] = commit
43
- end
44
- options
45
- end
17
+
46
18
  #判断缓存是否存在且有效命中缓存
47
- def find_pod_cache(name, git, branch, tag, commit, is_update)
48
- if is_update
49
- hash_map = self.get_request_params(git, branch, tag, commit)
50
- else
51
- if LRequest.shared.lock_params
52
- lock_tag = LRequest.shared.lock_params[:tag]
53
- lock_branch = LRequest.shared.lock_params[:branch]
54
- lock_commit = LRequest.shared.lock_params[:commit]
55
- hash_map = self.get_request_params(git, lock_branch, lock_tag, lock_commit)
56
- else
57
- hash_map = self.get_request_params(git, branch, tag, commit)
58
- end
59
- end
19
+ def find_pod_cache(name)
20
+ hash_map = LRequest.shared.get_cache_key_params
60
21
  request = LCache.download_request(name, hash_map)
61
22
  destination = LCache.path_for_pod(request, {})
62
23
  cache_pod_spec = LCache.path_for_spec(request, {})
63
24
  if File.exist?(destination) && File.exist?(cache_pod_spec)
64
- false
25
+ false
65
26
  else
66
27
  true
67
28
  end
@@ -112,7 +73,6 @@ module LgPodPlugin
112
73
  end
113
74
  end
114
75
  end
115
-
116
76
  [result, local_specs]
117
77
  end
118
78
 
@@ -180,16 +140,20 @@ module LgPodPlugin
180
140
 
181
141
  # 拷贝 pod 缓存文件到 sandbox
182
142
  def self.cache_pod(name, target, options = {})
183
- request = LCache.download_request(name, options)
143
+ hash_map = Hash.new.deep_merge(options).reject do |key, val|
144
+ !key || !val
145
+ end
146
+ request = LCache.download_request(name, hash_map)
184
147
  result, pods_pecs = get_local_spec(request, target)
185
148
  result.location = nil
149
+ result.checkout_options = hash_map
186
150
  pods_pecs.each do |s_name, s_spec|
187
- destination = path_for_pod(request, {})
151
+ destination = path_for_pod(request, :name => name, :params => hash_map)
188
152
  unless File.exist?(destination)
189
153
  LgPodPlugin.log_green "Copying #{name} from `#{target}` to `#{destination}` "
190
154
  copy_and_clean(target, destination, s_spec)
191
155
  end
192
- cache_pod_spec = path_for_spec(request, {})
156
+ cache_pod_spec = path_for_spec(request, :name => name, :params => result.checkout_options)
193
157
  unless File.exist?(cache_pod_spec)
194
158
  write_spec(s_spec, cache_pod_spec)
195
159
  end
@@ -201,36 +165,6 @@ module LgPodPlugin
201
165
 
202
166
  end
203
167
 
204
- # 根据下载参数生产缓存的路径
205
- def get_download_path(name)
206
- # hash_map = {:git => git}
207
- # if git && tag
208
- # hash_map[:tag] = tag
209
- # elsif git && commit
210
- # hash_map[:commit] = commit
211
- # elsif git && branch
212
- # hash_map[:commit] = commit
213
- # end
214
- # request = LCache.download_request(name, hash_map)
215
- # self.slug(name, request.params, nil)
216
- self.cache_root.join(name)
217
- end
218
-
219
- # 根据下载参数生产缓存目录
220
- def slug(params, spec)
221
- path = ""
222
- checksum = spec&.checksum && '-' << spec.checksum[0, 5]
223
- opts = params.to_a.sort_by(&:first).map { |k, v| "#{k}=#{v}" }.join('-')
224
- digest = Digest::MD5.hexdigest(opts)
225
- if digest
226
- path += "#{digest}"
227
- end
228
- if checksum
229
- path += "#{checksum}"
230
- end
231
- path
232
- end
233
-
234
168
  end
235
169
 
236
170
  end
@@ -1,26 +1,30 @@
1
1
  require 'zip'
2
+ require_relative 'log'
2
3
  module LgPodPlugin
3
4
  class LUtils
4
5
  def self.unzip_file (zip_file, dest_dir)
5
6
  begin
7
+ LgPodPlugin.log_green "正在解压`.zip`文件"
6
8
  Zip::File.open(zip_file) do |file|
7
9
  file.each do |f|
8
10
  file_path = File.join(dest_dir, f.name)
9
11
  FileUtils.mkdir_p(File.dirname(file_path))
10
- next if file_path.include?("Example")
11
12
  # next if file_path.include?("LICENSE")
13
+ next if file_path.include?("Example")
12
14
  next if file_path.include?(".gitignore")
13
15
  next if file_path.include?("node_modules")
14
16
  next if file_path.include?("package.json")
15
17
  next if file_path.include?(".swiftlint.yml")
16
18
  next if file_path.include?("_Pods.xcodeproj")
17
19
  next if file_path.include?("package-lock.json")
20
+ next if file_path.include?("README.md")
21
+ next if file_path.include?("commitlint.config.js")
18
22
  file.extract(f, file_path)
19
23
  end
20
24
  end
21
25
  return true
22
26
  rescue => err
23
- puts err
27
+ LgPodPlugin.log_red "解压zip失败, error => #{err}"
24
28
  return false
25
29
  end
26
30
 
@@ -9,7 +9,7 @@ module LgPodPlugin
9
9
 
10
10
  class LRequest
11
11
  include Singleton
12
- REQUIRED_ATTRS ||= %i[name options workspace cache downloader git_util lock_info lock_params is_update token].freeze
12
+ REQUIRED_ATTRS ||= %i[name request_params workspace cache downloader git_util lock_info checkout_options is_update token single_git libs].freeze
13
13
  attr_accessor(*REQUIRED_ATTRS)
14
14
 
15
15
  def is_update_pod
@@ -32,108 +32,117 @@ module LgPodPlugin
32
32
  lock_file = self.workspace.join("Podfile.lock")
33
33
  if lock_file.exist?
34
34
  json = YAML.load_file(lock_file.to_path)
35
- json["EXTERNAL SOURCES"]
35
+ external_source = json["EXTERNAL SOURCES"]
36
+ checkout_options = json["CHECKOUT OPTIONS"]
37
+ { "external_source" => external_source, "checkout_options" => checkout_options }
36
38
  else
37
39
  nil
38
40
  end
39
41
  end
40
42
 
41
- def get_lock_params(git, branch, tag, commit)
42
- unless self.lock_info
43
- return nil
44
- end
45
- current_pod_info = self.lock_info[name]
46
- unless current_pod_info
47
- return nil
48
- end
49
- lock_commit = current_pod_info[:commit]
50
- if git && tag
51
- lock_tag = current_pod_info[:tag]
52
- if lock_tag == tag
53
- return { :git => git, :commit => lock_commit, :tag => lock_tag }
54
- else
55
- return nil
56
- end
43
+ # 获取缓存用的hash_map
44
+ def get_cache_key_params
45
+ hash_map = Hash.new
46
+ git = self.checkout_options[:git] ||= self.request_params[:git]
47
+ tag = self.checkout_options[:tag] ||= self.request_params[:tag]
48
+ branch = self.checkout_options[:branch] ||= self.request_params[:branch]
49
+ commit = self.checkout_options[:commit] ||= self.request_params[:commit]
50
+ return hash_map unless git
51
+ hash_map[:git] = git
52
+ if git && commit
53
+ hash_map[:commit] = commit
54
+ elsif git && tag
55
+ hash_map[:tag] = tag
57
56
  elsif git && branch
58
- lock_branch = current_pod_info[:branch]
59
- if branch == lock_branch
60
- return { :git => git, :commit => lock_commit, :branch => lock_branch}
57
+ if commit
58
+ hash_map[:commit] = commit
61
59
  else
62
- return nil
60
+ _, new_commit_id = LGitUtil.git_ls_remote_refs(git, branch, nil, commit)
61
+ hash_map[:commit] = new_commit_id if new_commit_id
63
62
  end
64
- elsif commit == lock_commit
65
- return { :git => git, :commit => lock_commit }
66
63
  else
67
- nil
64
+ _, new_commit_id = LGitUtil.git_ls_remote_refs(git, branch, nil, commit)
65
+ hash_map[:commit] = new_commit_id if new_commit_id
68
66
  end
67
+ hash_map
69
68
  end
70
69
 
71
- def setup_pod_info(name, workspace, options = {})
72
- self.name = name
73
- hash_map = options
74
- tag = hash_map[:tag]
75
- git = hash_map[:git]
76
- path = hash_map[:path]
77
- commit = hash_map[:commit]
78
- branch = hash_map[:branch]
79
- self.workspace = workspace
80
- self.is_update = self.is_update_pod
81
- if self.lock_info == nil
82
- self.lock_info = self.get_lock_info
70
+ private
71
+
72
+ def get_lock_params
73
+ unless self.lock_info
74
+ self.lock_info = {"external_source" => {}, "checkout_options" => {}}
83
75
  end
84
- self.lock_params = self.get_lock_params(git, branch, tag, commit)
76
+ external_source = self.lock_info["external_source"][self.name] ||= {}
77
+ checkout_options = self.lock_info["checkout_options"][self.name] ||= {}
78
+
79
+ git = self.checkout_options[:git]
80
+ tag = self.checkout_options[:tag]
81
+ commit = self.checkout_options[:commit]
82
+ branch = self.checkout_options[:branch]
83
+
84
+ # lock_git = external_source[:git]
85
+ # lock_tag = external_source[:tag]
86
+ lock_commit = checkout_options[:commit]
87
+ lock_branch = external_source[:branch]
88
+ hash_map = Hash.new
89
+ hash_map[:git] = git if git
85
90
  if git && tag
86
- if self.lock_params && !self.is_update
87
- lock_tag = self.lock_params[:tag]
88
- lock_commit = self.lock_params[:commit]
89
- if lock_tag == tag && lock_commit
90
- hash_map[:commit] = lock_commit
91
- else
92
- _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
93
- hash_map[:commit] = new_commit
94
- end
95
- else
96
- _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag,commit)
97
- hash_map[:commit] = new_commit
98
- end
99
- elsif git && commit
100
- if self.lock_params && !self.is_update
101
- hash_map[:commit] = commit
102
- else
103
- new_branch, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
104
- if new_commit
105
- hash_map[:commit] = new_commit
106
- end
107
- if new_branch
108
- hash_map[:branch] = new_branch
109
- end
110
- end
91
+ hash_map[:tag] = tag
92
+ return hash_map
111
93
  elsif git && branch
112
- if self.lock_params && !self.is_update
113
- lock_branch = self.lock_params[:branch]
114
- lock_commit = self.lock_params[:commit]
115
- if branch == lock_branch && lock_commit
116
- hash_map[:commit] = lock_commit
117
- else
118
- _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
119
- hash_map[:commit] = new_commit
120
- end
94
+ if branch == lock_branch && !self.is_update
95
+ hash_map[:branch] = branch if branch
96
+ hash_map[:commit] = lock_commit if lock_commit
97
+ return hash_map
121
98
  else
99
+ hash_map[:branch] = branch if branch
122
100
  _, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
123
- hash_map[:commit] = new_commit
101
+ hash_map[:commit] = new_commit if new_commit
102
+ return hash_map
124
103
  end
125
- elsif !path
104
+ elsif git && commit
105
+ hash_map[:commit] = commit if commit
106
+ return hash_map
107
+ else
126
108
  new_branch, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
127
- hash_map[:commit] = new_commit
128
- hash_map[:branch] = new_branch
109
+ hash_map[:commit] = new_commit if new_commit
110
+ hash_map[:branch] = new_branch if new_branch
111
+ end
112
+ hash_map
113
+ end
114
+
115
+ private
116
+ #获取下载参数
117
+ def get_request_params
118
+ self.is_update = self.is_update_pod
119
+ if self.lock_info == nil
120
+ self.lock_info = self.get_lock_info
121
+ end
122
+ Hash.new.merge!(self.get_lock_params)
123
+ end
124
+
125
+ public
126
+ def setup_pod_info(name, workspace, options = {})
127
+ self.name = name
128
+ tag = options[:tag]
129
+ git = options[:git]
130
+ commit = options[:commit]
131
+ branch = options[:branch]
132
+ self.workspace = workspace
133
+ if (git && branch) || (git && commit) || (git && tag)
134
+ self.single_git = false
135
+ else
136
+ self.single_git = true
129
137
  end
138
+ self.checkout_options = Hash.new.deep_merge(options)
139
+ self.request_params = self.get_request_params
130
140
  if self.token == nil
131
141
  self.token = self.request_gitlab_token(git)
132
142
  end
133
- self.options = hash_map
134
143
  self.cache = LCache.new(self.workspace)
135
- self.git_util = LGitUtil.new(name, hash_map)
136
- self.downloader = LDownloader.new(name, hash_map)
144
+ self.git_util = LGitUtil.new(name, self.checkout_options)
145
+ self.downloader = LDownloader.new(name, self.checkout_options)
137
146
  end
138
147
 
139
148
  def self.shared
@@ -148,7 +157,7 @@ module LgPodPlugin
148
157
  #81.69.242.162
149
158
  uri = URI('http://81.69.242.162:8080/v1/member/user/gitlab/token')
150
159
  # uri = URI('http://127.0.0.1:8080/v1/member/user/gitlab/token')
151
- params = {"url" => git}
160
+ params = { "url" => git }
152
161
  res = Net::HTTP.post_form(uri, params)
153
162
  json = JSON.parse(res.body)
154
163
  rescue
@@ -157,8 +166,7 @@ module LgPodPlugin
157
166
  unless json
158
167
  return nil
159
168
  end
160
- token = json["data"]["token"]
161
- return token
169
+ json["data"]["token"]
162
170
  end
163
171
 
164
172
  end
@@ -1,3 +1,3 @@
1
1
  module LgPodPlugin
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.10"
3
3
  end
data/lib/lg_pod_plugin.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'git'
2
+ require 'claide'
2
3
  require 'cocoapods-downloader'
3
4
  require "lg_pod_plugin/version"
4
5
  require_relative 'lg_pod_plugin/log'
@@ -10,12 +11,15 @@ require_relative 'lg_pod_plugin/downloader'
10
11
  require 'cocoapods-core/podfile/target_definition'
11
12
 
12
13
  module LgPodPlugin
13
-
14
+ autoload :Command, 'command/command'
14
15
  class Error < StandardError; end
15
16
 
16
- public
17
- # 对 Profile 方法进行拓展
18
- def pod(name, *requirements)
19
- Installer.new(self, name, requirements)
17
+ def self.install(options = {})
18
+ LgPodPlugin::Installer.run("install", options)
19
+ end
20
+
21
+ def self.update(options = {})
22
+ LgPodPlugin::Installer.run("update", options)
20
23
  end
24
+
21
25
  end