rubygems-update 2.0.17 → 2.1.0.rc.1

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

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/.autotest +1 -1
  5. data/History.txt +82 -153
  6. data/Manifest.txt +35 -9
  7. data/Rakefile +35 -36
  8. data/lib/rubygems.rb +106 -18
  9. data/lib/rubygems/available_set.rb +68 -0
  10. data/lib/rubygems/basic_specification.rb +139 -0
  11. data/lib/rubygems/command_manager.rb +37 -40
  12. data/lib/rubygems/commands/cert_command.rb +78 -29
  13. data/lib/rubygems/commands/cleanup_command.rb +2 -2
  14. data/lib/rubygems/commands/contents_command.rb +101 -58
  15. data/lib/rubygems/commands/dependency_command.rb +94 -53
  16. data/lib/rubygems/commands/environment_command.rb +70 -53
  17. data/lib/rubygems/commands/fetch_command.rb +1 -2
  18. data/lib/rubygems/commands/help_command.rb +85 -55
  19. data/lib/rubygems/commands/install_command.rb +84 -42
  20. data/lib/rubygems/commands/outdated_command.rb +2 -12
  21. data/lib/rubygems/commands/owner_command.rb +6 -0
  22. data/lib/rubygems/commands/pristine_command.rb +26 -16
  23. data/lib/rubygems/commands/sources_command.rb +85 -70
  24. data/lib/rubygems/commands/uninstall_command.rb +32 -2
  25. data/lib/rubygems/commands/update_command.rb +111 -75
  26. data/lib/rubygems/config_file.rb +15 -3
  27. data/lib/rubygems/core_ext/kernel_require.rb +9 -31
  28. data/lib/rubygems/defaults.rb +8 -0
  29. data/lib/rubygems/dependency.rb +4 -2
  30. data/lib/rubygems/dependency_installer.rb +180 -170
  31. data/lib/rubygems/dependency_resolver.rb +191 -526
  32. data/lib/rubygems/dependency_resolver/activation_request.rb +109 -0
  33. data/lib/rubygems/dependency_resolver/api_set.rb +65 -0
  34. data/lib/rubygems/dependency_resolver/api_specification.rb +36 -0
  35. data/lib/rubygems/dependency_resolver/composed_set.rb +18 -0
  36. data/lib/rubygems/dependency_resolver/current_set.rb +16 -0
  37. data/lib/rubygems/dependency_resolver/dependency_conflict.rb +85 -0
  38. data/lib/rubygems/dependency_resolver/dependency_request.rb +51 -0
  39. data/lib/rubygems/dependency_resolver/index_set.rb +59 -0
  40. data/lib/rubygems/dependency_resolver/index_specification.rb +53 -0
  41. data/lib/rubygems/dependency_resolver/installed_specification.rb +38 -0
  42. data/lib/rubygems/dependency_resolver/installer_set.rb +130 -0
  43. data/lib/rubygems/exceptions.rb +88 -1
  44. data/lib/rubygems/ext/builder.rb +1 -1
  45. data/lib/rubygems/gem_runner.rb +17 -9
  46. data/lib/rubygems/gemcutter_utilities.rb +72 -42
  47. data/lib/rubygems/install_default_message.rb +12 -0
  48. data/lib/rubygems/install_update_options.rb +3 -0
  49. data/lib/rubygems/installer.rb +55 -30
  50. data/lib/rubygems/name_tuple.rb +18 -7
  51. data/lib/rubygems/package.rb +50 -25
  52. data/lib/rubygems/package/tar_test_case.rb +9 -9
  53. data/lib/rubygems/package/tar_writer.rb +35 -12
  54. data/lib/rubygems/package_task.rb +2 -5
  55. data/lib/rubygems/path_support.rb +10 -0
  56. data/lib/rubygems/platform.rb +9 -3
  57. data/lib/rubygems/psych_additions.rb +1 -1
  58. data/lib/rubygems/remote_fetcher.rb +9 -276
  59. data/lib/rubygems/request.rb +267 -0
  60. data/lib/rubygems/request_set.rb +123 -125
  61. data/lib/rubygems/request_set/gem_dependency_api.rb +39 -0
  62. data/lib/rubygems/security.rb +32 -23
  63. data/lib/rubygems/security/policy.rb +35 -9
  64. data/lib/rubygems/security/signer.rb +2 -2
  65. data/lib/rubygems/server.rb +8 -16
  66. data/lib/rubygems/source.rb +25 -14
  67. data/lib/rubygems/source/installed.rb +28 -0
  68. data/lib/rubygems/source/local.rb +122 -0
  69. data/lib/rubygems/source/specific_file.rb +28 -0
  70. data/lib/rubygems/source_local.rb +2 -89
  71. data/lib/rubygems/source_specific_file.rb +2 -26
  72. data/lib/rubygems/spec_fetcher.rb +11 -11
  73. data/lib/rubygems/specification.rb +186 -198
  74. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +88 -30
  75. data/lib/rubygems/ssl_certs/Entrust_net-Secure-Server-Certification-Authority.pem +90 -0
  76. data/lib/rubygems/ssl_certs/{GeoTrustGlobalCA.pem → GeoTrust_Global_CA.pem} +20 -20
  77. data/lib/rubygems/ssl_certs/VerisignClass3PublicPrimaryCertificationAuthority-G2.pem +57 -0
  78. data/lib/rubygems/stub_specification.rb +119 -0
  79. data/lib/rubygems/test_case.rb +117 -49
  80. data/lib/rubygems/uninstaller.rb +14 -9
  81. data/lib/rubygems/uri_formatter.rb +39 -0
  82. data/lib/rubygems/util/list.rb +44 -0
  83. data/lib/rubygems/version.rb +15 -5
  84. data/lib/rubygems/version_option.rb +8 -2
  85. data/test/rubygems/ca_cert.pem +23 -0
  86. data/test/rubygems/client.pem +49 -0
  87. data/test/rubygems/encrypted_private_key.pem +30 -0
  88. data/test/rubygems/invalid_client.pem +49 -0
  89. data/test/rubygems/specifications/bar-0.0.2.gemspec +9 -0
  90. data/test/rubygems/specifications/foo-0.0.1.gemspec +0 -0
  91. data/test/rubygems/test_gem.rb +76 -454
  92. data/test/rubygems/test_gem_command_manager.rb +23 -21
  93. data/test/rubygems/test_gem_commands_cert_command.rb +154 -14
  94. data/test/rubygems/test_gem_commands_cleanup_command.rb +15 -0
  95. data/test/rubygems/test_gem_commands_contents_command.rb +32 -4
  96. data/test/rubygems/test_gem_commands_environment_command.rb +9 -1
  97. data/test/rubygems/test_gem_commands_fetch_command.rb +2 -28
  98. data/test/rubygems/test_gem_commands_help_command.rb +6 -3
  99. data/test/rubygems/test_gem_commands_install_command.rb +2 -65
  100. data/test/rubygems/test_gem_commands_owner_command.rb +49 -0
  101. data/test/rubygems/test_gem_commands_pristine_command.rb +30 -0
  102. data/test/rubygems/test_gem_commands_sources_command.rb +1 -1
  103. data/test/rubygems/test_gem_commands_uninstall_command.rb +33 -0
  104. data/test/rubygems/test_gem_commands_update_command.rb +2 -1
  105. data/test/rubygems/test_gem_config_file.rb +12 -0
  106. data/test/rubygems/test_gem_dependency_installer.rb +58 -65
  107. data/test/rubygems/test_gem_dependency_resolver.rb +6 -3
  108. data/test/rubygems/test_gem_dependency_resolver_dependency_conflict.rb +36 -0
  109. data/test/rubygems/test_gem_ext_builder.rb +2 -4
  110. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +7 -2
  111. data/test/rubygems/test_gem_gem_runner.rb +17 -13
  112. data/test/rubygems/test_gem_gemcutter_utilities.rb +6 -19
  113. data/test/rubygems/test_gem_impossible_dependencies_error.rb +41 -0
  114. data/test/rubygems/test_gem_install_update_options.rb +4 -1
  115. data/test/rubygems/test_gem_installer.rb +31 -2
  116. data/test/rubygems/test_gem_name_tuple.rb +22 -0
  117. data/test/rubygems/test_gem_package.rb +122 -11
  118. data/test/rubygems/test_gem_package_old.rb +8 -0
  119. data/test/rubygems/test_gem_package_tar_reader.rb +9 -8
  120. data/test/rubygems/test_gem_package_tar_reader_entry.rb +1 -1
  121. data/test/rubygems/test_gem_package_tar_writer.rb +78 -56
  122. data/test/rubygems/test_gem_package_task.rb +2 -23
  123. data/test/rubygems/test_gem_path_support.rb +17 -0
  124. data/test/rubygems/test_gem_platform.rb +18 -0
  125. data/test/rubygems/test_gem_remote_fetcher.rb +106 -385
  126. data/test/rubygems/test_gem_request.rb +239 -0
  127. data/test/rubygems/test_gem_requirement.rb +9 -11
  128. data/test/rubygems/test_gem_security.rb +58 -2
  129. data/test/rubygems/test_gem_security_policy.rb +42 -1
  130. data/test/rubygems/test_gem_security_signer.rb +13 -1
  131. data/test/rubygems/test_gem_security_trust_dir.rb +5 -1
  132. data/test/rubygems/test_gem_server.rb +1 -105
  133. data/test/rubygems/test_gem_source.rb +4 -14
  134. data/test/rubygems/test_gem_source_local.rb +4 -4
  135. data/test/rubygems/test_gem_source_specific_file.rb +1 -1
  136. data/test/rubygems/test_gem_spec_fetcher.rb +0 -12
  137. data/test/rubygems/test_gem_specification.rb +452 -28
  138. data/test/rubygems/test_gem_stub_specification.rb +30 -0
  139. data/test/rubygems/test_gem_uninstaller.rb +14 -0
  140. data/test/rubygems/test_gem_uri_formatter.rb +20 -0
  141. data/test/rubygems/test_gem_version.rb +23 -13
  142. data/test/rubygems/test_gem_version_option.rb +63 -1
  143. data/test/rubygems/test_require.rb +0 -12
  144. data/util/create_encrypted_key.rb +16 -0
  145. metadata +161 -23
  146. metadata.gz.sig +0 -0
  147. data/CVE-2013-4287.txt +0 -36
  148. data/CVE-2013-4363.txt +0 -45
  149. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  150. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  151. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  152. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  153. data/test/rubygems/test_bundled_ca.rb +0 -59
  154. data/util/update_bundled_ca_certificates.rb +0 -103
