Permalink
Browse files

Allow install of maven gems with colon (:) to separate group/artifacts

  • Loading branch information...
1 parent 28dbefe commit 1b01bfbe6932aab63143252baedbd910ea650828 @nicksieger nicksieger committed with yokolet Jan 7, 2011
@@ -1,4 +1,5 @@
require 'rubygems/config_file'
+require 'rubygems/maven_gemify' # Maven support
require 'rbconfig'
module Gem
@@ -1,24 +1,24 @@
require 'uri'
-require 'rubygems/specification'
require 'rubygems/spec_fetcher'
require 'rubygems/remote_fetcher'
module Gem
- class Specification
- # return whether the spec name represents a maven artifact
- def self.maven_name?(name)
+ module MavenUtils
+ def maven_name?(name)
name = name.source if Regexp === name
name =~ /^[^:.]{2,}[.:]/
end
- end
- module MavenUtils
+ 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)
- Gem::Specification.maven_name?(gemname) && source_uri.scheme == "mvn" || source_uri.host == "maven"
+ maven_name?(gemname) && maven_source_uri?(source_uri)
end
end
@@ -35,40 +35,14 @@ def download_maven(spec, local_gem_path)
class SpecFetcher
include MavenUtils
- def gemify_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
- private :gemify_generate_spec
-
- # use maven to locate (generate) the specification for the dependency in question
- def find_matching_using_maven(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
- private :find_matching_using_maven
-
alias orig_find_matching_with_errors find_matching_with_errors
def find_matching_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
- if Gem::Specification.maven_name? dependency.name
- result = find_matching_using_maven(dependency)
+ if maven_name? dependency.name
+ result = maven_find_matching_with_errors(dependency)
end
- if result.nil? || result.flatten.empty?
+ if result && !result.flatten.empty?
+ result
+ else
orig_find_matching_with_errors(dependency, all, matching_platform, prerelease)
end
end
@@ -89,6 +63,33 @@ 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
@@ -1,6 +1,5 @@
require 'rubygems'
require 'rubygems/user_interaction'
-require 'rubygems/maven_gemify'
require 'uri'
##
@@ -2,7 +2,6 @@
require 'rubygems/user_interaction'
require 'rubygems/errors'
require 'rubygems/text'
-require 'rubygems/maven_gemify'
##
# SpecFetcher handles metadata updates from remote gem repositories.
@@ -105,7 +104,7 @@ def fetch_spec(spec, source_uri)
else
spec = if maven_spec?(spec[0], source_uri)
# from rubygems/maven_gemify.rb
- gemify_generate_spec(spec)
+ maven_generate_spec(spec)
end
unless spec
uri.path << '.rz'
@@ -7,7 +7,6 @@
require 'rubygems/version'
require 'rubygems/requirement'
require 'rubygems/platform'
-require 'rubygems/maven_gemify'
# :stopdoc:
class Date; end # for ruby_code if date.rb wasn't required
@@ -9,18 +9,19 @@
Gem::Maven::Gemify.verbose = true if $DEBUG || ENV['DEBUG']
Gem::Maven::Gemify.maven
- describe Gem::Specification, "maven_name?" do
+ describe Gem::MavenUtils, "maven_name?" do
+ include Gem::MavenUtils
it "matches dot-separated artifacts" do
- Gem::Specification.maven_name?('commons-lang.commons-lang').should be_true
+ maven_name?('commons-lang.commons-lang').should be_true
end
it "matches colon-separated artifacts" do
- Gem::Specification.maven_name?('commons-lang:commons-lang').should be_true
+ maven_name?('commons-lang:commons-lang').should be_true
end
it "does not match things that look like a windows filename" do
- Gem::Specification.maven_name?('c:ommons-lang:commons-lang').should be_false
- Gem::Specification.maven_name?('c:/temp/somefile').should be_false
+ maven_name?('c:ommons-lang:commons-lang').should be_false
+ maven_name?('c:/temp/somefile').should be_false
end
end

0 comments on commit 1b01bfb

Please sign in to comment.