lg_pod_plugin 1.1.6.7 → 1.1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/lib/command/command.rb +1 -0
  3. data/lib/command/doctor.rb +31 -0
  4. data/lib/command/install.rb +1 -1
  5. data/lib/command/update.rb +1 -1
  6. data/lib/lg_pod_plugin/config/l_config.rb +4 -5
  7. data/lib/lg_pod_plugin/db/database.rb +116 -110
  8. data/lib/lg_pod_plugin/downloader/downloader.rb +7 -6
  9. data/lib/lg_pod_plugin/downloader/l_cache.rb +11 -2
  10. data/lib/lg_pod_plugin/downloader/overload_cache.rb +329 -0
  11. data/lib/lg_pod_plugin/downloader/request.rb +32 -32
  12. data/lib/lg_pod_plugin/git/gitlab_api.rb +29 -18
  13. data/lib/lg_pod_plugin/installer/PodDownload +0 -0
  14. data/lib/lg_pod_plugin/installer/install.rb +1 -4
  15. data/lib/lg_pod_plugin/installer/main.rb +0 -1
  16. data/lib/lg_pod_plugin/installer/project.rb +2 -7
  17. data/lib/lg_pod_plugin/pod/release-pod.rb +11 -42
  18. data/lib/lg_pod_plugin/version.rb +1 -1
  19. data/lib/lg_pod_plugin.rb +1 -0
  20. metadata +29 -119
  21. data/lib/sqlite3-1.5.3-arm64-darwin/API_CHANGES.md +0 -49
  22. data/lib/sqlite3-1.5.3-arm64-darwin/CHANGELOG.md +0 -462
  23. data/lib/sqlite3-1.5.3-arm64-darwin/CONTRIBUTING.md +0 -24
  24. data/lib/sqlite3-1.5.3-arm64-darwin/ChangeLog.cvs +0 -88
  25. data/lib/sqlite3-1.5.3-arm64-darwin/README.md +0 -235
  26. data/lib/sqlite3-1.5.3-arm64-darwin/dependencies.yml +0 -14
  27. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/aggregator.c +0 -274
  28. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/aggregator.h +0 -12
  29. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/backup.c +0 -168
  30. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/backup.h +0 -15
  31. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/database.c +0 -853
  32. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/database.h +0 -17
  33. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/exception.c +0 -98
  34. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/exception.h +0 -8
  35. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/extconf.rb +0 -251
  36. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/sqlite3.c +0 -163
  37. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/sqlite3_ruby.h +0 -48
  38. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/statement.c +0 -442
  39. data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/statement.h +0 -16
  40. data/lib/sqlite3-1.5.3-arm64-darwin/faq/faq.md +0 -431
  41. data/lib/sqlite3-1.5.3-arm64-darwin/faq/faq.rb +0 -145
  42. data/lib/sqlite3-1.5.3-arm64-darwin/faq/faq.yml +0 -426
  43. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/2.6/sqlite3_native.bundle +0 -0
  44. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/2.7/sqlite3_native.bundle +0 -0
  45. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.0/sqlite3_native.bundle +0 -0
  46. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.1/sqlite3_native.bundle +0 -0
  47. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.2/sqlite3_native.bundle +0 -0
  48. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/constants.rb +0 -50
  49. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/database.rb +0 -741
  50. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/errors.rb +0 -35
  51. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/pragmas.rb +0 -595
  52. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/resultset.rb +0 -187
  53. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/statement.rb +0 -145
  54. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/translator.rb +0 -118
  55. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/value.rb +0 -57
  56. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/version.rb +0 -23
  57. data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3.rb +0 -15
  58. data/lib/sqlite3-1.5.3-arm64-darwin/test/helper.rb +0 -27
  59. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_backup.rb +0 -33
  60. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_collation.rb +0 -82
  61. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb +0 -545
  62. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb +0 -95
  63. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readonly.rb +0 -36
  64. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb +0 -41
  65. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_deprecated.rb +0 -44
  66. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_encoding.rb +0 -155
  67. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb +0 -507
  68. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_aggregate.rb +0 -336
  69. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_open_close.rb +0 -30
  70. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb +0 -115
  71. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb +0 -142
  72. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_statement.rb +0 -194
  73. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_result_set.rb +0 -37
  74. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_sqlite3.rb +0 -30
  75. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_statement.rb +0 -263
  76. data/lib/sqlite3-1.5.3-arm64-darwin/test/test_statement_execute.rb +0 -35
  77. data/lib/sqlite3-1.5.3-x86_64-darwin/API_CHANGES.md +0 -49
  78. data/lib/sqlite3-1.5.3-x86_64-darwin/CHANGELOG.md +0 -462
  79. data/lib/sqlite3-1.5.3-x86_64-darwin/CONTRIBUTING.md +0 -24
  80. data/lib/sqlite3-1.5.3-x86_64-darwin/ChangeLog.cvs +0 -88
  81. data/lib/sqlite3-1.5.3-x86_64-darwin/README.md +0 -235
  82. data/lib/sqlite3-1.5.3-x86_64-darwin/dependencies.yml +0 -14
  83. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/aggregator.c +0 -274
  84. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/aggregator.h +0 -12
  85. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/backup.c +0 -168
  86. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/backup.h +0 -15
  87. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/database.c +0 -853
  88. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/database.h +0 -17
  89. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/exception.c +0 -98
  90. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/exception.h +0 -8
  91. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/extconf.rb +0 -251
  92. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/sqlite3.c +0 -163
  93. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/sqlite3_ruby.h +0 -48
  94. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/statement.c +0 -442
  95. data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/statement.h +0 -16
  96. data/lib/sqlite3-1.5.3-x86_64-darwin/faq/faq.md +0 -431
  97. data/lib/sqlite3-1.5.3-x86_64-darwin/faq/faq.rb +0 -145
  98. data/lib/sqlite3-1.5.3-x86_64-darwin/faq/faq.yml +0 -426
  99. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/2.6/sqlite3_native.bundle +0 -0
  100. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/2.7/sqlite3_native.bundle +0 -0
  101. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.0/sqlite3_native.bundle +0 -0
  102. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.1/sqlite3_native.bundle +0 -0
  103. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.2/sqlite3_native.bundle +0 -0
  104. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/constants.rb +0 -50
  105. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/database.rb +0 -741
  106. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/errors.rb +0 -35
  107. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/pragmas.rb +0 -595
  108. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/resultset.rb +0 -187
  109. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/statement.rb +0 -145
  110. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/translator.rb +0 -118
  111. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/value.rb +0 -57
  112. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/version.rb +0 -23
  113. data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3.rb +0 -15
  114. data/lib/sqlite3-1.5.3-x86_64-darwin/test/helper.rb +0 -27
  115. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_backup.rb +0 -33
  116. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_collation.rb +0 -82
  117. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database.rb +0 -545
  118. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_flags.rb +0 -95
  119. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_readonly.rb +0 -36
  120. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_readwrite.rb +0 -41
  121. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_deprecated.rb +0 -44
  122. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_encoding.rb +0 -155
  123. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration.rb +0 -507
  124. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_aggregate.rb +0 -336
  125. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_open_close.rb +0 -30
  126. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_pending.rb +0 -115
  127. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_resultset.rb +0 -142
  128. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_statement.rb +0 -194
  129. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_result_set.rb +0 -37
  130. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_sqlite3.rb +0 -30
  131. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_statement.rb +0 -263
  132. data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_statement_execute.rb +0 -35