@@ -4,8 +4,6 @@ require 'rubygems/dependency_installer'
4
4
  require 'rubygems/local_remote_options'
5
5
  require 'rubygems/validator'
6
6
  require 'rubygems/version_option'
7
- require 'rubygems/install_message' # must come before rdoc for messaging
8
- require 'rubygems/rdoc'
9
7
 
10
8
  ##
11
9
  # Gem installer command line tool
@@ -40,6 +38,12 @@ class Gem::Commands::InstallCommand < Gem::Command
40
38
  o[:gemdeps] = v
41
39
  end
42
40
 
41
+ add_option(:"Install/Update", '--default',
42
+ 'Add the gem\'s full specification to',
43
+ 'specifications/default and extract only its bin') do |v,o|
44
+ o[:install_as_default] = v
45
+ end
46
+
43
47
  @installed_specs = nil
44
48
  end
45
49
 
@@ -109,7 +113,44 @@ to write the specification by hand. For example:
109
113
  "#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
110
114
  end
111
115
 
112
- def install_from_gemdeps(gf)
116
+ def check_install_dir # :nodoc:
117
+ if options[:install_dir] and options[:user_install] then
118
+ alert_error "Use --install-dir or --user-install but not both"
119
+ terminate_interaction 1
120
+ end
121
+ end
122
+
123
+ def check_version # :nodoc:
124
+ if options[:version] != Gem::Requirement.default and
125
+ get_all_gem_names.size > 1 then
126
+ alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
127
+ terminate_interaction 1
128
+ end
129
+ end
130
+
131
+ def execute
132
+ if gf = options[:gemdeps] then
133
+ install_from_gemdeps gf
134
+ return
135
+ end
136
+
137
+ @installed_specs = []
138
+
139
+ ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
140
+
141
+ check_install_dir
142
+ check_version
143
+
144
+ load_hooks
145
+
146
+ exit_code = install_gems
147
+
148
+ show_installed
149
+
150
+ raise Gem::SystemExitException, exit_code
151
+ end
152
+
153
+ def install_from_gemdeps gf # :nodoc:
113
154
  require 'rubygems/request_set'
