Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 1b01bfbe6932aab63143252baedbd910ea650828 1 parent 28dbefe
Nick Sieger authored January 07, 2011 yokolet committed January 07, 2011
1  lib/ruby/site_ruby/1.8/rubygems/defaults/jruby.rb
... ...
@@ -1,4 +1,5 @@
1 1
 require 'rubygems/config_file'
  2
+require 'rubygems/maven_gemify' # Maven support
2 3
 require 'rbconfig'
3 4
 
4 5
 module Gem
77  lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb
... ...
@@ -1,24 +1,24 @@
1 1
 require 'uri'
2  
-require 'rubygems/specification'
3 2
 require 'rubygems/spec_fetcher'
4 3
 require 'rubygems/remote_fetcher'
5 4
 
6 5
 module Gem
7  
-  class Specification
8  
-    # return whether the spec name represents a maven artifact
9  
-    def self.maven_name?(name)
  6
+  module MavenUtils
  7
+    def maven_name?(name)
10 8
       name = name.source if Regexp === name
11 9
       name =~ /^[^:.]{2,}[.:]/
12 10
     end
13  
-  end
14 11
 
15  
-  module MavenUtils
  12
+    def maven_source_uri?(source_uri)
  13
+      source_uri.scheme == "mvn" || source_uri.host == "maven"
  14
+    end
  15
+
16 16
     def maven_sources
17 17
       Gem.sources.select {|x| x =~ /^mvn:/}
18 18
     end
19 19
 
20 20
     def maven_spec?(gemname, source_uri)
21  
-      Gem::Specification.maven_name?(gemname) && source_uri.scheme == "mvn" || source_uri.host == "maven"
  21
+      maven_name?(gemname) && maven_source_uri?(source_uri)
22 22
     end
23 23
   end
24 24
 
@@ -35,40 +35,14 @@ def download_maven(spec, local_gem_path)
35 35
   class SpecFetcher
36 36
     include MavenUtils
37 37
 
38  
-    def gemify_generate_spec(spec)
39  
-      specfile = Gem::Maven::Gemify.new(maven_sources).generate_spec(spec[0], spec[1])
40  
-      return nil unless specfile
41  
-      Marshal.dump(Gem::Specification.from_yaml(File.read(specfile)))
42  
-    end
43  
-    private :gemify_generate_spec
44  
-
45  
-    # use maven to locate (generate) the specification for the dependency in question
46  
-    def find_matching_using_maven(dependency)
47  
-      specs_and_sources = []
48  
-      if dependency.name.is_a? Regexp
49  
-        dep_name = dependency.name.source.sub(/\^/, '')
50  
-      else
51  
-        dep_name = dependency.name
52  
-      end
53  
-
54  
-      Gem::Maven::Gemify.new(maven_sources).get_versions(dep_name).each do |version|
55  
-        # maven-versions which start with an letter get "0.0.0." prepended to
56  
-        # satisfy gem-version requirements
57  
-        if dependency.requirement.satisfied_by? Gem::Version.new "#{version.sub(/^0.0.0./, '1.')}"
58  
-          specs_and_sources.push [[dep_name, version, "java"], "http://maven/"]
59  
-        end
60  
-      end
61  
-
62  
-      [specs_and_sources, []]
63  
-    end
64  
-    private :find_matching_using_maven
65  
-
66 38
     alias orig_find_matching_with_errors find_matching_with_errors
67 39
     def find_matching_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
68  
-      if Gem::Specification.maven_name? dependency.name
69  
-        result = find_matching_using_maven(dependency)
  40
+      if maven_name? dependency.name
  41
+        result = maven_find_matching_with_errors(dependency)
70 42
       end
71  
-      if result.nil? || result.flatten.empty?
  43
+      if result && !result.flatten.empty?
  44
+        result
  45
+      else
72 46
         orig_find_matching_with_errors(dependency, all, matching_platform, prerelease)
73 47
       end
74 48
     end
@@ -89,6 +63,33 @@ def load_specs(source_uri, file)
89 63
       return if source_uri.scheme == "mvn"
90 64
       orig_load_specs(source_uri, file)
91 65
     end
  66
+
  67
+    private
  68