@@ -0,0 +1,329 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods'
4
+ require 'fileutils'
5
+ require 'tmpdir'
6
+
7
+ module Pod
8
+ module Downloader
9
+ # The class responsible for managing Pod downloads, transparently caching
10
+ # them in a cache directory.
11
+ #
12
+ class Cache
13
+ # @return [Pathname] The root directory where this cache store its
14
+ # downloads.
15
+ #
16
+ attr_reader :root
17
+
18
+ # Initialize a new instance
19
+ #
20
+ # @param [Pathname,String] root
21
+ # see {#root}
22
+ #
23
+ def initialize(root)
24
+ @root = Pathname(root)
25
+ ensure_matching_version
26
+ end
27
+
28
+ # Downloads the Pod from the given `request`
29
+ #
30
+ # @param [Request] request
31
+ # the request to be downloaded.
32
+ #
33
+ # @return [Response] the response from downloading `request`
34
+ #
35
+ def download_pod(request)
36
+ cached_pod(request) || uncached_pod(request)
37
+ rescue Informative
38
+ raise
39
+ rescue
40
+ UI.puts("\n[!] Error installing #{request.name}".red)
41
+ raise
42
+ end
43
+
44
+ # @return [Hash<String, Hash<Symbol, String>>]
45
+ # A hash whose keys are the pod name
46
+ # And values are a hash with the following keys:
47
+ # :spec_file : path to the spec file
48
+ # :name : name of the pod
49
+ # :version : pod version
50
+ # :release : boolean to tell if that's a release pod
51
+ # :slug : the slug path where the pod cache is located
52
+ #
53
+ def cache_descriptors_per_pod
54
+ specs_dir = root + 'Specs'
55
+ release_specs_dir = specs_dir + 'Release'
56
+ return {} unless specs_dir.exist?
57
+
58
+ spec_paths = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
59
+ spec_paths.reduce({}) do |hash, spec_path|
60
+ spec = Specification.from_file(spec_path)
61
+ hash[spec.name] ||= []
62
+ is_release = spec_path.to_s.start_with?(release_specs_dir.to_s)
63
+ request = Downloader::Request.new(:spec => spec, :released => is_release)
64
+ hash[spec.name] << {
65
+ :spec_file => spec_path,
66
+ :name => spec.name,
67
+ :version => spec.version,
68
+ :release => is_release,
69
+ :slug => root + request.slug,
70
+ }
71
+ hash
72
+ end
73
+ end
74
+
75
+ # Convenience method for acquiring a shared lock to safely read from the
76
+ # cache. See `Cache.lock` for more details.
77
+ #
78
+ # @param [Pathname] location
79
+ # the path to require a lock for.
80
+ #
81
+ # @param [block] &block
82
+ # the block to execute inside the lock.
83
+ #
84
+ # @return [void]
85
+ #
86
+ def self.read_lock(location, &block)
87
+ Cache.lock(location, File::LOCK_SH, &block)
88
+ end
89
+
90
+ # Convenience method for acquiring an exclusive lock to safely write to
91
+ # the cache. See `Cache.lock` for more details.
92
+ #
93
+ # @param [Pathname] location
94
+ # the path to require a lock for.
95
+ #
96
+ # @param [block] &block
97
+ # the block to execute inside the lock.
98
+ #
99
+ # @return [void]
100
+ #
101
+ def self.write_lock(location, &block)
102
+ Cache.lock(location, File::LOCK_EX, &block)
103
+ end
104
+
105
+ # Creates a .lock file at `location`, aquires a lock of type
106
+ # `lock_type`, checks that it is valid, and executes passed block while
107
+ # holding on to that lock. Afterwards, the .lock file is deleted, which is
108
+ # why validation of the lock is necessary, as you might have a lock on a
109
+ # file that doesn't exist on the filesystem anymore.
110
+ #
111
+ # @param [Pathname] location
112
+ # the path to require a lock for.
113
+ #
114
+ # @param [locking_constant] lock_type
115
+ # the type of lock, either exclusive (File::LOCK_EX) or shared
116
+ # (File::LOCK_SH).
117
+ #
118
+ # @return [void]
119
+ #
120
+ def self.lock(location, lock_type)
121
+ raise ArgumentError, 'no block given' unless block_given?
122
+ lockfile = "#{location}.lock"
123
+ f = nil
124
+ loop do
125
+ f.close if f
126
+ f = File.open(lockfile, File::CREAT, 0o644)
127
+ f.flock(lock_type)
128
+ break if Cache.valid_lock?(f, lockfile)
129
+ end
130
+ begin
131
+ yield location
132
+ ensure
133
+ if lock_type == File::LOCK_SH
134
+ f.flock(File::LOCK_EX)
135
+ File.delete(lockfile) if Cache.valid_lock?(f, lockfile)
136
+ else
137
+ File.delete(lockfile)
138
+ end
139
+ f.close
140
+ end
141
+ end
142
+
143
+ # Checks that the lock is on a file that still exists on the filesystem.
144
+ #
145
+ # @param [File] file
146
+ # the actual file that we have a lock for.
147
+ #
148
+ # @param [String] filename
149
+ # the filename of the file that we have a lock for.
150
+ #
151
+ # @return [Boolean]
152
+ # true if `filename` still exists and is the same file as `file`
153
+ #
154
+ def self.valid_lock?(file, filename)
155
+ file.stat.ino == File.stat(filename).ino
156
+ rescue Errno::ENOENT
157
+ false
158
+ end
159
+
160
+ private
161
+
162
+ # Ensures the cache on disk was created with the same CocoaPods version as
163
+ # is currently running.
164
+ #
165
+ # @return [Void]
166
+ #
167
+ def ensure_matching_version
168
+ version_file = root + 'VERSION'
169
+ if version_file.file?
170
+ version = version_file.read.strip
171
+ else
172
+ version = Pod::VERSION
173
+ end
174
+ pod_version = %x(bundle exec pod --version).split("\n").first
175
+ if version != pod_version
176
+ version = pod_version
177
+ version_file.open('w') { |f| f << version }
178
+ end
179
+ end
180
+
181
+ # @param [Request] request
182
+ # the request to be downloaded.
183
+ #
184
+ # @param [Hash<Symbol,String>] slug_opts
185
+ # the download options that should be used in constructing the
186
+ # cache slug for this request.
187
+ #
188
+ # @return [Pathname] The path for the Pod downloaded from the given
189
+ # `request`.
190
+ #
191
+ def path_for_pod(request, slug_opts = {})
192
+ root + request.slug(**slug_opts)
193
+ end
194
+
195
+ # @param [Request] request
196
+ # the request to be downloaded.
197
+ #
198
+ # @param [Hash<Symbol,String>] slug_opts
199
+ # the download options that should be used in constructing the
200
+ # cache slug for this request.
201
+ #
202
+ # @return [Pathname] The path for the podspec downloaded from the given
203
+ # `request`.
204
+ #
205
+ def path_for_spec(request, slug_opts = {})
206
+ path = root + 'Specs' + request.slug(**slug_opts)
207
+ Pathname.new(path.to_path + '.podspec.json')
208
+ end
209
+
210
+ # @param [Request] request
211
+ # the request to be downloaded.
212
+ #
213
+ # @return [Response] The download response for the given `request` that
214
+ # was found in the download cache.
215
+ #
216
+ def cached_pod(request)
217
+ cached_spec = cached_spec(request)
218
+ path = path_for_pod(request)
219
+
220
+ return unless cached_spec && path.directory?
221
+ spec = request.spec || cached_spec
222
+ Response.new(path, spec, request.params)
223
+ end
224
+
225
+ # @param [Request] request
226
+ # the request to be downloaded.
227
+ #
228
+ # @return [Specification] The cached specification for the given
229
+ # `request`.
230
+ #
231
+ def cached_spec(request)
232
+ path = path_for_spec(request)
233
+ path.file? && Specification.from_file(path)
234
+ rescue JSON::ParserError
235
+ nil
236
+ end
237
+
238
+ # @param [Request] request
239
+ # the request to be downloaded.
240
+ #
241
+ # @return [Response] The download response for the given `request` that
242
+ # was not found in the download cache.
243
+ #
244
+ def uncached_pod(request)
245
+ in_tmpdir do |target|
246
+ result, podspecs = download(request, target)
247
+ result.location = nil
248
+
249
+ podspecs.each do |name, spec|
250
+ destination = path_for_pod(request, :name => name, :params => result.checkout_options)
251
+ copy_and_clean(target, destination, spec)
252
+ write_spec(spec, path_for_spec(request, :name => name, :params => result.checkout_options))
253
+ if request.name == name
254
+ result.location = destination
255
+ end
256
+ end
257
+
258
+ result
259
+ end
260
+ end
261
+
262
+ def download(request, target)
263
+ Downloader.download_request(request, target)
264
+ end
265
+
266
+ # Performs the given block inside a temporary directory,
267
+ # which is removed at the end of the block's scope.
268
+ #
269
+ # @return [Object] The return value of the given block
270
+ #
271
+ def in_tmpdir(&blk)
272
+ tmpdir = Pathname(Dir.mktmpdir)
273
+ blk.call(tmpdir)
274
+ ensure
275
+ FileUtils.remove_entry(tmpdir, :force => true) if tmpdir && tmpdir.exist?
276
+ end
277
+
278
+ # Copies the `source` directory to `destination`, cleaning the directory
279
+ # of any files unused by `spec`.
280
+ #
281
+ # @param [Pathname] source
282
+ #
283
+ # @param [Pathname] destination
284
+ #
285
+ # @param [Specification] spec
286
+ #
287
+ # @return [Void]
288
+ #
289
+ def copy_and_clean(source, destination, spec)
290
+ specs_by_platform = group_subspecs_by_platform(spec)
291
+ destination.parent.mkpath
292
+ Cache.write_lock(destination) do
293
+ FileUtils.rm_rf(destination)
294
+ FileUtils.cp_r(source, destination)
295
+ Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
296
+ Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
297
+ end
298
+ end
299
+
300
+ def group_subspecs_by_platform(spec)
301
+ specs_by_platform = {}
302
+ [spec, *spec.recursive_subspecs].each do |ss|
303
+ ss.available_platforms.each do |platform|
304
+ specs_by_platform[platform] ||= []
305
+ specs_by_platform[platform] << ss
306
+ end
307
+ end
308
+ specs_by_platform
309
+ end
310
+
311
+ # Writes the given `spec` to the given `path`.
312
+ #
313
+ # @param [Specification] spec
314
+ # the specification to be written.
315
+ #
316
+ # @param [Pathname] path
317
+ # the path the specification is to be written to.
318
+ #
319
+ # @return [Void]
320
+ #
321
+ def write_spec(spec, path)
322
+ path.dirname.mkpath
323
+ Cache.write_lock(path) do
324
+ path.open('w') { |f| f.write spec.to_pretty_json }
325
+ end
326
+ end
327
+ end
328
+ end
329
+ end
@@ -1,5 +1,4 @@
1
1
  require 'net/http'
