lg_pod_plugin 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7a39307dd5e4f73faefa55775b51e880f9f0fda326cc618c62b957ddcba669e
4
- data.tar.gz: 46777e3af13f74c44086743bb48352373539806a22aafc758eb104dde3f4864c
3
+ metadata.gz: 61fa41fbaf71702b19bf2ef604d2283f68d472e5c47428890398463556a985f7
4
+ data.tar.gz: 9c45761ced23924ce2e70557245d70eb883b4f7158c63acfeb3f0547af2e1fdc
5
5
  SHA512:
6
- metadata.gz: a945450a624206b131df0b963fbd8616b4df179112b54f41625ed90a46b5480823d74b80c0dc75c227f56de3d74fe225cb44243396d11ff7d864399adcbd89a0
7
- data.tar.gz: c72bbba5713477f4f094387b650298768e94ec3de1a831daead4d2eb588654cb58190d3cbd474e983bc7b02c2b3ce144c032f27722ea75802020a513488490a8
6
+ metadata.gz: 549679243cd9e06a3d4626c06c79733bd779817e018bc5c46eb75f1731f7c5806f98bc02956ffd2e696b34e8ca1fb29f3fffb33feb231b9cb07180c3189ad586
7
+ data.tar.gz: 00d3b2bf9cf9d22c87141e63872b2dd466658d14972b1e8b4a4ae2a5f23d3fbb96195971cddc8063bc38cc97b4d7468422c9ccbe330e70aac6af80ce1126dcc0
@@ -1,18 +1,20 @@
1
1
  require 'git'
2
- require 'cocoapods/downloader.rb'
3
- require 'cocoapods/downloader/cache.rb'
4
- require 'cocoapods/downloader/response.rb'
5
- require 'cocoapods/downloader/request.rb'
2
+ require 'cocoapods/downloader'
3
+ require 'cocoapods/downloader/cache'
4
+ require 'cocoapods/downloader/response'
5
+ require 'cocoapods/downloader/request'
6
6
 
7
7
  module LgPodPlugin
8
8
 
9
9
  class CachePodInfo
10
- attr_accessor :sha
11
- attr_accessor :tag
12
- attr_accessor :name
13
- attr_accessor :path
14
- attr_accessor :branch
15
- attr_accessor :timestamp
10
+ # attr_accessor :sha
11
+ # attr_accessor :tag
12
+ # attr_accessor :name
13
+ # attr_accessor :path
14
+ # attr_accessor :branch
15
+ # attr_accessor :timestamp
16
+ REQUIRED_ATTRS ||= %i[sha tag name path branch timestamp].freeze
17
+ attr_accessor(*REQUIRED_ATTRS)
16
18
  def initialize
17
19
  super
18
20
  end
@@ -46,9 +48,9 @@ class Cache
46
48
  destination = Cache.path_for_pod(request, {})
47
49
  cache_pod_spec = Cache.path_for_spec(request, {})
48
50
  if File.exist?(destination) && File.exist?(cache_pod_spec)
49
- [false , last_commit]
51
+ [false , last_commit]
50
52
  else
51
- [true , last_commit]
53
+ [true , last_commit]
52
54
  end
53
55
  end
54
56
 
@@ -127,7 +129,7 @@ class Cache
127
129
  def self.copy_and_clean(source, destination, spec)
128
130
  specs_by_platform = group_sub_specs_by_platform(spec)
129
131
  destination.parent.mkpath
130
- Pod::Downloader::Cache.write_lock(destination) do
132
+ self.write_lock(destination) do
131
133
  FileUtils.rm_rf(destination)
132
134
  FileUtils.cp_r(source, destination)
133
135
  Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
@@ -135,12 +137,46 @@ class Cache
135
137
  end
136
138
  end
137
139
 
