cocoapods-downloader 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cocoapods-downloader might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96bf7705d6b8a1db8b835ade67743ab65bff9ad1
4
- data.tar.gz: 5017578a23c22971e72ac93c7b9caf0b79b2d2fa
3
+ metadata.gz: aa8a46dc2f695c41fea96ed47be215c794d7b525
4
+ data.tar.gz: 1484c387e242ed7e655d29b395d9a8924394e522
5
5
  SHA512:
6
- metadata.gz: 44973e1199503c02113bbebf09c14eb5186c4d9fda7a46bdbe15b83a8f88343b8e2ac9434f9dfd839884c2715b0464018c3db1c7c4631c782e330d2c1cc0326c
7
- data.tar.gz: 134caa87da0f72c8c018bf18e1d6371905440655ff4654e6efc102a05d7661af3b50dbfc482886e76788988054b9c0b0f7b63bee88bb4e771c6e21729a489489
6
+ metadata.gz: a667857e15a111546ab8f842f449567be58de096f4909ef0a0042035f997973cbc527958db579b368554d2dec266e5bd588633f0b26f5c8973af0d104e9e2410
7
+ data.tar.gz: 7ec7bb4994034106647d350b181769d14d79382447640cc6e57b193635447d5ce0906ed9e85869a1bfd2fc0305331635c0035b1823cd5dc973a5cc0c93423da0
@@ -1,11 +1,5 @@
1
1
  module Pod
2
2
  module Downloader
3
- if RUBY_VERSION >= '1.9.3'
4
- require 'English'
5
- else
6
- alias $CHILD_STATUS $CHILD_STATUS
7
- end
8
-
9
3
  require 'cocoapods-downloader/gem_version'
10
4
  require 'cocoapods-downloader/api'
11
5
  require 'cocoapods-downloader/api_exposable'
@@ -30,7 +24,7 @@ module Pod
30
24
  :git => Git,
31
25
  :hg => Mercurial,
32
26
  :http => Http,
33
- :svn => Subversion
27
+ :svn => Subversion,
34
28
  }
35
29
  end
36
30
 
@@ -52,12 +46,8 @@ module Pod
52
46
  # @return [Downloader::Base] A concrete downloader according to the
53
47
  # options.
54
48
  #
55
- # @todo Improve the common support for the cache in Base and add specs.
56
- # @todo Find a way to switch to GitHub tarballs if no cache is used. Have
57
- # global options for the Downloader cache?
58
- #
59
49
  def self.for_target(target_path, options)
60
- options = Hash[options.map{ |k, v| [k.to_sym, v] }]
50
+ options = Hash[options.map { |k, v| [k.to_sym, v] }]
61
51
 
62
52
  if target_path.nil?
63
53
  raise DownloaderError, 'No target path provided.'
@@ -77,11 +67,6 @@ module Pod
77
67
  sub_options = options.dup
78
68
  sub_options.delete(strategy)
79
69
  klass = downloader_class_by_key[strategy]
80
-
81
- if klass == Git && url.to_s =~ /github.com/
82
- klass = GitHub
83
- end
84
-
85
70
  klass.new(target_path, url, sub_options)
86
71
  end
87
72
  end
@@ -21,7 +21,7 @@ module Pod
21
21
  # @return [void]
22
22
  #
23
23
  def check_exit_code!(executable, command, output)
24
- if $CHILD_STATUS.to_i != 0
24
+ if $?.exitstatus != 0
25
25
  raise DownloaderError, "Error on `#{executable} #{command}`.\n#{output}"
26
26
  end
27
27
  end
@@ -45,17 +45,11 @@ module Pod
45
45
  # @param [String] url @see url
46
46
  # @param [Hash={Symbol=>String}] options @see options
47
47
  #
48
- # @todo There is no need of the download only option, it should be
49
- # deprecated and the GitHub downloader should be initialized by
50
- # other means.
51
- #
52
48
  def initialize(target_path, url, options)
53
49
  require 'pathname'
54
50
  @target_path, @url, @options = Pathname.new(target_path), url, options
55
- @max_cache_size = DEFAULT_MAX_CACHE_SIZE
56
51
 
