rubygems-update 0.9.2 → 0.9.3

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 (53) hide show
  1. data/ChangeLog +60 -0
  2. data/lib/rubygems.rb +18 -15
  3. data/lib/rubygems/builder.rb +29 -23
  4. data/lib/rubygems/{cmd_manager.rb → command_manager.rb} +35 -24
  5. data/lib/rubygems/commands/build_command.rb +57 -0
  6. data/lib/rubygems/commands/cert_command.rb +83 -0
  7. data/lib/rubygems/commands/check_command.rb +74 -0
  8. data/lib/rubygems/commands/cleanup_command.rb +75 -0
  9. data/lib/rubygems/commands/contents_command.rb +66 -0
  10. data/lib/rubygems/commands/dependency_command.rb +105 -0
  11. data/lib/rubygems/commands/environment_command.rb +59 -0
  12. data/lib/rubygems/commands/help_command.rb +82 -0
  13. data/lib/rubygems/commands/install_command.rb +139 -0
  14. data/lib/rubygems/commands/list_command.rb +33 -0
  15. data/lib/rubygems/commands/outdated_command.rb +21 -0
  16. data/lib/rubygems/commands/pristine_command.rb +103 -0
  17. data/lib/rubygems/commands/query_command.rb +86 -0
  18. data/lib/rubygems/commands/rdoc_command.rb +75 -0
  19. data/lib/rubygems/commands/search_command.rb +35 -0
  20. data/lib/rubygems/commands/sources_command.rb +73 -0
  21. data/lib/rubygems/commands/specification_command.rb +58 -0
  22. data/lib/rubygems/commands/uninstall_command.rb +51 -0
  23. data/lib/rubygems/commands/unpack_command.rb +76 -0
  24. data/lib/rubygems/commands/update_command.rb +102 -0
  25. data/lib/rubygems/digest/digest_adapter.rb +40 -0
  26. data/lib/rubygems/digest/md5.rb +20 -0
  27. data/lib/rubygems/digest/sha1.rb +17 -0
  28. data/lib/rubygems/digest/sha2.rb +17 -0
  29. data/lib/rubygems/format.rb +1 -1
  30. data/lib/rubygems/gem_commands.rb +6 -1407
  31. data/lib/rubygems/gem_runner.rb +2 -2
  32. data/lib/rubygems/installer.rb +13 -5
  33. data/lib/rubygems/open-uri.rb +2 -2
  34. data/lib/rubygems/package.rb +13 -14
  35. data/lib/rubygems/rubygems_version.rb +1 -1
  36. data/lib/rubygems/source_index.rb +4 -4
  37. data/lib/rubygems/specification.rb +5 -0
  38. data/lib/rubygems/validator.rb +8 -8
  39. data/setup.rb +806 -588
  40. data/test/gemutilities.rb +2 -2
  41. data/test/test_builder.rb +15 -0
  42. data/test/test_check_command.rb +1 -1
  43. data/test/test_command.rb +1 -1
  44. data/test/test_gem_digest.rb +44 -0
  45. data/test/test_gem_outdated_command.rb +2 -1
  46. data/test/test_gem_sources_command.rb +11 -6
  47. data/test/test_installer.rb +1 -1
  48. data/test/test_open_uri.rb +14 -0
  49. data/test/test_parse_commands.rb +25 -25
  50. data/test/test_process_commands.rb +5 -5
  51. data/test/test_specific_extras.rb +1 -1
  52. data/test/test_validator.rb +3 -3
  53. metadata +30 -4
