rubygems-update 1.7.2 → 1.8.0
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.
- data.tar.gz.sig +0 -0
- data/.autotest +5 -1
- data/History.txt +101 -4
- data/LICENSE.txt +42 -37
- data/MIT.txt +20 -0
- data/Manifest.txt +5 -4
- data/Rakefile +6 -7
- data/lib/rubygems.rb +175 -278
- data/lib/rubygems/builder.rb +7 -6
- data/lib/rubygems/command_manager.rb +16 -2
- data/lib/rubygems/commands/build_command.rb +13 -11
- data/lib/rubygems/commands/cert_command.rb +1 -1
- data/lib/rubygems/commands/cleanup_command.rb +10 -19
- data/lib/rubygems/commands/contents_command.rb +5 -5
- data/lib/rubygems/commands/dependency_command.rb +17 -40
- data/lib/rubygems/commands/fetch_command.rb +1 -1
- data/lib/rubygems/commands/install_command.rb +2 -1
- data/lib/rubygems/commands/lock_command.rb +4 -4
- data/lib/rubygems/commands/outdated_command.rb +18 -6
- data/lib/rubygems/commands/pristine_command.rb +25 -15
- data/lib/rubygems/commands/query_command.rb +9 -6
- data/lib/rubygems/commands/setup_command.rb +1 -1
- data/lib/rubygems/commands/specification_command.rb +8 -23
- data/lib/rubygems/commands/stale_command.rb +2 -1
- data/lib/rubygems/commands/unpack_command.rb +7 -5
- data/lib/rubygems/commands/update_command.rb +2 -4
- data/lib/rubygems/commands/which_command.rb +5 -9
- data/lib/rubygems/config_file.rb +9 -7
- data/lib/rubygems/custom_require.rb +6 -4
- data/lib/rubygems/defaults.rb +30 -14
- data/lib/rubygems/dependency.rb +44 -1
- data/lib/rubygems/dependency_installer.rb +37 -41
- data/lib/rubygems/dependency_list.rb +20 -9
- data/lib/rubygems/deprecate.rb +3 -3
- data/lib/rubygems/doc_manager.rb +10 -11
- data/lib/rubygems/ext/rake_builder.rb +1 -1
- data/lib/rubygems/gem_path_searcher.rb +19 -4
- data/lib/rubygems/gem_runner.rb +1 -1
- data/lib/rubygems/indexer.rb +117 -123
- data/lib/rubygems/installer.rb +101 -94
- data/lib/rubygems/installer_test_case.rb +28 -30
- data/lib/rubygems/local_remote_options.rb +1 -1
- data/lib/rubygems/mock_gem_ui.rb +10 -3
- data/lib/rubygems/package.rb +0 -26
- data/lib/rubygems/package/tar_input.rb +5 -6
- data/lib/rubygems/package_task.rb +1 -1
- data/lib/rubygems/path_support.rb +72 -0
- data/lib/rubygems/platform.rb +12 -2
- data/lib/rubygems/remote_fetcher.rb +7 -6
- data/lib/rubygems/requirement.rb +3 -0
- data/lib/rubygems/security.rb +1 -1
- data/lib/rubygems/server.rb +67 -67
- data/lib/rubygems/source_index.rb +58 -29
- data/lib/rubygems/spec_fetcher.rb +5 -1
- data/lib/rubygems/specification.rb +1422 -877
- data/lib/rubygems/test_case.rb +114 -64
- data/lib/rubygems/test_utilities.rb +4 -3
- data/lib/rubygems/text.rb +1 -1
- data/lib/rubygems/uninstaller.rb +37 -44
- data/test/rubygems/test_gem.rb +131 -102
- data/test/rubygems/test_gem_builder.rb +18 -1
- data/test/rubygems/test_gem_command_manager.rb +2 -0
- data/test/rubygems/test_gem_commands_build_command.rb +31 -3
- data/test/rubygems/test_gem_commands_cleanup_command.rb +51 -0
- data/test/rubygems/test_gem_commands_dependency_command.rb +1 -10
- data/test/rubygems/test_gem_commands_fetch_command.rb +5 -4
- data/test/rubygems/test_gem_commands_help_command.rb +58 -0
- data/test/rubygems/test_gem_commands_install_command.rb +25 -24
- data/test/rubygems/test_gem_commands_list_command.rb +1 -4
- data/test/rubygems/test_gem_commands_outdated_command.rb +10 -9
- data/test/rubygems/test_gem_commands_pristine_command.rb +63 -22
- data/test/rubygems/test_gem_commands_push_command.rb +1 -1
- data/test/rubygems/test_gem_commands_query_command.rb +15 -82
- data/test/rubygems/test_gem_commands_sources_command.rb +8 -9
- data/test/rubygems/test_gem_commands_specification_command.rb +10 -6
- data/test/rubygems/test_gem_commands_stale_command.rb +4 -4
- data/test/rubygems/test_gem_commands_unpack_command.rb +20 -21
- data/test/rubygems/test_gem_commands_update_command.rb +19 -23
- data/test/rubygems/test_gem_commands_which_command.rb +7 -4
- data/test/rubygems/test_gem_dependency.rb +14 -8
- data/test/rubygems/test_gem_dependency_installer.rb +87 -33
- data/test/rubygems/test_gem_dependency_list.rb +7 -3
- data/test/rubygems/test_gem_doc_manager.rb +3 -3
- data/test/rubygems/test_gem_format.rb +1 -1
- data/test/rubygems/test_gem_gem_path_searcher.rb +45 -29
- data/test/rubygems/test_gem_indexer.rb +48 -47
- data/test/rubygems/test_gem_install_update_options.rb +6 -5
- data/test/rubygems/test_gem_installer.rb +61 -37
- data/test/rubygems/test_gem_path_support.rb +58 -0
- data/test/rubygems/test_gem_platform.rb +5 -5
- data/test/rubygems/test_gem_remote_fetcher.rb +18 -21
- data/test/rubygems/test_gem_server.rb +23 -15
- data/test/rubygems/test_gem_source_index.rb +165 -127
- data/test/rubygems/test_gem_spec_fetcher.rb +42 -49
- data/test/rubygems/test_gem_specification.rb +104 -74
- data/test/rubygems/test_gem_text.rb +15 -0
- data/test/rubygems/test_gem_uninstaller.rb +15 -26
- data/test/rubygems/test_kernel.rb +1 -2
- metadata +64 -14
- metadata.gz.sig +0 -0
- data/GPL.txt +0 -340
- data/pkgs/sources/lib/sources.rb +0 -3
- data/pkgs/sources/sources.gemspec +0 -14
- data/test/rubygems/functional.rb +0 -92
data/lib/rubygems/builder.rb
CHANGED
@@ -38,7 +38,7 @@ class Gem::Builder
|
|
38
38
|
@signer = sign
|
39
39
|
write_package
|
40
40
|
say success if Gem.configuration.verbose
|
41
|
-
@spec.
|
41
|
+
File.basename @spec.cache_file
|
42
42
|
end
|
43
43
|
|
44
44
|
def success
|
@@ -46,7 +46,7 @@ class Gem::Builder
|
|
46
46
|
Successfully built RubyGem
|
47
47
|
Name: #{@spec.name}
|
48
48
|
Version: #{@spec.version}
|
49
|
-
File: #{@spec.
|
49
|
+
File: #{File.basename @spec.cache_file}
|
50
50
|
EOM
|
51
51
|
end
|
52
52
|
|
@@ -73,16 +73,17 @@ EOM
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def write_package
|
76
|
-
|
76
|
+
file_name = File.basename @spec.cache_file
|
77
|
+
open file_name, 'wb' do |gem_io|
|
77
78
|
Gem::Package.open gem_io, 'w', @signer do |pkg|
|
78
79
|
yaml = @spec.to_yaml
|
79
80
|
pkg.metadata = yaml
|
80
81
|
|
81
82
|
@spec.files.each do |file|
|
82
|
-
next if File.directory?
|
83
|
-
next if file ==
|
83
|
+
next if File.directory?(file)
|
84
|
+
next if file == file_name # Don't add gem onto itself
|
84
85
|
|
85
|
-
stat = File.stat
|
86
|
+
stat = File.stat(file)
|
86
87
|
mode = stat.mode & 0777
|
87
88
|
size = stat.size
|
88
89
|
|
@@ -37,6 +37,13 @@ class Gem::CommandManager
|
|
37
37
|
@command_manager ||= new
|
38
38
|
end
|
39
39
|
|
40
|
+
##
|
41
|
+
# Reset the authoritative instance of the command manager.
|
42
|
+
|
43
|
+
def self.reset
|
44
|
+
@command_manager = nil
|
45
|
+
end
|
46
|
+
|
40
47
|
##
|
41
48
|
# Register all the subcommands supported by the gem command.
|
42
49
|
|
@@ -80,6 +87,13 @@ class Gem::CommandManager
|
|
80
87
|
@commands[command] = false
|
81
88
|
end
|
82
89
|
|
90
|
+
##
|
91
|
+
# Unregister the Symbol +command+ as a gem command.
|
92
|
+
|
93
|
+
def unregister_command(command)
|
94
|
+
@commands.delete command
|
95
|
+
end
|
96
|
+
|
83
97
|
##
|
84
98
|
# Return the registered command from the command name.
|
85
99
|
|
@@ -160,7 +174,7 @@ class Gem::CommandManager
|
|
160
174
|
retried = false
|
161
175
|
|
162
176
|
begin
|
163
|
-
commands.const_get
|
177
|
+
commands.const_get(const_name).new
|
164
178
|
rescue NameError
|
165
179
|
raise if retried
|
166
180
|
|
@@ -173,7 +187,7 @@ class Gem::CommandManager
|
|
173
187
|
Gem.configuration.backtrace
|
174
188
|
end
|
175
189
|
retry
|
176
|
-
end
|
190
|
+
end
|
177
191
|
end
|
178
192
|
|
179
193
|
end
|
@@ -17,32 +17,34 @@ class Gem::Commands::BuildCommand < Gem::Command
|
|
17
17
|
|
18
18
|
def execute
|
19
19
|
gemspec = get_one_gem_name
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
|
21
|
+
if File.exist? gemspec
|
22
|
+
spec = load_gemspec gemspec
|
23
|
+
|
24
|
+
if spec then
|
23
25
|
Gem::Builder.new(spec).build
|
26
|
+
else
|
27
|
+
alert_error "Error loading gemspec. Aborting."
|
28
|
+
terminate_interaction 1
|
24
29
|
end
|
25
30
|
else
|
26
31
|
alert_error "Gemspec file not found: #{gemspec}"
|
32
|
+
terminate_interaction 1
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
|
-
def
|
36
|
+
def load_gemspec filename
|
31
37
|
if yaml?(filename)
|
32
|
-
result = []
|
33
38
|
open(filename) do |f|
|
34
39
|
begin
|
35
|
-
|
36
|
-
result << spec
|
37
|
-
end
|
40
|
+
Gem::Specification.from_yaml(f)
|
38
41
|
rescue Gem::EndOfYAMLException
|
39
|
-
|
42
|
+
nil
|
40
43
|
end
|
41
44
|
end
|
42
45
|
else
|
43
|
-
|
46
|
+
Gem::Specification.load(filename) # can return nil
|
44
47
|
end
|
45
|
-
result
|
46
48
|
end
|
47
49
|
|
48
50
|
def yaml?(filename)
|
@@ -50,7 +50,7 @@ class Gem::Commands::CertCommand < Gem::Command
|
|
50
50
|
'Build private key and self-signed',
|
51
51
|
'certificate for EMAIL_ADDR.') do |value, options|
|
52
52
|
vals = Gem::Security.build_self_signed_cert(value)
|
53
|
-
|
53
|
+
FileUtils.chmod 0600, vals[:key_path]
|
54
54
|
say "Public Cert: #{vals[:cert_path]}"
|
55
55
|
say "Private Key: #{vals[:key_path]}"
|
56
56
|
say "Don't forget to move the key file to somewhere private..."
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rubygems/command'
|
2
|
-
require 'rubygems/source_index'
|
3
2
|
require 'rubygems/dependency_list'
|
4
3
|
require 'rubygems/uninstaller'
|
5
4
|
|
@@ -38,28 +37,20 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it.
|
|
38
37
|
say "Cleaning up installed gems..."
|
39
38
|
primary_gems = {}
|
40
39
|
|
41
|
-
Gem.
|
40
|
+
Gem::Specification.each do |spec|
|
42
41
|
if primary_gems[spec.name].nil? or
|
43
42
|
primary_gems[spec.name].version < spec.version then
|
44
43
|
primary_gems[spec.name] = spec
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
gems_to_cleanup = []
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
gems_to_cleanup << spec
|
56
|
-
end
|
57
|
-
end
|
58
|
-
else
|
59
|
-
Gem.source_index.each do |name, spec|
|
60
|
-
gems_to_cleanup << spec
|
61
|
-
end
|
62
|
-
end
|
47
|
+
gems_to_cleanup = unless options[:args].empty? then
|
48
|
+
options[:args].map do |gem_name|
|
49
|
+
Gem::Specification.find_all_by_name gem_name
|
50
|
+
end.flatten
|
51
|
+
else
|
52
|
+
Gem::Specification.to_a
|
53
|
+
end
|
63
54
|
|
64
55
|
gems_to_cleanup = gems_to_cleanup.select { |spec|
|
65
56
|
primary_gems[spec.name].version != spec.version
|
@@ -83,8 +74,8 @@ installed elsewhere in GEM_PATH the cleanup command won't touch it.
|
|
83
74
|
:version => "= #{spec.version}",
|
84
75
|
}
|
85
76
|
|
86
|
-
if Gem.user_dir == spec.
|
87
|
-
uninstall_options[:install_dir] = spec.
|
77
|
+
if Gem.user_dir == spec.base_dir then
|
78
|
+
uninstall_options[:install_dir] = spec.base_dir
|
88
79
|
end
|
89
80
|
|
90
81
|
uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
|
@@ -52,22 +52,22 @@ class Gem::Commands::ContentsCommand < Gem::Command
|
|
52
52
|
end.flatten
|
53
53
|
|
54
54
|
path_kind = if spec_dirs.empty? then
|
55
|
-
spec_dirs = Gem::
|
55
|
+
spec_dirs = Gem::Specification.dirs
|
56
56
|
"default gem paths"
|
57
57
|
else
|
58
58
|
"specified path"
|
59
59
|
end
|
60
60
|
|
61
|
-
si = Gem::SourceIndex.new spec_dirs
|
62
|
-
|
63
61
|
gem_names = if options[:all] then
|
64
|
-
|
62
|
+
Gem::Specification.map(&:name)
|
65
63
|
else
|
66
64
|
get_all_gem_names
|
67
65
|
end
|
68
66
|
|
69
67
|
gem_names.each do |name|
|
70
|
-
|
68
|
+
# HACK: find_by_name fails for some reason... ARGH
|
69
|
+
# How many places must we embed our resolve logic?
|
70
|
+
spec = Gem::Specification.find_all_by_name(name, version).last
|
71
71
|
|
72
72
|
unless spec then
|
73
73
|
say "Unable to find gem '#{name}' in #{path_kind}"
|
@@ -44,11 +44,6 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|
44
44
|
|
45
45
|
def execute
|
46
46
|
options[:args] << '' if options[:args].empty?
|
47
|
-
specs = {}
|
48
|
-
|
49
|
-
source_indexes = Hash.new do |h, source_uri|
|
50
|
-
h[source_uri] = Gem::SourceIndex.new
|
51
|
-
end
|
52
47
|
|
53
48
|
pattern = if options[:args].length == 1 and
|
54
49
|
options[:args].first =~ /\A\/(.*)\/(i)?\z/m then
|
@@ -58,7 +53,10 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|
58
53
|
/\A#{Regexp.union(*options[:args])}/
|
59
54
|
end
|
60
55
|
|
61
|
-
|
56
|
+
# TODO: deprecate for real damnit
|
57
|
+
dependency = Deprecate.skip_during {
|
58
|
+
Gem::Dependency.new pattern, options[:version]
|
59
|
+
}
|
62
60
|
dependency.prerelease = options[:prerelease]
|
63
61
|
|
64
62
|
if options[:reverse_dependencies] and remote? and not local? then
|
@@ -66,26 +64,23 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|
66
64
|
terminate_interaction 1
|
67
65
|
end
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
67
|
+
specs = []
|
68
|
+
|
69
|
+
specs.concat dependency.matching_specs if local?
|
74
70
|
|
75
71
|
if remote? and not options[:reverse_dependencies] then
|
76
72
|
fetcher = Gem::SpecFetcher.fetcher
|
77
73
|
|
74
|
+
# REFACTOR: fetcher.find_specs_matching => specs
|
78
75
|
specs_and_sources = fetcher.find_matching(dependency, false, true,
|
79
76
|
dependency.prerelease?)
|
80
77
|
|
81
|
-
specs_and_sources.
|
82
|
-
|
83
|
-
|
84
|
-
source_indexes[source_uri].add_spec spec
|
85
|
-
end
|
78
|
+
specs.concat specs_and_sources.map { |spec_tuple, source_uri|
|
79
|
+
fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
|
80
|
+
}
|
86
81
|
end
|
87
82
|
|
88
|
-
if
|
83
|
+
if specs.empty? then
|
89
84
|
patterns = options[:args].join ','
|
90
85
|
say "No gems found matching #{patterns} (#{options[:version]})" if
|
91
86
|
Gem.configuration.verbose
|
@@ -93,24 +88,18 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|
93
88
|
terminate_interaction 1
|
94
89
|
end
|
95
90
|
|
96
|
-
specs =
|
97
|
-
|
98
|
-
source_indexes.values.each do |source_index|
|
99
|
-
source_index.gems.each do |name, spec|
|
100
|
-
specs[spec.full_name] = [source_index, spec]
|
101
|
-
end
|
102
|
-
end
|
91
|
+
specs = specs.uniq.sort
|
103
92
|
|
104
93
|
reverse = Hash.new { |h, k| h[k] = [] }
|
105
94
|
|
106
95
|
if options[:reverse_dependencies] then
|
107
|
-
specs.
|
96
|
+
specs.each do |spec|
|
108
97
|
reverse[spec.full_name] = find_reverse_dependencies spec
|
109
98
|
end
|
110
99
|
end
|
111
100
|
|
112
101
|
if options[:pipe_format] then
|
113
|
-
specs.
|
102
|
+
specs.each do |spec|
|
114
103
|
unless spec.dependencies.empty?
|
115
104
|
spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
|
116
105
|
say "#{dep.name} --version '#{dep.requirement}'"
|
@@ -120,7 +109,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|
120
109
|
else
|
121
110
|
response = ''
|
122
111
|
|
123
|
-
specs.
|
112
|
+
specs.each do |spec|
|
124
113
|
response << print_dependencies(spec)
|
125
114
|
unless reverse[spec.full_name].empty? then
|
126
115
|
response << " Used by\n"
|
@@ -152,7 +141,7 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|
152
141
|
def find_reverse_dependencies(spec)
|
153
142
|
result = []
|
154
143
|
|
155
|
-
Gem.
|
144
|
+
Gem::Specification.each do |sp|
|
156
145
|
sp.dependencies.each do |dep|
|
157
146
|
dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep
|
158
147
|
|
@@ -166,17 +155,5 @@ class Gem::Commands::DependencyCommand < Gem::Command
|
|
166
155
|
result
|
167
156
|
end
|
168
157
|
|
169
|
-
def find_gems(name, source_index)
|
170
|
-
specs = {}
|
171
|
-
|
172
|
-
spec_list = source_index.search name, options[:version]
|
173
|
-
|
174
|
-
spec_list.each do |spec|
|
175
|
-
specs[spec.full_name] = [source_index, spec]
|
176
|
-
end
|
177
|
-
|
178
|
-
specs
|
179
|
-
end
|
180
|
-
|
181
158
|
end
|
182
159
|
|
@@ -114,7 +114,8 @@ to write the specification by hand. For example:
|
|
114
114
|
|
115
115
|
get_all_gem_names.each do |gem_name|
|
116
116
|
begin
|
117
|
-
next if options[:conservative]
|
117
|
+
next if options[:conservative] and
|
118
|
+
not Gem::Dependency.new(gem_name, options[:version]).matching_specs.empty?
|
118
119
|
|
119
120
|
inst = Gem::DependencyInstaller.new options
|
120
121
|
inst.install gem_name, options[:version]
|
@@ -87,7 +87,7 @@ lock it down to the exact version.
|
|
87
87
|
|
88
88
|
spec.runtime_dependencies.each do |dep|
|
89
89
|
next if locked[dep.name]
|
90
|
-
candidates =
|
90
|
+
candidates = dep.matching_specs
|
91
91
|
|
92
92
|
if candidates.empty? then
|
93
93
|
complain "Unable to satisfy '#{dep}' from currently installed gems"
|
@@ -99,11 +99,11 @@ lock it down to the exact version.
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def spec_path(gem_full_name)
|
102
|
-
gemspecs = Gem.path.map
|
102
|
+
gemspecs = Gem.path.map { |path|
|
103
103
|
File.join path, "specifications", "#{gem_full_name}.gemspec"
|
104
|
-
|
104
|
+
}
|
105
105
|
|
106
|
-
gemspecs.find { |
|
106
|
+
gemspecs.find { |path| File.exist? path }
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
@@ -16,11 +16,8 @@ class Gem::Commands::OutdatedCommand < Gem::Command
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def execute
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
locals.outdated.sort.each do |name|
|
23
|
-
local = locals.find_name(name).last
|
19
|
+
outdated.sort.each do |name|
|
20
|
+
local = Gem::Specification.find_all_by_name(name).max
|
24
21
|
dep = Gem::Dependency.new local.name, ">= #{local.version}"
|
25
22
|
remotes = Gem::SpecFetcher.fetcher.fetch dep
|
26
23
|
|
@@ -31,5 +28,20 @@ class Gem::Commands::OutdatedCommand < Gem::Command
|
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
34
|
-
|
31
|
+
def outdated
|
32
|
+
outdateds = []
|
33
|
+
|
34
|
+
fetcher = Gem::SpecFetcher.fetcher
|
35
|
+
|
36
|
+
Gem::Specification.latest_specs.each do |local|
|
37
|
+
dependency = Gem::Dependency.new local.name, ">= #{local.version}"
|
38
|
+
remotes = fetcher.find_matching dependency
|
39
|
+
remotes = remotes.map { |(_, version, _), _| version }
|
40
|
+
latest = remotes.sort.last
|
35
41
|
|
42
|
+
outdateds << local.name if latest and local.version < latest
|
43
|
+
end
|
44
|
+
|
45
|
+
outdateds
|
46
|
+
end
|
47
|
+
end
|
@@ -10,7 +10,8 @@ class Gem::Commands::PristineCommand < Gem::Command
|
|
10
10
|
def initialize
|
11
11
|
super 'pristine',
|
12
12
|
'Restores installed gems to pristine condition from files located in the gem cache',
|
13
|
-
:version => Gem::Requirement.default
|
13
|
+
:version => Gem::Requirement.default, :extensions => true,
|
14
|
+
:all => false
|
14
15
|
|
15
16
|
add_option('--all',
|
16
17
|
'Restore all installed gems to pristine',
|
@@ -18,6 +19,11 @@ class Gem::Commands::PristineCommand < Gem::Command
|
|
18
19
|
options[:all] = value
|
19
20
|
end
|
20
21
|
|
22
|
+
add_option('--[no-]extensions',
|
23
|
+
'Restore gems with extensions') do |value, options|
|
24
|
+
options[:extensions] = value
|
25
|
+
end
|
26
|
+
|
21
27
|
add_version_option('restore to', 'pristine condition')
|
22
28
|
end
|
23
29
|
|
@@ -26,7 +32,7 @@ class Gem::Commands::PristineCommand < Gem::Command
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def defaults_str # :nodoc:
|
29
|
-
"--all"
|
35
|
+
"--all --extensions"
|
30
36
|
end
|
31
37
|
|
32
38
|
def description # :nodoc:
|
@@ -40,6 +46,9 @@ for the gem are regenerated.
|
|
40
46
|
|
41
47
|
If the cached gem cannot be found, you will need to use `gem install` to
|
42
48
|
revert the gem.
|
49
|
+
|
50
|
+
If --no-extensions is provided pristine will not attempt to restore gems with
|
51
|
+
extensions.
|
43
52
|
EOF
|
44
53
|
end
|
45
54
|
|
@@ -48,20 +57,17 @@ revert the gem.
|
|
48
57
|
end
|
49
58
|
|
50
59
|
def execute
|
51
|
-
gem_name = nil
|
52
|
-
|
53
60
|
specs = if options[:all] then
|
54
|
-
Gem.
|
55
|
-
spec
|
56
|
-
end
|
61
|
+
Gem::Specification.map
|
57
62
|
else
|
58
|
-
|
59
|
-
|
63
|
+
get_all_gem_names.map do |gem_name|
|
64
|
+
Gem::Specification.find_all_by_name gem_name, options[:version]
|
65
|
+
end.flatten
|
60
66
|
end
|
61
67
|
|
62
|
-
if specs.empty? then
|
68
|
+
if specs.to_a.empty? then
|
63
69
|
raise Gem::Exception,
|
64
|
-
"Failed to find
|
70
|
+
"Failed to find gems #{options[:args]} #{options[:version]}"
|
65
71
|
end
|
66
72
|
|
67
73
|
install_dir = Gem.dir # TODO use installer option
|
@@ -69,18 +75,22 @@ revert the gem.
|
|
69
75
|
raise Gem::FilePermissionError.new(install_dir) unless
|
70
76
|
File.writable?(install_dir)
|
71
77
|
|
72
|
-
say "Restoring
|
78
|
+
say "Restoring gems to pristine condition..."
|
73
79
|
|
74
80
|
specs.each do |spec|
|
75
|
-
|
81
|
+
unless spec.extensions.empty? or options[:extensions] then
|
82
|
+
say "Skipped #{spec.full_name}, it needs to compile an extension"
|
83
|
+
next
|
84
|
+
end
|
85
|
+
|
86
|
+
gem = spec.cache_file
|
76
87
|
|
77
|
-
|
88
|
+
unless File.exist? gem then
|
78
89
|
require 'rubygems/remote_fetcher'
|
79
90
|
|
80
91
|
say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
|
81
92
|
dep = Gem::Dependency.new spec.name, spec.version
|
82
93
|
Gem::RemoteFetcher.fetcher.download_to_cache dep
|
83
|
-
gem = spec.cache_gem
|
84
94
|
end
|
85
95
|
|
86
96
|
# TODO use installer options
|