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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d721ef21f17b74dbf52651003adf58424e8ffc7067457faea3edc50dda8b501
4
- data.tar.gz: 132e75f5b9fd55f6a22ca48318511f2e37f054dcc81b5ef90e0d022f227df0ed
3
+ metadata.gz: bfad1a89dbfca4907d2188cea319433a1d7e7bb9d067b63ed93cd71c285bf4d5
4
+ data.tar.gz: 90d653002dee76968ade7d6c43aede5fb0552280a9d210fdcb9423f1495574bc
5
5
  SHA512:
6
- metadata.gz: c154b062d336f06885fef82beca4074d5ec17772db61d079444f6b64704646a6f81ec91884926a8494120ba197f1f20539814f9b6457f1e8875737b834f091ea
7
- data.tar.gz: 334123319a80133e8c6c3b32c97bc16b0bb58ff263ec6318f85d3fd86df70f3aa38d7508d3c6c3f5c6394d1c7cdee1ea70400b696672e11ba3d912b5dfb35e69
6
+ metadata.gz: 444b1a2f4951337b0c552f74651b2ef8ad2278425733b70023bbdfad30da156fbbbba8efb703aca3ffaa0f6cb21cca16ed2b6ffbd54634e84a33cea314b05f09
7
+ data.tar.gz: c92fb25a5e438f6b6583122629328ab4019d1189d724026dfcd6fe5ddfca1b285a323efd612b0aea193223583f32ab969198ede1dd37e10d04b794b918751852
data/bin/lg ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'cocoapods'
3
+ require 'lg_pod_plugin'
4
+ LgPodPlugin.log_green "欢迎使用 `lg_pod_plugin`"
5
+ LgPodPlugin::Command.run(ARGV)
data/lib/command/cache.rb CHANGED
@@ -1,18 +1,22 @@
1
- # require 'claide'
2
- #
3
- # module LgPodPlugin
4
- # class Cache < Command
5
- # self.abstract_command = true
6
- # self.summary = 'Inter-process communication'
7
- # def initialize(argv)
8
- #
9
- # end
10
- # def output_pipe
11
- # pp "hello world"
12
- # end
13
- #
14
- # def run
15
- # pp "run"
16
- # end
17
- # end
18
- # end
1
+ require 'claide'
2
+ require_relative 'command'
3
+
4
+ module LgPodPlugin
5
+ class Command
6
+ class Cache < Command
7
+ self.abstract_command = true
8
+ self.summary = 'Manipulate the CocoaPods cache'
9
+
10
+ self.description = <<-DESC
11
+ Manipulate the download cache for pods, like printing the cache content
12
+ or cleaning the pods cache.
13
+ DESC
14
+
15
+ def initialize(argv)
16
+ # pp argv
17
+ super
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -1,35 +1,27 @@
1
- # require 'claide'
2
- #
3
- # module LgPodPlugin
4
- # class Command < CLAide::Command
5
- # require_relative './cache'
6
- #
7
- # self.abstract_command = true
8
- # self.command = 'pod'
9
- # self.version = VERSION
10
- # self.description = 'this is my command lint tool!'
11
- # self.plugin_prefixes = %w(claide cocoapods)
12
- #
13
- # def self.options
14
- # [
15
- # ['--allow-root', 'Allows CocoaPods to run as root'],
16
- # ['--silent', 'Show nothing'],
17
- # ].concat(super)
18
- # end
19
- #
20
- # def self.run(argv)
21
- # super(argv)
22
- # end
23
- #
24
- # def initialize(argv)
25
- # super
26
- # # config.silent = argv.flag?('silent', config.silent)
27
- # # config.allow_root = argv.flag?('allow-root', config.allow_root)
28
- # # config.verbose = self.verbose? unless verbose.nil?
29
- # unless self.ansi_output?
30
- # Colored2.disable!
31
- # String.send(:define_method, :colorize) { |string, _| string }
32
- # end
33
- # end
34
- # end
35
- # end
1
+ require 'claide'
2
+
3
+ module LgPodPlugin
4
+ class Command < CLAide::Command
5
+ require_relative 'cache'
6
+ require_relative 'update'
7
+ require_relative 'install'
8
+ self.command = 'lg'
9
+ self.version = VERSION
10
+ self.abstract_command = true
11
+ self.description = 'this is `lg_pod_plugin` command line tool!'
12
+ def self.options
13
+ [
14
+ ['--silent', 'Show nothing']
15
+ ].concat(super)
16
+ end
17
+
18
+ def self.run(argv)
19
+ super(argv)
20
+ end
21
+
22
+ def initialize(argv)
23
+ super
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,52 @@
1
+ require 'claide'
2
+
3
+ module LgPodPlugin
4
+ class Command
5
+ class Install < Command
6
+ REQUIRED_ATTRS ||= %i[log repo_update].freeze
7
+ attr_accessor(*REQUIRED_ATTRS)
8
+
9
+ self.summary = 'Install project dependencies according to versions from a Podfile.lock'
10
+
11
+ self.description = <<-DESC
12
+ Downloads all dependencies defined in `Podfile` and creates an Xcode
13
+ Pods library project in `./Pods`.
14
+
15
+ The Xcode project file should be specified in your `Podfile` like this:
16
+
17
+ project 'path/to/XcodeProject.xcodeproj'
18
+
19
+ If no project is specified, then a search for an Xcode project will
20
+ be made. If more than one Xcode project is found, the command will
21
+ raise an error.
22
+
23
+ This will configure the project to reference the Pods static library,
24
+ add a build configuration file, and add a post build script to copy
25
+ Pod resources.
26
+
27
+ This may return one of several error codes if it encounters problems.
28
+ * `1` Generic error code
29
+ * `31` Spec not found (i.e out-of-date source repos, mistyped Pod name etc...)
30
+ DESC
31
+
32
+ def self.options
33
+ [
34
+ ['--repo-update', 'Force running `pod repo update` before install'],
35
+ ['--deployment', 'Disallow any changes to the Podfile or the Podfile.lock during installation'],
36
+ ['--clean-install', 'Ignore the contents of the project cache and force a full pod installation. This only ' \
37
+ 'applies to projects that have enabled incremental installation'],
38
+ ].concat(super).reject { |(name, _)| name == '--no-repo-update' }
39
+ end
40
+
41
+ def initialize(argv)
42
+ self.log = argv.flag?('verbose')
43
+ self.repo_update = argv.flag?('repo-update')
44
+ super
45
+ end
46
+
47
+ def run
48
+ LgPodPlugin.install({ :verbose => self.log, :repo_update => self.repo_update })
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,39 @@
1
+ require 'claide'
2
+ module LgPodPlugin
3
+ class Command
4
+ class Update < Command
5
+ REQUIRED_ATTRS ||= %i[log repo_update].freeze
6
+ attr_accessor(*REQUIRED_ATTRS)
7
+ self.summary = 'Update outdated project dependencies and create new ' \
8
+ 'Podfile.lock'
9
+
10
+ self.description = <<-DESC
11
+ Updates the Pods identified by the specified `POD_NAMES`, which is a
12
+ space-delimited list of pod names. If no `POD_NAMES` are specified, it
13
+ updates all the Pods, ignoring the contents of the Podfile.lock. This
14
+ command is reserved for the update of dependencies; pod install should
15
+ be used to install changes to the Podfile.
16
+ DESC
17
+
18
+ def self.options
19
+ [
20
+ ["--sources=#{Pod::TrunkSource::TRUNK_REPO_URL}", 'The sources from which to update dependent pods. ' \
21
+ 'Multiple sources must be comma-delimited'],
22
+ ['--exclude-pods=podName', 'Pods to exclude during update. Multiple pods must be comma-delimited'],
23
+ ['--clean-install', 'Ignore the contents of the project cache and force a full pod installation. This only ' \
24
+ 'applies to projects that have enabled incremental installation'],
25
+ ].concat(super)
26
+ end
27
+
28
+ def initialize(argv)
29
+ self.log = argv.flag?('verbose')
30
+ self.repo_update = argv.flag?('repo-update')
31
+ super
32
+ end
33
+
34
+ def run
35
+ LgPodPlugin.update({ :verbose => self.log, :repo_update => self.repo_update })
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,5 @@
1
1
  require 'git'
