maven-tools 0.32.5 → 0.33.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ #
2
+ # Copyright (C) 2013 Christian Meier
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'fileutils'
22
+ require 'java' if defined? JRUBY_VERSION
23
+ require 'stringio'
24
+ require 'maven/tools/model'
25
+ require 'maven/tools/dsl'
26
+ require 'maven/tools/visitor'
27
+
28
+ module Maven
29
+ module Tools
30
+ class POM
31
+ include Maven::Tools::DSL
32
+
33
+ def initialize( file = nil )
34
+ if file && File.directory?( file )
35
+ dir = file
36
+ file = nil
37
+ else
38
+ dir = '.'
39
+ end
40
+
41
+ unless file
42
+ file = pom_file( 'pom.rb', dir )
43
+ file ||= pom_file( 'Mavenfile', dir )
44
+ file ||= pom_file( 'Gemfile', dir )
45
+ #file ||= pom_file( 'Jarfile', dir )
46
+ file ||= pom_file( '*.gemspec', dir )
47
+ end
48
+
49
+ FileUtils.cd( dir ) do
50
+ @model = to_model( File.basename( file ) )
51
+ end if file
52
+ end
53
+
54
+ def pom_file( pom, dir = '.' )
55
+ files = Dir[ File.join( dir, pom ) ]
56
+ case files.size
57
+ when 0
58
+ when 1
59
+ files.first
60
+ else
61
+ warn 'more than one pom file found'
62
+ end
63
+ end
64
+
65
+ def to_s
66
+ if @model
67
+ io = StringIO.new
68
+ v = ::Maven::Tools::Visitor.new( io )
69
+ v.accept_project( @model )
70
+ io.string
71
+ end
72
+ end
73
+
74
+ def to_file( file )
75
+ if @model
76
+ v = ::Maven::Tools::Visitor.new( File.open( file, 'w' ) )
77
+ v.accept_project( @model )
78
+ true
79
+ end
80
+ end
81
+
82
+ def to_model( file )
83
+ if File.exists?( file )
84
+ case file
85
+ when /pom.rb/
86
+ eval_pom( "tesla do\n#{ File.read( file ) }\nend", file )
87
+ when /(Maven|Gem|Jar)file/
88
+ eval_pom( "tesla do\n#{ File.read( file ) }\nend", file )
89
+ when /.+\.gemspec/
90
+ eval_pom( "tesla do\ngemspec( '#{ File.basename( file ) }' )\nend", file )
91
+ end
92
+ else
93
+ eval_pom( "tesla do\n#{file}\nend", nil )
94
+ end
95
+ rescue ArgumentError => e
96
+ warn 'fallback to old maven model'
97
+ puts e.message
98
+ puts e.backtrace.join("\n\t")
99
+ raise 'TODO old maven model'
100
+ end
101
+ end
102
+ end
103
+ end
@@ -20,6 +20,6 @@
20
20
  #
21
21
  module Maven
22
22
  module Tools
23
- VERSION = '0.32.5'.freeze
23
+ VERSION = '0.33.2'.freeze
24
24
  end
25
25
  end
@@ -26,9 +26,10 @@ module Maven
26
26
  :assembly_plugin => "2.4",
27
27
  :war_plugin => "2.2",
28
28
  :jar_plugin => "2.4",
29
- :jruby_plugins => "1.0.0-beta",
29
+ :clean_plugin => "2.4",
30
+ :jruby_plugins => "1.0.0-rc",
30
31
  :bundler_version => "1.3.5",
31
- :jruby_version => defined?(JRUBY_VERSION) ? JRUBY_VERSION : "1.7.4"
32
+ :jruby_version => "1.7.4"
32
33
  }.freeze
33
34
  end
34
35
  end
