maven-tools 0.33.5 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -134,6 +134,16 @@ module Maven
134
134
  [ self[:group_id], self[:artifact_id], self[:version], self[:classifier] ].select { |o| o }.join( ':' )
135
135
  end
136
136
 
137
+ def exclusions
138
+ if key?( :exclusions )
139
+ self[:exclusions].inspect.gsub( /[\[\]" ]/, '' ).split /,/
140
+ end
141
+ end
142
+
143
+ def to_coordinate
144
+ [ self[:group_id], self[:artifact_id], self[:type], self[:classifier], self[:version] ].select { |o| o }.join( ':' )
145
+ end
146
+
137
147
  def to_s
138
148
  [ self[:group_id], self[:artifact_id], self[:type], self[:classifier], self[:version], key?( :exclusions )? self[:exclusions].inspect.gsub( /[" ]/, '' ) : nil ].select { |o| o }.join( ':' )
139
149
  end
@@ -120,29 +120,38 @@ module Maven
120
120
  end
121
121
  end
122
122
  end
123
-
123
+
124
+ def snapshot_version( val )
125
+ if val.match /[a-z]|[A-Z]/ and not val.match /-SNAPSHOT|[${}]/
126
+ val + '-SNAPSHOT'
127
+ else
128
+ val
129
+ end
130
+ end
131
+
124
132
  def convert(arg, low = nil, high = nil)
125
133
  if arg =~ /~>/
126
134
  val = arg.sub(/~>\s*/, '')
127
135
  last = val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999')
128
- ["[#{val}", "#{last}]"]
136
+ ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"]
129
137
  elsif arg =~ />=/
130
138
  val = arg.sub(/>=\s*/, '')
131
- ["[#{val}", (nil || high)]
139
+ ["[#{snapshot_version(val)}", (nil || high)]
132
140
  elsif arg =~ /<=/
133
141
  val = arg.sub(/<=\s*/, '')
134
- [(nil || low), "#{val}]"]
142
+ [(nil || low), "#{snapshot_version(val)}]"]
135
143
  # treat '!' the same way as '>' since maven can not describe such range
136
144
  elsif arg =~ /[!>]/
137
145
  val = arg.sub(/[!>]\s*/, '')
138
- ["(#{val}", (nil || high)]
146
+ ["(#{snapshot_version(val)}", (nil || high)]
139
147
  elsif arg =~ /</
140
148
  val = arg.sub(/<\s*/, '')
141
- [(nil || low), "#{val})"]
149
+ [(nil || low), "#{snapshot_version(val)})"]
142
150
  elsif arg =~ /\=/
143
151
  val = arg.sub(/=\s*/, '')
144
- ["[" + val, val + '.0.0.0.0.1)']
145
- else
152
+ ["[#{snapshot_version(val)}", val + '.0.0.0.0.1)']
153
+ else
154
+ # no conversion here, i.e. assume maven version
146
155
  [arg, arg]
147
156
  end
148
157
  end
@@ -135,6 +135,10 @@ module Maven
135
135
  repository( 'http://rubygems-proxy.torquebox.org/releases',
136
136
  :id => 'rubygems-releases' )
137
137
  end
138
+ unless model.repositories.detect { |r| r.id == 'rubygems-prereleases' }
139
+ snapshot_repository( 'http://rubygems-proxy.torquebox.org/prereleases',
140
+ :id => 'rubygems-prereleases' )
141
+ end
138
142
 
139
143
  setup_jruby_plugins_version
140
144
 
@@ -215,11 +219,6 @@ module Maven
215
219
  end
216
220
 
217
221
  def gemspec( name = nil, options = @gemfile_options || {} )
218
- unless model.properties.member?( 'project.build.sourceEncoding' )
219
- properties( 'project.build.sourceEncoding' => 'utf-8' )
220
- end
221
-
222
- @gemfile_options = nil
223
222
  if name.is_a? Hash
224
223
  options = name
225
224
  name = nil
@@ -233,13 +232,32 @@ module Maven
233
232
  name = gemspecs.first
234
233
  end
235
234
  spec = nil
236
- FileUtils.cd( basedir ) do
237
- spec = eval( File.read( File.expand_path( name ) ) )
235
+ spec_file = File.read( File.expand_path( name ) )
236
+ begin
237
+ FileUtils.cd( basedir ) do
238
+ # TODO jruby java user.dir
239
+ spec = eval( spec_file )
240
+ end
241
+ rescue
242
+ spec = Gem::Specification.from_yaml( spec_file )
238
243
  end
244
+
245
+ self.spec( spec, name, options )
246
+ end
247
+
248
+ def spec( spec, name = nil, options = {} )
249
+ name ||= "#{spec.name}-#{spec.version}.gemspec"
250
+ unless model.properties.member?( 'project.build.sourceEncoding' )
251
+ properties( 'project.build.sourceEncoding' => 'utf-8' )
252
+ end
253
+
254
+ @gemfile_options = nil
239
255
 
240
256
  if @context == :project
241
257
  build.directory = '${basedir}/pkg'
242
- id "rubygems:#{spec.name}:#{spec.version}"
258
+ version = spec.version.to_s
259
+ version += '-SNAPSHOT' if spec.version.prerelease?
260
+ id "rubygems:#{spec.name}:#{version}"
243
261
  name( spec.summary || spec.name )
244
262
  description spec.description
245
263
  packaging 'gem'
@@ -478,24 +496,26 @@ module Maven
478
496
  end
479
497
 
480
498
  def snapshot_repository( url, options = {}, &block )
499
+ options[ :releases ] = false unless options.key?( :releases ) || options.key?( 'releases' )
500
+ options[ :snapshots ] = true unless options.key?( :snapshots ) || options.key?( 'snapshots' )
481
501
  do_repository( :snapshot_repository=, url, options, block )
482
502
  end
483
503
 
484
504
  def releases( config )
485
- respository_policy( :releases=, config )
505
+ @current.releases = respository_policy( config )
486
506
  end
487
507
 
488
508
  def snapshots( config )
489
- respository_policy( :snapshots=, config )
509
+ @current.snapshots = respository_policy( config )
490
510
  end
491
511
 
492
- def respository_policy( method, config )
512
+ def repository_policy( config )
493
513
  rp = RepositoryPolicy.new
494
514
  case config
495
515
  when Hash
496
- rp.enabled = snapshot[ :enabled ]
497
- rp.update_policy = snapshot[ :update ]
498
- rp.checksum_policy = snapshot[ :checksum ]
516
+ rp.enabled = config[ :enabled ]
517
+ rp.update_policy = config[ :update ]
518
+ rp.checksum_policy = config[ :checksum ]
499
519
  when TrueClass
500
520
  rp.enabled = true
501
521
  when FalseClass
@@ -503,7 +523,7 @@ module Maven
503
523
  else
504
524
  rp.enabled = 'true' == config
505
525
  end
506
- @current.send( method, rp )
526
+ rp
507
527
  end
508
528
 
509
529
  def args_and_options( *args )
@@ -564,13 +584,21 @@ module Maven
564
584
  end
565
585
  end
566
586
 
567
- def jruby_plugin( *gav, &block )
587
+ def do_jruby_plugin( method, *gav, &block )
568
588
  gav[ 0 ] = "de.saumya.mojo:#{gav[ 0 ]}-maven-plugin"
569
589
  if gav.size == 1 || gav[ 1 ].is_a?( Hash )
570
590
  setup_jruby_plugins_version
571
591
  gav.insert( 1, '${jruby.plugins.version}' )
572
592
  end
573
- plugin( *gav, &block )
593
+ send( method, *gav, &block )
594
+ end
595
+
596
+ def jruby_plugin( *gav, &block )
597
+ do_jruby_plugin( :plugin, *gav, &block )
598
+ end
599
+
600
+ def jruby_plugin!( *gav, &block )
601
+ do_jruby_plugin( :plugin!, *gav, &block )
574
602
  end
575
603
 
576
604
  def plugin!( *gav, &block )
@@ -991,15 +1019,17 @@ module Maven
991
1019
  r = DeploymentRepository.new
992
1020
  else
993
1021
  r = Repository.new
1022
+ c = options.delete( :snapshots )
1023
+ c = options.delete( 'snapshots' ) if c.nil?
1024
+ unless c.nil?
1025
+ r.snapshot = repository_policy( c )
1026
+ end
1027
+ c = options.delete( :releases )
1028
+ c = options.delete( 'releases' ) if c.nil?
1029
+ unless c.nil?
1030
+ r.releases = repository_policy( c )
1031
+ end
994
1032
  end
995
- # if config = ( options.delete( :snapshot ) ||
996
- # options.delete( 'snapshot' ) )
997
- # r.snapshot( repository_policy( config ) )
998
- # end
999
- # if config = ( options.delete( :release ) ||
1000
- # options.delete( 'release' ) )
1001
- # r.snapshot( repository_policy( config ) )
1002
- # end
1003
1033
  nested_block( :repository, r, block ) if block
1004
1034
  options.merge!( :url => url )
1005
1035
  fill_options( r, options )
@@ -140,12 +140,18 @@ module Maven
140
140
  if block
141
141
  block.call( dsl )
142
142
  end
143
+ # TODO all that container stuff needs to go into jbundler !!!
143
144
  if container
144
145
  dsl.artifacts.each do |a|
145
146
  if path = a[ :system_path ]
146
147
  container.add_local_jar( path )
147
- elsif not locked?( a.to_s )
148
- container.add_artifact( a.to_s )
148
+ elsif not locked?( coord = a.to_coordinate )
149
+ if exclusions = a.exclusions
150
+ container.add_artifact_with_exclusions( coord,
151
+ exclusions )
152
+ else
153
+ container.add_artifact( coord )
154
+ end
149
155
  end
150
156
  end
151
157
  dsl.repositories.each do |repo|
@@ -24,13 +24,20 @@ require 'stringio'
24
24
  require 'maven/tools/model'
25
25
  require 'maven/tools/dsl'
26
26
  require 'maven/tools/visitor'
27
+ require 'rubygems/specification'
27
28
 
28
29
  module Maven
29
30
  module Tools
30
31
  class POM
31
32
  include Maven::Tools::DSL
32
33
 
33
- def initialize( file = nil )
34
+ def eval_spec( s )
35
+ @model = tesla do
36
+ spec s
37
+ end
38
+ end
39
+
40
+ def eval_file( file )
34
41
  if file && File.directory?( file )
35
42
  dir = file
36
43
  file = nil
@@ -46,9 +53,19 @@ module Maven
46
53
  file ||= pom_file( '*.gemspec', dir )
47
54
  end
48
55
 
49
- FileUtils.cd( dir ) do
50
- @model = to_model( File.basename( file ) )
51
- end if file
56
+ if file
57
+ FileUtils.cd( dir ) do
58
+ @model = to_model( File.basename( file ) )
59
+ end
60
+ end
61
+ end
62
+
63
+ def initialize( file = nil )
64
+ if file.is_a? Gem::Specification
65
+ eval_spec( file )
66
+ else
67
+ eval_file( file )
68
+ end
52
69
  end
53
70
 
54
71
  def pom_file( pom, dir = '.' )
@@ -20,6 +20,6 @@
20
20
  #
21
21
  module Maven
22
22
  module Tools
23
- VERSION = '0.33.5'.freeze
23
+ VERSION = '0.34.0'.freeze
24
24
  end
25
25
  end
@@ -11,16 +11,22 @@ describe Maven::Tools::Coordinate do
11
11
  it 'should convert ruby version to maven version ranges' do
12
12
  subject.to_version.must_equal "[0,)"
13
13
  subject.to_version('!2.3.4').must_equal "(2.3.4,)"
14
+ subject.to_version('!2.3.4.rc').must_equal "(2.3.4.rc-SNAPSHOT,)"
14
15
  subject.to_version('=2.3.4').must_equal "[2.3.4,2.3.4.0.0.0.0.1)"
16
+ subject.to_version('=2.3.4.alpha').must_equal "[2.3.4.alpha-SNAPSHOT,2.3.4.alpha.0.0.0.0.1)"
15
17
  subject.to_version('~>1.8.2').must_equal "[1.8.2,1.8.99999]"
16
- subject.to_version('~>1.8.2.beta').must_equal "[1.8.2.beta,1.8.99999]"
17
- subject.to_version('~>1.8.2.beta123.12').must_equal "[1.8.2.beta123.12,1.8.99999]"
18
- subject.to_version('~>1.8.2.1beta').must_equal "[1.8.2.1beta,1.8.99999]"
18
+ subject.to_version('~>1.8.2.beta').must_equal "[1.8.2.beta-SNAPSHOT,1.8.99999]"
19
+ subject.to_version('~>1.8.2.beta123.12').must_equal "[1.8.2.beta123.12-SNAPSHOT,1.8.99999]"
20
+ subject.to_version('~>1.8.2.1beta').must_equal "[1.8.2.1beta-SNAPSHOT,1.8.99999]"
19
21
  subject.to_version('~>1.8').must_equal "[1.8,1.99999]"
20
22
  subject.to_version('>1.2').must_equal "(1.2,)"
23
+ subject.to_version('>1.2.GA').must_equal "(1.2.GA-SNAPSHOT,)"
21
24
  subject.to_version('<1.2').must_equal "[0,1.2)"
25
+ subject.to_version('<1.2.dev').must_equal "[0,1.2.dev-SNAPSHOT)"
22
26
  subject.to_version('>=1.2').must_equal "[1.2,)"
27
+ subject.to_version('>=1.2.gamma').must_equal "[1.2.gamma-SNAPSHOT,)"
23
28
  subject.to_version('<=1.2').must_equal "[0,1.2]"
29
+ subject.to_version('<=1.2.pre').must_equal "[0,1.2.pre-SNAPSHOT]"
24
30
  subject.to_version('>=1.2', '<2.0').must_equal "[1.2,2.0)"
25
31
  subject.to_version('>=1.2', '<=2.0').must_equal "[1.2,2.0]"
26
32
  subject.to_version('>1.2', '<2.0').must_equal "(1.2,2.0)"
@@ -35,6 +41,14 @@ describe Maven::Tools::Coordinate do
35
41
  subject.to_version('[1,2]').must_equal "[1,2]"
36
42
  end
37
43
 
44
+ it 'should keep maven snapshot version and ranges as they are' do
45
+ subject.to_version('1.2.3-SNAPSHOT').must_equal "1.2.3-SNAPSHOT"
46
+ subject.to_version('(1,2-SNAPSHOT)').must_equal "(1,2-SNAPSHOT)"
47
+ subject.to_version('[1-SNAPSHOT,2)').must_equal "[1-SNAPSHOT,2)"
48
+ subject.to_version('(1,2-SNAPSHOT]').must_equal "(1,2-SNAPSHOT]"
49
+ subject.to_version('[1-SNAPSHOT,2]').must_equal "[1-SNAPSHOT,2]"
50
+ end
51
+
38
52
  it 'should convert pom of jar deps to maven coordinate' do
39
53
  subject.to_coordinate('something "a:b"').must_be_nil
40
54
  subject.to_coordinate('#jar "a:b"').must_be_nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maven-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.5
4
+ version: 0.34.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-03 00:00:00.000000000 Z
12
+ date: 2013-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: virtus