2
2
  require_relative 'l_cache'
3
- # require_relative 'database'
4
3
  require_relative 'file_path'
5
4
 
6
5
  module LgPodPlugin
@@ -12,16 +11,12 @@ module LgPodPlugin
12
11
 
13
12
  def initialize(name, options = {})
14
13
  self.name = name
15
- self.options = options
16
- self.git = options[:git]
17
- self.tag = options[:tag]
18
- self.branch = options[:branch]
19
- self.commit = options[:commit]
14
+ self.options = Hash.new.deep_merge(options)
15
+ self.git = self.options[:git]
16
+ self.tag = self.options[:tag]
17
+ self.branch = self.options[:branch]
18
+ self.commit = self.options[:commit]
20
19
  end
21
-
22
- # def check_cache_valid(name, branch)
23
- # self.db.should_clean_pod_info(name, branch)
24
- # end
25
20
 
26
21
  # 预下载处理
27
22
  def pre_download_pod
@@ -31,15 +26,15 @@ module LgPodPlugin
31
26
  LgPodPlugin.log_green "Using `#{name}`"
32
27
  end
33
28
  # 发现本地有缓存, 不需要更新缓存
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
36
- LgPodPlugin.log_green "find the cache of `#{name}`, you can use it now."
37
- return
38
- else
29
+ need_download = LRequest.shared.cache.find_pod_cache(name)
30
+ if need_download
39
31
  LgPodPlugin.log_green "find the new commit of `#{name}`, Git downloading now."