@@ -0,0 +1,160 @@
1
+ module Maven
2
+ module Tools
3
+ class Visitor
4
+
5
+ def initialize( io = STDOUT )
6
+ @io = io
7
+ end
8
+
9
+ def indent
10
+ @indent ||= ''
11
+ end
12
+
13
+ def inc
14
+ @indent = @indent + ' '
15
+ end
16
+
17
+ def dec
18
+ @indent = @indent[ 0..-3 ]
19
+ end
20
+
21
+ def start_raw_tag( name, attr = {} )
22
+ @io.print "#{indent}<#{name}"
23
+ attr.each do |k,v|
24
+ @io.puts
25
+ @io.print "#{indent} #{k.to_s[1..-1]}='#{v}'"
26
+ end
27
+ @io.puts ">"
28
+ inc
29
+ end
30
+
31
+ def end_raw_tag( name )
32
+ dec
33
+ @io.puts "#{indent}</#{name}>"
34
+ end
35
+
36
+ def start_tag( name, attr = {} )
37
+ start_raw_tag( camel_case_lower( name ), attr )
38
+ end
39
+
40
+ def end_tag( name )
41
+ end_raw_tag( camel_case_lower( name ) )
42
+ end
43
+
44
+ def tag( name, value )
45
+ unless value.nil?
46
+ name = camel_case_lower( name )
47
+ @io.puts "#{indent}<#{name}>#{value}</#{name}>"
48
+ end
49
+ end
50
+
51
+ def raw_tag( name, value )
52
+ unless value.nil?
53
+ @io.puts "#{indent}<#{name}>#{value}</#{name}>"
54
+ end
55
+ end
56
+
57
+ def camel_case_lower( str )
58
+ str = str.to_s
59
+ str.split( '_' ).inject([]) do |buffer, e|
60
+ buffer.push( buffer.empty? ? e : e.capitalize )
61
+ end.join
62
+ end
63
+
64
+ def accept_project( project )
65
+ accept( 'project', project )
66
+ @io.close if @io.respond_to? :close
67
+ nil
68
+ end
69
+
70
+ def accept( name, model )
71
+ if model
72
+ start_tag( name )
73
+ visit( model )
74
+ end_tag( name )
75
+ end
76
+ end
77
+
78
+ def accept_array( name, array )
79
+ unless array.empty?
80
+ start_tag( name )
81
+ n = name.to_s.sub( /ies$/, 'y' ).sub( /s$/, '' )
82
+ case array.first
83
+ when Virtus
84
+ array.each do |i|
85
+ start_tag( n )
86
+ visit( i )
87
+ end_tag( n )
88
+ end
89
+ when Hash
90
+ array.each do |i|
91
+ accept_hash( n, i )
92
+ end
93
+ else
94
+ array.each do |i|
95
+ tag( n, i )
96
+ end
97
+ end
98
+ end_tag( name )
99
+ end
100
+ end
101
+
102
+ def accept_raw_hash( name, hash )
103
+ unless hash.empty?
104
+ attr = hash.select do |k, v|
105
+ [ k, v ] if k.to_s.match( /^@/ )
106
+ end
107
+ start_tag( name, attr )
108
+ hash.each do |k, v|
109
+ case v
110
+ when Array
111
+ accept_array( k, v )
112
+ else
113
+ raw_tag( k, v ) unless k.to_s.match( /^@/ )
114
+ end
115
+ end
116
+ end_tag( name )
117
+ end
118
+ end
119
+
120
+ def accept_hash( name, hash )
121
+ unless hash.empty?
122
+ # TODO attributes
123
+ attr = hash.select do |k, v|
124
+ [ k, v ] if k.to_s.match( /^@/ )
125
+ end
126
+ start_tag( name, attr )
127
+ hash.each do |k, v|
128
+ case v
129
+ when Array
130
+ accept_array( k, v )
131
+ else
132
+ # TODO xml content
133
+ tag( k, v ) unless k.to_s.match( /^@/ )
134
+ end
135
+ end
136
+ end_tag( name )
137
+ end
138
+ end
139
+
140
+ def visit( model )
141
+ model.attributes.each do |k, v|
142
+ if k == :properties
143
+ accept_raw_hash( k, v )
144
+ else
145
+ case v
146
+ when Virtus
147
+ accept( k, v )
148
+ when Array
149
+ accept_array( k, v )
150
+ when Hash
151
+ accept_hash( k, v )
152
+ else
153
+ tag( k, v )
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path( 'spec_helper', File.dirname( __FILE__ ) )
2
+ require 'maven/tools/artifact'
3
+
4
+ describe Maven::Tools::Artifact do
5
+
6
+ it 'should setup artifact' do
7
+ Maven::Tools::Artifact.new( "sdas", "das", "jar", "123", "tes" ).to_s.must_equal 'sdas:das:jar:tes:123'
8
+ Maven::Tools::Artifact.new( "sdas", "das", "jar", "123" ).to_s.must_equal 'sdas:das:jar:123'
9
+ Maven::Tools::Artifact.new( "sdas.asd", "das", "jar", "123", ["fds:fre"] ).to_s.must_equal 'sdas.asd:das:jar:123:[fds:fre]'
10
+ Maven::Tools::Artifact.new( "sdas.asd", "das", "jar","123", "bla", ["fds:fre", "ferf:de"] ).to_s.must_equal 'sdas.asd:das:jar:bla:123:[fds:fre,ferf:de]'
11
+ Maven::Tools::Artifact.new( "sdas.asd", "das", "jar", "123", "blub", ["fds:fre", "ferf:de"] ).to_s.must_equal 'sdas.asd:das:jar:blub:123:[fds:fre,ferf:de]'
12
+ end
13
+
14
+ it 'should convert ruby version contraints - gems' do
15
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '=1' ).to_s.must_equal 'rubygems:asd:gem:[1,1.0.0.0.0.1)'
16
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '>=1' ).to_s.must_equal 'rubygems:asd:gem:[1,)'
17
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '<=1' ).to_s.must_equal 'rubygems:asd:gem:[0,1]'
18
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '>1' ).to_s.must_equal 'rubygems:asd:gem:(1,)'
19
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '<1' ).to_s.must_equal 'rubygems:asd:gem:[0,1)'
20
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '!1' ).to_s.must_equal 'rubygems:asd:gem:(1,)'
21
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '<2', '>1' ).to_s.must_equal 'rubygems:asd:gem:(1,2)'
22
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '<=2', '>1' ).to_s.must_equal 'rubygems:asd:gem:(1,2]'
23
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '<2', '>=1' ).to_s.must_equal 'rubygems:asd:gem:[1,2)'
24
+ Maven::Tools::Artifact.from( :gem, 'rubygems:asd', '<=2', '>=1' ).to_s.must_equal 'rubygems:asd:gem:[1,2]'
25
+ end
26
+
27
+ it 'should convert ruby version contraints - jars' do
28
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '=1' ).to_s.must_equal 'rubygems:asd:jar:[1,1.0.0.0.0.1)'
29
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '>=1' ).to_s.must_equal 'rubygems:asd:jar:[1,)'
30
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '<=1' ).to_s.must_equal 'rubygems:asd:jar:[0,1]'
31
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '>1' ).to_s.must_equal 'rubygems:asd:jar:(1,)'
32
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '<1' ).to_s.must_equal 'rubygems:asd:jar:[0,1)'
33
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '!1' ).to_s.must_equal 'rubygems:asd:jar:(1,)'
34
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '<2', '>1' ).to_s.must_equal 'rubygems:asd:jar:(1,2)'
35
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '<=2', '>1' ).to_s.must_equal 'rubygems:asd:jar:(1,2]'
36
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '<2', '>=1' ).to_s.must_equal 'rubygems:asd:jar:[1,2)'
37
+ Maven::Tools::Artifact.from( :jar, 'rubygems:asd', '<=2', '>=1' ).to_s.must_equal 'rubygems:asd:jar:[1,2]'
38
+ end
39
+ end
@@ -1,3 +1,4 @@
1
+ require File.expand_path( 'spec_helper', File.dirname( __FILE__ ) )
1
2
  require 'maven/tools/coordinate'
