slimgems 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/ChangeLog +5811 -0
  2. data/History.txt +887 -0
  3. data/LICENSE.txt +51 -0
  4. data/README.md +87 -0
  5. data/Rakefile +120 -0
  6. data/bin/gem +25 -0
  7. data/bin/update_slimgems +35 -0
  8. data/bootstrap/Rakefile +4 -0
  9. data/hide_lib_for_update/note.txt +5 -0
  10. data/lib/gauntlet_rubygems.rb +50 -0
  11. data/lib/rbconfig/datadir.rb +20 -0
  12. data/lib/rubygems.rb +1220 -0
  13. data/lib/rubygems/builder.rb +102 -0
  14. data/lib/rubygems/command.rb +534 -0
  15. data/lib/rubygems/command_manager.rb +182 -0
  16. data/lib/rubygems/commands/build_command.rb +53 -0
  17. data/lib/rubygems/commands/cert_command.rb +86 -0
  18. data/lib/rubygems/commands/check_command.rb +80 -0
  19. data/lib/rubygems/commands/cleanup_command.rb +106 -0
  20. data/lib/rubygems/commands/contents_command.rb +98 -0
  21. data/lib/rubygems/commands/dependency_command.rb +195 -0
  22. data/lib/rubygems/commands/environment_command.rb +132 -0
  23. data/lib/rubygems/commands/fetch_command.rb +67 -0
  24. data/lib/rubygems/commands/generate_index_command.rb +133 -0
  25. data/lib/rubygems/commands/help_command.rb +172 -0
  26. data/lib/rubygems/commands/install_command.rb +178 -0
  27. data/lib/rubygems/commands/list_command.rb +35 -0
  28. data/lib/rubygems/commands/lock_command.rb +110 -0
  29. data/lib/rubygems/commands/mirror_command.rb +111 -0
  30. data/lib/rubygems/commands/outdated_command.rb +33 -0
  31. data/lib/rubygems/commands/owner_command.rb +75 -0
  32. data/lib/rubygems/commands/pristine_command.rb +93 -0
  33. data/lib/rubygems/commands/push_command.rb +56 -0
  34. data/lib/rubygems/commands/query_command.rb +280 -0
  35. data/lib/rubygems/commands/rdoc_command.rb +91 -0
  36. data/lib/rubygems/commands/search_command.rb +31 -0
  37. data/lib/rubygems/commands/server_command.rb +86 -0
  38. data/lib/rubygems/commands/setup_command.rb +387 -0
  39. data/lib/rubygems/commands/sources_command.rb +157 -0
  40. data/lib/rubygems/commands/specification_command.rb +125 -0
  41. data/lib/rubygems/commands/stale_command.rb +27 -0
  42. data/lib/rubygems/commands/uninstall_command.rb +83 -0
  43. data/lib/rubygems/commands/unpack_command.rb +121 -0
  44. data/lib/rubygems/commands/update_command.rb +212 -0
  45. data/lib/rubygems/commands/which_command.rb +86 -0
  46. data/lib/rubygems/config_file.rb +345 -0
  47. data/lib/rubygems/custom_require.rb +44 -0
  48. data/lib/rubygems/defaults.rb +101 -0
  49. data/lib/rubygems/dependency.rb +227 -0
  50. data/lib/rubygems/dependency_installer.rb +286 -0
  51. data/lib/rubygems/dependency_list.rb +208 -0
  52. data/lib/rubygems/doc_manager.rb +242 -0
  53. data/lib/rubygems/errors.rb +35 -0
  54. data/lib/rubygems/exceptions.rb +91 -0
  55. data/lib/rubygems/ext.rb +18 -0
  56. data/lib/rubygems/ext/builder.rb +56 -0
  57. data/lib/rubygems/ext/configure_builder.rb +25 -0
  58. data/lib/rubygems/ext/ext_conf_builder.rb +24 -0
  59. data/lib/rubygems/ext/rake_builder.rb +39 -0
  60. data/lib/rubygems/format.rb +81 -0
  61. data/lib/rubygems/gem_openssl.rb +92 -0
  62. data/lib/rubygems/gem_path_searcher.rb +100 -0
  63. data/lib/rubygems/gem_runner.rb +79 -0
  64. data/lib/rubygems/gemcutter_utilities.rb +49 -0
  65. data/lib/rubygems/indexer.rb +720 -0
  66. data/lib/rubygems/install_update_options.rb +125 -0
  67. data/lib/rubygems/installer.rb +604 -0
  68. data/lib/rubygems/local_remote_options.rb +135 -0
  69. data/lib/rubygems/old_format.rb +153 -0
  70. data/lib/rubygems/package.rb +97 -0
  71. data/lib/rubygems/package/f_sync_dir.rb +23 -0
  72. data/lib/rubygems/package/tar_header.rb +266 -0
  73. data/lib/rubygems/package/tar_input.rb +222 -0
  74. data/lib/rubygems/package/tar_output.rb +144 -0
  75. data/lib/rubygems/package/tar_reader.rb +106 -0
  76. data/lib/rubygems/package/tar_reader/entry.rb +141 -0
  77. data/lib/rubygems/package/tar_writer.rb +241 -0
  78. data/lib/rubygems/package_task.rb +126 -0
  79. data/lib/rubygems/platform.rb +183 -0
  80. data/lib/rubygems/remote_fetcher.rb +414 -0
  81. data/lib/rubygems/require_paths_builder.rb +18 -0
  82. data/lib/rubygems/requirement.rb +153 -0
  83. data/lib/rubygems/security.rb +814 -0
  84. data/lib/rubygems/server.rb +872 -0
  85. data/lib/rubygems/source_index.rb +597 -0
  86. data/lib/rubygems/source_info_cache.rb +395 -0
  87. data/lib/rubygems/source_info_cache_entry.rb +56 -0
  88. data/lib/rubygems/spec_fetcher.rb +337 -0
  89. data/lib/rubygems/specification.rb +1486 -0
  90. data/lib/rubygems/test_utilities.rb +147 -0
  91. data/lib/rubygems/text.rb +65 -0
  92. data/lib/rubygems/uninstaller.rb +278 -0
  93. data/lib/rubygems/user_interaction.rb +527 -0
  94. data/lib/rubygems/validator.rb +240 -0
  95. data/lib/rubygems/version.rb +316 -0
  96. data/lib/rubygems/version_option.rb +65 -0
  97. data/lib/ubygems.rb +10 -0
  98. data/setup.rb +42 -0
  99. data/test/bogussources.rb +8 -0
  100. data/test/data/gem-private_key.pem +27 -0
  101. data/test/data/gem-public_cert.pem +20 -0
  102. data/test/fake_certlib/openssl.rb +7 -0
  103. data/test/foo/discover.rb +0 -0
  104. data/test/functional.rb +92 -0
  105. data/test/gem_installer_test_case.rb +97 -0
  106. data/test/gem_package_tar_test_case.rb +132 -0
  107. data/test/gemutilities.rb +605 -0
  108. data/test/insure_session.rb +43 -0
  109. data/test/mockgemui.rb +56 -0
  110. data/test/plugin/exception/rubygems_plugin.rb +2 -0
  111. data/test/plugin/load/rubygems_plugin.rb +1 -0
  112. data/test/plugin/standarderror/rubygems_plugin.rb +2 -0
  113. data/test/private_key.pem +27 -0
  114. data/test/public_cert.pem +20 -0
  115. data/test/rubygems_plugin.rb +21 -0
  116. data/test/simple_gem.rb +66 -0
  117. data/test/test_config.rb +12 -0
  118. data/test/test_gem.rb +766 -0
  119. data/test/test_gem_builder.rb +27 -0
  120. data/test/test_gem_command.rb +178 -0
  121. data/test/test_gem_command_manager.rb +207 -0
  122. data/test/test_gem_commands_build_command.rb +74 -0
  123. data/test/test_gem_commands_cert_command.rb +124 -0
  124. data/test/test_gem_commands_check_command.rb +18 -0
  125. data/test/test_gem_commands_contents_command.rb +156 -0
  126. data/test/test_gem_commands_dependency_command.rb +216 -0
  127. data/test/test_gem_commands_environment_command.rb +144 -0
  128. data/test/test_gem_commands_fetch_command.rb +76 -0
  129. data/test/test_gem_commands_generate_index_command.rb +135 -0
  130. data/test/test_gem_commands_install_command.rb +315 -0
  131. data/test/test_gem_commands_list_command.rb +36 -0
  132. data/test/test_gem_commands_lock_command.rb +68 -0
  133. data/test/test_gem_commands_mirror_command.rb +60 -0
  134. data/test/test_gem_commands_outdated_command.rb +40 -0
  135. data/test/test_gem_commands_owner_command.rb +105 -0
  136. data/test/test_gem_commands_pristine_command.rb +108 -0
  137. data/test/test_gem_commands_push_command.rb +81 -0
  138. data/test/test_gem_commands_query_command.rb +426 -0
  139. data/test/test_gem_commands_server_command.rb +59 -0
  140. data/test/test_gem_commands_sources_command.rb +209 -0
  141. data/test/test_gem_commands_specification_command.rb +139 -0
  142. data/test/test_gem_commands_stale_command.rb +38 -0
  143. data/test/test_gem_commands_uninstall_command.rb +83 -0
  144. data/test/test_gem_commands_unpack_command.rb +199 -0
  145. data/test/test_gem_commands_update_command.rb +353 -0
  146. data/test/test_gem_commands_which_command.rb +66 -0
  147. data/test/test_gem_config_file.rb +287 -0
  148. data/test/test_gem_dependency.rb +149 -0
  149. data/test/test_gem_dependency_installer.rb +661 -0
  150. data/test/test_gem_dependency_list.rb +230 -0
  151. data/test/test_gem_doc_manager.rb +31 -0
  152. data/test/test_gem_ext_configure_builder.rb +84 -0
  153. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  154. data/test/test_gem_ext_rake_builder.rb +81 -0
  155. data/test/test_gem_format.rb +70 -0
  156. data/test/test_gem_gem_path_searcher.rb +78 -0
  157. data/test/test_gem_gem_runner.rb +45 -0
  158. data/test/test_gem_gemcutter_utilities.rb +103 -0
  159. data/test/test_gem_indexer.rb +673 -0
  160. data/test/test_gem_install_update_options.rb +68 -0
  161. data/test/test_gem_installer.rb +857 -0
  162. data/test/test_gem_local_remote_options.rb +97 -0
  163. data/test/test_gem_package_tar_header.rb +130 -0
  164. data/test/test_gem_package_tar_input.rb +112 -0
  165. data/test/test_gem_package_tar_output.rb +97 -0
  166. data/test/test_gem_package_tar_reader.rb +46 -0
  167. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  168. data/test/test_gem_package_tar_writer.rb +144 -0
  169. data/test/test_gem_package_task.rb +59 -0
  170. data/test/test_gem_platform.rb +264 -0
  171. data/test/test_gem_remote_fetcher.rb +740 -0
  172. data/test/test_gem_requirement.rb +292 -0
  173. data/test/test_gem_server.rb +356 -0
  174. data/test/test_gem_silent_ui.rb +113 -0
  175. data/test/test_gem_source_index.rb +461 -0
  176. data/test/test_gem_spec_fetcher.rb +410 -0
  177. data/test/test_gem_specification.rb +1291 -0
  178. data/test/test_gem_stream_ui.rb +218 -0
  179. data/test/test_gem_text.rb +43 -0
  180. data/test/test_gem_uninstaller.rb +146 -0
  181. data/test/test_gem_validator.rb +63 -0
  182. data/test/test_gem_version.rb +181 -0
  183. data/test/test_gem_version_option.rb +89 -0
  184. data/test/test_kernel.rb +59 -0
  185. metadata +413 -0