2
- # require 'singleton'
3
2
  require 'cocoapods-core'
4
3
 
5
4
  module LgPodPlugin
@@ -13,7 +12,7 @@ module LgPodPlugin
13
12
  attr_accessor :config
14
13
  attr_accessor :net_ping
15
14
  attr_accessor :params
16
- attr_accessor :lockfile
15
+ # attr_accessor :lockfile
17
16
  attr_accessor :checkout_options
18
17
  def initialize(pod)
19
18
  @name = pod.name
@@ -50,9 +49,9 @@ module LgPodPlugin
50
49
  end
51
50
 
52
51
  public
53
- def get_lockfile
54
- self.lockfile = LgPodPlugin::LockfileModel.from_file
55
- end
52
+ # def get_lockfile
53
+ # self.lockfile = LgPodPlugin::LockfileModel.from_file
54
+ # end
56
55
 
57
56
  # 获取缓存用的hash_map
58
57
  public
@@ -68,16 +67,17 @@ module LgPodPlugin
68
67
  tag = options[:tag] ||= self.params[:tag]
69
68
  branch = options[:branch] ||= self.params[:branch]
70
69
  commit = options[:commit] ||= self.params[:commit]
71
- return hash_map unless git
70
+ return nil unless git
72
71
  hash_map[:git] = git