140
+ def self.write_lock(location, &block)
141
+ self.lock(location, File::LOCK_EX, &block)
142
+ end
143
+
144
+ def self.lock(location, lock_type)
145
+ raise ArgumentError, 'no block given' unless block_given?
146
+ lockfile = "#{location}.lock"
147
+ f = nil
148
+ loop do
149
+ f.close if f
150
+ f = File.open(lockfile, File::CREAT, 0o644)
151
+ f.flock(lock_type)
152
+ break if self.valid_lock?(f, lockfile)
153
+ end
154
+ begin
155
+ yield location
156
+ ensure
157
+ if lock_type == File::LOCK_SH
158
+ f.flock(File::LOCK_EX)
159
+ File.delete(lockfile) if self.valid_lock?(f, lockfile)
160
+ else
161
+ File.delete(lockfile)
162
+ end
163
+ f.close
164
+ end
165
+ end
166
+
167
+ def self.valid_lock?(file, filename)
168
+ file.stat.ino == File.stat(filename).ino
169
+ rescue Errno::ENOENT
170
+ false
171
+ end
172
+
138
173
  def self.write_spec(spec, path)
139
174
  path.dirname.mkpath
140
175
  Pod::Downloader::Cache.write_lock(path) do
141
176
  path.open('w') { |f| f.write spec.to_pretty_json }
142
177
  end
143
178
  end
179
+
144
180
  # 拷贝 pod 缓存文件到 sandbox
145
181
  def self.cache_pod(name, target, is_update, options = {})
146
182
  request = Cache.download_request(name, options)
@@ -53,7 +53,7 @@ module LgPodPlugin
53
53
  self.delete_table(current_pod.name, current_pod.branch)
54
54
  end
55
55
  array = self.select_tables(name, branch)
56
- if array.count <= 1
56
+ if array.count <= 2
57
57
  return
58
58
  end
59
59
 
@@ -1,28 +1,42 @@
1
1
  require 'git'
2
- require_relative 'cache.rb'
3
- require_relative 'database.rb'
4
- require_relative 'file_path.rb'
2
+ require_relative 'cache'
3
+ require_relative 'database'
4
+ require_relative 'file_path'
5
5
 
6
6
  module LgPodPlugin
7
7
 
8
8
  class Downloader
9
- attr_accessor :git_util
10
- attr_accessor :db
11
- attr_accessor :cache
12
- REQUIRED_ATTRS ||= %i[git name commit branch tag options].freeze
9
+
10
+ REQUIRED_ATTRS ||= %i[git name commit branch tag options git_util db cache is_cache].freeze
13
11
  attr_accessor(*REQUIRED_ATTRS)
12
+
14
13
  def initialize
15
14
  self.cache = Cache.new
16
15
  self.db = SqliteDb.instance
17
16
  super
18
17
  end
18
+
19
19
  def download_init(name, options = {})
20
+ hash_map = options
20
21
  self.name = name
21
- self.options = options
22
- self.git = options[:git]
23
- self.tag = options[:tag]
24
- self.branch = options[:branch]
25
- self.commit = options[:commit]
22
+ self.git = hash_map[:git]
23
+ self.tag = hash_map[:tag]
24
+ self.branch = hash_map[:branch]
25
+ self.commit = hash_map[:commit]
26
+ self.is_cache = hash_map[:depth]
27
+ # 通过ls-remote获取 head 指向 branch
28
+ if !self.branch && self.git
29
+ ls = Git.ls_remote(self.git, :head => true)
30
+ head_ref = ls["head"][:sha]
31
+ ls["branches"].each do |key, value|
32
+ sha = value[:sha]
33
+ next if sha != head_ref
34
+ self.branch = key
35
+ hash_map[:branch] = key
36
+ break
37
+ end
38
+ end
39
+ self.options = hash_map
26
40
  end
27
41
 
28
42
  def is_update_pod
@@ -50,10 +64,6 @@ module LgPodPlugin
50
64
  self.git_util = git
51
65
  is_update = self.is_update_pod
52
66
  self.git_util.git_init(self.name, self.options)
