Browse files

Merge branch 'development'

* development:
  avoid adding two periods to possible executable filesnames when searching PATH on Windows. Fixes RR3 #350 - Cannot debug ruby file on Windows
  add missing libs necessary to get YAML to work
  • Loading branch information...
2 parents 750f120 + 6dd2253 commit 92440453bc03b5907a609d1a51d6b61e976b3741 @ashebanow ashebanow committed Apr 13, 2010
Showing with 19,741 additions and 13 deletions.
  1. +30 −13 plugins/com.aptana.util/src/com/aptana/util/ExecutableUtil.java
  2. +50 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/gauntlet_rubygems.rb
  3. +24 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/gemconfigure.rb
  4. +24 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rbconfig/datadir.rb
  5. +1,141 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems.rb
  6. +90 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/builder.rb
  7. +511 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/command.rb
  8. +174 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb
  9. +53 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/build_command.rb
  10. +86 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/cert_command.rb
  11. +80 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/check_command.rb
  12. +106 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/cleanup_command.rb
  13. +98 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/contents_command.rb
  14. +188 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/dependency_command.rb
  15. +128 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/environment_command.rb
  16. +62 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/fetch_command.rb
  17. +133 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/generate_index_command.rb
  18. +172 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/help_command.rb
  19. +174 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb
  20. +35 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/list_command.rb
  21. +110 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/lock_command.rb
  22. +111 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/mirror_command.rb
  23. +33 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/outdated_command.rb
  24. +93 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/pristine_command.rb
  25. +264 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/query_command.rb
  26. +76 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/rdoc_command.rb
  27. +31 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/search_command.rb
  28. +70 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/server_command.rb
  29. +363 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/setup_command.rb
  30. +157 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/sources_command.rb
  31. +124 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/specification_command.rb
  32. +27 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/stale_command.rb
  33. +83 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/uninstall_command.rb
  34. +97 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/unpack_command.rb
  35. +202 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/update_command.rb
  36. +87 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/which_command.rb
  37. +272 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/config_file.rb
  38. +46 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb
  39. +103 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/defaults.rb
  40. +95 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/defaults/jruby.rb
  41. +148 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/dependency.rb
  42. +261 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb
  43. +185 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/dependency_list.rb
  44. +49 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/digest/digest_adapter.rb
  45. +23 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/digest/md5.rb
  46. +22 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/digest/sha1.rb
  47. +22 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/digest/sha2.rb
  48. +230 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/doc_manager.rb
  49. +82 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/exceptions.rb
  50. +18 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/ext.rb
  51. +54 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/ext/builder.rb
  52. +25 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/ext/configure_builder.rb
  53. +24 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/ext/ext_conf_builder.rb
  54. +31 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/ext/rake_builder.rb
  55. +87 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/format.rb
  56. +94 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/gem_openssl.rb
  57. +102 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/gem_path_searcher.rb
  58. +78 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb
  59. +712 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/indexer.rb
  60. +125 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/install_update_options.rb
  61. +581 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/installer.rb
  62. +136 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/local_remote_options.rb
  63. +152 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/old_format.rb
  64. +95 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package.rb
  65. +22 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package/f_sync_dir.rb
  66. +265 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_header.rb
  67. +217 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_input.rb
  68. +143 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_output.rb
  69. +105 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_reader.rb
  70. +140 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_reader/entry.rb
  71. +240 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_writer.rb
  72. +118 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/package_task.rb
  73. +180 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/platform.rb
  74. +367 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb
  75. +17 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/require_paths_builder.rb
  76. +170 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/requirement.rb
  77. +19 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/rubygems_version.rb
  78. +786 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/security.rb
  79. +813 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/server.rb
  80. +597 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb
  81. +393 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/source_info_cache.rb
  82. +56 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/source_info_cache_entry.rb
  83. +278 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb
  84. +1,444 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb
  85. +131 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/test_utilities.rb
  86. +30 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/text.rb
  87. +28 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/timer.rb
  88. +262 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/uninstaller.rb
  89. +390 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/user_interaction.rb
  90. +242 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/validator.rb
  91. +251 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/version.rb
  92. +49 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/version_option.rb
  93. +10 −0 plugins/org.jruby/lib/ruby/site_ruby/1.8/ubygems.rb
  94. +5 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/core_ext/symbol.rb
  95. +19 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/java/java.io.rb
  96. +37 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/java/java.lang.rb
  97. +133 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/java/java.util.rb
  98. +83 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/java/java.util.regex.rb
  99. +97 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/java/org.jruby.ast.rb
  100. +47 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport.rb
  101. +3 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/core_ext.rb
  102. +24 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/core_ext/kernel.rb
  103. +56 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/core_ext/module.rb
  104. +124 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/core_ext/object.rb
  105. +62 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb
  106. +37 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/proxy/array.rb
  107. +36 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/proxy/interface.rb
  108. +23 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/utilities/array.rb
  109. +17 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/javasupport/utilities/base.rb
  110. +398 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/prelude.rb
  111. +266 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/builtin/rdoc_jruby.rb
  112. +1 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi.rb
  113. +31 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/autopointer.rb
  114. +5 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/buffer.rb
  115. +82 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/enum.rb
  116. +8 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/errno.rb
  117. +145 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/ffi.rb
  118. +16 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/io.rb
  119. +196 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/library.rb
  120. +55 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/managedstruct.rb
  121. +13 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/memorypointer.rb
  122. +11 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform.rb
  123. +71 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform/errno.rb.ffi
  124. +31 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform/etc.rb.ffi
  125. +32 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform/fcntl.rb.ffi
  126. +72 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform/i386-darwin/errno.rb
  127. +31 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform/i386-darwin/etc.rb
  128. +33 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform/i386-darwin/fcntl.rb
  129. +539 −0 plugins/org.jruby/lib/ruby/site_ruby/shared/ffi/platform/i386-darwin/platform.conf