73
- if git && commit
72
+ if git && commit
74
73
  hash_map[:commit] = commit
74
+ return hash_map
75
75
  elsif git && tag
76
76
  hash_map[:tag] = tag
77
- elsif git && branch && commit
78
- hash_map[:commit] = commit
77
+ return hash_map
78
+ else
79
+ return {:git => git}
79
80
  end
80
- hash_map
81
81
  end
82
82
 
83
83
  public
@@ -111,9 +111,9 @@ module LgPodPlugin
111
111
 
112
112
  #获取下载参数
113
113
  def get_request_params
114
- unless self.lockfile
115
- self.lockfile = self.get_lockfile
116
- end
114
+ # unless self.lockfile
115
+ # self.lockfile = self.get_lockfile
116
+ # end
117
117
  Hash.new.merge!(self.get_lock_params)
118
118
  end
119
119
 
@@ -124,28 +124,28 @@ module LgPodPlugin
124
124
  return [nil, nil] unless (ip && network_ok)
125
125
  if branch
126
126
  new_commit, _ = GitLabAPI.request_github_refs_heads git, branch, self.net_ping.uri
127
- unless new_commit
128
- id = LPodLatestRefs.get_pod_id(name, git, branch)
129
- pod_info = LSqliteDb.shared.query_pod_refs(id)
130
- new_commit = pod_info ? pod_info.commit : nil
131
- return [branch, new_commit]
132
- end
133
- if new_commit
134
- LSqliteDb.shared.insert_pod_refs(name, git, branch, nil, new_commit)
135
- end
127
+ # unless new_commit
128
+ # id = LPodLatestRefs.get_pod_id(name, git, branch)
129
+ # pod_info = LSqliteDb.shared.query_pod_refs(id)
130
+ # new_commit = pod_info ? pod_info.commit : nil
131
+ # return [branch, new_commit]
132
+ # end
133
+ # if new_commit
134
+ # LSqliteDb.shared.insert_pod_refs(name, git, branch, nil, new_commit)
135
+ # end
136
136
  [branch, new_commit]