114
155
  rs = Gem::RequestSet.new
115
156
  rs.load_gemdeps gf
@@ -131,51 +172,26 @@ to write the specification by hand. For example:
131
172
  raise Gem::SystemExitException, 0
132
173
  end
133
174
 
134
- def execute
135
- if gf = options[:gemdeps] then
136
- install_from_gemdeps gf
137
- return
138
- end
175
+ def install_gem name, version # :nodoc:
176
+ return if options[:conservative] and
177
+ not Gem::Dependency.new(name, version).matching_specs.empty?
139
178
 
140
- @installed_specs = []
179
+ inst = Gem::DependencyInstaller.new options
180
+ inst.install name, Gem::Requirement.create(version)
141
181
 
142
- ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
182
+ @installed_specs.push(*inst.installed_gems)
143
183
 
144
- if options[:install_dir] and options[:user_install]
145
- alert_error "Use --install-dir or --user-install but not both"
146
- terminate_interaction 1
147
- end
184
+ show_install_errors inst.errors
185
+ end
148
186
 
187
+ def install_gems # :nodoc:
149
188
  exit_code = 0
150
189
 
151
- if options[:version] != Gem::Requirement.default &&
152
- get_all_gem_names.size > 1 then
153
- alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
154
- terminate_interaction 1
155
- end
156
-
157
-
158
190
  get_all_gem_names_and_versions.each do |gem_name, gem_version|
