Skip to content
Browse files

Modifications to bring our RubyGems more in line with original.

* Removed Maven support.
* Have 'gem' just load 'jgem' in the same dir, since that's the
one that RubyGems updates.
  • Loading branch information...
1 parent 823990a commit ec3e8e56095e0e139f195b7608c98f03a8fa22cf @headius headius committed with Prathamesh Sonpatki Sep 12, 2012
View
25 bin/gem
@@ -1,25 +1,4 @@
#!/usr/bin/env jruby
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
-require 'rubygems'
-require 'rubygems/gem_runner'
-require 'rubygems/exceptions'
-
-required_version = Gem::Requirement.new ">= 1.8.7"
-
-unless required_version.satisfied_by? Gem.ruby_version then
- abort "Expected Ruby Version #{required_version}, is #{Gem.ruby_version}"
-end
-
-args = ARGV.clone
-
-begin
- Gem::GemRunner.new.run args
-rescue Gem::SystemExitException => e
- exit e.exit_code
-end
+# We just load jgem, since that's what RubyGems updates
+load File.join(File.dirname(__FILE__), "jgem")
View
11 bin/jgem
@@ -1,10 +1,19 @@
-#!/usr/bin/env jruby
+#!/Users/headius/projects/jruby/bin/jruby
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++
+# The prelude in 1.9.1 injects rubygems.rb into $LOADED_FEATURES
+# which prevents the `require 'rubygems'` from actually loading
+# the site's version of rubygems. So we have to use it's API
+# to get it's prelude out of the way.
+#
+if RUBY_VERSION =~ /^1\.9\.1/ && defined?(Gem::QuickLoader)
+ Gem::QuickLoader.load_full_rubygems_library
+end
+
require 'rubygems'
require 'rubygems/gem_runner'
require 'rubygems/exceptions'
View
12 lib/ruby/shared/rubygems/local_remote_options.rb
@@ -15,15 +15,15 @@ module Gem::LocalRemoteOptions
##
# Allows OptionParser to handle HTTP URIs.
- def accept_uri http = nil
- OptionParser.accept(http ? URI::HTTP : URI::Generic) do |value|
+ def accept_uri_http
+ OptionParser.accept URI::HTTP do |value|
begin
uri = URI.parse value
rescue URI::InvalidURIError
raise OptionParser::InvalidArgument, value
end
- if http && !['http', 'https', 'file'].include?(uri.scheme)
+ unless ['http', 'https', 'file'].include?(uri.scheme)
raise OptionParser::InvalidArgument, value
end
@@ -85,7 +85,7 @@ def add_clear_sources_option
# Add the --http-proxy option
def add_proxy_option
- accept_uri :http
+ accept_uri_http
add_option(:"Local/Remote", '-p', '--[no-]http-proxy [URL]', URI::HTTP,
'Use HTTP proxy for remote operations') do |value, options|
@@ -98,9 +98,9 @@ def add_proxy_option
# Add the --source option
def add_source_option
- accept_uri
+ accept_uri_http
- add_option(:"Local/Remote", '--source URL', URI::Generic,
+ add_option(:"Local/Remote", '--source URL', URI::HTTP,
'Add URL as a remote source for gems') do |source, options|
source << '/' if source !~ /\/\z/
View
376 lib/ruby/shared/rubygems/maven_gemify.rb
@@ -1,376 +0,0 @@
-require 'uri'
-require 'rubygems/remote_fetcher'
-
-module Gem
- module MavenUtils
- def maven_name?(name)
- name = name.source.sub(/\^/, '') if Regexp === name
- name =~ /^mvn:/
- end
-
- def maven_source_uri?(source_uri)
- source_uri.scheme == "mvn" || source_uri.host == "maven"
- end
-
- def maven_sources
- Gem.sources.select {|x| x =~ /^mvn:/}
- end
-
- def maven_spec?(gemname, source_uri)
- maven_name?(gemname) && maven_source_uri?(source_uri)
- end
- end
-
- class Maven3NotFound < StandardError; end
-
- class RemoteFetcher
- include MavenUtils
-
- def download_maven(spec, local_gem_path)
- FileUtils.cp Gem::Maven::Gemify.new(maven_sources).generate_gem(spec.name, spec.version), local_gem_path
- local_gem_path
- end
- private :download_maven
- end
-
- class SpecFetcher
- include MavenUtils
-
- alias orig_find_matching_with_errors find_matching_with_errors
- def find_matching_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
- if maven_name? dependency.name
- begin
- result = maven_find_matching_with_errors(dependency)
- rescue Gem::Maven3NotFound => e
- raise e
- rescue => e
- warn "maven find dependency failed for #{dependency}: #{e.to_s}" if Gem::Maven::Gemify.verbose?
- end
- end
- if result && !result.flatten.empty?
- result
- else
- orig_find_matching_with_errors(dependency, all, matching_platform, prerelease)
- end
- end
-
- alias orig_list list
- def list(*args)
- sources = Gem.sources
- begin
- Gem.sources -= maven_sources
- return orig_list(*args)
- ensure
- Gem.sources = sources
- end
- end
-
- alias orig_load_specs load_specs
- def load_specs(source_uri, file)
- return if source_uri.scheme == "mvn"
- orig_load_specs(source_uri, file)
- end
-
- private
- def maven_generate_spec(spec)
- specfile = Gem::Maven::Gemify.new(maven_sources).generate_spec(spec[0], spec[1])
- return nil unless specfile
- Marshal.dump(Gem::Specification.from_yaml(File.read(specfile)))
- end
-
- # use maven to locate (generate) the specification for the dependency in question
- def maven_find_matching_with_errors(dependency)
- specs_and_sources = []
- if dependency.name.is_a? Regexp
- dep_name = dependency.name.source.sub(/\^/, '')
- else
- dep_name = dependency.name
- end
-
- Gem::Maven::Gemify.new(maven_sources).get_versions(dep_name).each do |version|
- # maven-versions which start with an letter get "0.0.0." prepended to
- # satisfy gem-version requirements
- if dependency.requirement.satisfied_by? Gem::Version.new "#{version.sub(/^0.0.0./, '1.')}"
- specs_and_sources.push [[dep_name, version, "java"], "http://maven/"]
- end
- end
-
- [specs_and_sources, []]
- end
- end
-
- module Maven
- class Gemify
- DEFAULT_PLUGIN_VERSION = "0.26.0"
-
- attr_reader :repositories
-
- def initialize(*repositories)
- maven # ensure maven initialized
- @repositories = repositories.length > 0 ? [repositories].flatten : []
- @repositories.map! do |r|
- u = URI === r ? r : URI.parse(r)
- if u.scheme == "mvn"
- if u.opaque == "central"
- u = nil
- else
- u.scheme = "http"
- end
- end
- u
- end
- end
-
- @@verbose = false
- def self.verbose?
- @@verbose || $DEBUG
- end
- def verbose?
- self.class.verbose?
- end
- def self.verbose=(v)
- @@verbose = v
- end
-
- private
- def self.maven_config
- @maven_config ||= Gem.configuration["maven"] || {}
- end
- def maven_config; self.class.maven_config; end
-
- def self.base_goal
- @base_goal ||= "de.saumya.mojo:gemify-maven-plugin:#{maven_config['plugin_version'] || DEFAULT_PLUGIN_VERSION}"
- end
- def base_goal; self.class.base_goal; end
-
- def self.java_imports
- %w(
- org.codehaus.plexus.classworlds.ClassWorld
- org.codehaus.plexus.DefaultContainerConfiguration
- org.codehaus.plexus.DefaultPlexusContainer
- org.apache.maven.Maven
- org.apache.maven.repository.RepositorySystem
- org.apache.maven.execution.DefaultMavenExecutionRequest
- org.apache.maven.artifact.repository.MavenArtifactRepository
- org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout
- org.apache.maven.artifact.repository.ArtifactRepositoryPolicy
- ).each {|i| java_import i }
- end
-
- def self.create_maven
- require 'java' # done lazily, so we're not loading it all the time
- bin = nil
- if ENV['M2_HOME'] # use M2_HOME if set
- bin = File.join(ENV['M2_HOME'], "bin")
- else
- ENV['PATH'].split(File::PATH_SEPARATOR).detect do |path|
- mvn = File.join(path, "mvn")
- if File.exists?(mvn)
- if File.symlink?(mvn)
- link = File.readlink(mvn)
- if link =~ /^\// # is absolute path
- bin = File.dirname(File.expand_path(link))
- else # is relative path so join with dir of the maven command
- bin = File.dirname(File.expand_path(File.join(File.dirname(mvn), link)))
- end
- else # is no link so just expand it
- bin = File.expand_path(path)
- end
- else
- nil
- end
- end
- end
- bin = "/usr/share/maven2/bin" if bin.nil? # OK let's try debian default
- if File.exists?(bin)
- @mvn = File.join(bin, "mvn")
- if Dir.glob(File.join(bin, "..", "lib", "maven-core-3.*jar")).size == 0
- begin
- gem 'ruby-maven', ">=0"
- bin = File.dirname(Gem.bin_path('ruby-maven', "rmvn"))
- @mvn = File.join(bin, "rmvn")
- rescue LoadError
- bin = nil
- end
- end
- else
- bin = nil
- end
- raise Gem::Maven3NotFound.new("can not find maven3 installation. install ruby-maven with\n\n\tjruby -S gem install ruby-maven\n\n") if bin.nil?
-
- warn "Using Maven install at #{bin}" if verbose?
-
- boot = File.join(bin, "..", "boot")
- lib = File.join(bin, "..", "lib")
- ext = File.join(bin, "..", "ext")
- (Dir.glob(lib + "/*jar") + Dir.glob(boot + "/*jar")).each {|path| require path }
-
- java.lang.System.setProperty("classworlds.conf", File.join(bin, "m2.conf"))
- java.lang.System.setProperty("maven.home", File.join(bin, ".."))
- java_imports
-
- class_world = ClassWorld.new("plexus.core", java.lang.Thread.currentThread().getContextClassLoader());
- config = DefaultContainerConfiguration.new
- config.set_class_world class_world
- config.set_name "ruby-tools"
- container = DefaultPlexusContainer.new(config);
- @@execution_request_populator = container.lookup(org.apache.maven.execution.MavenExecutionRequestPopulator.java_class)
-
- @@settings_builder = container.lookup(org.apache.maven.settings.building.SettingsBuilder.java_class )
- container.lookup(Maven.java_class)
- end
-
- def self.maven
- @maven ||= create_maven
- end
- def maven; self.class.maven; end
-
- def self.temp_dir
- @temp_dir ||=
- begin
- f = java.io.File.createTempFile("gemify", "")
- f.delete
- f.mkdir
- f.deleteOnExit
- f.absolute_path
- end
- end
- def temp_dir; self.class.temp_dir; end
-
- def execute(goal, gemname, version, props = {})
- request = DefaultMavenExecutionRequest.new
- request.set_show_errors Gem.configuration.backtrace
- skip_dependencies = (!maven_config["dependencies"]).to_s
- request.user_properties.put("gemify.skipDependencies", skip_dependencies)
- request.user_properties.put("gemify.tempDir", temp_dir)
- request.user_properties.put("gemify.gemname", gemname)
- request.user_properties.put("gemify.version", version.to_s) if version
-
- if maven_config["repositories"]
- maven_config["repositories"].each { |r| @repositories << r }
- end
- if @repositories.size > 0
- request.user_properties.put("gemify.repositories", @repositories.join(","))
- end
-
- props.each do |k,v|
- request.user_properties.put(k.to_s, v.to_s)
- end
- request.set_goals [goal]
- request.set_logging_level 0
-
- settings = setup_settings(maven_config["settings"], request.user_properties)
- @@execution_request_populator.populateFromSettings(request, settings)
- @@execution_request_populator.populateDefaults(request)
-
- if profiles = maven_config["profiles"]
- profiles.each { |profile| request.addActiveProfile(profile) }
- end
- if verbose?
- active_profiles = request.getActiveProfiles.collect{ |p| p.to_s }
- puts "active profiles:\n\t[#{active_profiles.join(', ')}]"
- puts "maven goals:"
- request.goals.each { |g| puts "\t#{g}" }
- puts "system properties:"
- request.getUserProperties.map.each { |k,v| puts "\t#{k} => #{v}" }
- puts
- end
- out = java.lang.System.out
- string_io = java.io.ByteArrayOutputStream.new
- java.lang.System.setOut(java.io.PrintStream.new(string_io))
- result = maven.execute request
- java.lang.System.out = out
-
- result.exceptions.each do |e|
- e.print_stack_trace if request.is_show_errors
- string_io.write(e.get_message.to_java_string.get_bytes)
- end
- string_io.to_s
- end
-
- def setup_settings(user_settings_file, user_props)
- @settings ||=
- begin
- user_settings_file =
- if user_settings_file
- resolve_file(usr_settings_file)
- else
- user_maven_home = java.io.File.new(java.lang.System.getProperty("user.home"), ".m2")
- java.io.File.new(user_maven_home, "settings.xml")
- end
-
- global_settings_file =java.io.File.new(@conf, "settings.xml")
-
- settings_request = org.apache.maven.settings.building.DefaultSettingsBuildingRequest.new
- settings_request.setGlobalSettingsFile(global_settings_file)
- settings_request.setUserSettingsFile(user_settings_file)
- settings_request.setSystemProperties(java.lang.System.getProperties)
- settings_request.setUserProperties(user_props)
-
- settings_result = @@settings_builder.build(settings_request)
- settings_result.effective_settings
- end
- end
-
- def resolve_file(file)
- return nil if file.nil?
- return file if file.isAbsolute
- if file.getPath.startsWith(java.io.File.separator)
- # drive-relative Windows path
- return file.getAbsoluteFile
- else
- return java.io.File.new( java.lang.System.getProperty("user.dir"), file.getPath ).getAbsoluteFile
- end
- end
-
- public
- def get_versions(gemname)
- name = maven_name(gemname)
- result = execute("#{base_goal}:versions", name, nil)
-
- if result =~ /#{name} \[/
- result = result.gsub(/\r?\n/, '').sub(/.*\[/, "").sub(/\]/, '').gsub(/ /, '').split(',')
- puts "versions: #{result.inspect}" if verbose?
- result
- else
- []
- end
- end
-
- def generate_spec(gemname, version)
- result = execute("#{base_goal}:gemify", maven_name(gemname), version, "gemify.onlySpecs" => true)
- path = result.gsub(/\r?\n/, '')
- if path =~ /gemspec: /
- path = path.sub(/.*gemspec: /, '')
- if path.size > 0
- result = File.expand_path(path)
- java.io.File.new(result).deleteOnExit
- result
- end
- end
- end
-
- def generate_gem(gemname, version)
- result = execute("#{base_goal}:gemify", maven_name(gemname), version)
- path = result.gsub(/\r?\n/, '')
- if path =~ /gem: /
-
- path = path.sub(/.*gem: /, '')
- if path.size > 0
- result = File.expand_path(path)
- java.io.File.new(result).deleteOnExit
- result
- end
- else
- warn result.sub(/Failed.*pom:/, '').gsub(/\tmvn/, "\t#{@mvn}")
- raise "error gemify #{gemname}:#{version}"
- end
- end
-
- def maven_name(gemname)
- gemname = gemname.source if Regexp === gemname
- gemname
- end
- end
- end
-end
View
5 lib/ruby/shared/rubygems/remote_fetcher.rb
@@ -118,11 +118,6 @@ def download(spec, source_uri, install_dir = Gem.dir)
URI.escape(source_uri.to_s))
end
- # if it's a maven artifact, use maven to fetch it
- if maven_spec? spec.name, source_uri
- return download_maven(spec, local_gem_path)
- end
-
scheme = source_uri.scheme
# URI.parse gets confused by MS Windows paths with forward slashes.
View
16 lib/ruby/shared/rubygems/spec_fetcher.rb
@@ -116,16 +116,10 @@ def fetch_spec(spec, source_uri)
if File.exist? local_spec then
spec = Gem.read_binary local_spec
else
- spec = if maven_spec?(spec[0], source_uri)
- # from rubygems/maven_gemify.rb
- maven_generate_spec(spec)
- end
- unless spec
- uri.path << '.rz'
+ uri.path << '.rz'
- spec = @fetcher.fetch_path uri
- spec = Gem.inflate spec
- end
+ spec = @fetcher.fetch_path uri
+ spec = Gem.inflate spec
if @update_cache then
FileUtils.mkdir_p cache_dir
@@ -301,7 +295,3 @@ def load_specs(source_uri, file)
end
-# Load rubygems/maven_gemify.rb here because;
-# * want to require only spec_fetcher is required to avoid circular require.
-# * need to require after spec_fetcher and remote_fetcher to override those definitions.
-require 'rubygems/maven_gemify'
View
100 spec/java_integration/rubygems/maven_gemify_spec.rb
@@ -1,100 +0,0 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
-require 'rubygems'
-require 'rubygems/format'
-require 'rubygems/maven_gemify'
-require 'yaml'
-
-begin
- Gem::Maven::Gemify.verbose = true if $DEBUG || ENV['DEBUG']
- Gem::Maven::Gemify.maven
-
- describe Gem::MavenUtils, "maven_name?" do
- include Gem::MavenUtils
- it "matches colon-separated artifacts and needs tp start with 'mvn:'" do
- maven_name?('mvn:commons-lang:commons-lang').should be_true
- end
-
- it "does not match things that look like a windows filename" do
- maven_name?('c:ommons-lang:commons-lang').should be_false
- maven_name?('c:/temp/somefile').should be_false
- end
-
- it "does not match URLs" do
- maven_name?('http://example.com/some.gem').should be_false
- end
- it "does not match without 'mvn:' prefix" do
- maven_name?('commons-lang:commons-lang').should be_false
- end
- end
-
- describe Gem::SpecFetcher do
- it "downloads specs for maven artifacts" do
- matching = Gem::SpecFetcher.fetcher.find_matching Gem::Dependency.new("mvn:commons-lang:commons-lang")
- matching.should_not be_empty
- end
- end
-
- describe Gem::Maven::Gemify do
- it "creates an instance of the Maven class" do
- Gem::Maven::Gemify.maven.should be_kind_of(org.apache.maven.Maven)
- end
-
- it "gets a list of versions for a maven artifact" do
- Gem::Maven::Gemify.new.get_versions("mvn:commons-lang:commons-lang").should include("2.5.0")
- end
-
- it "gets a list of versions for a maven artifact from external repository" do
- Gem::Maven::Gemify.new('https://repository.jboss.org/nexus/content/groups/public-jboss').get_versions("mvn:org.jboss.logging:jboss-logging").should include("3.0.0.b.5")
- end
-
- it "allows use of colons as artifact delimiters" do
- Gem::Maven::Gemify.new.get_versions("mvn:commons-lang:commons-lang").should include("2.5.0")
- end
-
- it "generates a gemspec file for the maven artifact" do
- specfile = Gem::Maven::Gemify.new.generate_spec("mvn:commons-lang:commons-lang", "2.5.0")
- specfile.should_not be_nil
- gemspec = Gem::Specification.from_yaml(File.read(specfile))
- gemspec.name.should == "mvn:commons-lang:commons-lang"
- gemspec.version.should == Gem::Version.new("2.5.0")
- end
-
- it "generates a .gem for the maven artifact" do
- gemfile = Gem::Maven::Gemify.new.generate_gem("mvn:commons-lang:commons-lang", "2.5.0")
- format = Gem::Format.from_file_by_path gemfile
- format.file_entries.detect{|fe| fe[0]["path"] =~ /commons-lang\.jar/}.should be_true
- end
-
- it "generates a spec with a Gem::Dependency list for artifacts with dependencies" do
- specfile = Gem::Maven::Gemify.new.generate_spec("mvn:commons-logging:commons-logging", "1.1.1")
- specfile.should_not be_nil
- gemspec = Gem::Specification.from_yaml(File.read(specfile))
- gemspec.dependencies.length.should == 1
- gemspec.dependencies[0].name.should == 'mvn:junit:junit'
- gemspec.dependencies[0].type.should == :development
- end
-
- it "allows a non-standard maven repository" do
- gemify = Gem::Maven::Gemify.new "http://maven.glassfish.org/content/groups/public/"
- specfile = gemify.generate_spec("mvn:com.sun.akuma:akuma", "1.3")
- specfile.should_not be_nil
- gemspec = Gem::Specification.from_yaml(File.read(specfile))
- gemspec.dependencies.length.should == 1
- gemspec.dependencies[0].name.should == 'mvn:net.java.dev.jna:jna'
- end
-
- it "accepts a variety of string or URI parameters to #initialize" do
- expected = ["http://repository.codehaus.org/"]
- Gem::Maven::Gemify.new("http://repository.codehaus.org/").repositories.map(&:to_s).should == expected
- Gem::Maven::Gemify.new(URI.parse("http://repository.codehaus.org/")).repositories.map(&:to_s).should == expected
- Gem::Maven::Gemify.new(["http://repository.codehaus.org/"]).repositories.map(&:to_s).should == expected
- Gem::Maven::Gemify.new("mvn://repository.codehaus.org/").repositories.map(&:to_s).should == expected
- Gem::Maven::Gemify.new(URI.parse("mvn://repository.codehaus.org/")).repositories.map(&:to_s).should == expected
- Gem::Maven::Gemify.new(URI.parse("mvn:central")).repositories.should == [nil]
- end
- end
-rescue => e
- puts(e, *e.backtrace) if $DEBUG || ENV['DEBUG']
- # Skipping maven specs w/o M3 or ruby-maven gem installed
-end

0 comments on commit ec3e8e5

Please sign in to comment.
Something went wrong with that request. Please try again.