137
137
  else
138
138
  new_commit, new_branch = GitLabAPI.request_github_refs_heads git, nil, self.net_ping.uri
139
- unless new_commit
140
- id = LPodLatestRefs.get_pod_id(name, git, "HEAD")
141
- pod_info = LSqliteDb.shared.query_pod_refs(id)
142
- new_commit = pod_info ? pod_info.commit : nil
143
- new_branch = pod_info ? pod_info.branch : nil
144
- return [new_branch, new_commit]
145
- end
146
- if new_commit
147
- LSqliteDb.shared.insert_pod_refs(name, git, "HEAD", nil, new_commit)
148
- end
139
+ # unless new_commit
140
+ # id = LPodLatestRefs.get_pod_id(name, git, "HEAD")
141
+ # pod_info = LSqliteDb.shared.query_pod_refs(id)
142
+ # new_commit = pod_info ? pod_info.commit : nil
143
+ # new_branch = pod_info ? pod_info.branch : nil
144
+ # return [new_branch, new_commit]
145
+ # end
146
+ # if new_commit
147
+ # LSqliteDb.shared.insert_pod_refs(name, git, "HEAD", nil, new_commit)
148
+ # end
149
149
  [new_branch, new_commit]
150
150
  end
151
151
  end
@@ -9,7 +9,6 @@ module LgPodPlugin
9
9
 