32
+ # 本地 git 下载 pod 目录
33
+ LRequest.shared.git_util.pre_download_git_repository
34
+ else
35
+ LRequest.shared.libs.delete(self.name)
36
+ LgPodPlugin.log_green "find the cache of `#{name}`, you can use it now."
40
37
  end
41
- # 本地 git 下载 pod 目录
42
- LRequest.shared.git_util.pre_download_git_repository
43
38
 
44
39
  # 本地clone代码失败跳出去
45
40
  # unless real_pod_path.exist?
@@ -20,8 +20,10 @@ module LgPodPlugin
20
20
  self.commit = options[:commit]
21
21
  end
22
22
 
23
+ # 从 GitLab下载 zip包
23
24
  # 根据branch 下载 zip 包
24
- def git_download_branch_zip(path, temp_name)
25
+ def gitlab_download_branch_zip(path, temp_name)
26
+ branch = self.branch ||= "master"
25
27
  token = LRequest.shared.token
26
28
  unless token
27
29
  return self.git_clone_by_branch(path, temp_name)
@@ -32,25 +34,25 @@ module LgPodPlugin
32
34
  unless project_name
33
35
  return self.git_clone_by_branch(path, temp_name)
34
36
  end
35
- download_url = base_url + "/-/archive/" + self.branch + "/#{project_name}-#{self.branch}.zip"
37
+ download_url = base_url + "/-/archive/" + branch + "/#{project_name}-#{branch}.zip"
36
38
  LgPodPlugin.log_blue "开始下载 => #{download_url}"
37
- system("curl --header PRIVATE-TOKEN:#{token} -o #{file_name} --connect-timeout 15 #{download_url}")
39
+ system("curl --header PRIVATE-TOKEN:#{token} -o #{file_name} --connect-timeout 60 --retry 3 #{download_url}")
38
40
  unless File.exist?(file_name)
39
41
  LgPodPlugin.log_red("下载zip包失败, 尝试git clone #{self.git}")
40
42
  return self.git_clone_by_branch(path, temp_name)
41
43
  end
42
44
  # 解压文件