159
191
  gem_version ||= options[:version]
160
192
 
161
193
  begin
162
- next if options[:conservative] and
163
- not Gem::Dependency.new(gem_name, gem_version).matching_specs.empty?
164
-
165
- inst = Gem::DependencyInstaller.new options
166
- inst.install gem_name, Gem::Requirement.create(gem_version)
167
-
168
- @installed_specs.push(*inst.installed_gems)
169
-
170
- next unless errs = inst.errors
171
-
172
- errs.each do |x|
173
- next unless Gem::SourceFetchProblem === x
174
-
175
- msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
176
-
177
- alert_warning msg
178
- end
194
+ install_gem gem_name, gem_version
179
195
  rescue Gem::InstallError => e
180
196
  alert_error "Error installing #{gem_name}:\n\t#{e.message}"
181
197
  exit_code |= 1
@@ -186,12 +202,38 @@ to write the specification by hand. For example:
186
202
  end
187
203
  end
188
204
 
189
- unless @installed_specs.empty? then
190
- gems = @installed_specs.length == 1 ? 'gem' : 'gems'
191
- say "#{@installed_specs.length} #{gems} installed"
205
+ exit_code
206
+ end
207
+
208
+ ##
209
+ # Loads post-install hooks
210
+
211
+ def load_hooks # :nodoc:
212
+ if options[:install_as_default]
213
+ require 'rubygems/install_default_message'
214
+ else
215
+ require 'rubygems/install_message'
192
216
  end