10
10
  # 通过读取本地文件获取 access_token
11
11
  def self.get_gitlab_access_token(uri, user_id)
12
- text = LUtils.encrypt("AzfAjh-xTzyRBXmYuGBr", "AZMpxzVxzbo3sFDLRZMpxzVxzbo3sFDZ")
13
12
  db_path = LFileManager.download_director.join("database")
14
13
  db_path.mkdir unless db_path.exist?
15
14
  token_file = db_path.join("access_token.json")
@@ -48,9 +47,9 @@ module LgPodPlugin
48
47
  # 检查 token 是否在有效期内
49
48
  def self.check_gitlab_access_token_valid(uri, user_info)
50
49
  time_now = Time.now.to_i
50
+ refresh_token = user_info.refresh_token
51
51
  # 判断 token 是否失效
52
- if user_info.expires_in <= time_now
53
- refresh_token = user_info.refresh_token
52
+ if user_info.expires_in <= time_now
54
53
  if refresh_token.nil? || refresh_token == "" # 使用本地令牌访问
55
54
  project_name = LUtils.get_git_project_name(uri.to_s)
56
55
  token_vaild = GitLabAPI.request_user_emails(uri.hostname, user_info.access_token)
@@ -65,21 +64,28 @@ module LgPodPlugin
65
64
  end
