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
@@ -33,6 +33,39 @@ class Gem::CommandManager
33
33
 
34
34
  include Gem::UserInteraction
35
35
 
36
+ BUILTIN_COMMANDS = [ # :nodoc:
37
+ :build,
38
+ :cert,
39
+ :check,
40
+ :cleanup,
41
+ :contents,
42
+ :dependency,
43
+ :environment,
44
+ :fetch,
45
+ :generate_index,
46
+ :help,
47
+ :install,
48
+ :list,
49
+ :lock,
50
+ :mirror,
51
+ :outdated,
52
+ :owner,
53
+ :pristine,
54
+ :push,
55
+ :query,
56
+ :rdoc,
57
+ :search,
58
+ :server,
59
+ :sources,
60
+ :specification,
61
+ :stale,
62
+ :uninstall,
63
+ :unpack,
64
+ :update,
65
+ :which,
66
+ :yank,
67
+ ]
68
+
36
69
  ##
37
70
  # Return the authoritative instance of the command manager.
38
71
 
@@ -61,36 +94,10 @@ class Gem::CommandManager
61
94
  def initialize
62
95
  require 'timeout'
63
96
  @commands = {}
64
- register_command :build
65
- register_command :cert
66
- register_command :check
67
- register_command :cleanup
68
- register_command :contents
69
- register_command :dependency
70
- register_command :environment
71
- register_command :fetch
72
- register_command :generate_index
73
- register_command :help
74
- register_command :install
75
- register_command :list
76
- register_command :lock
77
- register_command :mirror
78
- register_command :outdated
79
- register_command :owner
80
- register_command :pristine
81
- register_command :push
82
- register_command :query
83
- register_command :rdoc
84
- register_command :search
85
- register_command :server
86
- register_command :sources
87
- register_command :specification
88
- register_command :stale
89
- register_command :uninstall
90
- register_command :unpack
91
- register_command :update
92
- register_command :which
93
- register_command :yank
97
+
98
+ BUILTIN_COMMANDS.each do |name|
99
+ register_command name
100
+ end
94
101
  end
95
102
 
96
103
  ##
@@ -132,14 +139,6 @@ class Gem::CommandManager
132
139
  alert_error "While executing gem ... (#{ex.class})\n #{ex.to_s}"
133
140
  ui.backtrace ex
134
141
 
135
- if Gem.configuration.really_verbose and \
136
- ex.kind_of?(Gem::Exception) and ex.source_exception
137
- e = ex.source_exception
138
-
139
- ui.errs.puts "Because of: (#{e.class})\n #{e.to_s}"
140
- ui.backtrace e
141
- end
142
-
143
142
  terminate_interaction(1)
144
143
  rescue Interrupt
145
144
  alert_error "Interrupted"
@@ -147,8 +146,6 @@ class Gem::CommandManager
147
146
  end
148
147
 
149
148
  def process_args(args, build_args=nil)
150
- args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
151
-
152
149
  if args.empty? then
153
150
  say Gem::Command::HELP
154
151
  terminate_interaction 1
@@ -1,6 +1,11 @@
1
1
  require 'rubygems/command'
2
2
  require 'rubygems/security'
3
- require 'openssl'
3
+ begin
4
+ require 'openssl'
5
+ rescue LoadError => e
6
+ raise unless (e.respond_to?(:path) && e.path == 'openssl') ||
7
+ e.message =~ / -- openssl$/
8
+ end
4
9
 
5
10
  class Gem::Commands::CertCommand < Gem::Command
6
11
 
@@ -21,7 +26,8 @@ class Gem::Commands::CertCommand < Gem::Command
21
26
 
22
27
  OptionParser.accept OpenSSL::PKey::RSA do |key_file|
23
28
  begin
24
- key = OpenSSL::PKey::RSA.new File.read key_file
29
+ passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
30
+ key = OpenSSL::PKey::RSA.new File.read(key_file), passphrase
25
31
  rescue Errno::ENOENT
26
32
  raise OptionParser::InvalidArgument, "#{key_file}: does not exist"