57
- accepted_options = self.class.options + [:download_only]
58
- unrecognized_options = options.keys - accepted_options
52
+ unrecognized_options = options.keys - self.class.options
59
53
  unless unrecognized_options.empty?
60
54
  raise DownloaderError, "Unrecognized options `#{unrecognized_options}`"
61
55
  end
@@ -73,29 +67,6 @@ module Pod
73
67
 
74
68
  #-----------------------------------------------------------------------#
75
69
 
76
- # @!group Configuration
77
-
78
- # @return [Fixnum] The maximum allowed size for the cache expressed in
79
- # Mb. Defaults to `500` Mb.
80
- #
81
- # @note This is specific per downloader class.
82
- #
83
- attr_accessor :max_cache_size
84
-
85
- # @return [String] The directory to use as root of the cache. If no
86
- # specified the caching will not be used. Defaults to `nil`.
87
- #
88
- attr_accessor :cache_root
89
-
90
- # @return [Bool] Whether the downloader should use a more aggressive
91
- # caching or ensure that the cache always return the value of the
92
- # remote. Defaults to `false`.
93
- #
94
- attr_accessor :aggressive_cache
95
- alias_method :aggressive_cache?, :aggressive_cache
96
-
97
- #-----------------------------------------------------------------------#
98
-
99
70
  # @!group Downloading
100
71
 
101
72
  # Downloads the revision specified in the option of a source. If no
@@ -107,7 +78,6 @@ module Pod
107
78
  ui_action("#{name} download") do
108
79
  target_path.mkpath
109
80
  download!
110
- prune_cache
111
81
  end
112
82
  end
113
83
 
@@ -119,7 +89,7 @@ module Pod
119
89
  #
120
90
  def download_head
121
91
  ui_action("#{name} HEAD download") do
122
- if self.respond_to?(:download_head!, true)
92
+ if head_supported?
123
93
  download_head!
124
94
  else
125
95
  raise DownloaderError, "The `#{name}` downloader does not support " \
@@ -128,6 +98,13 @@ module Pod
128
98
  end
129
99
  end
130
100
 
101
+ # @return [Bool] Whether the downloader supports the head download
102
+ # strategy.
103
+ #
104
+ def head_supported?
105
+ self.respond_to?(:download_head!, true)
106
+ end
107
+
131
108
  # @return [Bool] Whether the options provided completely identify a source
132
109
  # or could lead to the download of different files in future.
133
110
  #
@@ -144,61 +121,6 @@ module Pod
144
121
 
145
122
  #-----------------------------------------------------------------------#
146
123
 
147
- # @!group Cache
148
-
149
- public
150
-
151
- # @return [Pathname] The directory where the cache for the current url
152
- # should be stored.
153
- #
154
- # @note The name of the directory is the SHA1 hash value of the URL.
155
- #
156
- def cache_path
157
- require 'digest/sha1'
158
- if cache_root
159
- @cache_path ||= class_cache_dir + "#{Digest::SHA1.hexdigest(url.to_s)}"
160
- end
161
- end
162
-
163
- private
164
-
165
- # @return [Pathname] The directory where the caches are stored.
166
- #
167
- def class_cache_dir
168
- Pathname.new(File.expand_path(Pathname.pwd + cache_root)) + name
169
- end
170
-
171
- # @return [Bool] Whether the downloader should use the cache.
172
- #
173
- def use_cache?
174
- !(cache_root && !@options[:download_only]).nil?
175
- end
176
-
177
- # The default maximum allowed size for the cache expressed in Mb.
178
- #
179
- DEFAULT_MAX_CACHE_SIZE = 500
180
-
181
- # @return [Integer] The global size of the cache expressed in Mb.
182
- #
183
- def caches_size
184
- `du -cm`.split("\n").last.to_i
185
- end
186
-
187
- # @return [void] Deletes the oldest caches until they the global size is
188
- # below the maximum allowed.
189
- #
190
- def prune_cache
191
- return unless cache_root && class_cache_dir.exist?
192
- Dir.chdir(class_cache_dir) do
193
- repos = Pathname.new(class_cache_dir).children.select { |c| c.directory? }.sort_by(&:ctime)
194
- while caches_size >= max_cache_size && !repos.empty?
195
- dir = repos.shift
196
- ui_message "Removing #{name} cache for `#{cache_origin_url(dir)}'"
197
- dir.rmtree
198
- end
199
- end
200
- end
201
-
202
124
  # Defines two methods for an executable, based on its name. The bag