66
65
  else
67
66
  # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token
68
- new_user_info = GitLabAPI.refresh_gitlab_access_token uri.hostname, refresh_token
69
- if new_user_info.nil?
70
- username = user_info.username
71
- password = user_info.password
72
- user_info = GitLabAPI.get_gitlab_access_token_input(uri, user_info.user_id, username, password)
73
- return nil unless user_info
74
- else
75
- user_info = new_user_info
76
- end
67
+ return refreshUserToken uri, refresh_token, user_info.id, user_info.username, user_info.password
77
68
  end
78
69
  else
79
- return user_info
70
+ update_time = user_info.update_time.to_i
71
+ if time_now - update_time > 1800
72
+ user_info = refreshUserToken uri, refresh_token, user_info.id, user_info.username, user_info.password
73
+ return user_info
74
+ else
75
+ return user_info
76
+ end
80
77
  end
81
78
  end
82
79
 
80
+ def self.refreshUserToken(uri, refresh_token, user_id, username, password)
81
+ # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token
82
+ new_user_info = GitLabAPI.refresh_gitlab_access_token uri.hostname, refresh_token
83
+ unless new_user_info
84
+ return GitLabAPI.get_gitlab_access_token_input(uri, user_id, username, password)
85
+ end
86
+ return new_user_info
87
+ end
88
+
83
89
  public
84
90
  # 获取 GitLab access_token
85
91
  def self.request_gitlab_access_token(host, username, password)
@@ -94,6 +100,7 @@ module LgPodPlugin
94
100
  if error != nil
95
101
  if error == "invalid_grant"
96
102
  LSqliteDb.shared.delete_user_info(user_id)
103
+ LgPodPlugin.log_yellow "LSqliteDb.shared.delete_user_info(#{user_id}"
97
104
  end
98
105
  raise json["error_description"]
99
106
  end
@@ -101,7 +108,8 @@ module LgPodPlugin
101
108
  refresh_token = json["refresh_token"]
102
109
  expires_in = json["expires_in"] ||= 7200
103
110
  created_at = json["created_at"] ||= Time.now.to_i
104
- user_model = LUserAuthInfo.new(user_id, username, password, host, access_token, refresh_token, (created_at + expires_in))
111
+ time_now = Time.now.to_i
112
+ user_model = LUserAuthInfo.new(user_id, username, password, host, access_token, refresh_token, (created_at + expires_in), time_now)
105
113
  LSqliteDb.shared.insert_user_info(user_model)
106
114
  LgPodPlugin.log_green "请求成功: `access_token` => #{access_token}, expires_in => #{expires_in}"
107
115
  rescue => exception
@@ -121,7 +129,7 @@ module LgPodPlugin
121
129
  if res.body
122
130
  json = JSON.parse(res.body)
123
131
  else
124
- return nil
132
+ json = nil
125
133
  end
126
134
  return nil unless json.is_a?(Hash)
127
135
  error = json["error"]
@@ -129,16 +137,19 @@ module LgPodPlugin
129
137
  error_description = json["error_description"]
130
138
  raise error_description
131
139
  end
140
+ time_now = Time.now.to_i
132
141
  access_token = json["access_token"]
133
142
  refresh_token = json["refresh_token"]
134
143
  expires_in = json["expires_in"] ||= 7200
135
- created_at = json["created_at"] ||= Time.now.to_i
144
+ created_at = json["created_at"] ||= time_now
136
145
  user_id = LUserAuthInfo.get_user_id(host)