217
+ require 'rubygems/rdoc'
218
+ end
193
219
 
194
- raise Gem::SystemExitException, exit_code
220
+ def show_install_errors errors # :nodoc:
221
+ return unless errors
222
+
223
+ errors.each do |x|
224
+ return unless Gem::SourceFetchProblem === x
225
+
226
+ msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
227
+
228
+ alert_warning msg
229
+ end
230
+ end
231
+
232
+ def show_installed # :nodoc:
233
+ return if @installed_specs.empty?
234
+
235
+ gems = @installed_specs.length == 1 ? 'gem' : 'gems'
236
+ say "#{@installed_specs.length} #{gems} installed"
195
237
  end
196
238
 
197
239
  end
@@ -16,18 +16,8 @@ class Gem::Commands::OutdatedCommand < Gem::Command
16
16
  end
17
17
 
18
18
  def execute
19
- Gem::Specification.outdated.sort.each do |name|
20
- local = Gem::Specification.find_all_by_name(name).max
21
- dep = Gem::Dependency.new local.name, ">= #{local.version}"
22
- remotes, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
23
-
24
- next if remotes.empty?
25
-
26
- remotes.sort! { |a,b| a[0].version <=> b[0].version }
27
-
28
- highest = remotes.last.first
29
-
30
- say "#{local.name} (#{local.version} < #{highest.version})"
19
+ Gem::Specification.outdated_and_latest_version.each do |spec, remote_version|
20
+ say "#{spec.name} (#{spec.version} < #{remote_version})"
31
21
  end
32
22
  end
33
23
  end
@@ -31,9 +31,15 @@ class Gem::Commands::OwnerCommand < Gem::Command
31
31
  add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
32
32
  options[:remove] << value
33
33
  end
34
+
35
+ add_option '-h', '--host HOST', 'Use another gemcutter-compatible host' do |value, options|
36
+ options[:host] = value
37
+ end
34
38
  end
35
39
 
36
40
  def execute
41
+ @host = options[:host]
42
+
37
43
  sign_in
38
44
  name = get_one_gem_name
39
45
 
@@ -21,8 +21,7 @@ class Gem::Commands::PristineCommand < Gem::Command
21
21
  end
22
22
 
23
23
  add_option('--[no-]extensions',
24
- 'Restore gems with extensions',
25
- 'in addition to regular gems') do |value, options|
24
+ 'Restore gems with extensions') do |value, options|
26
25
  options[:extensions] = value
27
26
  end
28
27
 
@@ -31,6 +30,12 @@ class Gem::Commands::PristineCommand < Gem::Command
31
30
  options[:only_executables] = value
32
31
  end
33
32
 
33
+ add_option('-E', '--[no-]env-shebang',
34
+ 'Rewrite executables with a shebang',
35
+ 'of /usr/bin/env') do |value, options|
36
+ options[:env_shebang] = value
37
+ end
38
+
34
39
  add_version_option('restore to', 'pristine condition')
35
40
  end
36
41
 
@@ -44,23 +49,23 @@ class Gem::Commands::PristineCommand < Gem::Command
44
49
 
45
50
  def description # :nodoc:
46
51
  <<-EOF
47
- The pristine command compares an installed gem with the contents of its
48
- cached .gem file and restores any files that don't match the cached .gem's
49
- copy.
52
+ The pristine command compares the installed gems with the contents of the
53
+ cached gem and restores any files that don't match the cached gem's copy.
50
54
 
51
- If you have made modifications to an installed gem, the pristine command
52
- will revert them. All extensions are rebuilt and all bin stubs for the gem
53
- are regenerated after checking for modifications.
55
+ If you have made modifications to your installed gems, the pristine command
56
+ will revert them. After all the gem's files have been checked all bin stubs
57
+ for the gem are regenerated.
54
58
 