@@ -0,0 +1,35 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/commands/query_command'
3
+
4
+ ##
5
+ # An alternate to Gem::Commands::QueryCommand that searches for gems starting
6
+ # with the the supplied argument.
7
+
8
+ class Gem::Commands::ListCommand < Gem::Commands::QueryCommand
9
+
10
+ def initialize
11
+ super 'list', 'Display gems whose name starts with STRING'
12
+
13
+ remove_option('--name-matches')
14
+ end
15
+
16
+ def arguments # :nodoc:
17
+ "STRING start of gem name to look for"
18
+ end
19
+
20
+ def defaults_str # :nodoc:
21
+ "--local --no-details"
22
+ end
23
+
24
+ def usage # :nodoc:
25
+ "#{program_name} [STRING]"
26
+ end
27
+
28
+ def execute
29
+ string = get_one_optional_argument || ''
30
+ options[:name] = /^#{string}/i
31
+ super
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,110 @@
1
+ require 'rubygems/command'
2
+
3
+ class Gem::Commands::LockCommand < Gem::Command
4
+
5
+ def initialize
6
+ super 'lock', 'Generate a lockdown list of gems',
7
+ :strict => false
8
+
9
+ add_option '-s', '--[no-]strict',
10
+ 'fail if unable to satisfy a dependency' do |strict, options|
11
+ options[:strict] = strict
12
+ end
13
+ end
14
+
15
+ def arguments # :nodoc:
16
+ "GEMNAME name of gem to lock\nVERSION version of gem to lock"
17
+ end
18
+
19
+ def defaults_str # :nodoc:
20
+ "--no-strict"
21
+ end
22
+
23
+ def description # :nodoc:
24
+ <<-EOF
25
+ The lock command will generate a list of +gem+ statements that will lock down
26
+ the versions for the gem given in the command line. It will specify exact
27
+ versions in the requirements list to ensure that the gems loaded will always
28
+ be consistent. A full recursive search of all effected gems will be
29
+ generated.
30
+
31
+ Example:
32
+
33
+ gemlock rails-1.0.0 > lockdown.rb
34
+
35
+ will produce in lockdown.rb:
36
+
37
+ require "rubygems"
38
+ gem 'rails', '= 1.0.0'
39
+ gem 'rake', '= 0.7.0.1'
40
+ gem 'activesupport', '= 1.2.5'
41
+ gem 'activerecord', '= 1.13.2'
42
+ gem 'actionpack', '= 1.11.2'
43
+ gem 'actionmailer', '= 1.1.5'
44
+ gem 'actionwebservice', '= 1.0.0'
45
+
46
+ Just load lockdown.rb from your application to ensure that the current
47
+ versions are loaded. Make sure that lockdown.rb is loaded *before* any
48
+ other require statements.
49
+
50
+ Notice that rails 1.0.0 only requires that rake 0.6.2 or better be used.
51
+ Rake-0.7.0.1 is the most recent version installed that satisfies that, so we
52
+ lock it down to the exact version.
53
+ EOF
54
+ end
55
+
56
+ def usage # :nodoc:
57
+ "#{program_name} GEMNAME-VERSION [GEMNAME-VERSION ...]"
58
+ end
59
+
60
+ def complain(message)
61
+ if options[:strict] then
62
+ raise Gem::Exception, message
63
+ else
64
+ say "# #{message}"
65
+ end
66
+ end
67
+
68
+ def execute
69
+ say "require 'rubygems'"
70
+
71
+ locked = {}
72
+
73
+ pending = options[:args]
74
+
75
+ until pending.empty? do
76
+ full_name = pending.shift
77
+
78
+ spec = Gem::SourceIndex.load_specification spec_path(full_name)
79
+
80
+ if spec.nil? then
81
+ complain "Could not find gem #{full_name}, try using the full name"
82
+ next
83
+ end
84
+
85
+ say "gem '#{spec.name}', '= #{spec.version}'" unless locked[spec.name]
86
+ locked[spec.name] = true
87
+
88
+ spec.runtime_dependencies.each do |dep|
89
+ next if locked[dep.name]
90
+ candidates = Gem.source_index.search dep
91
+
92
+ if candidates.empty? then
93
+ complain "Unable to satisfy '#{dep}' from currently installed gems"
94
+ else
95
+ pending << candidates.last.full_name
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ def spec_path(gem_full_name)
102
+ gemspecs = Gem.path.map do |path|
103
+ File.join path, "specifications", "#{gem_full_name}.gemspec"
104
+ end
105
+
106
+ gemspecs.find { |gemspec| File.exist? gemspec }
107
+ end
108
+
109
+ end
110
+
@@ -0,0 +1,111 @@
1
+ require 'yaml'
2
+ require 'zlib'
3
+
4
+ require 'rubygems/command'
5
+ require 'open-uri'
6
+
7
+ class Gem::Commands::MirrorCommand < Gem::Command
8
+
9
+ def initialize
10
+ super 'mirror', 'Mirror a gem repository'
11
+ end
12
+
13
+ def description # :nodoc:
14
+ <<-EOF
15
+ The mirror command uses the ~/.gemmirrorrc config file to mirror remote gem
16
+ repositories to a local path. The config file is a YAML document that looks
17
+ like this:
18
+
19
+ ---
20
+ - from: http://gems.example.com # source repository URI
21
+ to: /path/to/mirror # destination directory
22
+
23
+ Multiple sources and destinations may be specified.
24
+ EOF
25
+ end
26
+
27
+ def execute
28
+ config_file = File.join Gem.user_home, '.gemmirrorrc'
29
+
30
+ raise "Config file #{config_file} not found" unless File.exist? config_file
31
+
32
+ mirrors = YAML.load_file config_file
33
+
34
+ raise "Invalid config file #{config_file}" unless mirrors.respond_to? :each
35
+
36
+ mirrors.each do |mir|
37
+ raise "mirror missing 'from' field" unless mir.has_key? 'from'
38
+ raise "mirror missing 'to' field" unless mir.has_key? 'to'
39
+
40
+ get_from = mir['from']
41
+ save_to = File.expand_path mir['to']
42
+
43
+ raise "Directory not found: #{save_to}" unless File.exist? save_to
44
+ raise "Not a directory: #{save_to}" unless File.directory? save_to
45
+
46
+ gems_dir = File.join save_to, "gems"
47
+
48
+ if File.exist? gems_dir then
49
+ raise "Not a directory: #{gems_dir}" unless File.directory? gems_dir
50
+ else
51
+ Dir.mkdir gems_dir
52
+ end
53
+
54
+ source_index_data = ''
55
+
56
+ say "fetching: #{get_from}/Marshal.#{Gem.marshal_version}.Z"
57
+
58
+ get_from = URI.parse get_from
59
+
60
+ if get_from.scheme.nil? then
61
+ get_from = get_from.to_s
62
+ elsif get_from.scheme == 'file' then
63
+ # check if specified URI contains a drive letter (file:/D:/Temp)
64
+ get_from = get_from.to_s
65
+ get_from = if get_from =~ /^file:.*[a-z]:/i then
66
+ get_from[6..-1]
67
+ else
68
+ get_from[5..-1]
69
+ end
70
+ end
71
+
72
+ open File.join(get_from.to_s, "Marshal.#{Gem.marshal_version}.Z"), "rb" do |y|
73
+ source_index_data = Zlib::Inflate.inflate y.read
74
+ open File.join(save_to, "Marshal.#{Gem.marshal_version}"), "wb" do |out|
75
+ out.write source_index_data
76
+ end
77
+ end
78
+
79
+ source_index = Marshal.load source_index_data
80
+
81
+ progress = ui.progress_reporter source_index.size,
82
+ "Fetching #{source_index.size} gems"
83
+ source_index.each do |fullname, gem|
84
+ gem_file = gem.file_name
85
+ gem_dest = File.join gems_dir, gem_file
86
+
87
+ unless File.exist? gem_dest then
88
+ begin
89
+ open "#{get_from}/gems/#{gem_file}", "rb" do |g|
90
+ contents = g.read
91
+ open gem_dest, "wb" do |out|
92
+ out.write contents
93
+ end
94
+ end
95
+ rescue
96
+ old_gf = gem_file
97
+ gem_file = gem_file.downcase
98
+ retry if old_gf != gem_file
99
+ alert_error $!
100
+ end
101
+ end
102
+
103
+ progress.updated gem_file
104
+ end
105
+
106
+ progress.done
107
+ end
108
+ end
109
+
110
+ end
111
+
@@ -0,0 +1,33 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/local_remote_options'
3
+ require 'rubygems/spec_fetcher'
4
+ require 'rubygems/version_option'
5
+
6
+ class Gem::Commands::OutdatedCommand < Gem::Command
7
+
8
+ include Gem::LocalRemoteOptions
9
+ include Gem::VersionOption
10
+
11
+ def initialize
12
+ super 'outdated', 'Display all gems that need updates'
13
+
14
+ add_local_remote_options
15
+ add_platform_option
16
+ end
17
+
18
+ def execute
19
+ locals = Gem::SourceIndex.from_installed_gems
20
+
21
+ locals.outdated.sort.each do |name|
22
+ local = locals.find_name(name).last
23
+
24
+ dep = Gem::Dependency.new local.name, ">= #{local.version}"
25
+ remotes = Gem::SpecFetcher.fetcher.fetch dep
26
+ remote = remotes.last.first
27
+
28
+ say "#{local.name} (#{local.version} < #{remote.version})"
29
+ end
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,75 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/local_remote_options'
3
+ require 'rubygems/gemcutter_utilities'
4
+
5
+ class Gem::Commands::OwnerCommand < Gem::Command
6
+ include Gem::LocalRemoteOptions
7
+ include Gem::GemcutterUtilities
8
+
9
+ def description # :nodoc:
10
+ "Manage gem owners on rubygems.org."
11
+ end
12
+
13
+ def arguments # :nodoc:
14
+ "GEM gem to manage owners for"
15
+ end
16
+
17
+ def initialize
18
+ super 'owner', description
19
+ add_proxy_option
20
+ defaults.merge! :add => [], :remove => []
21
+
22
+ add_option '-a', '--add EMAIL', 'Add an owner' do |value, options|
23
+ options[:add] << value
24
+ end
25
+
26
+ add_option '-r', '--remove EMAIL', 'Remove an owner' do |value, options|
27
+ options[:remove] << value
28
+ end
29
+ end
30
+
31
+ def execute
32
+ sign_in
33
+ name = get_one_gem_name
34
+
35
+ add_owners name, options[:add]
36
+ remove_owners name, options[:remove]
37
+ show_owners name
38
+ end
39
+
40
+ def show_owners name
41
+ response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request|
42
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
43
+ end
44
+
45
+ with_response response do |resp|
46
+ owners = YAML.load resp.body
47
+
48
+ say "Owners for gem: #{name}"
49
+ owners.each do |owner|
50
+ say "- #{owner['email']}"
51
+ end
52
+ end
53
+ end
54
+
55
+ def add_owners name, owners
56
+ manage_owners :post, name, owners
57
+ end
58
+
59
+ def remove_owners name, owners
60
+ manage_owners :delete, name, owners
61
+ end
62
+
63
+ def manage_owners method, name, owners
64
+ owners.each do |owner|
65
+ response = rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request|
66
+ request.set_form_data 'email' => owner
67
+ request.add_field "Authorization", Gem.configuration.rubygems_api_key
68
+ end
69
+
70
+ with_response response
71
+ end
72
+ end
73
+
74
+ end
75
+
@@ -0,0 +1,93 @@
1
+ require 'fileutils'
2
+ require 'rubygems/command'
3
+ require 'rubygems/format'
4
+ require 'rubygems/installer'
5
+ require 'rubygems/version_option'
6
+
7
+ class Gem::Commands::PristineCommand < Gem::Command
8
+
9
+ include Gem::VersionOption
10
+
11
+ def initialize
12
+ super 'pristine',
13
+ 'Restores installed gems to pristine condition from files located in the gem cache',
14
+ :version => Gem::Requirement.default
15
+
16
+ add_option('--all',
17
+ 'Restore all installed gems to pristine',
18
+ 'condition') do |value, options|
19
+ options[:all] = value
20
+ end
21
+
22
+ add_version_option('restore to', 'pristine condition')
23
+ end
24
+
25
+ def arguments # :nodoc:
26
+ "GEMNAME gem to restore to pristine condition (unless --all)"
27
+ end
28
+
29
+ def defaults_str # :nodoc:
30
+ "--all"
31
+ end
32
+
33
+ def description # :nodoc:
34
+ <<-EOF
35
+ The pristine command compares the installed gems with the contents of the
36
+ cached gem and restores any files that don't match the cached gem's copy.
37
+
38
+ If you have made modifications to your installed gems, the pristine command
39
+ will revert them. After all the gem's files have been checked all bin stubs
40
+ for the gem are regenerated.
41
+
42
+ If the cached gem cannot be found, you will need to use `gem install` to
43
+ revert the gem.
44
+ EOF
45
+ end
46
+
47
+ def usage # :nodoc:
48
+ "#{program_name} [args]"
49
+ end
50
+
51
+ def execute
52
+ gem_name = nil
53
+
54
+ specs = if options[:all] then
55
+ Gem::SourceIndex.from_installed_gems.map do |name, spec|
56
+ spec
57
+ end
58
+ else
59
+ gem_name = get_one_gem_name
60
+ Gem::SourceIndex.from_installed_gems.find_name(gem_name,
61
+ options[:version])
62
+ end
63
+
64
+ if specs.empty? then
65
+ raise Gem::Exception,
66
+ "Failed to find gem #{gem_name} #{options[:version]}"
67
+ end
68
+
69
+ install_dir = Gem.dir # TODO use installer option
70
+
71
+ raise Gem::FilePermissionError.new(install_dir) unless
72
+ File.writable?(install_dir)
73
+
74
+ say "Restoring gem(s) to pristine condition..."
75
+
76
+ specs.each do |spec|
77
+ gem = Dir[File.join(Gem.dir, 'cache', spec.file_name)].first
78
+
79
+ if gem.nil? then
80
+ alert_error "Cached gem for #{spec.full_name} not found, use `gem install` to restore"
81
+ next
82
+ end
83
+
84
+ # TODO use installer options
85
+ installer = Gem::Installer.new gem, :wrappers => true, :force => true
86
+ installer.install
87
+
88
+ say "Restored #{spec.full_name}"
89
+ end
90
+ end
91
+
92
+ end
93
+