53
- # if name == "LBase" || name == "LLogger" || name == "LUnityFramework" || name == "LUser"
54
- # pp name
55
- # end
56
- # tag = options[:tag]
57
67
  git_url = options[:git]
58
68
  # commit = options[:commit]
59
69
  branch = options[:branch]
@@ -94,14 +104,14 @@ module LgPodPlugin
94
104
  self.git_util.should_pull(git, current_branch, new_commit)
95
105
  current_commit = new_commit
96
106
  end
97
- hash_map = {:git => git_url}
107
+ hash_map = { :git => git_url }
98
108
  if current_commit
99
109
  hash_map[:commit] = current_commit
100
110
  end
101
111
  SqliteDb.instance.insert_table(name, branch, current_commit, nil, real_pod_path)
102
- LgPodPlugin::Cache.cache_pod(name,real_pod_path,is_update,hash_map)
112
+ LgPodPlugin::Cache.cache_pod(name, real_pod_path, is_update, hash_map)
103
113
  else
104
- branch_exist = git.branches.local.find {|e| e.to_s == branch}
114
+ branch_exist = git.branches.local.find { |e| e.to_s == branch }
105
115
  if branch_exist
106
116
  LgPodPlugin.log_green "git switch #{name} #{git_url} -b #{branch}"
107
117
  self.git_util.git_switch(branch)
@@ -115,15 +125,14 @@ module LgPodPlugin
115
125
  self.git_util.should_pull(git, current_branch, new_commit)
116
126
  current_commit = new_commit
117
127
  end
118
- hash_map = {:git => git_url}
128
+ hash_map = { :git => git_url }
119
129
  if current_commit
120
130
  hash_map[:commit] = current_commit
121
131
  end
122
132
  SqliteDb.instance.insert_table(name, branch, current_commit, nil, real_pod_path)
123
- LgPodPlugin::Cache.cache_pod(name,real_pod_path,is_update,hash_map)
133
+ LgPodPlugin::Cache.cache_pod(name, real_pod_path, is_update, hash_map)
124
134
  end
125
135
 
126
-
127
136
  end
128
137
 
129
138
  end
@@ -1,16 +1,20 @@
1
1
  require 'pp'
2
2
  require 'git'
3
+ require_relative 'cache'
3
4
 
4
5
  module LgPodPlugin
5
6
 
6
7
  class GitUtil
7
- attr_accessor :git
8
- attr_accessor :tag
9
- attr_accessor :path
10
- attr_accessor :name
11
- attr_accessor :commit
12
- attr_accessor :branch
13
- attr_accessor :temp_git_path
8
+ # attr_accessor :git
9
+ # attr_accessor :tag
10
+ # attr_accessor :path
11
+ # attr_accessor :name
12
+ # attr_accessor :commit
13
+ # attr_accessor :branch
14
+ # attr_accessor :temp_git_path
15
+ REQUIRED_ATTRS ||= %i[git tag path name commit branch temp_git_path is_cache].freeze
16
+ attr_accessor(*REQUIRED_ATTRS)
17
+
14
18
  def initialize
15
19
  super
16
20
  end
@@ -22,12 +26,13 @@ module LgPodPlugin
22
26
  self.path = options[:path]
23
27
  self.branch = options[:branch]
24
28
  self.commit = options[:commit]
29
+ self.is_cache = options[:depth]
25
30
  end
26
31
 
27
32
  def git_clone(path)
28
33
  if self.branch
29
34
  temp_git_path = path.join("l-temp-pod")
30
- LgPodPlugin.log_blue "git clone --template= --single-branch --depth 1 --branch #{self.branch} #{self.git}"
35
+ LgPodPlugin.log_yellow "git clone --template= --single-branch --depth 1 --branch #{self.branch} #{self.git}"
31
36
  system("git clone --template= --single-branch --depth 1 --branch #{self.branch} #{self.git} #{temp_git_path}")