203
125
  # version raises if the executable terminates with a non-zero exit code.
204
126
  #
@@ -3,6 +3,6 @@ module Pod
3
3
  # @return [String] Downloader’s version, following
4
4
  # [semver](http://semver.org).
5
5
  #
6
- VERSION = '0.6.1'
6
+ VERSION = '0.7.0'
7
7
  end
8
8
  end
@@ -23,256 +23,69 @@ module Pod
23
23
 
24
24
  private
25
25
 
26
- executable :git
26
+ # @!group Base class hooks
27
27
 
28
28
  def download!
29
- create_cache if use_cache? && !cache_exist?
30
- if options[:tag]
31
- download_tag
32
- elsif options[:branch]
33
- download_branch
34
- elsif options[:commit]
35
- download_commit
36
- else
37
- download_head!
38
- end
39
- Dir.chdir(target_path) { git! 'submodule update --init' } if options[:submodules]
29
+ clone
30
+ checkout_commit if options[:commit]
31
+ init_submodules if options[:submodules]
40
32
  end
41
33
 
42
- # @return [void] Checkouts the HEAD of the git source in the destination
34
+ # @return [void] Checks out the HEAD of the git source in the destination
43
35
  # path.
44
36
  #
45
37
  def download_head!
46
- update_cache if use_cache?
47
- clone(clone_url, target_path)
48
- Dir.chdir(target_path) { git! 'submodule update --init' } if options[:submodules]
38
+ clone(true)
39
+ init_submodules if options[:submodules]
49
40
  end
50
41
 
51
- #--------------------------------------#
52
-
53
42
  # @!group Download implementations
54
43
 