43
45
  result = LUtils.unzip_file(path.join(file_name).to_path, "./")
44
- new_file_name = "#{project_name}-#{self.branch}"
46
+ new_file_name = "#{project_name}-#{branch}"
45
47
  unless result && File.exist?(new_file_name)
46
- LgPodPlugin.log_red("解压文件失败, 尝试git clone #{self.git}")
48
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
47
49
  return self.git_clone_by_branch(path, temp_name)
48
50
  end
49
51
  path.join(new_file_name)
50
52
  end
51
53
 
52
54
  # 通过tag下载zip包
53
- def git_download_tag_zip(path, temp_name)
55
+ def gitlab_download_tag_zip(path, temp_name)
54
56
  token = LRequest.shared.token
55
57
  unless token
56
58
  return self.git_clone_by_tag(path, temp_name)
@@ -64,7 +66,7 @@ module LgPodPlugin
64
66
  download_url = base_url + "/-/archive/" + self.tag + "/#{project_name}-#{self.tag}.zip"
65
67
  # 下载文件
66
68
  LgPodPlugin.log_blue "开始下载 => #{download_url}"
67
- system("curl -s --header PRIVATE-TOKEN:#{token} -o #{file_name} #{download_url}")
69
+ system("curl -s --header PRIVATE-TOKEN:#{token} -o #{file_name} --connect-timeout 60 --retry 3 #{download_url}")
68
70
  unless File.exist?(file_name)
69
71
  LgPodPlugin.log_red("下载zip包失败, 尝试git clone #{self.git}")
70
72
  return self.git_clone_by_tag(path, temp_name)
@@ -73,13 +75,14 @@ module LgPodPlugin
73
75
  result = LUtils.unzip_file(path.join(file_name).to_path, "./")
74
76
  new_file_name = "#{project_name}-#{self.tag}"
75
77
  unless result && File.exist?(new_file_name)
76
- LgPodPlugin.log_red("解压文件失败, 尝试git clone #{self.git}")
78
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
77
79
  return self.git_clone_by_tag(path, temp_name)
78
80
  end
79
81
  path.join(new_file_name)
80
82
  end
83
+
81
84
  # 通过 commit 下载zip包
82
- def git_download_commit_zip(path, temp_name)
85
+ def gitlab_download_commit_zip(path, temp_name)
83
86
  token = LRequest.shared.token
84
87
  unless token
85
88
  return self.git_clone_by_commit(path, temp_name)
@@ -93,24 +96,119 @@ module LgPodPlugin
93
96
  download_url = base_url + "/-/archive/" + self.commit + "/#{project_name}-#{self.commit}.zip"
94
97
  # 下载文件
95
98
  LgPodPlugin.log_blue "开始下载 => #{download_url}"
96
- system("curl -s --header PRIVATE-TOKEN:#{token} -o #{file_name} #{download_url}")
99
+ system("curl -s --header PRIVATE-TOKEN:#{token} -o #{file_name} --connect-timeout 60 --retry 3 #{download_url}")
100
+ unless File.exist?(file_name)
101
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
102
+ return self.git_clone_by_commit(path, temp_name)
103
+ end
104
+ # 解压文件
105
+ result = LUtils.unzip_file(path.join(file_name).to_path, "./")
106
+ new_file_name = "#{project_name}-#{self.commit}"
107
+ unless result && File.exist?(new_file_name)
108
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
109
+ return self.git_clone_by_commit(path, temp_name)
110
+ end
111
+ path.join(new_file_name)
112
+ end
113
+
114
+ # 从 Github下载 zip 包
115
+ # 根据branch 下载 zip 包
116
+ def github_download_branch_zip(path, temp_name)
117
+ file_name = "#{temp_name}.zip"
118
+ branch = self.branch ||= "master"
119
+ if self.git.include?(".git")
120
+ base_url = self.git[0...self.git.length - 4]
121
+ else
122
+ base_url = self.git
123
+ end
124
+ project_name = base_url.split("/").last if base_url
125
+ origin_url = base_url + "/archive/#{branch}.zip"
126
+ download_url = "https://gh.api.99988866.xyz/#{origin_url}"
127
+ LgPodPlugin.log_blue "开始下载 => #{download_url}"
128
+ system("curl -o #{file_name} --connect-timeout 60 --retry 3 #{download_url}")
97
129
  unless File.exist?(file_name)