27
33
  rescue OpenSSL::PKey::RSAError
@@ -79,52 +85,67 @@ class Gem::Commands::CertCommand < Gem::Command
79
85
  end
80
86
  end
81
87
 
88
+ def add_certificate certificate # :nodoc:
89
+ Gem::Security.trust_dir.trust_cert certificate
90
+
91
+ say "Added '#{certificate.subject}'"
92
+ end
93
+
82
94
  def execute
83
95
  options[:add].each do |certificate|
84
- Gem::Security.trust_dir.trust_cert certificate
85
-
86
- say "Added '#{certificate.subject}'"
96
+ add_certificate certificate
87
97
  end
88
98
 
89
99
  options[:remove].each do |filter|
90
- certificates_matching filter do |certificate, path|
91
- FileUtils.rm path
92
- say "Removed '#{certificate.subject}'"
93
- end
100
+ remove_certificates_matching filter
94
101
  end
95
102
 
96
103
  options[:list].each do |filter|
97
- certificates_matching filter do |certificate, _|
98
- # this could probably be formatted more gracefully
99
- say certificate.subject.to_s
100
- end
104
+ list_certificates_matching filter
101
105
  end
102
106
 
103
107
  options[:build].each do |name|
104
108
  build name
105
109
  end
106
110
 
107
- unless options[:sign].empty? then
108
- load_default_cert unless options[:issuer_cert]
109
- load_default_key unless options[:key]
110
- end
111
-
112
- options[:sign].each do |cert_file|
113
- sign cert_file
114
- end
111
+ sign_certificates unless options[:sign].empty?
115
112
  end
116
113
 
117
114
  def build name
118
- key = options[:key] || Gem::Security.create_key
115
+ key, key_path = build_key
116
+ cert_path = build_cert name, key
119
117
 
118
+ say "Certificate: #{cert_path}"
119
+
120
+ if key_path
121
+ say "Private Key: #{key_path}"
122
+ say "Don't forget to move the key file to somewhere private!"
123
+ end
124
+ end
125
+
126
+ def build_cert name, key # :nodoc:
120
127
  cert = Gem::Security.create_cert_email name, key
128
+ Gem::Security.write cert, "gem-public_cert.pem"
129
+ end
121
130
 
122
- key_path = Gem::Security.write key, "gem-private_key.pem"
123
- cert_path = Gem::Security.write cert, "gem-public_cert.pem"
131
+ def build_key # :nodoc:
132
+ if options[:key] then
133
+ options[:key]
134
+ else
135
+ passphrase = ask_for_password 'Passphrase for your Private Key:'
136
+ say "\n"
124
137
 
125
- say "Certificate: #{cert_path}"
126
- say "Private Key: #{key_path}"
127
- say "Don't forget to move the key file to somewhere private!"
138
+ passphrase_confirmation = ask_for_password 'Please repeat the passphrase for your Private Key:'
139
+ say "\n"
140
+
141
+ raise Gem::CommandLineError,
142
+ "Passphrase and passphrase confirmation don't match" unless passphrase == passphrase_confirmation
143
+
144
+ key = Gem::Security.create_key
145
+ key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase
146
+
147
+ return key, key_path
148
+ end
128
149
  end
129
150
 
130
151
  def certificates_matching filter
@@ -179,6 +200,13 @@ For further reading on signing gems see `ri Gem::Security`.
179
200
  EOF
180
201
  end
181
202
 
203
+ def list_certificates_matching filter # :nodoc:
204
+ certificates_matching filter do |certificate, _|
205
+ # this could probably be formatted more gracefully
206
+ say certificate.subject.to_s
207
+ end
208
+ end
209
+
182
210
  def load_default_cert
183
211
  cert_file = File.join Gem.default_cert_path
184
212
  cert = File.read cert_file
@@ -198,7 +226,8 @@ For further reading on signing gems see `ri Gem::Security`.
198
226
  def load_default_key
199
227
  key_file = File.join Gem.default_key_path