+    def maven_generate_spec(spec)
  69
+      specfile = Gem::Maven::Gemify.new(maven_sources).generate_spec(spec[0], spec[1])
  70
+      return nil unless specfile
  71
+      Marshal.dump(Gem::Specification.from_yaml(File.read(specfile)))
  72
+    end
  73
+
  74
+    # use maven to locate (generate) the specification for the dependency in question
  75
+    def maven_find_matching_with_errors(dependency)
  76
+      specs_and_sources = []
  77
+      if dependency.name.is_a? Regexp
  78
+        dep_name = dependency.name.source.sub(/\^/, '')
  79
+      else
  80
+        dep_name = dependency.name
  81
+      end
  82
+
  83
+      Gem::Maven::Gemify.new(maven_sources).get_versions(dep_name).each do |version|
  84
+        # maven-versions which start with an letter get "0.0.0." prepended to
  85
+        # satisfy gem-version requirements
  86
+        if dependency.requirement.satisfied_by? Gem::Version.new "#{version.sub(/^0.0.0./, '1.')}"
  87
+          specs_and_sources.push [[dep_name, version, "java"], "http://maven/"]
  88
+        end
  89
+      end
  90
+
  91
+      [specs_and_sources, []]
  92
+    end
92 93
   end
93 94
 
94 95
   module Maven
1  lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb
... ...
@@ -1,6 +1,5 @@
1 1
 require 'rubygems'
2 2
 require 'rubygems/user_interaction'
3  
-require 'rubygems/maven_gemify'
4 3
 require 'uri'
5 4
 
6 5
 ##
3  lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb
@@ -2,7 +2,6 @@
2 2
 require 'rubygems/user_interaction'
3 3
 require 'rubygems/errors'
4 4
 require 'rubygems/text'
5  
-require 'rubygems/maven_gemify'
6 5
 
7 6
 ##
8 7
 # SpecFetcher handles metadata updates from remote gem repositories.
@@ -105,7 +104,7 @@ def fetch_spec(spec, source_uri)
105 104
     else
106 105
       spec = if maven_spec?(spec[0], source_uri)
107 106
         # from rubygems/maven_gemify.rb
108  
-        gemify_generate_spec(spec)
  107
+        maven_generate_spec(spec)
109 108
       end
110 109
       unless spec
111 110
         uri.path << '.rz'
1  lib/ruby/site_ruby/1.8/rubygems/specification.rb
@@ -7,7 +7,6 @@
7 7
 require 'rubygems/version'
8 8
 require 'rubygems/requirement'
9 9
 require 'rubygems/platform'
10  
-require 'rubygems/maven_gemify'
11 10
 
12 11
 # :stopdoc:
13 12
 class Date; end # for ruby_code if date.rb wasn't required
11  spec/java_integration/maven/maven_gemify_spec.rb
@@ -9,18 +9,19 @@
9 9
   Gem::Maven::Gemify.verbose = true if $DEBUG || ENV['DEBUG']
10 10
   Gem::Maven::Gemify.maven
11 11
 
12  
-  describe Gem::Specification, "maven_name?" do
  12
+  describe Gem::MavenUtils, "maven_name?" do
  13
+    include Gem::MavenUtils
13 14
     it "matches dot-separated artifacts" do
14  
-      Gem::Specification.maven_name?('commons-lang.commons-lang').should be_true
  15
+      maven_name?('commons-lang.commons-lang').should be_true
15 16
     end
16 17
 
17 18
     it "matches colon-separated artifacts" do
18  
-      Gem::Specification.maven_name?('commons-lang:commons-lang').should be_true
  19
+      maven_name?('commons-lang:commons-lang').should be_true
19 20
     end
20 21
 
21 22
     it "does not match things that look like a windows filename" do
22  
-      Gem::Specification.maven_name?('c:ommons-lang:commons-lang').should be_false
23  
-      Gem::Specification.maven_name?('c:/temp/somefile').should be_false
  23
+      maven_name?('c:ommons-lang:commons-lang').should be_false
  24
+      maven_name?('c:/temp/somefile').should be_false
24 25
     end
25 26
   end
26 27
 

0 notes on commit 1b01bfb

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