98
130
  LgPodPlugin.log_red("下载zip包失败, 尝试git clone #{self.git}")
131
+ return self.git_clone_by_branch(path, temp_name)
132
+ end
133
+ # 解压文件
134
+ result = LUtils.unzip_file(path.join(file_name).to_path, "./")
135
+ new_file_name = "#{project_name}-#{branch}"
136
+ unless result && File.exist?(new_file_name)
137
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
138
+ return self.git_clone_by_branch(path, temp_name)
139
+ end
140
+ path.join(new_file_name)
141
+ end
142
+
143
+ # 通过tag下载zip包
144
+ def github_download_tag_zip(path, temp_name)
145
+ file_name = "#{temp_name}.zip"
146
+ if self.git.include?(".git")
147
+ base_url = self.git[0...self.git.length - 4]
148
+ else
149
+ base_url = self.git
150
+ end
151
+ project_name = base_url.split("/").last if base_url
152
+ origin_url = base_url + "/archive/refs/tags/#{self.tag}.zip"
153
+ download_url = "https://gh.api.99988866.xyz/#{origin_url}"
154
+ # 下载文件
155
+ LgPodPlugin.log_blue "开始下载 => #{download_url}"
156
+ system("curl -s -o #{file_name} --connect-timeout 60 --retry 3 #{download_url}")
157
+ unless File.exist?(file_name)
158
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
159
+ return self.git_clone_by_tag(path, temp_name)
160
+ end
161
+ # 解压文件
162
+ result = LUtils.unzip_file(path.join(file_name).to_path, "./")
163
+ if self.tag.include?("v") && self.tag[0...1] == "v"
164
+ this_tag = self.tag[1...self.tag.length]
165
+ else
166
+ this_tag = self.tag
167
+ end
168
+ new_file_name = "#{project_name}-#{this_tag}"
169
+ unless result && File.exist?(new_file_name)
170
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
171
+ return self.git_clone_by_tag(path, temp_name)
172
+ end
173
+ path.join(new_file_name)
174
+ end
175
+
176
+ # 通过 commit 下载zip包
177
+ def github_download_commit_zip(path, temp_name)
178
+ file_name = "#{temp_name}.zip"
179
+ if self.git.include?(".git")
180
+ base_url = self.git[0...self.git.length - 4]
181
+ else
182
+ base_url = self.git
183
+ end
184
+ project_name = base_url.split("/").last if base_url
185
+ origin_url = base_url + "/archive/#{self.commit}.zip"
186
+ download_url = "https://gh.api.99988866.xyz/#{origin_url}"
187
+ # 下载文件
188
+ LgPodPlugin.log_blue "开始下载 => #{download_url}"
189
+ system("curl -s -o #{file_name} --connect-timeout 15 --retry 3 #{download_url}")
190
+ unless File.exist?(file_name)
191
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
99
192
  return self.git_clone_by_commit(path, temp_name)
100
193
  end
101
194
  # 解压文件
102
195
  result = LUtils.unzip_file(path.join(file_name).to_path, "./")
103
196
  new_file_name = "#{project_name}-#{self.commit}"
104
197
  unless result && File.exist?(new_file_name)
105
- LgPodPlugin.log_red("解压文件失败, 尝试git clone #{self.git}")
198
+ LgPodPlugin.log_red("正在尝试git clone #{self.git}")
106
199
  return self.git_clone_by_commit(path, temp_name)
107
200
  end
108
201
  path.join(new_file_name)
109
202
  end
110
203
 
111
204
  def git_clone_by_branch(path, temp_name)