200
228
  key = File.read key_file
201
- options[:key] = OpenSSL::PKey::RSA.new key
229
+ passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
230
+ options[:key] = OpenSSL::PKey::RSA.new key, passphrase
202
231
  rescue Errno::ENOENT
203
232
  alert_error \
204
233
  "--private-key not specified and ~/.gem/gem-private_key.pem does not exist"
@@ -211,6 +240,18 @@ For further reading on signing gems see `ri Gem::Security`.
211
240
  terminate_interaction 1
212
241
  end
213
242
 
243
+ def load_defaults # :nodoc:
244
+ load_default_cert unless options[:issuer_cert]
245
+ load_default_key unless options[:key]
246
+ end
247
+
248
+ def remove_certificates_matching filter # :nodoc:
249
+ certificates_matching filter do |certificate, path|
250
+ FileUtils.rm path
251
+ say "Removed '#{certificate.subject}'"
252
+ end
253
+ end
254
+
214
255
  def sign cert_file
215
256
  cert = File.read cert_file
216
257
  cert = OpenSSL::X509::Certificate.new cert
@@ -225,5 +266,13 @@ For further reading on signing gems see `ri Gem::Security`.
225
266
  Gem::Security.write cert, cert_file, permissions
226
267
  end
227
268
 
228
- end
269
+ def sign_certificates # :nodoc:
270
+ load_defaults unless options[:sign].empty?
271
+
272
+ options[:sign].each do |cert_file|
273
+ sign cert_file
274
+ end
275
+ end
276
+
277
+ end if defined?(OpenSSL::SSL)
229
278
 
@@ -9,7 +9,8 @@ class Gem::Commands::CleanupCommand < Gem::Command
9
9
  'Clean up old versions of installed gems in the local repository',
10
10
  :force => false, :install_dir => Gem.dir
11
11
 
12
- add_option('-d', '--dryrun', "") do |value, options|
12
+ add_option('-n', '-d', '--dryrun',
13
+ 'Do not uninstall gems') do |value, options|
13
14
  options[:dryrun] = true
14
15
  end
15
16
 
@@ -162,4 +163,3 @@ are not removed.
162
163
  end
163
164
 
164
165
  end
165
-
@@ -31,6 +31,10 @@ class Gem::Commands::ContentsCommand < Gem::Command
31
31
  "Don't include installed path prefix") do |prefix, options|
32
32
  options[:prefix] = prefix
33
33
  end
34
+
35
+ @path_kind = nil
36
+ @spec_dirs = nil
37
+ @version = nil
34
38
  end
35
39
 
36
40
  def arguments # :nodoc:
@@ -46,74 +50,113 @@ class Gem::Commands::ContentsCommand < Gem::Command
46
50
  end
47
51
 
48
52
  def execute
49
- version = options[:version] || Gem::Requirement.default
53
+ @version = options[:version] || Gem::Requirement.default
54
+ @spec_dirs = specification_directories
55
+ @path_kind = path_description @spec_dirs
50
56
 
51
- spec_dirs = options[:specdirs].map do |i|
52
- [i, File.join(i, "specifications")]
53
- end.flatten
57
+ names = gem_names
54
58
 
55
- path_kind = if spec_dirs.empty? then
56
- spec_dirs = Gem::Specification.dirs
57
- "default gem paths"
58
- else
59
- "specified path"
60
- end
61
-
62
- gem_names = if options[:all] then
63
- Gem::Specification.map(&:name)
64
- else
65
- get_all_gem_names
66
- end
67
-
68
- gem_names.each do |name|
69
- # HACK: find_by_name fails for some reason... ARGH
70
- # How many places must we embed our resolve logic?
71
- spec = Gem::Specification.find_all_by_name(name, version).last
72
-
73
- unless spec then
74
- say "Unable to find gem '#{name}' in #{path_kind}"
75
-
76
- if Gem.configuration.verbose then
77
- say "\nDirectories searched:"
78
- spec_dirs.sort.each { |dir| say dir }
79
- end
80
-
81
- terminate_interaction 1 if gem_names.length == 1
82
- end
59
+ names.each do |name|
60
+ found = gem_contents name
61
+
62
+ terminate_interaction 1 unless found or names.length > 1
63
+ end
64
+ end
65
+
66
+ def files_in spec
67
+ if spec.default_gem? then
68
+ files_in_default_gem spec
69
+ else
70
+ files_in_gem spec
71
+ end
72
+ end
83
73
 