Sorry, we could not display the entire diff because it was too big.
View
43 plugins/com.aptana.util/src/com/aptana/util/ExecutableUtil.java
@@ -26,23 +26,30 @@
*/
public static IPath find(String executableName, boolean appendExtension, IPath preferencesPath, List<IPath> searchLocations)
{
- if (preferencesPath != null) {
- if (isExecutable(preferencesPath)) {
+ if (preferencesPath != null)
+ {
+ if (isExecutable(preferencesPath))
+ {
return preferencesPath;
}
}
- if (Platform.OS_WIN32.equals(Platform.getOS())) {
+ if (Platform.OS_WIN32.equals(Platform.getOS()))
+ {
// Grab PATH and search it!
String[] paths = System.getenv("PATH").split(File.pathSeparator); //$NON-NLS-1$
- for (String pathString : paths) {
+ for (String pathString : paths)
+ {
IPath path = Path.fromOSString(pathString).append(executableName);
IPath result = findExecutable(path, appendExtension);
- if (result != null) {
+ if (result != null)
+ {
return result;
}
}
- } else {
+ }
+ else
+ {
// No explicit path. Try it with "which"
String whichResult = ProcessUtil.outputForCommand("/usr/bin/which", null, executableName); //$NON-NLS-1$
if (whichResult != null && whichResult.trim().length() > 0) {
@@ -53,31 +60,41 @@ public static IPath find(String executableName, boolean appendExtension, IPath p
}
// Still no path. Let's try some default locations.
- for (IPath location : searchLocations) {
+ for (IPath location : searchLocations)
+ {
IPath result = findExecutable(location.append(executableName), appendExtension);
if (result != null)
return result;
}
return null;
}
- private static IPath findExecutable(IPath basename, boolean appendExtension) {
- if (Platform.OS_WIN32.equals(Platform.getOS()) && appendExtension) {
+ private static IPath findExecutable(IPath basename, boolean appendExtension)
+ {
+ if (Platform.OS_WIN32.equals(Platform.getOS()) && appendExtension)
+ {
String[] extensions = System.getenv("PATHEXT").split(File.pathSeparator); //$NON-NLS-1$
- for (String ext : extensions) {
+ for (String ext : extensions)
+ {
+ if (ext.startsWith("."))
+ ext = ext.substring(1);
IPath pathWithExt = basename.addFileExtension(ext);
- if (isExecutable(pathWithExt)) {
+ if (isExecutable(pathWithExt))
+ {
return pathWithExt;
}
}
- } else if (isExecutable(basename)) {
+ }
+ else if (isExecutable(basename))
+ {
return basename;
}
return null;
}
- private static boolean isExecutable(IPath path) {
+ private static boolean isExecutable(IPath path)
+ {
File file = path.toFile();
return file.exists() && file.canExecute();
}
View
50 plugins/org.jruby/lib/ruby/site_ruby/1.8/gauntlet_rubygems.rb
@@ -0,0 +1,50 @@
+require 'rubygems'
+require 'gauntlet'
+
+##
+# GemGauntlet validates all current gems. Currently these packages are
+# borked:
+#
+# Asami-0.04 : No such file or directory - bin/Asami.rb
+# ObjectGraph-1.0.1 : No such file or directory - bin/objectgraph
+# evil-ruby-0.1.0 : authors must be Array of Strings
+# fresh_cookies-1.0.0 : authors must be Array of Strings
+# plugems_deploy-0.2.0 : authors must be Array of Strings
+# pmsrb-0.2.0 : authors must be Array of Strings
+# pqa-1.6 : authors must be Array of Strings
+# rant-0.5.7 : authors must be Array of Strings
+# rvsh-0.4.5 : No such file or directory - bin/rvsh
+# xen-0.1.2.1 : authors must be Array of Strings
+
+class GemGauntlet < Gauntlet
+ def run(name)
+ warn name
+
+ spec = begin
+ Gem::Specification.load 'gemspec'
+ rescue SyntaxError
+ Gem::Specification.from_yaml File.read('gemspec')
+ end
+ spec.validate
+
+ self.data[name] = false
+ self.dirty = true
+ rescue SystemCallError, Gem::InvalidSpecificationException => e
+ self.data[name] = e.message
+ self.dirty = true
+ end
+
+ def should_skip?(name)
+ self.data[name] == false
+ end
+
+ def report
+ self.data.sort.reject { |k,v| !v }.each do |k,v|
+ puts "%-21s: %s" % [k, v]
+ end
+ end
+end
+
+gauntlet = GemGauntlet.new
+gauntlet.run_the_gauntlet ARGV.shift
+gauntlet.report
View
24 plugins/org.jruby/lib/ruby/site_ruby/1.8/gemconfigure.rb
@@ -0,0 +1,24 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+module Gem
+
+ # Activate the gems specfied by the gem_pairs list.
+ #
+ # gem_pairs ::
+ # List of gem/version pairs.
+ # Eg. [['rake', '= 0.8.15'], ['RedCloth', '~> 3.0']]
+ # options ::
+ # options[:verbose] => print gems as they are required.
+ #
+ def self.configure(gem_pairs, options={})
+ gem_pairs.each do |name, version|
+ require 'rubygems'
+ puts "Activating gem #{name} (version #{version})" if options[:verbose]
+ gem name, version
+ end
+ end
+end
View
24 plugins/org.jruby/lib/ruby/site_ruby/1.8/rbconfig/datadir.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+
+module Config
+
+ # Only define datadir if it doesn't already exist.
+ unless Config.respond_to?(:datadir)
+
+ # Return the path to the data directory associated with the given
+ # package name. Normally this is just
+ # "#{Config::CONFIG['datadir']}/#{package_name}", but may be
+ # modified by packages like RubyGems to handle versioned data
+ # directories.
+ def Config.datadir(package_name)
+ File.join(CONFIG['datadir'], package_name)
+ end
+
+ end
+end
View
1,141 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems.rb
@@ -0,0 +1,1141 @@
+# -*- ruby -*-
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'rubygems/defaults'
+require 'thread'
+require 'etc'
+
+module Gem
+
+ RubyGemsVersion = VERSION = '1.3.5'
+
+ ##
+ # Raised when RubyGems is unable to load or activate a gem. Contains the
+ # name and version requirements of the gem that either conflicts with
+ # already activated gems or that RubyGems is otherwise unable to activate.
+
+ class LoadError < ::LoadError
+
+ ##
+ # Name of gem
+
+ attr_accessor :name
+
+ ##
+ # Version requirement of gem
+
+ attr_accessor :version_requirement
+
+ end
+
+end
+
+module Kernel
+
+ ##
+ # Use Kernel#gem to activate a specific version of +gem_name+.
+ #
+ # +version_requirements+ is a list of version requirements that the
+ # specified gem must match, most commonly "= example.version.number". See
+ # Gem::Requirement for how to specify a version requirement.
+ #
+ # If you will be activating the latest version of a gem, there is no need to
+ # call Kernel#gem, Kernel#require will do the right thing for you.
+ #
+ # Kernel#gem returns true if the gem was activated, otherwise false. If the
+ # gem could not be found, didn't match the version requirements, or a
+ # different version was already activated, an exception will be raised.
+ #
+ # Kernel#gem should be called *before* any require statements (otherwise
+ # RubyGems may load a conflicting library version).
+ #
+ # In older RubyGems versions, the environment variable GEM_SKIP could be
+ # used to skip activation of specified gems, for example to test out changes
+ # that haven't been installed yet. Now RubyGems defers to -I and the
+ # RUBYLIB environment variable to skip activation of a gem.
+ #
+ # Example:
+ #
+ # GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
+
+ def gem(gem_name, *version_requirements) # :doc:
+ skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
+ raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
+ Gem.activate(gem_name, *version_requirements)
+ end
+
+ private :gem
+
+end
+
+##
+# RubyGems is the Ruby standard for publishing and managing third party
+# libraries.
+#
+# For user documentation, see:
+#
+# * <tt>gem help</tt> and <tt>gem help [command]</tt>
+# * {RubyGems User Guide}[http://docs.rubygems.org/read/book/1]
+# * {Frequently Asked Questions}[http://docs.rubygems.org/read/book/3]
+#
+# For gem developer documentation see:
+#
+# * {Creating Gems}[http://docs.rubygems.org/read/chapter/5]
+# * Gem::Specification
+#
+# Further RubyGems documentation can be found at:
+#
+# * {RubyGems API}[http://rubygems.rubyforge.org/rdoc] (also available from
+# <tt>gem server</tt>)
+# * {RubyGems Bookshelf}[http://rubygem.org]
+#
+# == RubyGems Plugins
+#
+# As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or
+# $LOAD_PATH. Plugins must be named 'rubygems_plugin' are discovered via
+# Gem::find_files then loaded. Take care when implementing a plugin as your
+# plugin file may be loaded multiple times if multiple versions of your gem
+# are installed.
+#
+# For an example plugin, see the graph gem which adds a `gem graph` command.
+#
+# == RubyGems Defaults, Packaging
+#
+# RubyGems defaults are stored in rubygems/defaults.rb. If you're packaging
+# RubyGems or implementing Ruby you can change RubyGems' defaults.
+#
+# For RubyGems packagers, provide lib/rubygems/operating_system.rb and
+# override any defaults from lib/rubygems/defaults.rb.
+#
+# For Ruby implementers, provide lib/rubygems/#{RUBY_ENGINE}.rb and override
+# any defaults from lib/rubygems/defaults.rb.
+#
+# If you need RubyGems to perform extra work on install or uninstall, your
+# defaults override file can set pre and post install and uninstall hooks.
+# See Gem::pre_install, Gem::pre_uninstall, Gem::post_install,
+# Gem::post_uninstall.
+#
+# == Bugs
+#
+# You can submit bugs to the
+# {RubyGems bug tracker}[http://rubyforge.org/tracker/?atid=575&group_id=126&func=browse]
+# on RubyForge
+#
+# == Credits
+#
+# RubyGems is currently maintained by Eric Hodel.
+#
+# RubyGems was originally developed at RubyConf 2003 by:
+#
+# * Rich Kilmer -- rich(at)infoether.com
+# * Chad Fowler -- chad(at)chadfowler.com
+# * David Black -- dblack(at)wobblini.net
+# * Paul Brannan -- paul(at)atdesk.com
+# * Jim Weirch -- {jim(at)weirichhouse.org}[mailto:jim@weirichhouse.org]
+#
+# Contributors:
+#
+# * Gavin Sinclair -- gsinclair(at)soyabean.com.au
+# * George Marrows -- george.marrows(at)ntlworld.com
+# * Dick Davies -- rasputnik(at)hellooperator.net
+# * Mauricio Fernandez -- batsman.geo(at)yahoo.com
+# * Simon Strandgaard -- neoneye(at)adslhome.dk
+# * Dave Glasser -- glasser(at)mit.edu
+# * Paul Duncan -- pabs(at)pablotron.org
+# * Ville Aine -- vaine(at)cs.helsinki.fi
+# * Eric Hodel -- drbrain(at)segment7.net
+# * Daniel Berger -- djberg96(at)gmail.com
+# * Phil Hagelberg -- technomancy(at)gmail.com
+# * Ryan Davis
+#
+# (If your name is missing, PLEASE let us know!)
+#
+# Thanks!
+#
+# -The RubyGems Team
+
+module Gem
+
+ ##
+ # Configuration settings from ::RbConfig
+
+ ConfigMap = {} unless defined?(ConfigMap)
+
+ require 'rbconfig'
+ # :stopdoc:
+ RbConfig = Config unless defined? ::RbConfig
+ # :startdoc:
+
+ ConfigMap.merge!(
+ :EXEEXT => RbConfig::CONFIG["EXEEXT"],
+ :RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
+ :arch => RbConfig::CONFIG["arch"],
+ :bindir => RbConfig::CONFIG["bindir"],
+ :datadir => RbConfig::CONFIG["datadir"],
+ :libdir => RbConfig::CONFIG["libdir"],
+ :ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
+ :ruby_version => RbConfig::CONFIG["ruby_version"],
+ :sitedir => RbConfig::CONFIG["sitedir"],
+ :sitelibdir => RbConfig::CONFIG["sitelibdir"],
+ :vendordir => RbConfig::CONFIG["vendordir"] ,
+ :vendorlibdir => RbConfig::CONFIG["vendorlibdir"]
+ )
+
+ ##
+ # Default directories in a gem repository
+
+ DIRECTORIES = %w[cache doc gems specifications] unless defined?(DIRECTORIES)
+
+ # :stopdoc:
+ MUTEX = Mutex.new
+
+ RubyGemsPackageVersion = RubyGemsVersion
+ # :startdoc:
+
+ ##
+ # An Array of Regexps that match windows ruby platforms.
+
+ WIN_PATTERNS = [
+ /bccwin/i,
+ /cygwin/i,
+ /djgpp/i,
+ /mingw/i,
+ /mswin/i,
+ /wince/i,
+ ]
+
+ @@source_index = nil
+ @@win_platform = nil
+
+ @configuration = nil
+ @loaded_specs = {}
+ @loaded_stacks = {}
+ @platforms = []
+ @ruby = nil
+ @sources = []
+
+ @post_install_hooks ||= []
+ @post_uninstall_hooks ||= []
+ @pre_uninstall_hooks ||= []
+ @pre_install_hooks ||= []
+
+ ##
+ # Activates an installed gem matching +gem+. The gem must satisfy
+ # +version_requirements+.
+ #
+ # Returns true if the gem is activated, false if it is already
+ # loaded, or an exception otherwise.
+ #
+ # Gem#activate adds the library paths in +gem+ to $LOAD_PATH. Before a Gem
+ # is activated its required Gems are activated. If the version information
+ # is omitted, the highest version Gem of the supplied name is loaded. If a
+ # Gem is not found that meets the version requirements or a required Gem is
+ # not found, a Gem::LoadError is raised.
+ #
+ # More information on version requirements can be found in the
+ # Gem::Requirement and Gem::Version documentation.
+
+ def self.activate(gem, *version_requirements)
+ if version_requirements.last.is_a?(Hash)
+ options = version_requirements.pop
+ else
+ options = {}
+ end
+
+ sources = options[:sources] || []
+
+ if version_requirements.empty? then
+ version_requirements = Gem::Requirement.default
+ end
+
+ unless gem.respond_to?(:name) and
+ gem.respond_to?(:version_requirements) then
+ gem = Gem::Dependency.new(gem, version_requirements)
+ end
+
+ matches = Gem.source_index.find_name(gem.name, gem.version_requirements)
+ report_activate_error(gem) if matches.empty?
+
+ if @loaded_specs[gem.name] then
+ # This gem is already loaded. If the currently loaded gem is not in the
+ # list of candidate gems, then we have a version conflict.
+ existing_spec = @loaded_specs[gem.name]
+
+ unless matches.any? { |spec| spec.version == existing_spec.version } then
+ sources_message = sources.map { |spec| spec.full_name }
+ stack_message = @loaded_stacks[gem.name].map { |spec| spec.full_name }
+
+ msg = "can't activate #{gem} for #{sources_message.inspect}, "
+ msg << "already activated #{existing_spec.full_name} for "
+ msg << "#{stack_message.inspect}"
+
+ e = Gem::LoadError.new msg
+ e.name = gem.name
+ e.version_requirement = gem.version_requirements
+
+ raise e
+ end
+
+ return false
+ end
+
+ # new load
+ spec = matches.last
+ return false if spec.loaded?
+
+ spec.loaded = true
+ @loaded_specs[spec.name] = spec
+ @loaded_stacks[spec.name] = sources.dup
+
+ # Load dependent gems first
+ spec.runtime_dependencies.each do |dep_gem|
+ activate dep_gem, :sources => [spec, *sources]
+ end
+
+ # bin directory must come before library directories
+ spec.require_paths.unshift spec.bindir if spec.bindir
+
+ require_paths = spec.require_paths.map do |path|
+ File.join spec.full_gem_path, path
+ end
+
+ sitelibdir = ConfigMap[:sitelibdir]
+
+ # gem directories must come after -I and ENV['RUBYLIB']
+ insert_index = load_path_insert_index
+
+ if insert_index then
+ # gem directories must come after -I and ENV['RUBYLIB']
+ $LOAD_PATH.insert(insert_index, *require_paths)
+ else
+ # we are probably testing in core, -I and RUBYLIB don't apply
+ $LOAD_PATH.unshift(*require_paths)
+ end
+
+ return true
+ end
+
+ ##
+ # An Array of all possible load paths for all versions of all gems in the
+ # Gem installation.
+
+ def self.all_load_paths
+ result = []
+
+ Gem.path.each do |gemdir|
+ each_load_path all_partials(gemdir) do |load_path|
+ result << load_path
+ end
+ end
+
+ result
+ end
+
+ ##
+ # Return all the partial paths in +gemdir+.
+
+ def self.all_partials(gemdir)
+ Dir[File.join(gemdir, 'gems/*')]
+ end
+
+ private_class_method :all_partials
+
+ ##
+ # See if a given gem is available.
+
+ def self.available?(gem, *requirements)
+ requirements = Gem::Requirement.default if requirements.empty?
+
+ unless gem.respond_to?(:name) and
+ gem.respond_to?(:version_requirements) then
+ gem = Gem::Dependency.new gem, requirements
+ end
+
+ !Gem.source_index.search(gem).empty?
+ end
+
+ ##
+ # Find the full path to the executable for gem +name+. If the +exec_name+
+ # is not given, the gem's default_executable is chosen, otherwise the
+ # specifed executable's path is returned. +version_requirements+ allows you
+ # to specify specific gem versions.
+
+ def self.bin_path(name, exec_name = nil, *version_requirements)
+ version_requirements = Gem::Requirement.default if
+ version_requirements.empty?
+ spec = Gem.source_index.find_name(name, version_requirements).last
+
+ raise Gem::GemNotFoundException,
+ "can't find gem #{name} (#{version_requirements})" unless spec
+
+ exec_name ||= spec.default_executable
+
+ unless exec_name
+ msg = "no default executable for #{spec.full_name}"
+ raise Gem::Exception, msg
+ end
+
+ unless spec.executables.include? exec_name
+ msg = "can't find executable #{exec_name} for #{spec.full_name}"
+ raise Gem::Exception, msg
+ end
+
+ File.join(spec.full_gem_path, spec.bindir, exec_name)
+ end
+
+ ##
+ # The mode needed to read a file as straight binary.
+
+ def self.binary_mode
+ @binary_mode ||= RUBY_VERSION > '1.9' ? 'rb:ascii-8bit' : 'rb'
+ end
+
+ ##
+ # The path where gem executables are to be installed.
+
+ def self.bindir(install_dir=Gem.dir)
+ return File.join(install_dir, 'bin') unless
+ install_dir.to_s == Gem.default_dir
+ Gem.default_bindir
+ end
+
+ ##
+ # Reset the +dir+ and +path+ values. The next time +dir+ or +path+
+ # is requested, the values will be calculated from scratch. This is
+ # mainly used by the unit tests to provide test isolation.
+
+ def self.clear_paths
+ @gem_home = nil
+ @gem_path = nil
+ @user_home = nil
+
+ @@source_index = nil
+
+ MUTEX.synchronize do
+ @searcher = nil
+ end
+ end
+
+ ##
+ # The path to standard location of the user's .gemrc file.
+
+ def self.config_file
+ File.join Gem.user_home, '.gemrc'
+ end
+
+ ##
+ # The standard configuration object for gems.
+
+ def self.configuration
+ @configuration ||= Gem::ConfigFile.new []
+ end
+
+ ##
+ # Use the given configuration object (which implements the ConfigFile
+ # protocol) as the standard configuration object.
+
+ def self.configuration=(config)
+ @configuration = config
+ end
+
+ ##
+ # The path the the data directory specified by the gem name. If the
+ # package is not available as a gem, return nil.
+
+ def self.datadir(gem_name)
+ spec = @loaded_specs[gem_name]
+ return nil if spec.nil?
+ File.join(spec.full_gem_path, 'data', gem_name)
+ end
+
+ ##
+ # A Zlib::Deflate.deflate wrapper
+
+ def self.deflate(data)
+ require 'zlib'
+ Zlib::Deflate.deflate data
+ end
+
+ ##
+ # The path where gems are to be installed.
+
+ def self.dir
+ @gem_home ||= nil
+ set_home(ENV['GEM_HOME'] || Gem.configuration.home || default_dir) unless @gem_home
+ @gem_home
+ end
+
+ ##
+ # Expand each partial gem path with each of the required paths specified
+ # in the Gem spec. Each expanded path is yielded.
+
+ def self.each_load_path(partials)
+ partials.each do |gp|
+ base = File.basename(gp)
+ specfn = File.join(dir, "specifications", base + ".gemspec")
+ if File.exist?(specfn)
+ spec = eval(File.read(specfn))
+ spec.require_paths.each do |rp|
+ yield(File.join(gp, rp))
+ end
+ else
+ filename = File.join(gp, 'lib')
+ yield(filename) if File.exist?(filename)
+ end
+ end
+ end
+
+ private_class_method :each_load_path
+
+ ##
+ # Quietly ensure the named Gem directory contains all the proper
+ # subdirectories. If we can't create a directory due to a permission
+ # problem, then we will silently continue.
+
+ def self.ensure_gem_subdirectories(gemdir)
+ require 'fileutils'
+
+ Gem::DIRECTORIES.each do |filename|
+ fn = File.join gemdir, filename
+ FileUtils.mkdir_p fn rescue nil unless File.exist? fn
+ end
+ end
+
+ ##
+ # Returns a list of paths matching +file+ that can be used by a gem to pick
+ # up features from other gems. For example:
+ #
+ # Gem.find_files('rdoc/discover').each do |path| load path end
+ #
+ # find_files search $LOAD_PATH for files as well as gems.
+ #
+ # Note that find_files will return all files even if they are from different
+ # versions of the same gem.
+
+ def self.find_files(path)
+ load_path_files = $LOAD_PATH.map do |load_path|
+ files = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
+
+ files.select do |load_path_file|
+ File.file? load_path_file.untaint
+ end
+ end.flatten
+
+ specs = searcher.find_all path
+
+ specs_files = specs.map do |spec|
+ searcher.matching_files spec, path
+ end.flatten
+
+ (load_path_files + specs_files).flatten.uniq
+ end
+
+ ##
+ # Finds the user's home directory.
+ #--
+ # Some comments from the ruby-talk list regarding finding the home
+ # directory:
+ #
+ # I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems
+ # to be depending on HOME in those code samples. I propose that
+ # it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at
+ # least on Win32).
+
+ def self.find_home
+ ['HOME', 'USERPROFILE'].each do |homekey|
+ return ENV[homekey] if ENV[homekey]
+ end
+
+ if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
+ return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
+ end
+
+ begin
+ File.expand_path("~")
+ rescue
+ if File::ALT_SEPARATOR then
+ "C:/"
+ else
+ "/"
+ end
+ end
+ end
+
+ private_class_method :find_home
+
+ ##
+ # Zlib::GzipReader wrapper that unzips +data+.
+
+ def self.gunzip(data)
+ require 'stringio'
+ require 'zlib'
+ data = StringIO.new data
+
+ Zlib::GzipReader.new(data).read
+ end
+
+ ##
+ # Zlib::GzipWriter wrapper that zips +data+.
+
+ def self.gzip(data)
+ require 'stringio'
+ require 'zlib'
+ zipped = StringIO.new
+
+ Zlib::GzipWriter.wrap zipped do |io| io.write data end
+
+ zipped.string
+ end
+
+ ##
+ # A Zlib::Inflate#inflate wrapper
+
+ def self.inflate(data)
+ require 'zlib'
+ Zlib::Inflate.inflate data
+ end
+
+ ##
+ # Return a list of all possible load paths for the latest version for all
+ # gems in the Gem installation.
+
+ def self.latest_load_paths
+ result = []
+
+ Gem.path.each do |gemdir|
+ each_load_path(latest_partials(gemdir)) do |load_path|
+ result << load_path
+ end
+ end
+
+ result
+ end
+
+ ##
+ # Return only the latest partial paths in the given +gemdir+.
+
+ def self.latest_partials(gemdir)
+ latest = {}
+ all_partials(gemdir).each do |gp|
+ base = File.basename(gp)
+ if base =~ /(.*)-((\d+\.)*\d+)/ then
+ name, version = $1, $2
+ ver = Gem::Version.new(version)
+ if latest[name].nil? || ver > latest[name][0]
+ latest[name] = [ver, gp]
+ end
+ end
+ end
+ latest.collect { |k,v| v[1] }
+ end
+
+ private_class_method :latest_partials
+
+ ##
+ # The index to insert activated gem paths into the $LOAD_PATH.
+ #
+ # Defaults to the site lib directory unless gem_prelude.rb has loaded paths,
+ # then it inserts the activated gem's paths before the gem_prelude.rb paths
+ # so you can override the gem_prelude.rb default $LOAD_PATH paths.
+
+ def self.load_path_insert_index
+ index = $LOAD_PATH.index ConfigMap[:sitelibdir]
+
+ $LOAD_PATH.each_with_index do |path, i|
+ if path.instance_variables.include?(:@gem_prelude_index) or
+ path.instance_variables.include?('@gem_prelude_index') then
+ index = i
+ break
+ end
+ end
+
+ index
+ end
+
+ ##
+ # The file name and line number of the caller of the caller of this method.
+
+ def self.location_of_caller
+ caller[1] =~ /(.*?):(\d+).*?$/i
+ file = $1
+ lineno = $2.to_i
+
+ [file, lineno]
+ end
+
+ ##
+ # The version of the Marshal format for your Ruby.
+
+ def self.marshal_version
+ "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
+ end
+
+ ##
+ # Array of paths to search for Gems.
+
+ def self.path
+ @gem_path ||= nil
+
+ unless @gem_path then
+ paths = [ENV['GEM_PATH'] || Gem.configuration.path || default_path]
+
+ if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
+ paths << APPLE_GEM_HOME
+ end
+
+ set_paths paths.compact.join(File::PATH_SEPARATOR)
+ end
+
+ @gem_path
+ end
+
+ ##
+ # Set array of platforms this RubyGems supports (primarily for testing).
+
+ def self.platforms=(platforms)
+ @platforms = platforms
+ end
+
+ ##
+ # Array of platforms this RubyGems supports.
+
+ def self.platforms
+ @platforms ||= []
+ if @platforms.empty?
+ @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
+ end
+ @platforms
+ end
+
+ ##
+ # Adds a post-install hook that will be passed an Gem::Installer instance
+ # when Gem::Installer#install is called
+
+ def self.post_install(&hook)
+ @post_install_hooks << hook
+ end
+
+ ##
+ # Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance
+ # and the spec that was uninstalled when Gem::Uninstaller#uninstall is
+ # called
+
+ def self.post_uninstall(&hook)
+ @post_uninstall_hooks << hook
+ end
+
+ ##
+ # Adds a pre-install hook that will be passed an Gem::Installer instance
+ # when Gem::Installer#install is called
+
+ def self.pre_install(&hook)
+ @pre_install_hooks << hook
+ end
+
+ ##
+ # Adds a pre-uninstall hook that will be passed an Gem::Uninstaller instance
+ # and the spec that will be uninstalled when Gem::Uninstaller#uninstall is
+ # called
+
+ def self.pre_uninstall(&hook)
+ @pre_uninstall_hooks << hook
+ end
+
+ ##
+ # The directory prefix this RubyGems was installed at.
+
+ def self.prefix
+ prefix = File.dirname File.expand_path(__FILE__)
+
+ if File.dirname(prefix) == File.expand_path(ConfigMap[:sitelibdir]) or
+ File.dirname(prefix) == File.expand_path(ConfigMap[:libdir]) or
+ 'lib' != File.basename(prefix) then
+ nil
+ else
+ File.dirname prefix
+ end
+ end
+
+ ##
+ # Promotes the load paths of the +gem_name+ over the load paths of
+ # +over_name+. Useful for allowing one gem to override features in another
+ # using #find_files.
+
+ def self.promote_load_path(gem_name, over_name)
+ gem = Gem.loaded_specs[gem_name]
+ over = Gem.loaded_specs[over_name]
+
+ raise ArgumentError, "gem #{gem_name} is not activated" if gem.nil?
+ raise ArgumentError, "gem #{over_name} is not activated" if over.nil?
+
+ last_gem_path = File.join gem.full_gem_path, gem.require_paths.last
+
+ over_paths = over.require_paths.map do |path|
+ File.join over.full_gem_path, path
+ end
+
+ over_paths.each do |path|
+ $LOAD_PATH.delete path
+ end
+
+ gem = $LOAD_PATH.index(last_gem_path) + 1
+
+ $LOAD_PATH.insert(gem, *over_paths)
+ end
+
+ ##
+ # Refresh source_index from disk and clear searcher.
+
+ def self.refresh
+ source_index.refresh!
+
+ MUTEX.synchronize do
+ @searcher = nil
+ end
+ end
+
+ ##
+ # Safely read a file in binary mode on all platforms.
+
+ def self.read_binary(path)
+ File.open path, binary_mode do |f| f.read end
+ end
+
+ ##
+ # Report a load error during activation. The message of load error
+ # depends on whether it was a version mismatch or if there are not gems of
+ # any version by the requested name.
+
+ def self.report_activate_error(gem)
+ matches = Gem.source_index.find_name(gem.name)
+
+ if matches.empty? then
+ error = Gem::LoadError.new(
+ "Could not find RubyGem #{gem.name} (#{gem.version_requirements})\n")
+ else
+ error = Gem::LoadError.new(
+ "RubyGem version error: " +
+ "#{gem.name}(#{matches.first.version} not #{gem.version_requirements})\n")
+ end
+
+ error.name = gem.name
+ error.version_requirement = gem.version_requirements
+ raise error
+ end
+
+ private_class_method :report_activate_error
+
+ ##
+ # Full path to +libfile+ in +gemname+. Searches for the latest gem unless
+ # +requirements+ is given.
+
+ def self.required_location(gemname, libfile, *requirements)
+ requirements = Gem::Requirement.default if requirements.empty?
+
+ matches = Gem.source_index.find_name gemname, requirements
+
+ return nil if matches.empty?
+
+ spec = matches.last
+ spec.require_paths.each do |path|
+ result = File.join spec.full_gem_path, path, libfile
+ return result if File.exist? result
+ end
+
+ nil
+ end
+
+ ##
+ # The path to the running Ruby interpreter.
+
+ def self.ruby
+ if @ruby.nil? then
+ @ruby = File.join(ConfigMap[:bindir],
+ ConfigMap[:ruby_install_name])
+ @ruby << ConfigMap[:EXEEXT]
+
+ # escape string in case path to ruby executable contain spaces.
+ @ruby.sub!(/.*\s.*/m, '"\&"')
+ end
+
+ @ruby
+ end
+
+ ##
+ # A Gem::Version for the currently running ruby.
+
+ def self.ruby_version
+ return @ruby_version if defined? @ruby_version
+ version = RUBY_VERSION.dup
+
+ if defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL != -1 then
+ version << ".#{RUBY_PATCHLEVEL}"
+ elsif defined?(RUBY_REVISION) then
+ version << ".dev.#{RUBY_REVISION}"
+ end
+
+ @ruby_version = Gem::Version.new version
+ end
+
+ ##
+ # The GemPathSearcher object used to search for matching installed gems.
+
+ def self.searcher
+ MUTEX.synchronize do
+ @searcher ||= Gem::GemPathSearcher.new
+ end
+ end
+
+ ##
+ # Set the Gem home directory (as reported by Gem.dir).
+
+ def self.set_home(home)
+ home = home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
+ @gem_home = home
+ ensure_gem_subdirectories(@gem_home)
+ end
+
+ private_class_method :set_home
+
+ ##
+ # Set the Gem search path (as reported by Gem.path).
+
+ def self.set_paths(gpaths)
+ if gpaths
+ @gem_path = gpaths.split(File::PATH_SEPARATOR)
+
+ if File::ALT_SEPARATOR then
+ @gem_path.map! do |path|
+ path.gsub File::ALT_SEPARATOR, File::SEPARATOR
+ end
+ end
+
+ @gem_path << Gem.dir
+ else
+ # TODO: should this be Gem.default_path instead?
+ @gem_path = [Gem.dir]
+ end
+
+ @gem_path.uniq!
+ @gem_path.each do |path|
+ if 0 == File.expand_path(path).index(Gem.user_home)
+ next unless File.directory? Gem.user_home
+ unless win_platform? then
+ # only create by matching user
+ if Etc.getpwuid.nil? || Etc.getpwuid.uid != File::Stat.new(Gem.user_home).uid
+ next
+ end
+ end
+ end
+ ensure_gem_subdirectories path
+ end
+ end
+
+ private_class_method :set_paths
+
+ ##
+ # Returns the Gem::SourceIndex of specifications that are in the Gem.path
+
+ def self.source_index
+ @@source_index ||= SourceIndex.from_installed_gems
+ end
+
+ ##
+ # Returns an Array of sources to fetch remote gems from. If the sources
+ # list is empty, attempts to load the "sources" gem, then uses
+ # default_sources if it is not installed.
+
+ def self.sources
+ if @sources.empty? then
+ begin
+ gem 'sources', '> 0.0.1'
+ require 'sources'
+ rescue LoadError
+ @sources = default_sources
+ end
+ end
+
+ @sources
+ end
+
+ ##
+ # Need to be able to set the sources without calling
+ # Gem.sources.replace since that would cause an infinite loop.
+
+ def self.sources=(new_sources)
+ @sources = new_sources
+ end
+
+ ##
+ # Glob pattern for require-able path suffixes.
+
+ def self.suffix_pattern
+ @suffix_pattern ||= "{#{suffixes.join(',')}}"
+ end
+
+ ##
+ # Suffixes for require-able paths.
+
+ def self.suffixes
+ ['', '.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar']
+ end
+
+ ##
+ # Prints the amount of time the supplied block takes to run using the debug
+ # UI output.
+
+ def self.time(msg, width = 0, display = Gem.configuration.verbose)
+ now = Time.now
+
+ value = yield
+
+ elapsed = Time.now - now
+
+ ui.say "%2$*1$s: %3$3.3fs" % [-width, msg, elapsed] if display
+
+ value
+ end
+
+ ##
+ # Lazily loads DefaultUserInteraction and returns the default UI.
+
+ def self.ui
+ require 'rubygems/user_interaction'
+
+ Gem::DefaultUserInteraction.ui
+ end
+
+ ##
+ # Use the +home+ and +paths+ values for Gem.dir and Gem.path. Used mainly
+ # by the unit tests to provide environment isolation.
+
+ def self.use_paths(home, paths=[])
+ clear_paths
+ set_home(home) if home
+ set_paths(paths.join(File::PATH_SEPARATOR)) if paths
+ end
+
+ ##
+ # The home directory for the user.
+
+ def self.user_home
+ @user_home ||= find_home
+ end
+
+ ##
+ # Is this a windows platform?
+
+ def self.win_platform?
+ if @@win_platform.nil? then
+ @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
+ end
+
+ @@win_platform
+ end
+
+ class << self
+
+ ##
+ # Hash of loaded Gem::Specification keyed by name
+
+ attr_reader :loaded_specs
+
+ ##
+ # The list of hooks to be run before Gem::Install#install does any work
+
+ attr_reader :post_install_hooks
+
+ ##
+ # The list of hooks to be run before Gem::Uninstall#uninstall does any
+ # work
+
+ attr_reader :post_uninstall_hooks
+
+ ##
+ # The list of hooks to be run after Gem::Install#install is finished
+
+ attr_reader :pre_install_hooks
+
+ ##
+ # The list of hooks to be run after Gem::Uninstall#uninstall is finished
+
+ attr_reader :pre_uninstall_hooks
+
+ # :stopdoc:
+
+ alias cache source_index # an alias for the old name
+
+ # :startdoc:
+
+ end
+
+ ##
+ # Location of Marshal quick gemspecs on remote repositories
+
+ MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"
+
+ ##
+ # Location of legacy YAML quick gemspecs on remote repositories
+
+ YAML_SPEC_DIR = 'quick/'
+
+end
+
+module Config
+ # :stopdoc:
+ class << self
+ # Return the path to the data directory associated with the named
+ # package. If the package is loaded as a gem, return the gem
+ # specific data directory. Otherwise return a path to the share
+ # area as define by "#{ConfigMap[:datadir]}/#{package_name}".
+ def datadir(package_name)
+ Gem.datadir(package_name) ||
+ File.join(Gem::ConfigMap[:datadir], package_name)
+ end
+ end
+ # :startdoc:
+end
+
+require 'rubygems/exceptions'
+require 'rubygems/version'
+require 'rubygems/requirement'
+require 'rubygems/dependency'
+require 'rubygems/gem_path_searcher' # Needed for Kernel#gem
+require 'rubygems/source_index' # Needed for Kernel#gem
+require 'rubygems/platform'
+require 'rubygems/builder' # HACK: Needed for rake's package task.
+
+begin
+ require 'rubygems/defaults/operating_system'
+rescue LoadError
+end
+
+if defined?(RUBY_ENGINE) then
+ begin
+ require "rubygems/defaults/#{RUBY_ENGINE}"
+ rescue LoadError
+ end
+end
+
+require 'rubygems/config_file'
+
+#if RUBY_VERSION < '1.9' then
+ require 'rubygems/custom_require'
+#end
+
+Gem.clear_paths
+
+plugins = Gem.find_files 'rubygems_plugin'
+
+plugins.each do |plugin|
+ begin
+ load plugin
+ rescue => e
+ warn "error loading #{plugin.inspect}: #{e.message} (#{e.class})"
+ end
+end
+
View
90 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/builder.rb
@@ -0,0 +1,90 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+##
+# The Builder class processes RubyGem specification files
+# to produce a .gem file.
+
+class Gem::Builder
+
+ include Gem::UserInteraction
+ ##
+ # Constructs a builder instance for the provided specification
+ #
+ # spec:: [Gem::Specification] The specification instance
+
+ def initialize(spec)
+ require "yaml"
+ require "rubygems/package"
+ require "rubygems/security"
+
+ @spec = spec
+ end
+
+ ##
+ # Builds the gem from the specification. Returns the name of the file
+ # written.
+
+ def build
+ @spec.mark_version
+ @spec.validate
+ @signer = sign
+ write_package
+ say success
+ @spec.file_name
+ end
+
+ def success
+ <<-EOM
+ Successfully built RubyGem
+ Name: #{@spec.name}
+ Version: #{@spec.version}
+ File: #{@spec.full_name+'.gem'}
+EOM
+ end
+
+ private
+
+ ##
+ # If the signing key was specified, then load the file, and swap to the
+ # public key (TODO: we should probably just omit the signing key in favor of
+ # the signing certificate, but that's for the future, also the signature
+ # algorithm should be configurable)
+
+ def sign
+ signer = nil
+
+ if @spec.respond_to?(:signing_key) and @spec.signing_key then
+ signer = Gem::Security::Signer.new @spec.signing_key, @spec.cert_chain
+ @spec.signing_key = nil
+ @spec.cert_chain = signer.cert_chain.map { |cert| cert.to_s }
+ end
+
+ signer
+ end
+
+ def write_package
+ open @spec.file_name, 'wb' do |gem_io|
+ Gem::Package.open gem_io, 'w', @signer do |pkg|
+ pkg.metadata = @spec.to_yaml
+
+ @spec.files.each do |file|
+ next if File.directory? file
+ next if file == @spec.file_name # Don't add gem onto itself
+
+ stat = File.stat file
+ mode = stat.mode & 0777
+ size = stat.size
+
+ pkg.add_file_simple file, mode, size do |tar_io|
+ tar_io.write open(file, "rb") { |f| f.read }
+ end
+ end
+ end
+ end
+ end
+end
+
View
511 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/command.rb
@@ -0,0 +1,511 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'optparse'
+require 'rubygems/user_interaction'
+
+##
+# Base class for all Gem commands. When creating a new gem command, define
+# #new, #execute, #arguments, #defaults_str, #description and #usage
+# (as appropriate). See the above mentioned methods for details.
+#
+# A very good example to look at is Gem::Commands::ContentsCommand
+
+class Gem::Command
+
+ include Gem::UserInteraction
+
+ ##
+ # The name of the command.
+
+ attr_reader :command
+
+ ##
+ # The options for the command.
+
+ attr_reader :options
+
+ ##
+ # The default options for the command.
+
+ attr_accessor :defaults
+
+ ##
+ # The name of the command for command-line invocation.
+
+ attr_accessor :program_name
+
+ ##
+ # A short description of the command.
+
+ attr_accessor :summary
+
+ ##
+ # Arguments used when building gems
+
+ def self.build_args
+ @build_args ||= []
+ end
+
+ def self.build_args=(value)
+ @build_args = value
+ end
+
+ def self.common_options
+ @common_options ||= []
+ end
+
+ def self.add_common_option(*args, &handler)
+ Gem::Command.common_options << [args, handler]
+ end
+
+ def self.extra_args
+ @extra_args ||= []
+ end
+
+ def self.extra_args=(value)
+ case value
+ when Array
+ @extra_args = value
+ when String
+ @extra_args = value.split
+ end
+ end
+
+ ##
+ # Return an array of extra arguments for the command. The extra arguments
+ # come from the gem configuration file read at program startup.
+
+ def self.specific_extra_args(cmd)
+ specific_extra_args_hash[cmd]
+ end
+
+ ##
+ # Add a list of extra arguments for the given command. +args+ may be an
+ # array or a string to be split on white space.
+
+ def self.add_specific_extra_args(cmd,args)
+ args = args.split(/\s+/) if args.kind_of? String
+ specific_extra_args_hash[cmd] = args
+ end
+
+ ##
+ # Accessor for the specific extra args hash (self initializing).
+
+ def self.specific_extra_args_hash
+ @specific_extra_args_hash ||= Hash.new do |h,k|
+ h[k] = Array.new
+ end
+ end
+
+ ##
+ # Initializes a generic gem command named +command+. +summary+ is a short
+ # description displayed in `gem help commands`. +defaults+ are the default
+ # options. Defaults should be mirrored in #defaults_str, unless there are
+ # none.
+ #
+ # When defining a new command subclass, use add_option to add command-line
+ # switches.
+ #
+ # Unhandled arguments (gem names, files, etc.) are left in
+ # <tt>options[:args]</tt>.
+
+ def initialize(command, summary=nil, defaults={})
+ @command = command
+ @summary = summary
+ @program_name = "gem #{command}"
+ @defaults = defaults
+ @options = defaults.dup
+ @option_groups = Hash.new { |h,k| h[k] = [] }
+ @parser = nil
+ @when_invoked = nil
+ end
+
+ ##
+ # True if +long+ begins with the characters from +short+.
+
+ def begins?(long, short)
+ return false if short.nil?
+ long[0, short.length] == short
+ end
+
+ ##
+ # Override to provide command handling.
+ #
+ # #options will be filled in with your parsed options, unparsed options will
+ # be left in <tt>options[:args]</tt>.
+ #
+ # See also: #get_all_gem_names, #get_one_gem_name,
+ # #get_one_optional_argument
+
+ def execute
+ raise Gem::Exception, "generic command has no actions"
+ end
+
+ ##
+ # Get all gem names from the command line.
+
+ def get_all_gem_names
+ args = options[:args]
+
+ if args.nil? or args.empty? then
+ raise Gem::CommandLineError,
+ "Please specify at least one gem name (e.g. gem build GEMNAME)"
+ end
+
+ gem_names = args.select { |arg| arg !~ /^-/ }
+ end
+
+ ##
+ # Get the single gem name from the command line. Fail if there is no gem
+ # name or if there is more than one gem name given.
+
+ def get_one_gem_name
+ args = options[:args]
+
+ if args.nil? or args.empty? then
+ raise Gem::CommandLineError,
+ "Please specify a gem name on the command line (e.g. gem build GEMNAME)"
+ end
+
+ if args.size > 1 then
+ raise Gem::CommandLineError,
+ "Too many gem names (#{args.join(', ')}); please specify only one"
+ end
+
+ args.first
+ end
+
+ ##
+ # Get a single optional argument from the command line. If more than one
+ # argument is given, return only the first. Return nil if none are given.
+
+ def get_one_optional_argument
+ args = options[:args] || []
+ args.first
+ end
+
+ ##
+ # Override to provide details of the arguments a command takes. It should
+ # return a left-justified string, one argument per line.
+ #
+ # For example:
+ #
+ # def usage
+ # "#{program_name} FILE [FILE ...]"
+ # end
+ #
+ # def arguments
+ # "FILE name of file to find"
+ # end
+
+ def arguments
+ ""
+ end
+
+ ##
+ # Override to display the default values of the command options. (similar to
+ # +arguments+, but displays the default values).
+ #
+ # For example:
+ #
+ # def defaults_str
+ # --no-gems-first --no-all
+ # end
+
+ def defaults_str
+ ""
+ end
+
+ ##
+ # Override to display a longer description of what this command does.
+
+ def description
+ nil
+ end
+
+ ##
+ # Override to display the usage for an individual gem command.
+ #
+ # The text "[options]" is automatically appended to the usage text.
+
+ def usage
+ program_name
+ end
+
+ ##
+ # Display the help message for the command.
+
+ def show_help
+ parser.program_name = usage
+ say parser
+ end
+
+ ##
+ # Invoke the command with the given list of arguments.
+
+ def invoke(*args)
+ handle_options(args)
+ if options[:help]
+ show_help
+ elsif @when_invoked
+ @when_invoked.call(options)
+ else
+ execute
+ end
+ end
+
+ ##
+ # Call the given block when invoked.
+ #
+ # Normal command invocations just executes the +execute+ method of the
+ # command. Specifying an invocation block allows the test methods to
+ # override the normal action of a command to determine that it has been
+ # invoked correctly.
+
+ def when_invoked(&block)
+ @when_invoked = block
+ end
+
+ ##
+ # Add a command-line option and handler to the command.
+ #
+ # See OptionParser#make_switch for an explanation of +opts+.
+ #
+ # +handler+ will be called with two values, the value of the argument and
+ # the options hash.
+ #
+ # If the first argument of add_option is a Symbol, it's used to group
+ # options in output. See `gem help list` for an example.
+
+ def add_option(*opts, &handler) # :yields: value, options
+ group_name = Symbol === opts.first ? opts.shift : :options
+
+ @option_groups[group_name] << [opts, handler]
+ end
+
+ ##
+ # Remove previously defined command-line argument +name+.
+
+ def remove_option(name)
+ @option_groups.each do |_, option_list|
+ option_list.reject! { |args, _| args.any? { |x| x =~ /^#{name}/ } }
+ end
+ end
+
+ ##
+ # Merge a set of command options with the set of default options (without
+ # modifying the default option hash).
+
+ def merge_options(new_options)
+ @options = @defaults.clone
+ new_options.each do |k,v| @options[k] = v end
+ end
+
+ ##
+ # True if the command handles the given argument list.
+
+ def handles?(args)
+ begin
+ parser.parse!(args.dup)
+ return true
+ rescue
+ return false
+ end
+ end
+
+ ##
+ # Handle the given list of arguments by parsing them and recording the
+ # results.
+
+ def handle_options(args)
+ args = add_extra_args(args)
+ @options = @defaults.clone
+ parser.parse!(args)
+ @options[:args] = args
+ end
+
+ ##
+ # Adds extra args from ~/.gemrc
+
+ def add_extra_args(args)
+ result = []
+
+ s_extra = Gem::Command.specific_extra_args(@command)
+ extra = Gem::Command.extra_args + s_extra
+
+ until extra.empty? do
+ ex = []
+ ex << extra.shift
+ ex << extra.shift if extra.first.to_s =~ /^[^-]/
+ result << ex if handles?(ex)
+ end
+
+ result.flatten!
+ result.concat(args)
+ result
+ end
+
+ private
+
+ ##
+ # Create on demand parser.
+
+ def parser
+ create_option_parser if @parser.nil?
+ @parser
+ end
+
+ def create_option_parser
+ @parser = OptionParser.new
+
+ @parser.separator("")
+ regular_options = @option_groups.delete :options
+
+ configure_options "", regular_options
+
+ @option_groups.sort_by { |n,_| n.to_s }.each do |group_name, option_list|
+ configure_options group_name, option_list
+ end
+
+ configure_options "Common", Gem::Command.common_options
+
+ @parser.separator("")
+ unless arguments.empty?
+ @parser.separator(" Arguments:")
+ arguments.split(/\n/).each do |arg_desc|
+ @parser.separator(" #{arg_desc}")
+ end
+ @parser.separator("")
+ end
+
+ @parser.separator(" Summary:")
+ wrap(@summary, 80 - 4).split("\n").each do |line|
+ @parser.separator(" #{line.strip}")
+ end
+
+ if description then
+ formatted = description.split("\n\n").map do |chunk|
+ wrap(chunk, 80 - 4)
+ end.join("\n")
+
+ @parser.separator ""
+ @parser.separator " Description:"
+ formatted.split("\n").each do |line|
+ @parser.separator " #{line.rstrip}"
+ end
+ end
+
+ unless defaults_str.empty?
+ @parser.separator("")
+ @parser.separator(" Defaults:")
+ defaults_str.split(/\n/).each do |line|
+ @parser.separator(" #{line}")
+ end
+ end
+ end
+
+ def configure_options(header, option_list)
+ return if option_list.nil? or option_list.empty?
+
+ header = header.to_s.empty? ? '' : "#{header} "
+ @parser.separator " #{header}Options:"
+
+ option_list.each do |args, handler|
+ dashes = args.select { |arg| arg =~ /^-/ }
+ @parser.on(*args) do |value|
+ handler.call(value, @options)
+ end
+ end
+
+ @parser.separator ''
+ end
+
+ ##
+ # Wraps +text+ to +width+
+
+ def wrap(text, width) # :doc:
+ text.gsub(/(.{1,#{width}})( +|$\n?)|(.{1,#{width}})/, "\\1\\3\n")
+ end
+
+ # ----------------------------------------------------------------
+ # Add the options common to all commands.
+
+ add_common_option('-h', '--help',
+ 'Get help on this command') do |value, options|
+ options[:help] = true
+ end
+
+ add_common_option('-V', '--[no-]verbose',
+ 'Set the verbose level of output') do |value, options|
+ # Set us to "really verbose" so the progress meter works
+ if Gem.configuration.verbose and value then
+ Gem.configuration.verbose = 1
+ else
+ Gem.configuration.verbose = value
+ end
+ end
+
+ add_common_option('-q', '--quiet', 'Silence commands') do |value, options|
+ Gem.configuration.verbose = false
+ end
+
+ # Backtrace and config-file are added so they show up in the help
+ # commands. Both options are actually handled before the other
+ # options get parsed.
+
+ add_common_option('--config-file FILE',
+ 'Use this config file instead of default') do
+ end
+
+ add_common_option('--backtrace',
+ 'Show stack backtrace on errors') do
+ end
+
+ add_common_option('--debug',
+ 'Turn on Ruby debugging') do
+ end
+
+ # :stopdoc:
+
+ HELP = %{
+ RubyGems is a sophisticated package manager for Ruby. This is a
+ basic help message containing pointers to more information.
+
+ Usage:
+ gem -h/--help
+ gem -v/--version
+ gem command [arguments...] [options...]
+
+ Examples:
+ gem install rake
+ gem list --local
+ gem build package.gemspec
+ gem help install
+
+ Further help:
+ gem help commands list all 'gem' commands
+ gem help examples show some examples of usage
+ gem help platforms show information about platforms
+ gem help <COMMAND> show help on COMMAND
+ (e.g. 'gem help install')
+ gem server present a web page at
+ http://localhost:8808/
+ with info about installed gems
+ Further information:
+ http://rubygems.rubyforge.org
+ }.gsub(/^ /, '')
+
+ # :startdoc:
+
+end
+
+##
+# This is where Commands will be placed in the namespace
+
+module Gem::Commands
+end
+
View
174 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb
@@ -0,0 +1,174 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'timeout'
+require 'rubygems/command'
+require 'rubygems/user_interaction'
+
+##
+# The command manager registers and installs all the individual sub-commands
+# supported by the gem command.
+#
+# Extra commands can be provided by writing a rubygems_plugin.rb
+# file in an installed gem. You should register your command against the
+# Gem::CommandManager instance, like this:
+#
+# # file rubygems_plugin.rb
+# require 'rubygems/command_manager'
+#
+# class Gem::Commands::EditCommand < Gem::Command
+# # ...
+# end
+#
+# Gem::CommandManager.instance.register_command :edit
+#
+# See Gem::Command for instructions on writing gem commands.
+
+class Gem::CommandManager
+
+ include Gem::UserInteraction
+
+ ##
+ # Return the authoritative instance of the command manager.
+
+ def self.instance
+ @command_manager ||= new
+ end
+
+ ##
+ # Register all the subcommands supported by the gem command.
+
+ def initialize
+ @commands = {}
+ register_command :build
+ register_command :cert
+ register_command :check
+ register_command :cleanup
+ register_command :contents
+ register_command :dependency
+ register_command :environment
+ register_command :fetch
+ register_command :generate_index
+ register_command :help
+ register_command :install
+ register_command :list
+ register_command :lock
+ register_command :mirror
+ register_command :outdated
+ register_command :pristine
+ register_command :query
+ register_command :rdoc
+ register_command :search
+ register_command :server
+ register_command :sources
+ register_command :specification
+ register_command :stale
+ register_command :uninstall
+ register_command :unpack
+ register_command :update
+ register_command :which
+ end
+
+ ##
+ # Register the command object.
+
+ def register_command(command_obj)
+ @commands[command_obj] = false
+ end
+
+ ##
+ # Return the registered command from the command name.
+
+ def [](command_name)
+ command_name = command_name.intern
+ return nil if @commands[command_name].nil?
+ @commands[command_name] ||= load_and_instantiate(command_name)
+ end
+
+ ##
+ # Return a sorted list of all command names (as strings).
+
+ def command_names
+ @commands.keys.collect {|key| key.to_s}.sort
+ end
+
+ ##
+ # Run the config specified by +args+.
+
+ def run(args)
+ process_args(args)
+ rescue StandardError, Timeout::Error => ex
+ alert_error "While executing gem ... (#{ex.class})\n #{ex.to_s}"
+ ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
+ Gem.configuration.backtrace
+ terminate_interaction(1)
+ rescue Interrupt
+ alert_error "Interrupted"
+ terminate_interaction(1)
+ end
+
+ def process_args(args)
+ args = args.to_str.split(/\s+/) if args.respond_to?(:to_str)
+ if args.size == 0
+ say Gem::Command::HELP
+ terminate_interaction(1)
+ end
+ case args[0]
+ when '-h', '--help'
+ say Gem::Command::HELP
+ terminate_interaction(0)
+ when '-v', '--version'
+ say Gem::RubyGemsVersion
+ terminate_interaction(0)
+ when /^-/
+ alert_error "Invalid option: #{args[0]}. See 'gem --help'."
+ terminate_interaction(1)
+ else
+ cmd_name = args.shift.downcase
+ cmd = find_command(cmd_name)
+ cmd.invoke(*args)
+ end
+ end
+
+ def find_command(cmd_name)
+ possibilities = find_command_possibilities cmd_name
+ if possibilities.size > 1 then
+ raise "Ambiguous command #{cmd_name} matches [#{possibilities.join(', ')}]"
+ elsif possibilities.size < 1 then
+ raise "Unknown command #{cmd_name}"
+ end
+
+ self[possibilities.first]
+ end
+
+ def find_command_possibilities(cmd_name)
+ len = cmd_name.length
+
+ command_names.select { |n| cmd_name == n[0, len] }
+ end
+
+ private
+
+ def load_and_instantiate(command_name)
+ command_name = command_name.to_s
+ retried = false
+
+ begin
+ const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase }
+ Gem::Commands.const_get("#{const_name}Command").new
+ rescue NameError
+ if retried then
+ raise
+ else
+ retried = true
+ require "rubygems/commands/#{command_name}_command"
+ retry
+ end
+ end
+ end
+
+end
+
View
53 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/build_command.rb
@@ -0,0 +1,53 @@
+require 'rubygems/command'
+require 'rubygems/builder'
+
+class Gem::Commands::BuildCommand < Gem::Command
+
+ def initialize
+ super('build', 'Build a gem from a gemspec')
+ end
+
+ def arguments # :nodoc:
+ "GEMSPEC_FILE gemspec file name to build a gem for"
+ end
+
+ def usage # :nodoc:
+ "#{program_name} GEMSPEC_FILE"
+ end
+
+ def execute
+ gemspec = get_one_gem_name
+ if File.exist?(gemspec)
+ specs = load_gemspecs(gemspec)
+ specs.each do |spec|
+ Gem::Builder.new(spec).build
+ end
+ else
+ alert_error "Gemspec file not found: #{gemspec}"
+ end
+ end
+
+ def load_gemspecs(filename)
+ if yaml?(filename)
+ result = []
+ open(filename) do |f|
+ begin
+ while not f.eof? and spec = Gem::Specification.from_yaml(f)
+ result << spec
+ end
+ rescue Gem::EndOfYAMLException => e
+ # OK
+ end
+ end
+ else
+ result = [Gem::Specification.load(filename)]
+ end
+ result
+ end
+
+ def yaml?(filename)
+ line = open(filename) { |f| line = f.gets }
+ result = line =~ %r{!ruby/object:Gem::Specification}
+ result
+ end
+end
View
86 plugins/org.jruby/lib/ruby/site_ruby/1.8/rubygems/commands/cert_command.rb
@@ -0,0 +1,86 @@
+require 'rubygems/command'
+require 'rubygems/security'
+
+class Gem::Commands::CertCommand < Gem::Command
+
+ def initialize
+ super 'cert', 'Manage RubyGems certificates and signing settings'
+
+ add_option('-a', '--add CERT',
+ 'Add a trusted certificate.') do |value, options|
+ cert = OpenSSL::X509::Certificate.new(File.read(value))
+ Gem::Security.add_trusted_cert(cert)
+ say "Added '#{cert.subject.to_s}'"
+ end
+
+ add_option('-l', '--list',
+ 'List trusted certificates.') do |value, options|
+ glob_str = File::join(Gem::Security::OPT[:trust_dir], '*.pem')
+ Dir::glob(glob_str) do |path|
+ begin
+ cert = OpenSSL::X509::Certificate.new(File.read(path))
+ # this could probably be formatted more gracefully
+ say cert.subject.to_s
+ rescue OpenSSL::X509::CertificateError
+ next
+ end
+ end
+ end
+
+ add_option('-r', '--remove STRING',
+ 'Remove trusted certificates containing',
+ 'STRING.') do |value, options|
+ trust_dir = Gem::Security::OPT[:trust_dir]
+ glob_str = File::join(trust_dir, '*.pem')