112
- LgPodPlugin.log_blue "git clone --depth=1 --branch #{self.branch} #{self.git}"
113
- system("git clone --depth=1 -b #{self.branch} #{self.git} #{temp_name}")
205
+ if self.git && self.branch
206
+ LgPodPlugin.log_blue "git clone --depth=1 --branch #{self.branch} #{self.git}"
207
+ system("git clone --depth=1 -b #{self.branch} #{self.git} #{temp_name}")
208
+ else
209
+ LgPodPlugin.log_blue "git clone --depth=1 #{self.git}"
210
+ system("git clone --depth=1 #{self.git} #{temp_name}")
211
+ end
114
212
  path.join(temp_name)
115
213
  end
116
214
 
@@ -136,42 +234,38 @@ module LgPodPlugin
136
234
  temp_name = "lg_temp_pod"
137
235
  if self.git && self.tag
138
236
  if self.git.include?("capp/iOS")
139
- return git_download_tag_zip(path, temp_name)
237
+ return gitlab_download_tag_zip(path, temp_name)
238
+ elsif self.git.include?("https://github.com")
239
+ return github_download_tag_zip path, temp_name
140
240
  else
141
241
  return self.git_clone_by_tag(path, temp_name)
142
242
  end
143
243
  elsif self.git && self.branch
144
244
  if self.git.include?("capp/iOS")
145
- return self.git_download_branch_zip(path, temp_name)
245
+ return self.gitlab_download_branch_zip(path, temp_name)
246
+ elsif self.git.include?("https://github.com")
247
+ return self.github_download_branch_zip path, temp_name
146
248
  else
147
249
  return self.git_clone_by_branch(path, temp_name)
148
250
  end
149
251
  elsif self.git && self.commit
150
252
  if self.git.include?("capp/iOS")
151
- return self.git_download_commit_zip(path, temp_name)
253
+ return self.gitlab_download_commit_zip(path, temp_name)
254
+ elsif self.git.include?("https://github.com")
255
+ return self.github_download_commit_zip path, temp_name
152
256
  else
153
257
  return self.git_clone_by_commit(path, temp_name)
154
258
  end
259
+ elsif self.git
260
+ if self.git.include?("capp/iOS")
261
+ return self.gitlab_download_branch_zip(path, temp_name)
262
+ elsif self.git.include?("https://github.com")
263
+ return self.github_download_branch_zip path, temp_name
264
+ else
265
+ return self.git_clone_by_branch(path, temp_name)
266
+ end
155
267
  end
156
- end
157
-
158
- # def git_checkout(branch)
159
- # system("git checkout -b #{branch}")
160
- # end
161
- #
162
- # def git_switch(branch)
163
- # system("git switch #{branch}")
164
- # end
165
268
 
166
- def request_params
167
- hash_map = {:git => git}
168
- if git && tag
169
- hash_map[:tag] = tag
170
- hash_map[:commit] = self.commit
171
- else
172
- hash_map[:commit] = commit
173
- end
174
- hash_map
175
269
  end
176
270
 
177
271
  def pre_download_git_repository
@@ -188,20 +282,24 @@ module LgPodPlugin
188
282
  unless get_temp_folder.exist?
189
283
  return nil
190
284
  end
191
- LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, self.request_params)
285
+ if LRequest.shared.single_git
286
+ LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, { :git => self.git })
287
+ end
288
+ LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, LRequest.shared.get_cache_key_params)
192
289
  FileUtils.chdir(LFileManager.download_director)
193
290
  FileUtils.rm_rf(lg_pod_path)
194
291
  end
195
-
292
+
196
293
  # 获取最新的一条 commit 信息
197
294
  def self.git_ls_remote_refs(git, branch, tag, commit)
198
295
  if branch
199
296
  LgPodPlugin.log_yellow "git ls-remote #{git} #{branch}"