84
- if spec.default_gem?
85
- files = spec.files.sort.map do |file|
86
- case file
87
- when /\A#{spec.bindir}\//
88
- [Gem::ConfigMap[:bindir], $POSTMATCH]
89
- when /\.so\z/
90
- [Gem::ConfigMap[:archdir], file]
91
- else
92
- [Gem::ConfigMap[:rubylibdir], file]
93
- end
94
- end
74
+ def files_in_gem spec
75
+ gem_path = spec.full_gem_path
76
+ extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
77
+ glob = "#{gem_path}#{extra}/**/*"
78
+ prefix_re = /#{Regexp.escape(gem_path)}\//
79
+
80
+ Dir[glob].map do |file|
81
+ [gem_path, file.sub(prefix_re, "")]
82
+ end
83
+ end
84
+
85
+ def files_in_default_gem spec
86
+ spec.files.sort.map do |file|
87
+ case file
88
+ when /\A#{spec.bindir}\//
89
+ [Gem::ConfigMap[:bindir], $POSTMATCH]
90
+ when /\.so\z/
91
+ [Gem::ConfigMap[:archdir], file]
95
92
  else
96
- gem_path = spec.full_gem_path
97
- extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
98
- glob = "#{gem_path}#{extra}/**/*"
99
- prefix_re = /#{Regexp.escape(gem_path)}\//
100
- files = Dir[glob].map do |file|
101
- [gem_path, file.sub(prefix_re, "")]
102
- end
93
+ [Gem::ConfigMap[:rubylibdir], file]
103
94
  end
95
+ end
96
+ end
97
+
98
+ def gem_contents name
99
+ spec = spec_for name
100
+
101
+ return false unless spec
102
+
103
+ files = files_in spec
104
+
105
+ show_files files
104
106
 
105
- files.sort.each do |prefix, basename|
106
- absolute_path = File.join(prefix, basename)
107
- next if File.directory? absolute_path
107
+ true
108
+ end
109
+
110
+ def gem_names # :nodoc:
111
+ if options[:all] then
112
+ Gem::Specification.map(&:name)
113
+ else
114
+ get_all_gem_names
115
+ end
116
+ end
117
+
118
+ def path_description spec_dirs # :nodoc:
119
+ if spec_dirs.empty? then
120
+ spec_dirs = Gem::Specification.dirs
121
+ "default gem paths"
122
+ else
123
+ "specified path"
124
+ end
125
+ end
126
+
127
+ def show_files files
128
+ files.sort.each do |prefix, basename|
129
+ absolute_path = File.join(prefix, basename)
130
+ next if File.directory? absolute_path
108
131
 
109
- if options[:prefix]
110
- say absolute_path
111
- else
112
- say basename
113
- end
132
+ if options[:prefix] then
133
+ say absolute_path
134
+ else
135
+ say basename
114
136
  end
115
137
  end
116
138
  end
117
139
 
140
+ def spec_for name
141
+ spec = Gem::Specification.find_all_by_name(name, @version).last
142
+
143
+ return spec if spec
144
+
145
+ say "Unable to find gem '#{name}' in #{@path_kind}"
146
+
147
+ if Gem.configuration.verbose then
148
+ say "\nDirectories searched:"
149
+ @spec_dirs.sort.each { |dir| say dir }
150
+ end
151
+
152
+ return nil
153
+ end
154
+
155
+ def specification_directories # :nodoc:
156
+ options[:specdirs].map do |i|
157
+ [i, File.join(i, "specifications")]
158
+ end.flatten
159
+ end
160
+
118
161
  end
119
162