libgems 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) 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 +113 -0
  6. data/lib/gauntlet_libgems.rb +50 -0
  7. data/lib/libgems.rb +1246 -0
  8. data/lib/libgems/builder.rb +102 -0
  9. data/lib/libgems/command.rb +534 -0
  10. data/lib/libgems/command_manager.rb +182 -0
  11. data/lib/libgems/commands/build_command.rb +53 -0
  12. data/lib/libgems/commands/cert_command.rb +86 -0
  13. data/lib/libgems/commands/check_command.rb +80 -0
  14. data/lib/libgems/commands/cleanup_command.rb +106 -0
  15. data/lib/libgems/commands/contents_command.rb +98 -0
  16. data/lib/libgems/commands/dependency_command.rb +195 -0
  17. data/lib/libgems/commands/environment_command.rb +133 -0
  18. data/lib/libgems/commands/fetch_command.rb +67 -0
  19. data/lib/libgems/commands/generate_index_command.rb +133 -0
  20. data/lib/libgems/commands/help_command.rb +172 -0
  21. data/lib/libgems/commands/install_command.rb +178 -0
  22. data/lib/libgems/commands/list_command.rb +35 -0
  23. data/lib/libgems/commands/lock_command.rb +110 -0
  24. data/lib/libgems/commands/mirror_command.rb +111 -0
  25. data/lib/libgems/commands/outdated_command.rb +33 -0
  26. data/lib/libgems/commands/owner_command.rb +75 -0
  27. data/lib/libgems/commands/pristine_command.rb +93 -0
  28. data/lib/libgems/commands/push_command.rb +56 -0
  29. data/lib/libgems/commands/query_command.rb +280 -0
  30. data/lib/libgems/commands/rdoc_command.rb +91 -0
  31. data/lib/libgems/commands/search_command.rb +31 -0
  32. data/lib/libgems/commands/server_command.rb +86 -0
  33. data/lib/libgems/commands/sources_command.rb +157 -0
  34. data/lib/libgems/commands/specification_command.rb +125 -0
  35. data/lib/libgems/commands/stale_command.rb +27 -0
  36. data/lib/libgems/commands/uninstall_command.rb +83 -0
  37. data/lib/libgems/commands/unpack_command.rb +121 -0
  38. data/lib/libgems/commands/update_command.rb +160 -0
  39. data/lib/libgems/commands/which_command.rb +86 -0
  40. data/lib/libgems/config_file.rb +345 -0
  41. data/lib/libgems/custom_require.rb +44 -0
  42. data/lib/libgems/defaults.rb +101 -0
  43. data/lib/libgems/dependency.rb +227 -0
  44. data/lib/libgems/dependency_installer.rb +286 -0
  45. data/lib/libgems/dependency_list.rb +208 -0
  46. data/lib/libgems/doc_manager.rb +242 -0
  47. data/lib/libgems/errors.rb +35 -0
  48. data/lib/libgems/exceptions.rb +91 -0
  49. data/lib/libgems/ext.rb +18 -0
  50. data/lib/libgems/ext/builder.rb +56 -0
  51. data/lib/libgems/ext/configure_builder.rb +25 -0
  52. data/lib/libgems/ext/ext_conf_builder.rb +24 -0
  53. data/lib/libgems/ext/rake_builder.rb +39 -0
  54. data/lib/libgems/format.rb +81 -0
  55. data/lib/libgems/gem_openssl.rb +92 -0
  56. data/lib/libgems/gem_path_searcher.rb +100 -0
  57. data/lib/libgems/gem_runner.rb +79 -0
  58. data/lib/libgems/gemcutter_utilities.rb +49 -0
  59. data/lib/libgems/indexer.rb +720 -0
  60. data/lib/libgems/install_update_options.rb +125 -0
  61. data/lib/libgems/installer.rb +604 -0
  62. data/lib/libgems/local_remote_options.rb +135 -0
  63. data/lib/libgems/old_format.rb +153 -0
  64. data/lib/libgems/package.rb +97 -0
  65. data/lib/libgems/package/f_sync_dir.rb +23 -0
  66. data/lib/libgems/package/tar_header.rb +266 -0
  67. data/lib/libgems/package/tar_input.rb +222 -0
  68. data/lib/libgems/package/tar_output.rb +144 -0
  69. data/lib/libgems/package/tar_reader.rb +106 -0
  70. data/lib/libgems/package/tar_reader/entry.rb +141 -0
  71. data/lib/libgems/package/tar_writer.rb +241 -0
  72. data/lib/libgems/package_task.rb +126 -0
  73. data/lib/libgems/platform.rb +183 -0
  74. data/lib/libgems/remote_fetcher.rb +414 -0
  75. data/lib/libgems/require_paths_builder.rb +18 -0
  76. data/lib/libgems/requirement.rb +153 -0
  77. data/lib/libgems/security.rb +814 -0
  78. data/lib/libgems/server.rb +872 -0
  79. data/lib/libgems/source_index.rb +597 -0
  80. data/lib/libgems/source_info_cache.rb +395 -0
  81. data/lib/libgems/source_info_cache_entry.rb +56 -0
  82. data/lib/libgems/spec_fetcher.rb +337 -0
  83. data/lib/libgems/specification.rb +1487 -0
  84. data/lib/libgems/test_utilities.rb +147 -0
  85. data/lib/libgems/text.rb +65 -0
  86. data/lib/libgems/uninstaller.rb +278 -0
  87. data/lib/libgems/user_interaction.rb +527 -0
  88. data/lib/libgems/validator.rb +240 -0
  89. data/lib/libgems/version.rb +316 -0
  90. data/lib/libgems/version_option.rb +65 -0
  91. data/lib/rbconfig/datadir.rb +20 -0
  92. data/test/bogussources.rb +8 -0
  93. data/test/data/gem-private_key.pem +27 -0
  94. data/test/data/gem-public_cert.pem +20 -0
  95. data/test/fake_certlib/openssl.rb +7 -0
  96. data/test/foo/discover.rb +0 -0
  97. data/test/gem_installer_test_case.rb +97 -0
  98. data/test/gem_package_tar_test_case.rb +132 -0
  99. data/test/gemutilities.rb +605 -0
  100. data/test/insure_session.rb +43 -0
  101. data/test/mockgemui.rb +56 -0
  102. data/test/plugin/exception/libgems_plugin.rb +2 -0
  103. data/test/plugin/load/libgems_plugin.rb +1 -0
  104. data/test/plugin/standarderror/libgems_plugin.rb +2 -0
  105. data/test/private_key.pem +27 -0
  106. data/test/public_cert.pem +20 -0
  107. data/test/rubygems_plugin.rb +21 -0
  108. data/test/simple_gem.rb +66 -0
  109. data/test/test_config.rb +12 -0
  110. data/test/test_gem.rb +780 -0
  111. data/test/test_gem_builder.rb +27 -0
  112. data/test/test_gem_command.rb +178 -0
  113. data/test/test_gem_command_manager.rb +207 -0
  114. data/test/test_gem_commands_build_command.rb +74 -0
  115. data/test/test_gem_commands_cert_command.rb +124 -0
  116. data/test/test_gem_commands_check_command.rb +18 -0
  117. data/test/test_gem_commands_contents_command.rb +156 -0
  118. data/test/test_gem_commands_dependency_command.rb +216 -0
  119. data/test/test_gem_commands_environment_command.rb +144 -0
  120. data/test/test_gem_commands_fetch_command.rb +76 -0
  121. data/test/test_gem_commands_generate_index_command.rb +135 -0
  122. data/test/test_gem_commands_install_command.rb +315 -0
  123. data/test/test_gem_commands_list_command.rb +36 -0
  124. data/test/test_gem_commands_lock_command.rb +68 -0
  125. data/test/test_gem_commands_mirror_command.rb +60 -0
  126. data/test/test_gem_commands_outdated_command.rb +40 -0
  127. data/test/test_gem_commands_owner_command.rb +105 -0
  128. data/test/test_gem_commands_pristine_command.rb +108 -0
  129. data/test/test_gem_commands_push_command.rb +81 -0
  130. data/test/test_gem_commands_query_command.rb +426 -0
  131. data/test/test_gem_commands_server_command.rb +59 -0
  132. data/test/test_gem_commands_sources_command.rb +209 -0
  133. data/test/test_gem_commands_specification_command.rb +139 -0
  134. data/test/test_gem_commands_stale_command.rb +38 -0
  135. data/test/test_gem_commands_uninstall_command.rb +83 -0
  136. data/test/test_gem_commands_unpack_command.rb +199 -0
  137. data/test/test_gem_commands_update_command.rb +207 -0
  138. data/test/test_gem_commands_which_command.rb +66 -0
  139. data/test/test_gem_config_file.rb +287 -0
  140. data/test/test_gem_dependency.rb +149 -0
  141. data/test/test_gem_dependency_installer.rb +661 -0
  142. data/test/test_gem_dependency_list.rb +230 -0
  143. data/test/test_gem_doc_manager.rb +31 -0
  144. data/test/test_gem_ext_configure_builder.rb +84 -0
  145. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  146. data/test/test_gem_ext_rake_builder.rb +81 -0
  147. data/test/test_gem_format.rb +70 -0
  148. data/test/test_gem_gem_path_searcher.rb +78 -0
  149. data/test/test_gem_gem_runner.rb +45 -0
  150. data/test/test_gem_gemcutter_utilities.rb +103 -0
  151. data/test/test_gem_indexer.rb +673 -0
  152. data/test/test_gem_install_update_options.rb +68 -0
  153. data/test/test_gem_installer.rb +857 -0
  154. data/test/test_gem_local_remote_options.rb +97 -0
  155. data/test/test_gem_package_tar_header.rb +130 -0
  156. data/test/test_gem_package_tar_input.rb +112 -0
  157. data/test/test_gem_package_tar_output.rb +97 -0
  158. data/test/test_gem_package_tar_reader.rb +46 -0
  159. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  160. data/test/test_gem_package_tar_writer.rb +144 -0
  161. data/test/test_gem_package_task.rb +59 -0
  162. data/test/test_gem_platform.rb +264 -0
  163. data/test/test_gem_remote_fetcher.rb +740 -0
  164. data/test/test_gem_requirement.rb +292 -0
  165. data/test/test_gem_server.rb +356 -0
  166. data/test/test_gem_silent_ui.rb +113 -0
  167. data/test/test_gem_source_index.rb +461 -0
  168. data/test/test_gem_spec_fetcher.rb +410 -0
  169. data/test/test_gem_specification.rb +1334 -0
  170. data/test/test_gem_stream_ui.rb +218 -0
  171. data/test/test_gem_text.rb +43 -0
  172. data/test/test_gem_uninstaller.rb +146 -0
  173. data/test/test_gem_validator.rb +63 -0
  174. data/test/test_gem_version.rb +181 -0
  175. data/test/test_gem_version_option.rb +89 -0
  176. data/test/test_kernel.rb +59 -0
  177. metadata +402 -0