55
- If the cached gem cannot be found it will be downloaded.
59
+ If the cached gem cannot be found, you will need to use `gem install` to
60
+ revert the gem.
56
61
 
57
- If --no-extensions is provided pristine will not attempt to restore a gem
58
- with an extension.
62
+ If --no-extensions is provided pristine will not attempt to restore gems
63
+ with extensions.
59
64
  EOF
60
65
  end
61
66
 
62
67
  def usage # :nodoc:
63
- "#{program_name} [GEMNAME ...]"
68
+ "#{program_name} [args]"
64
69
  end
65
70
 
66
71
  def execute
@@ -105,16 +110,21 @@ with an extension.
105
110
  Gem::RemoteFetcher.fetcher.download_to_cache dep
106
111
  end
107
112
 
108
- # TODO use installer options
109
- install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install']
110
- installer_env_shebang = install_defaults.to_s['--env-shebang']
113
+ env_shebang =
114
+ if options.include? :env_shebang then
115
+ options[:env_shebang]
116
+ else
117
+ install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install']
118
+ install_defaults.to_s['--env-shebang']
119
+ end
111
120
 
112
121
  installer = Gem::Installer.new(gem,
113
122
  :wrappers => true,
114
123
  :force => true,
115
124
  :install_dir => spec.base_dir,
116
- :env_shebang => installer_env_shebang,
125
+ :env_shebang => env_shebang,
117
126
  :build_args => spec.build_args)
127
+
118
128
  if options[:only_executables] then
119
129
  installer.generate_bin
120
130
  else
@@ -37,103 +37,118 @@ class Gem::Commands::SourcesCommand < Gem::Command
37
37
  add_proxy_option
38
38
  end
39
39
 
40
- def defaults_str
41
- '--list'
42
- end
40
+ def add_source source_uri # :nodoc:
41
+ check_rubygems_https source_uri
43
42
 
44
- def execute
45
- options[:list] = !(options[:add] ||
46
- options[:clear_all] ||
47
- options[:remove] ||
48
- options[:update])
43
+ source = Gem::Source.new source_uri
49
44
 
50
- if options[:clear_all] then
51
- path = File.join Gem.user_home, '.gem', 'specs'
52
- FileUtils.rm_rf path
53
-
54
- unless File.exist? path then
55
- say "*** Removed specs cache ***"
45
+ begin
46
+ if Gem.sources.include? source_uri then
47
+ say "source #{source_uri} already present in the cache"
56
48
  else
57
- unless File.writable? path then
58
- say "*** Unable to remove source cache (write protected) ***"
59
- else
60
- say "*** Unable to remove source cache ***"
61
- end
49
+ source.load_specs :released
50
+ Gem.sources << source
51
+ Gem.configuration.write
62
52
 
63
- terminate_interaction 1
53
+ say "#{source_uri} added to sources"
64
54
  end
55
+ rescue URI::Error, ArgumentError
56
+ say "#{source_uri} is not a URI"
57
+ terminate_interaction 1
58
+ rescue Gem::RemoteFetcher::FetchError => e
59
+ say "Error fetching #{source_uri}:\n\t#{e.message}"
60
+ terminate_interaction 1
65
61
  end
62
+ end
66
63
 
67
- if source_uri = options[:add] then
68
- uri = URI source_uri
64
+ def check_rubygems_https source_uri # :nodoc:
65
+ uri = URI source_uri
69
66
 
70
- if uri.scheme and uri.scheme.downcase == 'http' and
71
- uri.host.downcase == 'rubygems.org' then
72
- question = <<-QUESTION.chomp
67
+ if uri.scheme and uri.scheme.downcase == 'http' and
68
+ uri.host.downcase == 'rubygems.org' then
69
+ question = <<-QUESTION.chomp
73
70
  https://rubygems.org is recommended for security over #{uri}