55
- # @return [Pathname] The clone URL, which resolves to the cache path.
56
- #
57
- def clone_url
58
- use_cache? ? cache_path : url
59
- end
60
-
61
- # @return [void] Convenience method to perform clones operations.
62
- #
63
- def clone(from, to, flags = '')
64
- ui_sub_action('Cloning to Pods folder') do
65
- command = %Q(clone #{from.shellescape} #{to.shellescape})
66
- command << ' ' + flags if flags
67
- git!(command)
68
- end
69
- end
44
+ executable :git
70
45
 
71
- # @return [void] Checkouts a specific tag of the git source in the
72
- # destination path.
46
+ # Clones the repo. If possible the repo will be shallowly cloned.
73
47
  #
74
- # @note Tags trigger a cache update unless aggressive cache is
75
- # specified.
48
+ # @note The `:commit` option requires a specific strategy as it is not
49
+ # possible to specify the commit to the `clone` command.
76
50
  #
77
- # @note Git fetch and checkout output to standard error and thus they
78
- # are redirected to stdout.
51
+ # @note `--branch` command line option can also take tags and detaches
52
+ # the HEAD.
79
53
  #
80
- # @note For performance if the cache is used the repo is inialized with
81
- # git clone (see CocoaPods/CocoaPods#1077).
54
+ # @param [Bool] force_head
55
+ # If any specific option should be ignored and the HEAD of the
56
+ # repo should be cloned.
82
57
  #
83
- def download_tag
84
- if use_cache?
85
- if aggressive_cache?
86
- ensure_ref_exists(options[:tag])
87
- else
88
- update_cache
58
+ def clone(force_head = false)
59
+ ui_sub_action('Git download') do
60
+ command = ['clone', url.shellescape, target_path.shellescape]
61
+
62
+ unless options[:commit]
63
+ command += ['--single-branch', '--depth 1']
89
64
  end
90
- end
91
65
 
92
- Dir.chdir(target_path) do
93
- if use_cache?
94
- clone(clone_url, target_path)
95
- else
96
- git! 'init'
97
- git! "remote add origin '#{clone_url}'"
66
+ unless force_head
67
+ if tag_or_branch = options[:tag] || options[:branch]
68
+ command += ['--branch', tag_or_branch]
69
+ end
98
70
  end
99
71
 
100
- git! "fetch origin tags/#{options[:tag]} 2>&1"
101
- git! 'reset --hard FETCH_HEAD'
102
- git! 'checkout -b activated-pod-commit 2>&1'
72
+ git! command.join(' ')
103
73
  end
104
74
  end
105
75
 
106
- # @return [void] Checkouts a specific commit of the git source in the
107
- # destination path.
76
+ # Checks out a specific commit of the cloned repo.
108
77
  #
109
- # @note Git checkouts output to standard error and thus it is
110
- # redirected to stdout.
111
- #
112
- def download_commit
113
- ensure_ref_exists(options[:commit]) if use_cache?
114
- clone(clone_url, target_path)
78
+ def checkout_commit
115
79
  Dir.chdir(target_path) do
116
- git! "checkout -b activated-pod-commit #{options[:commit]} 2>&1"
80
+ git! "checkout -b activated-commit #{options[:commit]}"
117
81
  end
118
82
  end
119
83
 
120
- # @return [void] Checkouts the HEAD of a specific branch of the git
121
- # source in the destination path.
122
- #
123
- # @note Git checkouts output to standard error and thus it is
124
- # redirected to stdout.
84
+ # Initializes and updates the submodules of the cloned repo.
125
85
  #
126
- def download_branch
127
- update_cache if use_cache?
128
- clone(clone_url, target_path)
86
+ def init_submodules
129
87
  Dir.chdir(target_path) do
130
- git! "remote add upstream '#{@url}'" # we need to add the original url, not the cache url
131
- git! 'fetch -q upstream' # refresh the branches
132
- git! "checkout --track -b activated-pod-commit upstream/#{options[:branch]} 2>&1" # create a new tracking branch
133
- ui_message("Downloaded and checked out branch: #{options[:branch]} from upstream #{clone_url}")
134
- end
135
- end
136
-
137
- #--------------------------------------#
138
-
139
- # @!group Checking references
140
-
141
- # @return [Bool] Whether a reference (commit SHA or tag)
142
- #
143
- def ref_exists?(ref)
144
- if cache_exist?
145
- Dir.chdir(cache_path) { git "rev-list --max-count=1 #{ref}" }
146
- $CHILD_STATUS == 0
147
- else
148
- false
149
- end
150
- end
151
-
152
- # @return [void] Checks if a reference exists in the cache and updates
153
- # only if necessary.
154
- #
155
- # @raise If after the update the reference can't be found.
156
- #
157
- def ensure_ref_exists(ref)
158
- return if ref_exists?(ref)
159
- update_cache
160
- raise DownloaderError, "Cache unable to find git reference `#{ref}' for `#{url}'." unless ref_exists?(ref)
161
- end
162
-
163
- # @return [Bool] Whether a branch exists in the cache.
164
- #
165
- def branch_exists?(branch)
166
- Dir.chdir(cache_path) { git "branch --all | grep #{branch}$" } # check for remote branch and do suffix matching ($ anchor)
167
- $CHILD_STATUS == 0
168
- end
169
-
170
- # @return [void] Checks if a branch exists in the cache and updates
171
- # only if necessary.
172
- #
173
- # @raise If after the update the branch can't be found.
174
- #
175
- def ensure_remote_branch_exists(branch)
176
- return if branch_exists?(branch)
177
- update_cache
178
- raise DownloaderError, "Cache unable to find git reference `#{branch}' for `#{url}' (#{$CHILD_STATUS})." unless branch_exists?(branch)
179
- end
180
-
181
- #--------------------------------------#
182
-
183
- # @!group Cache
184
-
185
- # @return [Bool] Whether the cache exits.
186
- #
187
- # @note The previous implementation of the cache didn't use a barebone
188
- # git repo. This method takes into account this fact and checks
189
- # that the cache is actually a barebone repo. If the cache was
190
- # not barebone it will be deleted and recreated.
191
- #
192
- def cache_exist?
193
- cache_path.exist? &&
194
- cache_origin_url(cache_path).to_s == url.to_s &&
195
- Dir.chdir(cache_path) { git('config core.bare').chomp == 'true' }
196
- end
197
-
198
- # @return [String] The origin URL of the cache with the given directory.
199
- #
200
- # @param [String] dir The directory of the cache.
201
- #
202
- def cache_origin_url(dir)
203
- Dir.chdir(dir) { `git config remote.origin.url`.chomp }
204
- end
205
-
206
- # @return [void] Creates the barebone repo that will serve as the cache
207
- # for the current repo.
208
- #
209
- def create_cache
210
- ui_sub_action("Creating cache git repo (#{cache_path})") do
211
- cache_path.rmtree if cache_path.exist?
212
- cache_path.mkpath
213
- clone(url, cache_path, '--mirror')
214
- end
215
- end
216
-
217
- # @return [void] Updates the barebone repo used as a cache against its
218
- # remote creating it if needed.
219
- #
220
- def update_cache
221
- if cache_exist?
222
- ui_sub_action("Updating cache git repo (#{cache_path})") do
223
- Dir.chdir(cache_path) { git! 'remote update' }
224
- end
225
- else
226
- create_cache
227
- end
228
- end
229
- end
230
-
231
- #---------------------------------------------------------------------------#
232
-
233
- # Allows to download tarballs from GitHub.
234
- #
235
- class GitHub < Git
236
- require 'open-uri'
237
-
238
- def download_head!
239
- download_only? ? download_and_extract_tarball('master') : super
240
- end
241
-
242
- def download_tag
243
- download_only? ? download_and_extract_tarball(options[:tag]) : super
244
- end
245
-
246
- def download_commit
247
- download_only? ? download_and_extract_tarball(options[:commit]) : super
248
- end
249
-
250
- def download_branch
251
- download_only? ? download_and_extract_tarball(options[:branch]) : super
252
- end
253
-
254
- def tarball_url_for(id)
255
- match = url.match(%r{[:/]([\w\-]+)/([\w\-]+)\.git})
256
- "https://github.com/#{match[1]}/#{match[2]}/tarball/#{id}"
257
- end
258
-
259
- def tmp_path
260
- target_path + 'tarball.tar.gz'
261
- end
262
-
263
- private
264
-
265
- def download_only?
266
- @options[:download_only]
267
- end
268
-
269
- def download_and_extract_tarball(id)
270
- File.open(tmp_path, 'w+') do |tmpfile|
271
- open tarball_url_for(id) do |archive|
272
- tmpfile.write Zlib::GzipReader.new(archive).read
273
- end
274
-
275
- system "tar xf #{tmpfile.path.shellescape} -C #{target_path.shellescape} --strip-components 1"
88
+ git! 'submodule update --init --depth 1'
276
89
  end
277
90
  end
278
91
  end
@@ -25,10 +25,6 @@ module Pod
25
25
  extract_with_type(@download_path, type)
26
26
  end
27
27
 
28
- def download_head!
29
- download!
30
- end
31
-
32
28
  def type
33
29
  if options[:type]
34
30
  options[:type].to_sym
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-downloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Duran
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-20 00:00:00.000000000 Z
12
+ date: 2014-09-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -19,9 +19,6 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - LICENSE
23
- - README.markdown
24
- - lib/cocoapods-downloader.rb
25
22
  - lib/cocoapods-downloader/api.rb
26
23
  - lib/cocoapods-downloader/api_exposable.rb
27
24
  - lib/cocoapods-downloader/base.rb
@@ -31,6 +28,9 @@ files:
31
28
  - lib/cocoapods-downloader/http.rb
32
29
  - lib/cocoapods-downloader/mercurial.rb
33
30
  - lib/cocoapods-downloader/subversion.rb
31
+ - lib/cocoapods-downloader.rb
32
+ - README.markdown
33
+ - LICENSE
34
34
  homepage: https://github.com/CocoaPods/Downloader
35
35
  licenses:
36
36
  - MIT
@@ -41,17 +41,17 @@ require_paths:
41
41
  - lib
42
42
  required_ruby_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - ">="
49
+ - - '>='
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
53
  rubyforge_project:
54
- rubygems_version: 2.2.2
54
+ rubygems_version: 2.0.14
55
55
  signing_key:
56
56
  specification_version: 3
57
57
  summary: A small library for downloading files from remotes in a folder.