200
- new_commit = %x(git ls-remote #{git} #{branch}).split(" ").first
297
+ result = %x(git ls-remote #{git} #{branch})
298
+ new_commit = result.split(" ").first if result
201
299
  return [branch, new_commit]
202
- end
203
- ls = Git.ls_remote(git, :head => true )
204
- if tag
300
+ elsif tag
301
+ LgPodPlugin.log_yellow "git ls-remote #{git}"
302
+ ls = Git.ls_remote(git, :head => true)
205
303
  map = ls["tags"]
206
304
  keys = map.keys
207
305
  idx = keys.index("#{tag}")
@@ -212,75 +310,21 @@ module LgPodPlugin
212
310
  new_commit = map[key][:sha]
213
311
  return [nil, new_commit]
214
312
  else
215
- new_commit = new_branch = nil
216
- find_commit = commit ? commit : ls["head"][:sha]
217
- ls["branches"].each do |key, value|
218
- sha = value[:sha]
219
- next if sha != find_commit
220
- new_branch = key
221
- new_commit = find_commit
222
- return [new_branch, new_commit]
223
- end
224
- return [new_branch , new_commit]
225
- end
226
- end
227
-
228
- # 本地pod库git操作
229
- def git_local_pod_check(path)
230
- FileUtils.chdir(path)
231
- git = Git.open(Pathname("./"))
232
- current_branch = git.current_branch
233
- last_stash_message = "#{current_branch}_pod_install_cache"
234
- if self.branch == current_branch || !self.branch
235
- # 是否恢复储藏内容到暂存区
236
- self.should_pull(git ,current_branch)
237
- else
238
- # 存储上一个 branch 未暂存的内容
239
- # 判断 git status 是否有要暂存的内容
240
- have_changes = git.status.changed.map { |change|
241
- change.to_s
242
- }
243
- # 如果有要暂存的内容, 就 git stash save
244
- unless have_changes.empty?
245
- # "当前#{current_branch}分支有未暂存的内容"
246
- git.branch.stashes.save(last_stash_message)
313
+ if commit
314
+ return nil, commit
315
+ else
316
+ LgPodPlugin.log_yellow "git ls-remote #{git}"
317
+ ls = Git.ls_remote(git, :head => true)
318
+ find_commit = ls["head"][:sha]
319
+ ls["branches"].each do |key, value|
320
+ sha = value[:sha]
321
+ next if sha != find_commit
322
+ return [key, find_commit]
323
+ end
324
+ return nil, find_commit
247
325
  end
248
- # 这里 checkout到目标分支, 本地有git switch -b xxx, 本地没有 git checkout -b xxx
249
- git.checkout(git.branch(branch))
250
- current_branch = git.current_branch
251
- self.should_pull(git ,current_branch)
252
- # 是否恢复储藏内容到暂存区
253
- self.should_pop_stash(git, current_branch)
254
- end
255
- end
256
- # 是否pull 代码
257
- def should_pull(git, branch, new_commit = nil)
258
- new_branch = branch ||= self.branch
259
- git_url = git.remote.url ||= self.git
260
- if new_commit == nil
261
- _, new_commit = LGitUtil.git_ls_remote_refs(git_url, new_branch,nil, nil)
262
326
  end
263
- local_commit = git.log(1).to_s #本地最后一条 commit hash 值
264
- if local_commit != new_commit
265
- system("git pull origin #{branch}")
266
- end
267
- end
268
327
 
269
- def should_pop_stash(git, branch)
270
- last_stash_message = "#{branch}_pod_install_cache"
271
- # 查看下贮存的有没有代码
272
- stashes = git.branch.stashes.all.flatten.select do |ss|
273
- ss.is_a?(String)
274
- end
275
- unless stashes.include?(last_stash_message)
276
- return
277
- end
278
- drop_index = stashes.index(last_stash_message)
279
- # 恢复上次贮藏的代码
280
- system("git stash apply stash@{#{drop_index}} ")
281
- # pop 掉已恢复到暂缓区的代码
282
- git_command = "git stash drop stash@{" + "#{drop_index}" + "}"
283
- system(git_command)
284
328
  end
285
329
 
286
330
  end