2
3
  class A
3
4
  include Maven::Tools::Coordinate
@@ -41,8 +42,10 @@ describe Maven::Tools::Coordinate do
41
42
  subject.to_coordinate("pom 'b:c', '!2.3.4'").must_equal "b:c:pom:(2.3.4,)"
42
43
  subject.to_coordinate('jar "c:d", "2.3.4"').must_equal "c:d:jar:2.3.4"
43
44
  subject.to_coordinate("jar 'd:e', '~>1.8.2'").must_equal "d:e:jar:[1.8.2,1.8.99999]"
44
- subject.to_coordinate('pom "e:f", "[1.8,1.9.9)"').must_equal "e:f:pom:[1.8,1.9.9)"
45
45
  subject.to_coordinate('pom "f:g", ">1.2", "<=2.0"').must_equal "f:g:pom:(1.2,2.0]"
46
+ subject.to_coordinate('pom "e:f", "[1.8,1.9.9)"').must_equal "e:f:pom:[1.8,1.9.9)"
47
+ subject.to_coordinate('pom "e:f", "(1.8,1.9.9)"').must_equal "e:f:pom:(1.8,1.9.9)"
48
+ subject.to_coordinate('pom "e:f", "[1.8, 1.9.9]"').must_equal "e:f:pom:[1.8,1.9.9]"
46
49
  end
47
50
 
48
51
  it 'should support classifiers' do
@@ -52,7 +55,9 @@ describe Maven::Tools::Coordinate do
52
55
  subject.to_coordinate("pom 'b:c:jdk15', '!2.3.4'").must_equal "b:c:pom:jdk15:(2.3.4,)"
