lg_pod_plugin 1.1.0 → 1.1.1
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/command/command.rb +2 -0
- data/lib/command/init.rb +34 -0
- data/lib/lg_pod_plugin/database.rb +234 -104
- data/lib/lg_pod_plugin/downloader.rb +17 -53
- data/lib/lg_pod_plugin/gitlab_api.rb +151 -0
- data/lib/lg_pod_plugin/gitlab_archive.rb +287 -0
- data/lib/lg_pod_plugin/gitlab_download.rb +181 -0
- data/lib/lg_pod_plugin/install.rb +37 -20
- data/lib/lg_pod_plugin/l_cache.rb +5 -3
- data/lib/lg_pod_plugin/l_config.rb +83 -0
- data/lib/lg_pod_plugin/l_util.rb +117 -27
- data/lib/lg_pod_plugin/net-ping.rb +41 -0
- data/lib/lg_pod_plugin/podspec.rb +156 -0
- data/lib/lg_pod_plugin/request.rb +73 -75
- data/lib/lg_pod_plugin/string.rb +1 -1
- data/lib/lg_pod_plugin/version.rb +1 -1
- data/lib/lg_pod_plugin.rb +2 -1
- metadata +26 -6
- data/lib/lg_pod_plugin/git_util.rb +0 -331
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'uri'
|
3
|
+
require 'io/console'
|
4
|
+
require_relative 'request'
|
5
|
+
require_relative 'database'
|
6
|
+
require_relative 'gitlab_api'
|
7
|
+
|
8
|
+
module LgPodPlugin
|
9
|
+
|
10
|
+
class LConfig
|
11
|
+
attr_accessor :host
|
12
|
+
attr_accessor :base_url
|
13
|
+
attr_accessor :project_name
|
14
|
+
attr_accessor :access_token
|
15
|
+
attr_accessor :refresh_token
|
16
|
+
attr_accessor :project
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
end
|
20
|
+
|
21
|
+
public
|
22
|
+
def self.getConfig(git)
|
23
|
+
return nil if git.include?("github.com") || git.include?("gitee.com") || git.include?("coding.net") || git.include?("code.aliyun.com")
|
24
|
+
ip_address = LRequest.shared.net_ping.ip
|
25
|
+
network_ok = LRequest.shared.net_ping.network_ok
|
26
|
+
return nil unless ip_address && network_ok
|
27
|
+
if git.include?("ssh") || git.include?("git@gitlab") || git.include?("git@")
|
28
|
+
host = "http://" + ip_address
|
29
|
+
else
|
30
|
+
uri = LRequest.shared.net_ping.uri
|
31
|
+
host = uri ? ("#{uri.scheme}://" + ip_address) : ("http://" + ip_address)
|
32
|
+
end
|
33
|
+
user_id = LUserAuthInfo.get_user_id(host)
|
34
|
+
user_info = LSqliteDb.shared.query_user_info(user_id)
|
35
|
+
unless user_info
|
36
|
+
LgPodPlugin.log_yellow "请输入 `#{uri}` 的用户名"
|
37
|
+
username = STDIN.gets.chomp
|
38
|
+
LgPodPlugin.log_yellow "请输入 `#{uri}` 的密码"
|
39
|
+
password = STDIN.noecho(&:gets).chomp
|
40
|
+
GitLabAPI.request_gitlab_access_token(host, username, password)
|
41
|
+
return nil unless user_info = LSqliteDb.shared.query_user_info(user_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
time = Time.now.to_i
|
45
|
+
# 判断 token 是否失效
|
46
|
+
if user_info.expires_in <= time
|
47
|
+
new_user_info = GitLabAPI.refresh_gitlab_access_token(host, user_info.refresh_token)
|
48
|
+
unless new_user_info
|
49
|
+
username = user_info.username
|
50
|
+
password = user_info.password
|
51
|
+
unless username && password
|
52
|
+
LgPodPlugin.log_yellow "请输入 `#{uri}` 的用户名"
|
53
|
+
username = STDIN.gets.chomp
|
54
|
+
LgPodPlugin.log_yellow "请输入 `#{uri}` 的密码"
|
55
|
+
password = STDIN.noecho(&:gets).chomp
|
56
|
+
end
|
57
|
+
GitLabAPI.request_gitlab_access_token(host, username, password)
|
58
|
+
return nil unless new_user_info = LSqliteDb.shared.query_user_info(user_id)
|
59
|
+
end
|
60
|
+
|
61
|
+
config = LConfig.new
|
62
|
+
config.host = host
|
63
|
+
config.access_token = new_user_info.access_token
|
64
|
+
config.refresh_token = new_user_info.refresh_token
|
65
|
+
config.base_url = LUtils.get_gitlab_base_url(git)
|
66
|
+
config.project_name = LUtils.get_git_project_name(git)
|
67
|
+
config.project = LSqliteDb.shared.query_project_info(config.project_name, git)
|
68
|
+
return config
|
69
|
+
else
|
70
|
+
config = LConfig.new
|
71
|
+
config.host = host
|
72
|
+
config.access_token = user_info.access_token
|
73
|
+
config.refresh_token = user_info.refresh_token
|
74
|
+
config.base_url = LUtils.get_gitlab_base_url(git)
|
75
|
+
config.project_name = LUtils.get_git_project_name(git)
|
76
|
+
config.project = LSqliteDb.shared.query_project_info(config.project_name, git)
|
77
|
+
return config
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/lib/lg_pod_plugin/l_util.rb
CHANGED
@@ -1,43 +1,133 @@
|
|
1
|
-
require
|
1
|
+
require 'resolv'
|
2
|
+
require "ipaddr"
|
3
|
+
require 'archive/zip'
|
2
4
|
require_relative 'log'
|
5
|
+
require_relative 'l_config'
|
6
|
+
|
3
7
|
module LgPodPlugin
|
4
8
|
class LUtils
|
9
|
+
|
10
|
+
#判断对象是不是 String
|
11
|
+
def self.is_string(obj)
|
12
|
+
if "#{obj.class}" == "String"
|
13
|
+
return true
|
14
|
+
else
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# 解压文件
|
5
20
|
def self.unzip_file (zip_file, dest_dir)
|
6
21
|
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# next if file_path.include?("LICENSE")
|
13
|
-
next if file_path.include?("Example")
|
14
|
-
next if file_path.include?(".gitignore")
|
15
|
-
next if file_path.include?("node_modules")
|
16
|
-
next if file_path.include?("package.json")
|
17
|
-
next if file_path.include?(".swiftlint.yml")
|
18
|
-
next if file_path.include?("_Pods.xcodeproj")
|
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")
|
22
|
-
file.extract(f, file_path)
|
23
|
-
end
|
24
|
-
end
|
22
|
+
Archive::Zip.extract(
|
23
|
+
zip_file,
|
24
|
+
dest_dir,
|
25
|
+
:symlinks => true
|
26
|
+
)
|
25
27
|
return true
|
26
28
|
rescue => err
|
27
|
-
LgPodPlugin.log_red "解压zip失败, error => #{err}"
|
28
29
|
return false
|
29
30
|
end
|
30
31
|
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
|
34
|
+
# 下载 zip 格式文件
|
35
|
+
def self.download_gitlab_zip_file(download_url, token, file_name)
|
36
|
+
cmds = ['curl']
|
37
|
+
cmds << "--header \"Authorization: Bearer #{token}\"" if token
|
38
|
+
# cmds << "--progress-bar"
|
39
|
+
cmds << "-o #{file_name}"
|
40
|
+
cmds << "--connect-timeout 15"
|
41
|
+
cmds << "--retry 3"
|
42
|
+
cmds << download_url
|
43
|
+
cmds_to_s = cmds.join(" ")
|
44
|
+
system(cmds_to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
# gitlab 下载压缩文件
|
48
|
+
def self.download_github_zip_file(download_url, file_name)
|
49
|
+
cmds = ['curl']
|
50
|
+
cmds << "-o #{file_name}"
|
51
|
+
cmds << "--connect-timeout 15"
|
52
|
+
cmds << "--retry 3"
|
53
|
+
cmds << download_url
|
54
|
+
cmds_to_s = cmds.join(" ")
|
55
|
+
system(cmds_to_s)
|
39
56
|
end
|
40
57
|
|
58
|
+
def self.git_to_uri(git)
|
59
|
+
begin
|
60
|
+
uri = URI(git)
|
61
|
+
rescue
|
62
|
+
if git.include?("git@") && git.include?(":")
|
63
|
+
uri = URI("http://" + git[4...git.length].split(":").first)
|
64
|
+
else
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.commit_from_ls_remote(output, branch_name)
|
71
|
+
return nil if branch_name.nil?
|
72
|
+
encoded_branch_name = branch_name.dup.force_encoding(Encoding::ASCII_8BIT)
|
73
|
+
if branch_name == "HEAD"
|
74
|
+
match = %r{([a-z0-9]*)\t#{Regexp.quote(encoded_branch_name)}}.match(output)
|
75
|
+
else
|
76
|
+
match = %r{([a-z0-9]*)\trefs\/(heads|tags)\/#{Regexp.quote(encoded_branch_name)}}.match(output)
|
77
|
+
end
|
78
|
+
match[1] unless match.nil?
|
79
|
+
end
|
80
|
+
|
81
|
+
#截取git-url 拿到项目绝对名称 比如 l-base-ios
|
82
|
+
def self.get_git_project_name(git)
|
83
|
+
self.get_gitlab_base_url(git).split("/").last
|
84
|
+
end
|
85
|
+
|
86
|
+
# 是否能够使用 gitlab 下载 zip 文件
|
87
|
+
def self.is_use_gitlab_archive_file(git)
|
88
|
+
return false if git.include?("https://github.com") || git.include?("https://gitee.com")
|
89
|
+
config = LRequest.shared.config
|
90
|
+
return false if (!config || !config.access_token)
|
91
|
+
return true if project = config.project
|
92
|
+
project_name = self.get_git_project_name(git)
|
93
|
+
LRequest.shared.config.project = GitLabAPI.request_project_info(config.host, project_name, config.access_token, git)
|
94
|
+
return true if LRequest.shared.config.project
|
95
|
+
end
|
96
|
+
|
97
|
+
# 截取 url
|
98
|
+
def self.get_gitlab_base_url(git)
|
99
|
+
if git.include?(".git")
|
100
|
+
base_url = git.split(".git").first
|
101
|
+
else
|
102
|
+
base_url = git
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# 根据参数生成下载 url
|
107
|
+
def self.get_gitlab_download_url(base_url, branch, tag, commit, project_name)
|
108
|
+
if base_url.include?("http:") || base_url.include?("https:")
|
109
|
+
if branch
|
110
|
+
return base_url + "/-/archive/" + branch + "/#{project_name}-#{branch}.zip"
|
111
|
+
elsif tag
|
112
|
+
return base_url + "/-/archive/" + tag + "/#{project_name}-#{tag}.zip"
|
113
|
+
elsif commit
|
114
|
+
return base_url + "/-/archive/" + commit + "/#{project_name}-#{commit}.zip"
|
115
|
+
else
|
116
|
+
return nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
return nil unless base_url.include?("ssh://git@gitlab") || base_url.include?("git@")
|
120
|
+
project = LRequest.shared.config.project
|
121
|
+
if project && project.web_url && project.web_url.include?("http")
|
122
|
+
self.get_gitlab_download_url(project.web_url, branch, tag, commit, project_name)
|
123
|
+
else
|
124
|
+
return nil
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.url_encode(url)
|
129
|
+
url.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m| sprintf('%%%02X', m.unpack1('C')) }
|
130
|
+
end
|
41
131
|
|
42
132
|
end
|
43
|
-
end
|
133
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'resolv'
|
3
|
+
require "ipaddr"
|
4
|
+
require_relative 'l_util'
|
5
|
+
|
6
|
+
module LgPodPlugin
|
7
|
+
|
8
|
+
class Ping
|
9
|
+
attr_accessor :uri
|
10
|
+
attr_accessor :ip
|
11
|
+
attr_accessor :network_ok
|
12
|
+
def initialize(url)
|
13
|
+
self.uri = LUtils.git_to_uri(url)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ping
|
17
|
+
return false unless self.uri
|
18
|
+
result = %x(ping #{uri.host} -t 1)
|
19
|
+
if result.include?("timeout")
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
if result && result.include?("(") && result.include?("):")
|
23
|
+
ip_address = result.split("(").last.split(")").first
|
24
|
+
begin
|
25
|
+
if IPAddr.new ip_address
|
26
|
+
self.ip = ip_address
|
27
|
+
return true
|
28
|
+
else
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
else
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'cocoapods'
|
2
|
+
require 'cocoapods-core'
|
3
|
+
|
4
|
+
module LgPodPlugin
|
5
|
+
|
6
|
+
class PodSpec
|
7
|
+
attr_accessor :source_files
|
8
|
+
def self.form_file(path)
|
9
|
+
spec = Pod::Specification.from_file(path)
|
10
|
+
return PodSpec.new(spec)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(spec)
|
14
|
+
set = Set[]
|
15
|
+
attributes_hash = spec.send(:attributes_hash)
|
16
|
+
return nil unless attributes_hash.is_a?(Hash)
|
17
|
+
license = attributes_hash["license"]
|
18
|
+
if license.is_a?(Hash)
|
19
|
+
license_file = license["file"]
|
20
|
+
set.add(license_file) if license_file
|
21
|
+
else
|
22
|
+
set.add("LICENSE")
|
23
|
+
end
|
24
|
+
# 解析主模块依赖信息
|
25
|
+
set.merge(parse_subspec_with(attributes_hash))
|
26
|
+
subspecs = spec.subspecs
|
27
|
+
unless subspecs.is_a?(Array)
|
28
|
+
self.source_files = set
|
29
|
+
return
|
30
|
+
end
|
31
|
+
subspecs.each do |sub_spec|
|
32
|
+
next unless sub_attributes_hash = sub_spec.send(:attributes_hash)
|
33
|
+
next unless sub_attributes_hash.is_a?(Hash)
|
34
|
+
sub_set = self.parse_subspec_with(sub_attributes_hash)
|
35
|
+
next if sub_set.empty?
|
36
|
+
set.merge(sub_set)
|
37
|
+
end
|
38
|
+
self.source_files = set
|
39
|
+
end
|
40
|
+
|
41
|
+
# 公共解析解析subspec
|
42
|
+
def parse_subspec_with(hash)
|
43
|
+
set = Set[]
|
44
|
+
source_files = self.parse_source_files(hash["source_files"])
|
45
|
+
set.merge(source_files) unless source_files.empty?
|
46
|
+
resources = self.parse_resource_files(hash["resource"] ||= hash["resources"])
|
47
|
+
set.merge(resources) unless resources.empty?
|
48
|
+
resource_bundles = self.parse_resource_bundles(hash["resource_bundle"] ||= hash["resource_bundles"])
|
49
|
+
set.merge(resource_bundles) unless resource_bundles.empty?
|
50
|
+
project_header_files = self.parse_project_header_files(hash["project_header_files"])
|
51
|
+
set.merge(resource_bundles) unless project_header_files.empty?
|
52
|
+
private_header_files = self.parse_private_header_files(hash["private_header_files"])
|
53
|
+
set.merge(private_header_files) unless private_header_files.empty?
|
54
|
+
vendored_frameworks = self.parse_vendored_frameworks(hash["vendored_frameworks"])
|
55
|
+
set.merge(vendored_frameworks) unless vendored_frameworks.empty?
|
56
|
+
vendored_library = self.parse_vendored_library(hash["vendored_library"] ||= hash["vendored_libraries"])
|
57
|
+
set.merge(vendored_library) unless vendored_library.empty?
|
58
|
+
#parse_preserve_path
|
59
|
+
preserve_paths = self.parse_preserve_path(hash["preserve_path"] ||= hash["preserve_paths"])
|
60
|
+
set.merge(preserve_paths) unless preserve_paths.empty?
|
61
|
+
module_map = self.parse_module_map(hash["module_map"])
|
62
|
+
set.merge(module_map) unless module_map.empty?
|
63
|
+
return set
|
64
|
+
end
|
65
|
+
|
66
|
+
# 公共解析文件路径的方法
|
67
|
+
def parse_public_source_filse(source_files)
|
68
|
+
return [] unless source_files
|
69
|
+
array = []
|
70
|
+
if LUtils.is_string(source_files)
|
71
|
+
if source_files.include?("/")
|
72
|
+
array.append(source_files.split("/").first)
|
73
|
+
else
|
74
|
+
array.append(source_files)
|
75
|
+
end
|
76
|
+
elsif source_files.is_a?(Array)
|
77
|
+
source_files.each do |element|
|
78
|
+
next unless LUtils.is_string(element)
|
79
|
+
if element.include?("/")
|
80
|
+
array.append(element.split("/").first)
|
81
|
+
else
|
82
|
+
array.append(element)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
elsif source_files.is_a?(Hash)
|
86
|
+
source_files.each do |key,val|
|
87
|
+
if LUtils.is_string(val)
|
88
|
+
if val.include?("/")
|
89
|
+
array.append(val.split("/").first)
|
90
|
+
else
|
91
|
+
array.append(val)
|
92
|
+
end
|
93
|
+
elsif val.is_a?(Array)
|
94
|
+
val.each do |element|
|
95
|
+
next unless LUtils.is_string(element)
|
96
|
+
if element.include?("/")
|
97
|
+
array.append(element.split("/").first)
|
98
|
+
else
|
99
|
+
array.append(element)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
return array
|
106
|
+
end
|
107
|
+
|
108
|
+
# 解析source_fils路径
|
109
|
+
def parse_source_files(source_files)
|
110
|
+
return self.parse_public_source_filse(source_files)
|
111
|
+
end
|
112
|
+
|
113
|
+
# 解析 resource所在路径
|
114
|
+
def parse_resource_files(source_files)
|
115
|
+
return self.parse_public_source_filse(source_files)
|
116
|
+
end
|
117
|
+
|
118
|
+
# 解析public_header_files字段的值
|
119
|
+
def parse_public_header_files(source_files)
|
120
|
+
return self.parse_public_source_filse(source_files)
|
121
|
+
end
|
122
|
+
# 解析 parse_resource_bundles
|
123
|
+
def parse_resource_bundles(source_files)
|
124
|
+
return self.parse_public_source_filse(source_files)
|
125
|
+
end
|
126
|
+
# 解析 project_header_files
|
127
|
+
def parse_project_header_files(source_files)
|
128
|
+
return self.parse_public_source_filse(source_files)
|
129
|
+
end
|
130
|
+
|
131
|
+
# 解析 private_header_files
|
132
|
+
def parse_private_header_files(source_files)
|
133
|
+
return self.parse_public_source_filse(source_files)
|
134
|
+
end
|
135
|
+
# 解析 vendored_frameworks
|
136
|
+
def parse_vendored_frameworks(source_files)
|
137
|
+
return self.parse_public_source_filse(source_files)
|
138
|
+
end
|
139
|
+
# 解析 parse_vendored_library
|
140
|
+
def parse_vendored_library(source_files)
|
141
|
+
return self.parse_public_source_filse(source_files)
|
142
|
+
end
|
143
|
+
|
144
|
+
# 解析 parse_preserve_path
|
145
|
+
def parse_preserve_path(source_files)
|
146
|
+
return self.parse_public_source_filse(source_files)
|
147
|
+
end
|
148
|
+
|
149
|
+
# 解析 module_map
|
150
|
+
def parse_module_map(source_files)
|
151
|
+
return self.parse_public_source_filse(source_files)
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
@@ -2,45 +2,63 @@ require 'yaml'
|
|
2
2
|
require 'json'
|
3
3
|
require 'net/http'
|
4
4
|
require 'singleton'
|
5
|
+
require_relative 'l_config'
|
5
6
|
require_relative 'l_cache'
|
6
|
-
require_relative '
|
7
|
-
require_relative 'downloader
|
7
|
+
require_relative 'net-ping'
|
8
|
+
require_relative 'downloader'
|
9
|
+
require_relative 'gitlab_download'
|
8
10
|
module LgPodPlugin
|
9
11
|
|
10
12
|
class LRequest
|
11
13
|
include Singleton
|
12
|
-
|
13
|
-
attr_accessor
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
14
|
+
# pod name
|
15
|
+
attr_accessor :name
|
16
|
+
# 当前token
|
17
|
+
attr_accessor :token
|
18
|
+
# 缓存
|
19
|
+
attr_accessor :cache
|
20
|
+
# 配置
|
21
|
+
attr_accessor :config
|
22
|
+
# 是否更新
|
23
|
+
attr_accessor :is_update
|
24
|
+
# 工作目录
|
25
|
+
attr_accessor :workspace
|
26
|
+
# 是否是还有 git 地址参数
|
27
|
+
attr_accessor :single_git
|
28
|
+
# git 工具类
|
29
|
+
attr_accessor :git_util
|
30
|
+
# 需要更新的 pod 集合
|
31
|
+
attr_accessor :libs
|
32
|
+
# 下载类
|
33
|
+
attr_accessor :downloader
|
34
|
+
# lock_info
|
35
|
+
attr_accessor :lock_info
|
36
|
+
# 实际下载请求参数
|
37
|
+
attr_accessor :request_params
|
38
|
+
# 传入的请求参数
|
39
|
+
attr_accessor :checkout_options
|
40
|
+
# 网络ip 信息
|
41
|
+
attr_accessor :net_ping
|
30
42
|
|
43
|
+
public
|
31
44
|
def get_lock_info
|
32
45
|
lock_file = self.workspace.join("Podfile.lock")
|
33
46
|
if lock_file.exist?
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
begin
|
48
|
+
json = YAML.load_file(lock_file.to_path)
|
49
|
+
rescue
|
50
|
+
json = {}
|
51
|
+
end
|
52
|
+
external_source = json["EXTERNAL SOURCES"] ||= {}
|
53
|
+
checkout_options = json["CHECKOUT OPTIONS"] ||= {}
|
37
54
|
{ "external_source" => external_source, "checkout_options" => checkout_options }
|
38
55
|
else
|
39
|
-
|
56
|
+
{ "external_source" => {}, "checkout_options" => {} }
|
40
57
|
end
|
41
58
|
end
|
42
59
|
|
43
60
|
# 获取缓存用的hash_map
|
61
|
+
public
|
44
62
|
def get_cache_key_params
|
45
63
|
hash_map = Hash.new
|
46
64
|
git = self.checkout_options[:git] ||= self.request_params[:git]
|
@@ -53,38 +71,29 @@ module LgPodPlugin
|
|
53
71
|
hash_map[:commit] = commit
|
54
72
|
elsif git && tag
|
55
73
|
hash_map[:tag] = tag
|
56
|
-
elsif git && branch
|
57
|
-
|
58
|
-
hash_map[:commit] = commit
|
59
|
-
else
|
60
|
-
_, new_commit_id = LGitUtil.git_ls_remote_refs(git, branch, nil, commit)
|
61
|
-
hash_map[:commit] = new_commit_id if new_commit_id
|
62
|
-
end
|
63
|
-
else
|
64
|
-
_, new_commit_id = LGitUtil.git_ls_remote_refs(git, branch, nil, commit)
|
65
|
-
hash_map[:commit] = new_commit_id if new_commit_id
|
74
|
+
elsif git && branch && commit
|
75
|
+
hash_map[:commit] = commit
|
66
76
|
end
|
67
77
|
hash_map
|
68
78
|
end
|
69
79
|
|
70
|
-
|
71
|
-
|
80
|
+
public
|
72
81
|
def get_lock_params
|
73
|
-
|
74
|
-
self.lock_info
|
82
|
+
begin
|
83
|
+
_external_source = self.lock_info["external_source"][self.name] ||= {}
|
84
|
+
_checkout_options = self.lock_info["checkout_options"][self.name] ||= {}
|
85
|
+
rescue
|
86
|
+
_external_source = {}
|
87
|
+
_checkout_options = {}
|
75
88
|
end
|
76
|
-
external_source = self.lock_info["external_source"][self.name] ||= {}
|
77
|
-
checkout_options = self.lock_info["checkout_options"][self.name] ||= {}
|
78
89
|
|
79
90
|
git = self.checkout_options[:git]
|
80
91
|
tag = self.checkout_options[:tag]
|
81
92
|
commit = self.checkout_options[:commit]
|
82
93
|
branch = self.checkout_options[:branch]
|
83
94
|
|
84
|
-
|
85
|
-
|
86
|
-
lock_commit = checkout_options[:commit]
|
87
|
-
lock_branch = external_source[:branch]
|
95
|
+
lock_commit = _checkout_options[:commit] ||= ""
|
96
|
+
lock_branch = _external_source[:branch] ||= ""
|
88
97
|
hash_map = Hash.new
|
89
98
|
hash_map[:git] = git if git
|
90
99
|
if git && tag
|
@@ -97,25 +106,34 @@ module LgPodPlugin
|
|
97
106
|
return hash_map
|
98
107
|
else
|
99
108
|
hash_map[:branch] = branch if branch
|
100
|
-
_, new_commit = LGitUtil.git_ls_remote_refs(git, branch, tag, commit)
|
101
|
-
|
102
|
-
|
109
|
+
_, new_commit = LGitUtil.git_ls_remote_refs(self.name ,git, branch, tag, commit)
|
110
|
+
if new_commit && (new_commit != lock_commit)
|
111
|
+
hash_map[:commit] = new_commit
|
112
|
+
hash_map["is_delete"] = false
|
113
|
+
else
|
114
|
+
hash_map["is_delete"] = true
|
115
|
+
end
|
103
116
|
end
|
104
117
|
elsif git && commit
|
105
118
|
hash_map[:commit] = commit if commit
|
106
119
|
return hash_map
|
107
120
|
else
|
108
|
-
|
109
|
-
|
110
|
-
|
121
|
+
_, new_commit = LGitUtil.git_ls_remote_refs(self.name ,git, branch, tag, commit)
|
122
|
+
if (new_commit != lock_commit)
|
123
|
+
hash_map[:commit] = new_commit
|
124
|
+
hash_map["is_delete"] = false
|
125
|
+
else
|
126
|
+
hash_map[:commit] = new_commit if new_commit
|
127
|
+
hash_map["is_delete"] = true
|
128
|
+
end
|
111
129
|
end
|
112
130
|
hash_map
|
113
131
|
end
|
114
132
|
|
115
|
-
|
133
|
+
public
|
134
|
+
|
116
135
|
#获取下载参数
|
117
136
|
def get_request_params
|
118
|
-
self.is_update = self.is_update_pod
|
119
137
|
if self.lock_info == nil
|
120
138
|
self.lock_info = self.get_lock_info
|
121
139
|
end
|
@@ -135,11 +153,11 @@ module LgPodPlugin
|
|
135
153
|
else
|
136
154
|
self.single_git = true
|
137
155
|
end
|
156
|
+
self.net_ping = Ping.new(git)
|
157
|
+
self.net_ping.network_ok = self.net_ping.ping
|
138
158
|
self.checkout_options = Hash.new.deep_merge(options)
|
139
159
|
self.request_params = self.get_request_params
|
140
|
-
|
141
|
-
self.token = self.request_gitlab_token(git)
|
142
|
-
end
|
160
|
+
self.config = LConfig.getConfig(git)
|
143
161
|
self.cache = LCache.new(self.workspace)
|
144
162
|
self.git_util = LGitUtil.new(name, self.checkout_options)
|
145
163
|
self.downloader = LDownloader.new(name, self.checkout_options)
|
@@ -149,26 +167,6 @@ module LgPodPlugin
|
|
149
167
|
return LRequest.instance
|
150
168
|
end
|
151
169
|
|
152
|
-
def request_gitlab_token(git)
|
153
|
-
if git == nil
|
154
|
-
return nil
|
155
|
-
end
|
156
|
-
begin
|
157
|
-
#81.69.242.162
|
158
|
-
uri = URI('http://81.69.242.162:8080/v1/member/user/gitlab/token')
|
159
|
-
# uri = URI('http://127.0.0.1:8080/v1/member/user/gitlab/token')
|
160
|
-
params = { "url" => git }
|
161
|
-
res = Net::HTTP.post_form(uri, params)
|
162
|
-
json = JSON.parse(res.body)
|
163
|
-
rescue
|
164
|
-
return nil
|
165
|
-
end
|
166
|
-
unless json
|
167
|
-
return nil
|
168
|
-
end
|
169
|
-
json["data"]["token"]
|
170
|
-
end
|
171
|
-
|
172
170
|
end
|
173
171
|
|
174
172
|
end
|
data/lib/lg_pod_plugin/string.rb
CHANGED
data/lib/lg_pod_plugin.rb
CHANGED
@@ -6,8 +6,9 @@ require_relative 'lg_pod_plugin/log'
|
|
6
6
|
require_relative 'lg_pod_plugin/install'
|
7
7
|
require_relative 'lg_pod_plugin/request'
|
8
8
|
require_relative 'lg_pod_plugin/database'
|
9
|
-
require_relative 'lg_pod_plugin/git_util'
|
10
9
|
require_relative 'lg_pod_plugin/downloader'
|
10
|
+
require_relative 'lg_pod_plugin/gitlab_api'
|
11
|
+
require_relative 'lg_pod_plugin/gitlab_download'
|
11
12
|
require 'cocoapods-core/podfile/target_definition'
|
12
13
|
|
13
14
|
module LgPodPlugin
|