data/ChangeLog CHANGED
@@ -1,3 +1,63 @@
1
+ 2007-05-10 Jim Weirich <jim@weirichhouse.org>
2
+
3
+ * lib/rubygems/remote_installer.rb: Uncommented the require
4
+ 'sources' line.
5
+
6
+ * lib/rubygems/source_info_cache.rb: Uncommented the require
7
+ 'sources' line.
8
+
9
+ * lib/rubygems/rubygems_version.rb (Gem): Bumped to version 0.9.3
10
+ in preparation for release.
11
+
12
+ * lib/rubygems/package.rb (Gem::TarInput::zipped_stream):
13
+ Zipped_stream now always uses the in memory string IO buffer.
14
+ There were just too many problems with ZLib (on windows)
15
+ otherwise.
16
+
17
+ 2007-03-26 Jim Weirich <jim@weirichhouse.org>
18
+
19
+ * (Index): new digest technique.
20
+
21
+ * lib/rubygems/validator.rb (Gem::Validator::verify_gem): Removed
22
+ really old MD5 and replaced with gem based digests.
23
+
24
+ * experimental/deployment.rb (Gem::Deployment::Manager::initialize):
25
+ New digest technique.
26
+
27
+ * experimental/test_deployment.rb (TestDeployment::test_deployed_file):
28
+ New digest technique.
29
+
30
+ 2007-03-26 Chad Fowler <chad@chadfowler.com>
31
+
32
+ * Extracted the big ball of mud that was gem_commands.rb into
33
+ separate files.
34
+
35
+ 2007-03-17 Chad Fowler <chad@chadfowler.com>
36
+
37
+ * Various ruby 1.8.6 fixes for failing tests.
38
+
39
+ * Updated setup.rb to 3.4.1
40
+
41
+ * Renamed cmd_manager to command_manager to keep names consistent
42
+
43
+ * lib/installer.rb: Rework path checking to use Pathname (ara howard bug #8811)
44
+
45
+ 2007-03-02 Eric Hodel <drbrain@segment7.net>
46
+
47
+ * lib/rubygems.rb: Add bin directory before library directory,
48
+ otherwise gems like rake don't work.
49
+
50
+ 2007-03-01 Eric Hodel <drbrain@segment7.net>
51
+
52
+ * lib/rubygems/open-uri.rb: Fix all the infinite loop errors.
53
+
54
+ * lib/rubygems.rb: Add dirs from activate after -I and ENV['RUBYLIB']
55
+ dirs. Otherwise gems won't allow -I to work when #gem is called.
56
+
57
+ 2007-02-11 Chad Fowler <chad@chadfowler.com>
58
+
59
+ * test/gemutilities.rb: Fix to make Windows tests pass. (Anatol Pomozov)
60
+
1
61
  2007-02-05 Jim Weirich <jim@weirichhouse.org>
2
62
 
3
63
  * lib/rubygems/rubygems_version.rb (Gem): Bumped to version 0.9.2
@@ -113,7 +113,7 @@ module Gem
113
113
  require 'rubygems/installer'
114
114
  require 'rubygems/validator'
115
115
  require 'rubygems/doc_manager'
116
- require 'rubygems/cmd_manager'
116
+ require 'rubygems/command_manager'
117
117
  require 'rubygems/gem_runner'
118
118
  require 'rubygems/config_file'
119
119
  end
@@ -253,28 +253,31 @@ module Gem
253
253
  if spec.loaded?
254
254
  return false unless autorequire
255
255
  result = spec.autorequire ? require(spec.autorequire) : false
256
- return result || false
256
+ return result || false
257
257
  end
258
258
 
259
259
  spec.loaded = true
260
260
  @loaded_specs[spec.name] = spec
261
-
261
+
262
262
  # Load dependent gems first
263
263
  spec.dependencies.each do |dep_gem|
264
264
  activate(dep_gem, autorequire)
265
265
  end
266
-
267
- # add bin dir to require_path
268
- if(spec.bindir) then
269
- spec.require_paths << spec.bindir
270
- end
271
-
272
- # Now add the require_paths to the LOAD_PATH
273
- spec.require_paths.each do |path|
274
- $:.unshift File.join(spec.full_gem_path, path)
266
+
267
+ # bin directory must come before library directories
268
+ spec.require_paths.unshift spec.bindir if spec.bindir
269
+
270
+ require_paths = spec.require_paths.map do |path|
271
+ File.join spec.full_gem_path, path
275
272
  end
276
-
277
- if autorequire && spec.autorequire then
273
+
274
+ sitelibdir = Config::CONFIG['sitelibdir']
275
+
276
+ # gem directories must come after -I and ENV['RUBYLIB']
277
+ $:.insert($:.index(sitelibdir), *require_paths)
278
+
279
+ # Now autorequire
280
+ if autorequire && spec.autorequire then # DEPRECATED
278
281
  Array(spec.autorequire).each do |a_lib|
279
282
  require a_lib
280
283
  end
@@ -282,7 +285,7 @@ module Gem
282
285
 
283
286
  return true
284
287
  end
285
-
288
+
286
289
  # Report a load error during activation. The message of load
287
290
  # error depends on whether it was a version mismatch or if there
288
291
  # are not gems of any version by the requested name.
@@ -33,7 +33,23 @@ module Gem
33
33
  def build
34
34
  @spec.mark_version
35
35
  @spec.validate
36
-
36
+ @signer = sign
37
+ write_package
38
+ say success
39
+ @spec.file_name
40
+ end
41
+
42
+ def success
43
+ <<-EOM
44
+ Successfully built RubyGem
45
+ Name: #{@spec.name}
46
+ Version: #{@spec.version}
47
+ File: #{@spec.full_name+'.gem'}
48
+ EOM
49
+ end
50
+
51
+ private
52
+ def sign
37
53
  # if the signing key was specified, then load the file, and swap
38
54
  # to the public key (TODO: we should probably just omit the
39
55
  # signing key in favor of the signing certificate, but that's for
@@ -44,30 +60,20 @@ module Gem
44
60
  @spec.signing_key = nil
45
61
  @spec.cert_chain = signer.cert_chain.map { |cert| cert.to_s }
46
62
  end
47
-
48
- file_name = @spec.full_name+".gem"
49
-
50
- Package.open(file_name, "w", signer) do |pkg|
51
- pkg.metadata = @spec.to_yaml
52
- @spec.files.each do |file|
53
- next if File.directory? file
54
- pkg.add_file_simple(file, File.stat(file_name).mode & 0777,
55
- File.size(file)) do |os|
56
- os.write File.open(file, "rb"){|f|f.read}
57
- end
58
- end
59
- end
60
- say success
61
- file_name
63
+ signer
62
64
  end
63
65
 
64
- def success
65
- <<-EOM
66
- Successfully built RubyGem
67
- Name: #{@spec.name}
68
- Version: #{@spec.version}
69
- File: #{@spec.full_name+'.gem'}
70
- EOM
66
+ def write_package
67
+ Package.open(@spec.file_name, "w", @signer) do |pkg|
68
+ pkg.metadata = @spec.to_yaml
69
+ @spec.files.each do |file|
70
+ next if File.directory? file
71
+ pkg.add_file_simple(file, File.stat(@spec.file_name).mode & 0777,
72
+ File.size(file)) do |os|
73
+ os.write File.open(file, "rb"){|f|f.read}
74
+ end
75
+ end
76
+ end
71
77
  end
72
78
  end
73
79
  end
@@ -40,40 +40,40 @@ module Gem
40
40
  # sub-commands supported by the gem command.
41
41
  class CommandManager
42
42
  include UserInteraction
43
-
43
+ include Commands
44
+
44
45
  # Return the authoratative instance of the command manager.
45
46
  def self.instance
46
- @cmd_manager ||= CommandManager.new
47
+ @command_manager ||= CommandManager.new
47
48
  end
48
-
49
+
49
50
  # Register all the subcommands supported by the gem command.
50
51
  def initialize
51
52
  @commands = {}
52
- register_command BuildCommand.new
53
- register_command CertCommand.new
54
- register_command CheckCommand.new
55
- register_command CleanupCommand.new
56
- register_command ContentsCommand.new
57
- register_command DependencyCommand.new
58
- register_command EnvironmentCommand.new
59
- register_command HelpCommand.new
60
- register_command InstallCommand.new
61
- register_command ListCommand.new
62
- register_command OutdatedCommand.new
63
- register_command PristineCommand.new
64
- register_command QueryCommand.new
65
- register_command RDocCommand.new
66
- register_command SearchCommand.new
67
- register_command SourcesCommand.new
68
- register_command SpecificationCommand.new
69
- register_command UninstallCommand.new
70
- register_command UnpackCommand.new
71
- register_command UpdateCommand.new
53
+ register_command :build
54
+ register_command :cert
55
+ register_command :check
56
+ register_command :contents
57
+ register_command :dependency
58
+ register_command :environment
59
+ register_command :help
60
+ register_command :install
61
+ register_command :outdated
62
+ register_command :pristine
63
+ register_command :query
64
+ register_command :list
65
+ register_command :rdoc
66
+ register_command :search
67
+ register_command :sources
68
+ register_command :specification
69
+ register_command :uninstall
70
+ register_command :unpack
71
+ register_command :update
72
72
  end
73
73
 
74
74
  # Register the command object.
75
75
  def register_command(command_obj)
76
- @commands[command_obj.command.intern] = command_obj
76
+ @commands[command_obj] = load_and_instantiate(command_obj)
77
77
  end
78
78
 
79
79
  # Return the registered command from the command name.
@@ -136,5 +136,16 @@ module Gem
136
136
  len = cmd_name.length
137
137
  self.command_names.select { |n| cmd_name == n[0,len] }
138
138
  end
139
+
140
+ private
141
+ def load_and_instantiate(command_name)
142
+ command_name = command_name.to_s
143
+ begin
144
+ Gem::Commands.const_get("#{command_name.capitalize}Command").new
145
+ rescue
146
+ require "rubygems/commands/#{command_name}_command"
147
+ retry
148
+ end
149
+ end
139
150
  end
140
151
  end
@@ -0,0 +1,57 @@
1
+ module Gem
2
+ module Commands
3
+ class BuildCommand < Command
4
+ include CommandAids
5
+
6
+ def initialize
7
+ super('build', 'Build a gem from a gemspec')
8
+ end
9
+
10
+ def usage
11
+ "#{program_name} GEMSPEC_FILE"
12
+ end
13
+
14
+ def arguments
15
+ "GEMSPEC_FILE name of gemspec file used to build the gem"
16
+ end
17
+
18
+ def execute
19
+ gemspec = get_one_gem_name
20
+ if File.exist?(gemspec)
21
+ specs = load_gemspecs(gemspec)
22
+ specs.each do |spec|
23
+ Gem::Builder.new(spec).build
24
+ end
25
+ return
26
+ else
27
+ alert_error "Gemspec file not found: #{gemspec}"
28
+ end
29
+ end
30
+
31
+ def load_gemspecs(filename)
32
+ if yaml?(filename)
33
+ require 'yaml'
34
+ result = []
35
+ open(filename) do |f|
36
+ begin
37
+ while spec = Gem::Specification.from_yaml(f)
38
+ result << spec
39
+ end
40
+ rescue EndOfYAMLException => e
41
+ # OK
42
+ end
43
+ end
44
+ else
45
+ result = [Gem::Specification.load(filename)]
46
+ end
47
+ result
48
+ end
49
+
50
+ def yaml?(filename)
51
+ line = open(filename) { |f| line = f.gets }
52
+ result = line =~ %r{^--- *!ruby/object:Gem::Specification}
53
+ result
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,83 @@
1
+ module Gem
2
+ module Commands
3
+
4
+ class CertCommand < Command
5
+ include CommandAids
6
+
7
+ def initialize
8
+ super(
9
+ 'cert',
10
+ 'Adjust RubyGems certificate settings',
11
+ {
12
+ })
13
+
14
+ add_option('-a', '--add CERT', 'Add a trusted certificate.') do |value, options|
15
+ cert = OpenSSL::X509::Certificate.new(File.read(value))
16
+ Gem::Security.add_trusted_cert(cert)
17
+ puts "Added #{cert.subject.to_s}"
18
+ end
19
+
20
+ add_option('-l', '--list', 'List trusted certificates.') do |value, options|
21
+ glob_str = File::join(Gem::Security::OPT[:trust_dir], '*.pem')
22
+ Dir::glob(glob_str) do |path|
23
+ cert = OpenSSL::X509::Certificate.new(File.read(path))
24
+ # this could proably be formatted more gracefully
25
+ puts cert.subject.to_s
26
+ end
27
+ end
28
+
29
+ add_option('-r', '--remove STRING',
30
+ 'Remove trusted certificates containing',
31
+ 'STRING.') do |value, options|
32
+ trust_dir = Gem::Security::OPT[:trust_dir]
33
+ glob_str = File::join(trust_dir, '*.pem')
34
+
35
+ Dir::glob(glob_str) do |path|
36
+ cert = OpenSSL::X509::Certificate.new(File.read(path))
37
+ if cert.subject.to_s.downcase.index(value)
38
+ puts "Removing '#{cert.subject.to_s}'"
39
+ File.unlink(path)
40
+ end
41
+ end
42
+ end
43
+
44
+ add_option('-b', '--build EMAIL_ADDR',
45
+ 'Build private key and self-signed',
46
+ 'certificate for EMAIL_ADDR.') do |value, options|
47
+ vals = Gem::Security::build_self_signed_cert(value)
48
+ File::chmod(0600, vals[:key_path])
49
+ puts "Public Cert: #{vals[:cert_path]}",
50
+ "Private Key: #{vals[:key_path]}",
51
+ "Don't forget to move the key file to somewhere private..."
52
+ end
53
+
54
+ add_option('-C', '--certificate CERT',
55
+ 'Certificate for --sign command.') do |value, options|
56
+ cert = OpenSSL::X509::Certificate.new(File.read(value))
57
+ Gem::Security::OPT[:issuer_cert] = cert
58
+ end
59
+
60
+ add_option('-K', '--private-key KEY',
61
+ 'Private key for --sign command.') do |value, options|
62
+ key = OpenSSL::PKey::RSA.new(File.read(value))
63
+ Gem::Security::OPT[:issuer_key] = key
64
+ end
65
+
66
+
67
+ add_option('-s', '--sign NEWCERT',
68
+ 'Sign a certificate with my key and',
69
+ 'certificate.') do |value, options|
70
+ cert = OpenSSL::X509::Certificate.new(File.read(value))
71
+ my_cert = Gem::Security::OPT[:issuer_cert]
72
+ my_key = Gem::Security::OPT[:issuer_key]
73
+ cert = Gem::Security.sign_cert(cert, my_key, my_cert)
74
+ File::open(value, 'wb') { |file| file.write(cert.to_pem) }
75
+ end
76
+
77
+ end
78
+
79
+ def execute
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,74 @@
1
+ module Gem
2
+ module Commands
3
+ class CheckCommand < Command
4
+ include CommandAids
5
+
6
+ def initialize
7
+ super('check', 'Check installed gems',
8
+ {:verify => false, :alien => false})
9
+
10
+ add_option('-v', '--verify FILE',
11
+ 'Verify gem file against its internal',
12
+ 'checksum') do |value, options|
13
+ options[:verify] = value
14
+ end
15
+
16
+ add_option('-a', '--alien', "Report 'unmanaged' or rogue files in the",
17
+ "gem repository") do |value, options|
18
+ options[:alien] = true
19
+ end
20
+
21
+ add_option('-t', '--test', "Run unit tests for gem") do |value, options|
22
+ options[:test] = true
23
+ end
24
+
25
+ add_option('-V', '--version',
26
+ "Specify version for which to run unit tests") do |value, options|
27
+ options[:version] = value
28
+ end
29
+ end
30
+
31
+ def execute
32
+ if options[:test]
33
+ version = options[:version] || "> 0.0.0"
34
+ gem_spec = Gem::SourceIndex.from_installed_gems.search(get_one_gem_name, version).first
35
+ Gem::Validator.new.unit_test(gem_spec)
36
+ end
37
+ if options[:alien]
38
+ say "Performing the 'alien' operation"
39
+ Gem::Validator.new.alien.each do |key, val|
40
+ if(val.size > 0)
41
+ say "#{key} has #{val.size} problems"
42
+ val.each do |error_entry|
43
+ say "\t#{error_entry.path}:"
44
+ say "\t#{error_entry.problem}"
45
+ say
46
+ end
47
+ else
48
+ say "#{key} is error-free"
49
+ end
50
+ say
51
+ end
52
+ end
53
+ if options[:verify]
54
+ gem_name = options[:verify]
55
+ unless gem_name
56
+ alert_error "Must specify a .gem file with --verify NAME"
57
+ return
58
+ end
59
+ unless File.exist?(gem_name)
60
+ alert_error "Unknown file: #{gem_name}."
61
+ return
62
+ end
63
+ say "Verifying gem: '#{gem_name}'"
64
+ begin
65
+ Gem::Validator.new.verify_gem_file(gem_name)
66
+ rescue Exception => e
67
+ alert_error "#{gem_name} is invalid."
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ end