lg_pod_plugin 1.0.3 → 1.0.4
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 +4 -4
- data/lib/lg_pod_plugin/database.rb +5 -5
- data/lib/lg_pod_plugin/download.rb +72 -114
- data/lib/lg_pod_plugin/file_path.rb +8 -4
- data/lib/lg_pod_plugin/git_util.rb +81 -77
- data/lib/lg_pod_plugin/install.rb +51 -76
- data/lib/lg_pod_plugin/l_cache.rb +237 -0
- data/lib/lg_pod_plugin/log.rb +26 -0
- data/lib/lg_pod_plugin/request.rb +141 -0
- data/lib/lg_pod_plugin/string.rb +33 -0
- data/lib/lg_pod_plugin/version.rb +1 -1
- data/lib/lg_pod_plugin.rb +6 -58
- metadata +6 -4
- data/lib/lg_pod_plugin/cache.rb +0 -226
- data/lib/lg_pod_plugin/pod_spec.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e16255ce6cf29df74aa508c022dc083727d4fd78f65d95a0b68b57b10e075767
|
4
|
+
data.tar.gz: f1ac6d11e1cae7f98ee7332aca930d2389b9c07799270755dd8fd1b03a9e1cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f5dafc9da762041041bd32f38dfe4cc5d1ef399ff5caaf443574f048fc8a14b915b76ae1ec22916ad458a0f53433877ec8301079e725da097e8736c886cee71
|
7
|
+
data.tar.gz: bfc2c0c5835737c9c2cecc3002f61baffcc96ef75057dea47bc7aea9131c1e8df6ca58c54b307e25f8d3b9c5a318b583583586c010952001343f824eb6701813
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require "sqlite3"
|
2
2
|
require 'singleton'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'l_cache'
|
4
4
|
|
5
5
|
module LgPodPlugin
|
6
6
|
|
7
|
-
class
|
7
|
+
class LSqliteDb
|
8
8
|
include Singleton
|
9
9
|
REQUIRED_ATTRS ||= %i[db table_name].freeze
|
10
10
|
attr_accessor(*REQUIRED_ATTRS)
|
11
11
|
# 初始化 db
|
12
12
|
def initialize
|
13
|
-
root_path =
|
13
|
+
root_path = LFileManager.download_director.join("database")
|
14
14
|
db_file_path = root_path.join("my.db")
|
15
15
|
if !root_path.exist? || !db_file_path.exist?
|
16
16
|
FileUtils.mkdir(root_path)
|
@@ -68,7 +68,7 @@ module LgPodPlugin
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def select_table(name, branch)
|
71
|
-
pod_info =
|
71
|
+
pod_info = LCachePodInfo.new
|
72
72
|
self.db.execute( "select * from #{self.table_name} where name = '#{name}' and branch = '#{branch}'; ") do |row|
|
73
73
|
pod_info.name = row[1]
|
74
74
|
pod_info.branch = row[2]
|
@@ -83,7 +83,7 @@ module LgPodPlugin
|
|
83
83
|
def select_tables(name, branch)
|
84
84
|
array = []
|
85
85
|
self.db.execute( "select * from #{self.table_name} where name = '#{name}' and branch != '#{branch}' order by update_time;") do |row|
|
86
|
-
pod_info =
|
86
|
+
pod_info = LCachePodInfo.new
|
87
87
|
pod_info.name = row[1]
|
88
88
|
pod_info.branch = row[2]
|
89
89
|
pod_info.sha = row[3]
|
@@ -1,137 +1,95 @@
|
|
1
1
|
require 'git'
|
2
|
-
require_relative '
|
2
|
+
require_relative 'l_cache'
|
3
3
|
require_relative 'database'
|
4
4
|
require_relative 'file_path'
|
5
5
|
|
6
6
|
module LgPodPlugin
|
7
7
|
|
8
|
-
class
|
8
|
+
class LDownloader
|
9
9
|
|
10
|
-
REQUIRED_ATTRS ||= %i[git name commit branch tag options
|
10
|
+
REQUIRED_ATTRS ||= %i[git name commit branch tag options].freeze
|
11
11
|
attr_accessor(*REQUIRED_ATTRS)
|
12
12
|
|
13
|
-
def initialize
|
14
|
-
self.cache = Cache.new
|
15
|
-
self.db = SqliteDb.instance
|
16
|
-
super
|
17
|
-
end
|
18
|
-
|
19
|
-
def download_init(name, options = {})
|
20
|
-
hash_map = options
|
13
|
+
def initialize(name, options = {})
|
21
14
|
self.name = name
|
22
|
-
self.
|
23
|
-
self.
|
24
|
-
self.
|
25
|
-
self.
|
26
|
-
self.
|
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
|
15
|
+
self.options = options
|
16
|
+
self.git = options[:git]
|
17
|
+
self.tag = options[:tag]
|
18
|
+
self.branch = options[:branch]
|
19
|
+
self.commit = options[:commit]
|
40
20
|
end
|
21
|
+
|
22
|
+
# def check_cache_valid(name, branch)
|
23
|
+
# self.db.should_clean_pod_info(name, branch)
|
24
|
+
# end
|
41
25
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
return false
|
47
|
-
end
|
48
|
-
first_key = command_keys[0].to_s ||= ""
|
49
|
-
if first_key.include?("install")
|
50
|
-
false
|
51
|
-
elsif first_key.include?("update")
|
52
|
-
true
|
26
|
+
# 预下载处理
|
27
|
+
def pre_download_pod
|
28
|
+
if self.branch
|
29
|
+
LgPodPlugin.log_green "Using `#{name}` (#{branch})"
|
53
30
|
else
|
54
|
-
|
31
|
+
LgPodPlugin.log_green "Using `#{name}`"
|
55
32
|
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def check_cache_valid(name, branch)
|
59
|
-
self.db.should_clean_pod_info(name, branch)
|
60
|
-
end
|
61
|
-
|
62
|
-
# 预下载处理
|
63
|
-
def pre_download_pod(git)
|
64
|
-
self.git_util = git
|
65
|
-
is_update = self.is_update_pod
|
66
|
-
self.git_util.git_init(self.name, self.options)
|
67
|
-
git_url = options[:git]
|
68
|
-
# commit = options[:commit]
|
69
|
-
branch = options[:branch]
|
70
|
-
LgPodPlugin.log_green "Using `#{name}` (#{branch})"
|
71
33
|
# 发现本地有缓存, 不需要更新缓存
|
72
|
-
need_download
|
73
|
-
|
34
|
+
need_download = LRequest.shared.cache.find_pod_cache(self.name, self.git, self.branch, self.tag, self.commit, LRequest.shared.is_update)
|
35
|
+
if !need_download
|
74
36
|
LgPodPlugin.log_green "find the cache of `#{name}`, you can use it now."
|
75
37
|
return
|
38
|
+
else
|
39
|
+
LgPodPlugin.log_green "find the new commit of `#{name}`, Git downloading now."
|
76
40
|
end
|
77
|
-
|
78
|
-
# 检查是否要清空缓存
|
79
|
-
if is_update
|
80
|
-
check_cache_valid(name, branch)
|
81
|
-
end
|
82
|
-
|
83
41
|
# 本地 git 下载 pod 目录
|
84
|
-
|
85
|
-
|
42
|
+
LRequest.shared.git_util.pre_download_git_repository
|
43
|
+
|
86
44
|
# 本地clone代码失败跳出去
|
87
|
-
unless real_pod_path.exist?
|
88
|
-
|
89
|
-
end
|
90
|
-
# 切换到本地git仓库目录下
|
91
|
-
FileUtils.chdir(real_pod_path)
|
92
|
-
unless real_pod_path.glob("*.git")
|
93
|
-
|
94
|
-
end
|
95
|
-
# 使用branch克隆代码
|
96
|
-
git = Git.open(Pathname("./"))
|
97
|
-
current_branch = git.current_branch
|
98
|
-
if current_branch == branch # 要 clone 的分支正好等于当前分支
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
else
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
45
|
+
# unless real_pod_path.exist?
|
46
|
+
# return
|
47
|
+
# end
|
48
|
+
# # 切换到本地git仓库目录下
|
49
|
+
# FileUtils.chdir(real_pod_path)
|
50
|
+
# unless real_pod_path.glob("*.git")
|
51
|
+
# return
|
52
|
+
# end
|
53
|
+
# # 使用branch克隆代码
|
54
|
+
# git = Git.open(Pathname("./"))
|
55
|
+
# current_branch = git.current_branch
|
56
|
+
# if current_branch == branch # 要 clone 的分支正好等于当前分支
|
57
|
+
# current_commit = git.log(1).to_s
|
58
|
+
# if new_commit != current_commit && is_update
|
59
|
+
# #删除旧的pod 缓存
|
60
|
+
# self.cache.clean_old_cache(name, git_url, current_commit)
|
61
|
+
# LgPodPlugin.log_green "git pull #{name} origin/#{current_branch}"
|
62
|
+
# self.git_util.should_pull(git, current_branch, new_commit)
|
63
|
+
# current_commit = new_commit
|
64
|
+
# end
|
65
|
+
# hash_map = { :git => git_url }
|
66
|
+
# if current_commit
|
67
|
+
# hash_map[:commit] = current_commit
|
68
|
+
# end
|
69
|
+
# LSqliteDb.instance.insert_table(name, branch, current_commit, nil, real_pod_path)
|
70
|
+
# LgPodPlugin::LCache.cache_pod(name, real_pod_path, is_update, hash_map)
|
71
|
+
# else
|
72
|
+
# branch_exist = git.branches.local.find { |e| e.to_s == branch }
|
73
|
+
# if branch_exist
|
74
|
+
# LgPodPlugin.log_green "git switch #{name} #{git_url} -b #{branch}"
|
75
|
+
# self.git_util.git_switch(branch)
|
76
|
+
# else
|
77
|
+
# LgPodPlugin.log_green "git checkout #{name} #{git_url} -b #{branch}"
|
78
|
+
# self.git_util.git_checkout(branch)
|
79
|
+
# end
|
80
|
+
# current_commit = git.log(1).to_s
|
81
|
+
# if current_commit != new_commit
|
82
|
+
# LgPodPlugin.log_green "git pull #{name} #{git_url} -b #{branch}"
|
83
|
+
# self.git_util.should_pull(git, current_branch, new_commit)
|
84
|
+
# current_commit = new_commit
|
85
|
+
# end
|
86
|
+
# hash_map = { :git => git_url }
|
87
|
+
# if current_commit
|
88
|
+
# hash_map[:commit] = current_commit
|
89
|
+
# end
|
90
|
+
# LSqliteDb.instance.insert_table(name, branch, current_commit, nil, real_pod_path)
|
91
|
+
# LgPodPlugin::LCache.cache_pod(name, real_pod_path, is_update, hash_map)
|
92
|
+
# end
|
135
93
|
|
136
94
|
end
|
137
95
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module LgPodPlugin
|
3
3
|
|
4
|
-
class
|
4
|
+
class LFileManager
|
5
5
|
|
6
6
|
def self.cache_director
|
7
7
|
Pathname(File.join(Dir.home, "Library/Caches"))
|
@@ -9,7 +9,7 @@ module LgPodPlugin
|
|
9
9
|
|
10
10
|
# 本地下载路径 ~Library/Caches/LgPodPlugin
|
11
11
|
def self.download_director
|
12
|
-
cache_path =
|
12
|
+
cache_path = self.cache_director.join("LgPodPlugin")
|
13
13
|
unless cache_path.exist?
|
14
14
|
# pp "文件路径不存在"
|
15
15
|
cache_path.mkdir(0700)
|
@@ -17,8 +17,12 @@ module LgPodPlugin
|
|
17
17
|
cache_path
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# pod缓存工作目录, 根据项目所在路径计算所得 确保唯一
|
21
|
+
def self.cache_workspace(root)
|
22
|
+
timestamp = "_#{Time.now.to_i}_"
|
23
|
+
key = root.to_path + timestamp + "#{(rand() * 10000000).to_i}"
|
24
|
+
director = Digest::MD5.hexdigest(key)
|
25
|
+
return self.download_director.join(director)
|
22
26
|
end
|
23
27
|
|
24
28
|
end
|
@@ -1,92 +1,80 @@
|
|
1
1
|
require 'pp'
|
2
2
|
require 'git'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'request'
|
4
|
+
require_relative 'l_cache'
|
4
5
|
|
5
6
|
module LgPodPlugin
|
6
7
|
|
7
|
-
class
|
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)
|
8
|
+
class LGitUtil
|
17
9
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
10
|
+
REQUIRED_ATTRS ||= %i[git tag path name commit branch].freeze
|
11
|
+
attr_accessor(*REQUIRED_ATTRS)
|
21
12
|
|
22
|
-
def
|
13
|
+
def initialize(name, options = {})
|
23
14
|
self.name = name
|
24
15
|
self.git = options[:git]
|
25
16
|
self.tag = options[:tag]
|
26
17
|
self.path = options[:path]
|
27
18
|
self.branch = options[:branch]
|
28
19
|
self.commit = options[:commit]
|
29
|
-
self.is_cache = options[:depth]
|
30
20
|
end
|
31
21
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
22
|
+
def git_clone_repository(path)
|
23
|
+
FileUtils.chdir(path)
|
24
|
+
temp_name = "lg_temp_pod"
|
25
|
+
if self.git && self.tag
|
26
|
+
LgPodPlugin.log_blue "git clone --tag #{self.tag} #{self.git}"
|
27
|
+
system("git clone --depth=1 -b #{self.tag} #{self.git} #{temp_name}")
|
28
|
+
elsif self.git && self.branch
|
29
|
+
LgPodPlugin.log_blue "git clone --depth=1 --branch #{self.branch} #{self.git}"
|
30
|
+
system("git clone --depth=1 -b #{self.branch} #{self.git} #{temp_name}")
|
31
|
+
elsif self.git && self.commit
|
32
|
+
LgPodPlugin.log_blue "git clone #{self.git}"
|
33
|
+
git = Git.init(temp_name)
|
34
|
+
FileUtils.chdir(temp_name)
|
35
|
+
system("git remote add origin #{self.git}")
|
36
|
+
system("git fetch origin #{self.commit}")
|
37
|
+
system("git reset --hard FETCH_HEAD")
|
40
38
|
end
|
39
|
+
return path.join(temp_name)
|
41
40
|
end
|
42
41
|
|
43
|
-
def git_checkout(branch)
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
def git_switch(branch)
|
48
|
-
|
49
|
-
end
|
42
|
+
# def git_checkout(branch)
|
43
|
+
# system("git checkout -b #{branch}")
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# def git_switch(branch)
|
47
|
+
# system("git switch #{branch}")
|
48
|
+
# end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
def request_params
|
51
|
+
hash_map = {:git => git}
|
52
|
+
if git && tag
|
53
|
+
hash_map[:tag] = tag
|
54
|
+
hash_map[:commit] = self.commit
|
55
|
+
else
|
56
|
+
hash_map[:commit] = commit
|
58
57
|
end
|
58
|
+
return hash_map
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
temp_path =
|
61
|
+
def pre_download_git_repository
|
62
|
+
temp_path = LFileManager.download_director.join("temp")
|
62
63
|
if temp_path.exist?
|
63
|
-
FileUtils.
|
64
|
+
FileUtils.rm_rf(temp_path)
|
64
65
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
lg_pod_path = LRequest.shared.cache.cache_root
|
67
|
+
unless lg_pod_path.exist?
|
68
|
+
lg_pod_path.mkdir(0700)
|
69
|
+
end
|
70
|
+
get_temp_folder = git_clone_repository(lg_pod_path)
|
69
71
|
#下载 git 仓库失败
|
70
72
|
unless get_temp_folder.exist?
|
71
73
|
return nil
|
72
74
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
88
|
-
end
|
89
|
-
|
75
|
+
LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, self.request_params)
|
76
|
+
FileUtils.chdir(LFileManager.download_director)
|
77
|
+
FileUtils.rm_rf(lg_pod_path)
|
90
78
|
end
|
91
79
|
|
92
80
|
# 本地pod库git操作
|
@@ -119,29 +107,45 @@ module LgPodPlugin
|
|
119
107
|
end
|
120
108
|
|
121
109
|
# 获取最新的一条 commit 信息
|
122
|
-
def self.git_ls_remote_refs(git, branch)
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
110
|
+
def self.git_ls_remote_refs(git, branch, tag, commit)
|
111
|
+
if branch
|
112
|
+
LgPodPlugin.log_yellow "git ls-remote #{git} #{branch}"
|
113
|
+
new_commit = %x(git ls-remote #{git} #{branch}).split(" ").first
|
114
|
+
return [branch, new_commit]
|
115
|
+
end
|
116
|
+
ls = Git.ls_remote(git, :head => true )
|
117
|
+
if tag
|
118
|
+
map = ls["tags"]
|
119
|
+
keys = map.keys
|
120
|
+
idx = keys.index("#{tag}")
|
121
|
+
unless idx
|
122
|
+
return [nil, nil]
|
123
|
+
end
|
124
|
+
key = keys[idx]
|
125
|
+
new_commit = map[key][:sha]
|
126
|
+
return [nil, new_commit]
|
129
127
|
else
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
128
|
+
new_commit = nil
|
129
|
+
new_branch = nil
|
130
|
+
find_commit = commit ||= ls["head"][:sha]
|
131
|
+
ls["branches"].each do |key, value|
|
132
|
+
sha = value[:sha]
|
133
|
+
next if sha != find_commit
|
134
|
+
new_branch = key
|
135
|
+
new_commit = find_commit
|
136
|
+
return [new_branch, new_commit]
|
137
|
+
break
|
135
138
|
end
|
136
|
-
return
|
139
|
+
return [new_branch , new_commit]
|
137
140
|
end
|
138
141
|
end
|
139
142
|
|
140
143
|
# 是否pull 代码
|
141
144
|
def should_pull(git, branch, new_commit = nil)
|
142
|
-
|
145
|
+
new_barnch = branch ||= self.branch
|
146
|
+
git_url = git.remote.url ||= self.git
|
143
147
|
if new_commit == nil
|
144
|
-
new_commit =
|
148
|
+
new_branch, new_commit = LGitUtil.git_ls_remote_refs(git_url, new_barnch,nil, nil)
|
145
149
|
end
|
146
150
|
local_commit = git.log(1).to_s #本地最后一条 commit hash 值
|
147
151
|
if local_commit != new_commit
|