53
56
  subject.to_coordinate('jar "c:d:jdk15", "2.3.4"').must_equal "c:d:jar:jdk15:2.3.4"
54
57
  subject.to_coordinate("jar 'd:e:jdk15', '~>1.8.2'").must_equal "d:e:jar:jdk15:[1.8.2,1.8.99999]"
55
- subject.to_coordinate('pom "e:f:jdk15", "[1.8,1.9.9)"').must_equal "e:f:pom:jdk15:[1.8,1.9.9)"
56
58
  subject.to_coordinate('pom "f:g:jdk15", ">1.2", "<=2.0"').must_equal "f:g:pom:jdk15:(1.2,2.0]"
59
+ subject.to_coordinate('pom "e:f:jdk15", "[1.8,1.9.9)"').must_equal "e:f:pom:jdk15:[1.8,1.9.9)"
60
+ subject.to_coordinate('pom "e:f:jdk15", "(1.8,1.9.9)"').must_equal "e:f:pom:jdk15:(1.8,1.9.9)"
61
+ subject.to_coordinate('pom "e:f:jdk15", "[1.8, 1.9.9]"').must_equal "e:f:pom:jdk15:[1.8,1.9.9]"
57
62
  end
58
63
  end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path( 'spec_helper', File.dirname( __FILE__ ) )
2
+ require 'maven/tools/gemspec_dependencies'
3
+
4
+ describe Maven::Tools::GemspecDependencies do
5
+
6
+ let( :spec ) do
7
+ Gem::Specification.new do |s|
8
+ s.add_dependency 'thor', '>= 0.14.6', '< 2.0'
9
+ s.add_dependency 'maven-tools', "~> 0.32.3"
10
+ s.add_development_dependency 'minitest', '~> 5.0'
11
+ s.add_development_dependency 'rake', '~> 10.0'
12
+ s.requirements << 'jar sdas:das:tes, 123'
13
+ s.requirements << 'jar sdas:das, 123'
14
+ s.requirements << 'jar sdas.asd:das, 123, [fds:fre]'
15
+ s.requirements << 'jar sdas.asd:das:bla, 123,[fds:fre, ferf:de]'
16
+ s.requirements << 'jar sdas.asd:das, blub, 123,[fds:fre, ferf:de]'
17
+ s.requirements << 'jar "de.sdas:das:tes",123'
18
+ s.requirements << 'jar de.sdas:das, "123"'
19
+ s.requirements << 'jar "de.sdas.asd:das", 123, ["fds:fre"]'
20
+ s.requirements << "jar 'de.sdas.asd:das:bla', '123',['fds:fre', 'ferf:de']"
21
+ s.requirements << 'jar "de.sdas.asd:das", "blub", 123,"[fds:fre, ferf:de]"'
22
+ end
23
+ end
24
+
25
+ subject { Maven::Tools::GemspecDependencies.new( spec ) }
26
+
27
+ it 'should setup artifact' do
28
+ subject.runtime.must_equal ["rubygems:thor:[0.14.6,2.0)", "rubygems:maven-tools:[0.32.3,0.32.99999]"]
29
+ subject.development.must_equal ["rubygems:minitest:[5.0,5.99999]", "rubygems:rake:[10.0,10.99999]"]
30
+ subject.java_runtime.must_equal [ ["sdas", "das", "jar", "tes", "123"],
31
+ ["sdas", "das", "jar", "123"],
32
+ ["sdas.asd", "das", "jar", "123", ["fds:fre"]],
33
+ ["sdas.asd", "das", "jar", "bla", "123", ["fds:fre", "ferf:de"]],
34
+ ["sdas.asd", "das", "jar", "blub", "123", ["fds:fre", "ferf:de"]],
35
+ ["de.sdas", "das", "jar", "tes", "123"],
36
+ ["de.sdas", "das", "jar", "123"],
37
+ ["de.sdas.asd", "das", "jar", "123", ["fds:fre"]],
38
+ ["de.sdas.asd", "das", "jar", "bla", "123", ["fds:fre", "ferf:de"]],
39
+ ["de.sdas.asd", "das", "jar", "blub", "123", ["fds:fre","ferf:de"]] ]
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end
@@ -0,0 +1,4 @@
1
+ class BouncyCastle
2
+ MAVEN_VERSION = '1.49' unless defined? MAVEN_VERSION
3
+ VERSION_ = MAVEN_VERSION.sub( /[.]/, '' ) unless defined? BouncyCastle::VERSION_
4
+ end