@@ -0,0 +1,35 @@
1
+ require 'libgems/command'
2
+ require 'libgems/commands/query_command'
3
+
4
+ ##
5
+ # An alternate to LibGems::Commands::QueryCommand that searches for gems starting
6
+ # with the the supplied argument.
7
+
8
+ class LibGems::Commands::ListCommand < LibGems::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 'libgems/command'
2
+
3
+ class LibGems::Commands::LockCommand < LibGems::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 "libgems"
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 LibGems::Exception, message
63
+ else
64
+ say "# #{message}"
65
+ end
66
+ end
67
+
68
+ def execute
69
+ say "require 'libgems'"
70
+
71
+ locked = {}
72
+
73
+ pending = options[:args]
74
+
75
+ until pending.empty? do
76
+ full_name = pending.shift
77
+
78
+ spec = LibGems::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 = LibGems.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 = LibGems.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 'libgems/command'
5
+ require 'open-uri'
6
+
7
+ class LibGems::Commands::MirrorCommand < LibGems::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 LibGems.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.#{LibGems.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.#{LibGems.marshal_version}.Z"), "rb" do |y|
73
+ source_index_data = Zlib::Inflate.inflate y.read
74
+ open File.join(save_to, "Marshal.#{LibGems.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 'libgems/command'
2
+ require 'libgems/local_remote_options'
3
+ require 'libgems/spec_fetcher'
4
+ require 'libgems/version_option'
5
+
6
+ class LibGems::Commands::OutdatedCommand < LibGems::Command
7
+
8
+ include LibGems::LocalRemoteOptions
9
+ include LibGems::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 = LibGems::SourceIndex.from_installed_gems
20
+
21
+ locals.outdated.sort.each do |name|
22
+ local = locals.find_name(name).last
23
+
24
+ dep = LibGems::Dependency.new local.name, ">= #{local.version}"
25
+ remotes = LibGems::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 'libgems/command'
2
+ require 'libgems/local_remote_options'
3
+ require 'libgems/gemcutter_utilities'
4
+
5
+ class LibGems::Commands::OwnerCommand < LibGems::Command
6
+ include LibGems::LocalRemoteOptions
7
+ include LibGems::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", LibGems.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", LibGems.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 'libgems/command'
3
+ require 'libgems/format'
4
+ require 'libgems/installer'
5
+ require 'libgems/version_option'
6
+
7
+ class LibGems::Commands::PristineCommand < LibGems::Command
8
+
9
+ include LibGems::VersionOption
10
+
11
+ def initialize
12
+ super 'pristine',
13
+ 'Restores installed gems to pristine condition from files located in the gem cache',
14
+ :version => LibGems::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
+ LibGems::SourceIndex.from_installed_gems.map do |name, spec|
56
+ spec
57
+ end
58
+ else
59
+ gem_name = get_one_gem_name
60
+ LibGems::SourceIndex.from_installed_gems.find_name(gem_name,
61
+ options[:version])
62
+ end
63
+
64
+ if specs.empty? then
65
+ raise LibGems::Exception,
66
+ "Failed to find gem #{gem_name} #{options[:version]}"
67
+ end
68
+
69
+ install_dir = LibGems.dir # TODO use installer option
70
+
71
+ raise LibGems::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(LibGems.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 = LibGems::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
+