32
37
  temp_git_path
33
38
  else
@@ -53,7 +58,7 @@ module LgPodPlugin
53
58
  end
54
59
 
55
60
  FileUtils.chdir(root_path)
56
- temp_path = root_path.join("tmp")
61
+ temp_path = root_path.join("temp")
57
62
  if temp_path.exist?
58
63
  FileUtils.rm_r(temp_path)
59
64
  end
@@ -65,13 +70,23 @@ module LgPodPlugin
65
70
  unless get_temp_folder.exist?
66
71
  return nil
67
72
  end
68
- pod_root_director = FileManager.download_pod_path(name)
69
- unless pod_root_director.exist?
70
- FileUtils.mkdir(pod_root_director)
73
+
74
+ if self.is_cache
75
+ pod_root_director = FileManager.download_pod_path(name)
76
+ unless pod_root_director.exist?
77
+ FileUtils.mkdir(pod_root_director)
78
+ end
79
+ FileUtils.mv(get_temp_folder, lg_pod_path)
80
+ temp_path.rmdir
81
+ lg_pod_path
82
+ else
83
+ commit = GitUtil.git_ls_remote_refs(self.git, self.branch)
84
+ LgPodPlugin::Cache.cache_pod(self.name, get_temp_folder, true, {:git => self.git, :commit => commit})
85
+ system("cd ..")
86
+ system("rm -rf #{get_temp_folder.to_path}")
87
+ return lg_pod_path
71
88
  end
72
- FileUtils.mv(get_temp_folder, lg_pod_path)
73
- temp_path.rmdir
74
- lg_pod_path
89
+
75
90
  end
76
91
 
77
92
  # 本地pod库git操作
@@ -106,7 +121,7 @@ module LgPodPlugin
106
121
  # 获取最新的一条 commit 信息
107
122
  def self.git_ls_remote_refs(git, branch)
108
123
  last_commit = nil