74
71
 
75
72
  Do you want to add this insecure source?
76
- QUESTION
77
-
78
- terminate_interaction 1 unless ask_yes_no question
79
- end
73
+ QUESTION
80
74
 
81
- source = Gem::Source.new source_uri
82
-
83
- begin
84
- if Gem.sources.include? source_uri then
85
- say "source #{source_uri} already present in the cache"
86
- else
87
- source.load_specs :released
88
- Gem.sources << source
89
- Gem.configuration.write
90
-
91
- say "#{source_uri} added to sources"
92
- end
93
- rescue URI::Error, ArgumentError
94
- say "#{source_uri} is not a URI"
95
- terminate_interaction 1
96
- rescue Gem::RemoteFetcher::FetchError => e
97
- say "Error fetching #{source_uri}:\n\t#{e.message}"
98
- terminate_interaction 1
99
- end
75
+ terminate_interaction 1 unless ask_yes_no question
100
76
  end
77
+ end
101
78
 
102
- if options[:remove] then
103
- source_uri = options[:remove]
79
+ def clear_all # :nodoc:
80
+ path = Gem.spec_cache_dir
81
+ FileUtils.rm_rf path
104
82
 
105
- unless Gem.sources.include? source_uri then
106
- say "source #{source_uri} not present in cache"
83
+ unless File.exist? path then
84
+ say "*** Removed specs cache ***"
85
+ else
86
+ unless File.writable? path then
87
+ say "*** Unable to remove source cache (write protected) ***"
107
88
  else
108
- Gem.sources.delete source_uri
109
- Gem.configuration.write
110
-
111
- say "#{source_uri} removed from sources"
89
+ say "*** Unable to remove source cache ***"
112
90
  end
91
+
92
+ terminate_interaction 1
113
93
  end
94
+ end
114
95
 
115
- if options[:update] then
116
- Gem.sources.each_source do |src|
117
- src.load_specs :released
118
- src.load_specs :latest
119
- end
96
+ def defaults_str # :nodoc:
97
+ '--list'
98
+ end
99
+
100
+ def list # :nodoc:
101
+ say "*** CURRENT SOURCES ***"
102
+ say
120
103
 
121
- say "source cache successfully updated"
104
+ Gem.sources.each do |src|
105
+ say src
122
106
  end
107
+ end
123
108
 
124
- if options[:list] then
125
- say "*** CURRENT SOURCES ***"
126
- say
109
+ def list? # :nodoc:
110
+ !(options[:list] ||
111
+ options[:add] ||
112
+ options[:clear_all] ||
113
+ options[:remove] ||
114
+ options[:update])
115
+ end
127
116
 
128
- Gem.sources.each do |src|
129
- say src
130
- end
117
+ def execute
118
+ clear_all if options[:clear_all]
119
+
120
+ source_uri = options[:add]
121
+ add_source source_uri if source_uri
122
+
123
+ source_uri = options[:remove]
124
+ remove_source source_uri if source_uri
125
+
126
+ update if options[:update]
127
+
128
+ list if list?
129
+ end
130
+
131
+ def remove_source source_uri # :nodoc:
132
+ unless Gem.sources.include? source_uri then
133
+ say "source #{source_uri} not present in cache"
134
+ else
135
+ Gem.sources.delete source_uri
136
+ Gem.configuration.write
137
+
138
+ say "#{source_uri} removed from sources"
131
139
  end
132
140
  end
133
141
 
134
- private
142
+ def update # :nodoc:
143
+ Gem.sources.each_source do |src|
144
+ src.load_specs :released
145
+ src.load_specs :latest
146
+ end
147
+
148
+ say "source cache successfully updated"
149
+ end
135
150
 
136
- def remove_cache_file(desc, path)
151
+ def remove_cache_file desc, path # :nodoc:
137
152
  FileUtils.rm_rf path
138
153
 
139
154
  if not File.exist?(path) then