137
146
  user_model = LSqliteDb.shared.query_user_info(user_id)
138
147
  user_model.expires_in = (created_at + expires_in)
139
148
  user_model.access_token = access_token
140
149
  user_model.refresh_token = refresh_token
150
+ user_model.update_time = time_now
141
151
  LSqliteDb.shared.insert_user_info(user_model)
152
+ LgPodPlugin.log_green "刷新token成功: `refresh_token` => #{refresh_token}, expires_in => #{expires_in}"
142
153
  return user_model
143
154
  rescue => exception
144
155
  LgPodPlugin.log_yellow "刷新 `access_token` 失败, error => #{exception.to_s}"
@@ -166,7 +177,7 @@ module LgPodPlugin
166
177
  path = json["path"] ||= ""
167
178
  path_with_namespace = json["path_with_namespace"] ||= ""
168
179
  name_with_namespace = (json["name_with_namespace"] ||= "").gsub(/[ ]/, '')
169
- if git.include?(path_with_namespace)
180
+ if git.include?(path_with_namespace) || git.downcase.include?(name_with_namespace.downcase)
170
181
  id = json["id"]
171
182
  web_url = json["web_url"]
172
183
  description = json["description"]
@@ -233,7 +244,7 @@ module LgPodPlugin
233
244
  # 通过github api 获取 git 最新commit
234
245
  def self.request_github_refs_heads(git, branch, uri = nil)
235
246
  return [nil, nil] unless git
236
- unless git.include?("https://github.com/") || git.include?("git@github.com:")
247
+ unless git.include?("github.com/") || git.include?("git@github.com:")
237
248
  if LgPodPlugin::LUtils.is_gitlab_uri(git, "")
238
249
  return self.request_gitlab_refs_heads(git, branch, uri)
239
250
  end
@@ -21,10 +21,7 @@ module LgPodPlugin
21
21
  def install(pod)
22
22
  hash = pod.checkout_options
23
23
  path = hash[:path]
24
- unless path.nil?
25
- LProject.shared.need_update_pods[pod.name] = "1"
26
- return nil
27
- end
24
+ return nil unless path.nil?
28
25
  @downloader = LDownloader.new(pod)
29
26
  self.download_params = @downloader.pre_download_pod
30
27
  return self.download_params
@@ -45,7 +45,6 @@ module LgPodPlugin
45
45
  if download_params
46
46
  name = download_params["name"]
47
47
  all_installers[name] = installer
48
- LProject.shared.need_update_pods[name] = "1"
49
48
  end
50
49
  end
51
50
  end
@@ -8,22 +8,18 @@ module LgPodPlugin
8
8
  include Singleton
9
9
 
10
10
  attr_reader :podfile
11
- attr_reader :lockfile
12
11
  attr_reader :update
13
12
  attr_reader :targets
14
13
  attr_reader :workspace
15
14
  attr_reader :repo_update
16
15
  attr_reader :external_pods
17
- attr_reader :need_update_pods
18
16
  attr_accessor :cache_specs
19
- # attr_accessor :redirect_url_hash
17
+ attr_accessor :refreshToken
20
18
  def setup(workspace,podfile_path, update, repo_update)
21
19
  @podfile = Pod::Podfile.from_file(podfile_path)
22
20
  @update = update
23
21
  @workspace = workspace
24
22
  @repo_update = repo_update
25
- lockfile_path = workspace.join("Podfile.lock")
26
- @lockfile = Pod::Lockfile.from_file(lockfile_path) if lockfile_path.exist?
27
23
  target = @podfile.send(:current_target_definition)
28
24
  children = target.children
29
25
  @targets = Array.new
@@ -35,8 +31,7 @@ module LgPodPlugin
35
31
  end
36
32
  @cache_specs = Hash.new
37
33
  @external_pods = Hash.new.merge!(external_pods)
38
- @need_update_pods = Hash.new
39
- # @redirect_url_hash = Hash.new
34
+ @refreshToken = nil
40
35
  return self
41
36
  end
42
37