109
- LgPodPlugin.log_green "git ls-remote #{git} #{branch}"
124
+ LgPodPlugin.log_yellow "git ls-remote #{git} #{branch}"
110
125
  sha = %x(git ls-remote #{git} #{branch}).split(" ").first
111
126
  if sha
112
127
  last_commit = sha
@@ -6,19 +6,14 @@ require 'cocoapods'
6
6
  require_relative 'database'
7
7
  require_relative 'download'
8
8
  require_relative 'git_util'
9
- require_relative 'pod_spec.rb'
9
+ require_relative 'pod_spec'
10
10
 
11
11
  module LgPodPlugin
12
12
 
13
13
  class Installer
14
- attr_accessor :name
15
- attr_accessor :version
16
- attr_accessor :options
17
- attr_accessor :profile
18
- attr_accessor :target
19
- attr_accessor :real_name
20
- attr_accessor :downloader
21
- attr_accessor :git_util
14
+
15
+ REQUIRED_ATTRS ||= %i[name version options profile target real_name downloader git_util].freeze
16
+ attr_accessor(*REQUIRED_ATTRS)
22
17
 
23
18
  def initialize(profile, name, *requirements)
24
19
  if name.include?("/")
@@ -33,7 +28,7 @@ module LgPodPlugin
33
28
  self.target = profile.send(:current_target_definition)
34
29
 
35
30
  unless requirements && !requirements.empty?
36
- self.pod(self.real_name, requirements)
31
+ self.lg_pod(self.real_name, requirements)
37
32
  return
38
33
  end
39
34
 
@@ -49,16 +44,15 @@ module LgPodPlugin
49
44
  self.options = hash_map
50
45
  end
51
46
 
52
- self.pod(name, requirements)
47
+ self.lg_pod(name, requirements)
53
48
 
54
49
  end
55
50
 
56
- private
57
-
51
+ public
58
52
  # @param [Object] name
59
53
  # @param [Hash] options
60
54
  # @return [Object] nil
61
- def pod(name, *requirements)
55
+ def lg_pod(name, *requirements)
62
56
  unless name
63
57
  raise StandardError, 'A dependency requires a name.'
64
58
  end
@@ -74,7 +68,9 @@ module LgPodPlugin
74
68
  end
75
69
 
76
70
  if self.version && self.options
77
- self.target.store_pod(self.real_name, self.version, self.options)
71
+ hash_map = self.options
72
+ hash_map.delete(:depth)
73
+ self.target.store_pod(self.real_name, self.version, hash_map)
78
74
  return
79
75
  end
80
76
 
@@ -90,7 +86,7 @@ module LgPodPlugin
90
86
  path = hash_map[:path]
91
87
  commit = hash_map[:commit]
92
88
  branch = hash_map[:branch]
93
- depth = hash_map[:depth] ||= true
89
+ is_cache = options[:depth]
94
90
  if path
95
91
  profile_path = self.profile.send(:defined_in_file).dirname
96
92
  real_path = Pathname.new(path).expand_path(profile_path)
@@ -98,33 +94,34 @@ module LgPodPlugin
98
94
  # 找到本地组件库 执行 git pull
99
95
  if real_path && File.directory?(real_path)
100
96
  hash_map[:path] = real_path
97
+ hash_map.delete(:depth)
101
98
  self.install_local_pod(self.name, hash_map)
102
99
  return
103
100
  end
104
101
 
105
102
  # 根据tag, commit下载文件
106
103
  hash_map.delete(:path)
107
- if tag || commit
108
- hash_map.delete(:branch)
104
+ if (tag && url) || (commit && url)
109
105
  hash_map.delete(:depth)
106
+ hash_map.delete(:branch)
110
107
  self.target.store_pod(self.real_name, hash_map)
111
108
  return
112
109
  end
113
110
 
114
111
  # 根据 branch 下载代码
115
- if url && branch && depth
112
+ if url
116
113
  hash_map.delete(:tag)
117
114
  hash_map.delete(:commit)
118
- hash_map.delete(:depth)
119
- self.downloader.download_init(self.name, options)
115
+ self.downloader.download_init(self.name, hash_map)
120
116
  self.downloader.pre_download_pod(self.git_util)
117
+ hash_map.delete(:depth)
121
118
  self.target.store_pod(self.real_name, hash_map)
122
119
  end
123
120
 
124
- end
125
121
 
126
- private
122
+ end
127
123
 
124
+ public
128
125
  def install_form_specs(spec_path = nil)
129
126
  spec_path ||= './Specs'
130
127
  path = File.expand_path(spec_path, Dir.pwd)
@@ -136,14 +133,13 @@ module LgPodPlugin
136
133
  file_objects.each do |file|
137
134
  if file.install
138
135
  options = file.pod_requirements
139
- self.pod(file.name, options)
136
+ self.lg_pod(file.name, options)
140
137
  end
141
138
  end
142
139
 
143
140
  end
144
141
 
145
- private
146
-
142
+ public
147
143
  def install_local_pod(name, options = {})
148
144
  hash_map = options
149
145
  local_path = options[:path]
@@ -1,3 +1,3 @@
1
1
  module LgPodPlugin
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
data/lib/lg_pod_plugin.rb CHANGED
@@ -56,14 +56,20 @@ module LgPodPlugin
56
56
  Pod::CoreUI.puts msg.green
57
57
  end
58
58
 
59
+ def self.log_yellow(msg)
60
+ Pod::CoreUI.puts msg.yellow
61
+ end
62
+
59
63
  def self.log(msg)
60
64
  Pod::CoreUI.puts msg
61
65
  end
62
66
 
67
+ public
63
68
  # 对 Profile 方法进行拓展
64
69
  def pod(name, *requirements)
65
70
  Installer.new(self, name, requirements)
66
71
  end
67
72
 
73
+
68
74
  end
69
75
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lg_pod_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - dongzb01
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
11
+ date: 2022-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide