maven-tools 0.34.5 → 1.0.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/lib/maven/tools/artifact.rb +18 -12
  3. data/lib/maven/tools/dsl.rb +282 -121
  4. data/lib/maven/tools/gemfile_lock.rb +0 -6
  5. data/lib/maven/tools/model.rb +78 -69
  6. data/lib/maven/tools/pom.rb +8 -8
  7. data/lib/maven/tools/version.rb +1 -1
  8. data/lib/maven/tools/versions.rb +4 -4
  9. data/lib/maven/tools/visitor.rb +2 -2
  10. data/spec/gemfile_with_lock/bouncy-castle-version.rb +4 -0
  11. data/spec/pom_maven_alternative_style/pom.rb +116 -169
  12. data/spec/pom_maven_hash_style/pom.rb +134 -100
  13. data/spec/pom_maven_style/pom.rb +160 -163
  14. data/spec/pom_spec.rb +3 -1
  15. metadata +12 -90
  16. data/lib/maven/model/dependencies.rb +0 -249
  17. data/lib/maven/model/model.rb +0 -618
  18. data/lib/maven/model/utils.rb +0 -393
  19. data/lib/maven/tools/execute_in_phase.rb +0 -28
  20. data/lib/maven/tools/gem_project.rb +0 -513
  21. data/lib/maven/tools/maven_project.rb +0 -72
  22. data/lib/maven/tools/minimal_project.rb +0 -84
  23. data/lib/maven/tools/pom_generator.rb +0 -83
  24. data/lib/maven/tools/rails_project.rb +0 -133
  25. data/rspec/maven/model/dependencies_spec.rb +0 -260
  26. data/rspec/maven/model/model_spec.rb +0 -714
  27. data/rspec/maven/tools/Gemfile.gems +0 -11
  28. data/rspec/maven/tools/Gemfile.groups +0 -15
  29. data/rspec/maven/tools/Gemfile.ignored +0 -30
  30. data/rspec/maven/tools/Gemfile.lockfile +0 -8
  31. data/rspec/maven/tools/Gemfile.lockfile.lock +0 -53
  32. data/rspec/maven/tools/Gemfile.minimal +0 -1
  33. data/rspec/maven/tools/Gemfile.nolock +0 -1
  34. data/rspec/maven/tools/Gemfile.rails +0 -16
  35. data/rspec/maven/tools/Gemfile.simple +0 -7
  36. data/rspec/maven/tools/Gemfile.withlock +0 -1
  37. data/rspec/maven/tools/Gemfile.withlock.lock +0 -28
  38. data/rspec/maven/tools/Jarfile.with +0 -2
  39. data/rspec/maven/tools/Jarfile.with.lock +0 -1
  40. data/rspec/maven/tools/Jarfile.without +0 -2
  41. data/rspec/maven/tools/deps.gemspec +0 -8
  42. data/rspec/maven/tools/gem_project_spec.rb +0 -1126
  43. data/rspec/maven/tools/maven-tools.gemspec +0 -17
  44. data/rspec/maven/tools/minimal.gemspec +0 -5
  45. data/rspec/maven/tools/no-deps.gemspec +0 -27
  46. data/rspec/maven/tools/rails_project_spec.rb +0 -284
  47. data/rspec/maven/tools/spec_helper.rb +0 -22
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0043d501457131717a2e0d1b85efddcabe5723c0
4
+ data.tar.gz: 631f64b5a850b277e3ffca5bff4ec0f2ffba265a
5
+ SHA512:
6
+ metadata.gz: 455460b23c182cf47ca87631a33176befbdf815cefede9492e8a7e6b5b1c7507bd8d11fd1dc700a826315c5770414bb9e2e450485a0cc6815cf745d2ab444028
7
+ data.tar.gz: 11024c1588037abc38e39cc11da922c5b391c3e4c98d62456ccdd71b4cc3b7f8e32e0da7723e23d716e6e2f740e3c4d3816ad854bffcf33a6425fa6ee047804d
@@ -32,7 +32,7 @@ module Maven
32
32
  end
33
33
 
34
34
  def self.new_local( path, type, options = {} )
35
- name = File.basename( path ).sub( /.#{type}$/, '' )
35
+ name = ::File.basename( path ).sub( /.#{type}$/, '' )
36
36
  if ind = name.rindex( '-' )
37
37
  version = name[ind + 1..-1]
38
38
  name = name[0..ind - 1]
@@ -77,18 +77,24 @@ module Maven
77
77
  # jar "asd:Asd:[dsa:rew,fe:fer]",'>123', '<345'
78
78
  # jar "asd:Asd:test:[dsa:rew,fe:fer]",'>123', '<345'
79
79
  # jar "asd:Asd:test:[dsa:rew,fe:fer]", '123', 'source'
80
- v = helper.to_version( *args[1..-1] )
81
- case v
82
- when String
83
- group_id, artifact_id, classifier, exclusions = args[0].split( /:/ )
84
- self.new( group_id, artifact_id, type,
85
- v, classifier, exclusions,
86
- options )
80
+ if args[ 0 ].match /:/
81
+ v = helper.to_version( *args[1..-1] )
82
+ case v
83
+ when String
84
+ group_id, artifact_id, classifier, exclusions = args[0].split( /:/ )
85
+ self.new( group_id, artifact_id, type,
86
+ v, classifier, exclusions,
87
+ options )
88
+ else
89
+ group_id, artifact_id = args[0].split( /:/ )
90
+ self.new( group_id, artifact_id, type,
91
+ args[1], args[2], nil,
92
+ options )
93
+ end
87
94
  else
88
- group_id, artifact_id = args[0].split( /:/ )
89
- self.new( group_id, artifact_id, type,
90
- args[1], args[2], nil,
91
- options )
95
+ self.new( args[ 0 ], args[ 1 ], type,
96
+ args[ 2 ], nil, nil,
97
+ options )
92
98
  end
93
99
  else
94
100
  nil
@@ -3,6 +3,7 @@ require 'maven/tools/gemspec_dependencies'
3
3
  require 'maven/tools/artifact'
4
4
  require 'maven/tools/jarfile'
5
5
  require 'maven/tools/versions'
6
+ require 'maven/tools/gemfile_lock'
6
7
 
7
8
  module Maven
8
9
  module Tools
@@ -11,7 +12,7 @@ module Maven
11
12
  def tesla( &block )
12
13
  @model = Model.new
13
14
  @model.model_version = '4.0.0'
14
- @model.name = File.basename( basedir )
15
+ @model.name = ::File.basename( basedir )
15
16
  @model.group_id = 'dummy'
16
17
  @model.artifact_id = model.name
17
18
  @model.version = '0.0.0'
@@ -21,8 +22,8 @@ module Maven
21
22
  if ! @model.repositories.detect { |r| r.id == 'rubygems-prereleases' } && @model.dependencies.detect { |d| d.group_id == 'rubygems' && d.version.match( /[a-zA-Z]/ ) }
22
23
 
23
24
  @current = @model
24
- snapshot_repository( 'http://rubygems-proxy.torquebox.org/prereleases',
25
- :id => 'rubygems-prereleases' )
25
+ snapshot_repository( 'rubygems-prereleases',
26
+ 'http://rubygems-proxy.torquebox.org/prereleases' )
26
27
  @current = nil
27
28
  end
28
29
  @needs_torquebox = nil
@@ -47,19 +48,19 @@ module Maven
47
48
 
48
49
  def eval_pom( src, reference_file = '.' )
49
50
  @source = reference_file
50
- eval( src )
51
+ eval( src, nil, ::File.expand_path( @source ) )
51
52
  ensure
52
53
  @source = nil
53
54
  @basedir = nil
54
55
  end
55
56
 
56
57
  def basedir( basedir = nil )
57
- @basedir ||= basedir if basedir
58
+ @basedir = basedir if basedir
58
59
  if @source
59
- @basedir ||= File.directory?( @source ) ? @source :
60
- File.dirname( File.expand_path( @source ) )
60
+ @basedir ||= ::File.directory?( @source ) ? @source :
61
+ ::File.dirname( ::File.expand_path( @source ) )
61
62
  end
62
- @basedir ||= File.expand_path( '.' )
63
+ @basedir ||= ::File.expand_path( '.' )
63
64
  end
64
65
 
65
66
  def artifact( a )
@@ -108,19 +109,54 @@ module Maven
108
109
  options = name
109
110
  name = 'Gemfile'
110
111
  end
111
- name = File.join( basedir, name ) unless File.exists?( name )
112
- basedir = File.dirname( name ) unless basedir
112
+ name = ::File.join( basedir, name ) unless ::File.exists?( name )
113
+ basedir = ::File.dirname( name ) unless basedir
113
114
 
114
- @gemfile_options = options
115
- FileUtils.cd( basedir ) do
116
- eval( File.read( File.expand_path( name ) ) )
115
+ @inside_gemfile = true
116
+ # the eval might need those options for gemspec declaration
117
+ pr = profile :gemfile do
118
+ activation do
119
+ file( :missing => name + '.lock' )
120
+ end
121
+
122
+ FileUtils.cd( basedir ) do
123
+ f = ::File.expand_path( name )
124
+ eval( ::File.read( f ), nil, f )
125
+ end
117
126
  end
118
127
 
119
- if @gemfile_options
120
- @gemfile_options = nil
128
+ if @gemspec_args
129
+ @inside_gemfile = :gemfile
130
+ case @gemspec_args[ 0 ]
131
+ when Hash
132
+ gemspec( @gemspec_args[ 0 ].merge( options ) )
133
+ when NilClass
134
+ gemspec( @gemspec_args[ 0 ], options )
135
+ else
136
+ @gemspec_args[ 1 ].merge!( options )
137
+ gemspec( *@gemspec_args )
138
+ end
139
+ else
121
140
  setup_gem_support( options )
122
141
  end
123
142
 
143
+ if pr.dependencies.empty?
144
+ @current.profiles.delete( pr )
145
+ end
146
+
147
+ lockfile = ::File.expand_path( name + '.lock' )
148
+ if File.exists? lockfile
149
+ profile :gemfile_lock do
150
+ activation do
151
+ file( :exists => name + '.lock' )
152
+ end
153
+ locked = GemfileLock.new( lockfile )
154
+ locked.hull.each do |name, version|
155
+ gem name, version unless model.artifact_id == name && model.group_id == 'rubygems'
156
+ end
157
+ end
158
+ end
159
+
124
160
  if @has_path or @has_git
125
161
  gem 'bundler', :scope => :provided unless gem? 'bundler'
126
162
  jruby_plugin :gem do
@@ -128,17 +164,16 @@ module Maven
128
164
  end
129
165
  end
130
166
  ensure
167
+ @inside_gemfile = nil
168
+ @gemspec_args = nil
131
169
  @has_path = nil
132
170
  @has_git = nil
133
171
  end
134
172
 
135
173
  def setup_gem_support( options, spec = nil, config = {} )
136
- unless model.properties.member?( 'project.build.sourceEncoding' )
137
- properties( 'project.build.sourceEncoding' => 'utf-8' )
138
- end
139
174
  if spec.nil?
140
175
  require_path = '.'
141
- name = File.basename( File.expand_path( '.' ) )
176
+ name = ::File.basename( ::File.expand_path( '.' ) )
142
177
  else
143
178
  require_path = spec.require_path
144
179
  name = spec.name
@@ -147,8 +182,8 @@ module Maven
147
182
  unless options[ :only_metadata ]
148
183
 
149
184
  unless model.repositories.detect { |r| r.id == 'rubygems-releases' }
150
- repository( 'http://rubygems-proxy.torquebox.org/releases',
151
- :id => 'rubygems-releases' )
185
+ repository( 'rubygems-releases',
186
+ 'http://rubygems-proxy.torquebox.org/releases' )
152
187
  end
153
188
  @needs_torquebox = true
154
189
 
@@ -158,8 +193,8 @@ module Maven
158
193
  if options.key?( :jar ) || options.key?( 'jar' )
159
194
  jarpath = options[ :jar ] || options[ 'jar' ]
160
195
  if jarpath
161
- jar = File.basename( jarpath ).sub( /.jar$/, '' )
162
- output = File.dirname( "#{require_path}/#{jarpath}" )
196
+ jar = ::File.basename( jarpath ).sub( /.jar$/, '' )
197
+ output = ::File.dirname( "#{require_path}/#{jarpath}" )
163
198
  output.sub!( /\/$/, '' )
164
199
  end
165
200
  else
@@ -173,7 +208,7 @@ module Maven
173
208
  end
174
209
  end
175
210
  if jar && ( source ||
176
- File.exists?( File.join( basedir, 'src', 'main', 'java' ) ) )
211
+ ::File.exists?( ::File.join( basedir, 'src', 'main', 'java' ) ) )
177
212
  plugin( :jar, VERSIONS[ :jar_plugin ],
178
213
  :outputDirectory => output,
179
214
  :finalName => jar ) do
@@ -194,19 +229,21 @@ module Maven
194
229
  :id => 'jruby-snapshots' )
195
230
  end
196
231
  scope( jruby_scope ) do
197
- if jruby < '1.7'
232
+ if ( jruby < '1.6' )
233
+ raise 'jruby before 1.6 are not supported'
234
+ elsif ( jruby < '1.7' )
198
235
  warn 'jruby version below 1.7 uses jruby-complete'
199
236
  jar 'org.jruby:jruby-core', jruby
200
- elsif jruby.sub( /1\.7\./, '').to_i < 5
237
+ elsif ( jruby.sub( /1\.7\./, '').to_i < 5 )
201
238
  jar 'org.jruby:jruby-core', jruby
202
239
  elsif jruby =~ /-no_asm$/
203
240
  pom 'org.jruby:jruby-noasm', jruby.sub( /-no_asm$/, '' )
204
- else
241
+ else
205
242
  pom 'org.jruby:jruby', jruby
206
243
  end
207
244
  end
208
245
  end
209
- #private :setup_jruby
246
+ private :setup_jruby
210
247
 
211
248
  def jarfile( file = 'Jarfile', options = {} )
212
249
  if file.is_a? Hash
@@ -214,7 +251,7 @@ module Maven
214
251
  file = 'Jarfile'
215
252
  end
216
253
  unless file.is_a?( Maven::Tools::Jarfile )
217
- file = Maven::Tools::Jarfile.new( File.expand_path( file ) )
254
+ file = Maven::Tools::Jarfile.new( ::File.expand_path( file ) )
218
255
  end
219
256
 
220
257
  if options[ :skip_locked ] or not file.exists_lock?
@@ -239,28 +276,33 @@ module Maven
239
276
  end
240
277
  end
241
278
 
242
- def gemspec( name = nil, options = @gemfile_options || {} )
279
+ def gemspec( name = nil, options = {} )
280
+ if @inside_gemfile == true
281
+ @gemspec_args = [ name, options ]
282
+ return
283
+ end
243
284
  if name.is_a? Hash
244
285
  options = name
245
286
  name = nil
246
287
  end
247
288
  if name
248
- name = File.join( basedir, name )
289
+ name = ::File.join( basedir, name )
249
290
  else name
250
- gemspecs = Dir[ File.join( basedir, "*.gemspec" ) ]
291
+ gemspecs = Dir[ ::File.join( basedir, "*.gemspec" ) ]
251
292
  raise "more then one gemspec file found" if gemspecs.size > 1
252
293
  raise "no gemspec file found" if gemspecs.size == 0
253
294
  name = gemspecs.first
254
295
  end
255
296
  spec = nil
256
- spec_file = File.read( File.expand_path( name ) )
297
+ f = ::File.expand_path( name )
298
+ spec_file = ::File.read( f )
257
299
  begin
300
+ spec = Gem::Specification.from_yaml( spec_file )
301
+ rescue Gem::Exception
258
302
  FileUtils.cd( basedir ) do
259
303
  # TODO jruby java user.dir
260
- spec = eval( spec_file )
304
+ spec = eval( spec_file, nil, f )
261
305
  end
262
- rescue
263
- spec = Gem::Specification.from_yaml( spec_file )
264
306
  end
265
307
 
266
308
  self.spec( spec, name, options )
@@ -268,6 +310,9 @@ module Maven
268
310
 
269
311
  def spec( spec, name = nil, options = {} )
270
312
  name ||= "#{spec.name}-#{spec.version}.gemspec"
313
+ unless model.properties.member?( 'project.build.sourceEncoding' )
314
+ properties( 'project.build.sourceEncoding' => 'utf-8' )
315
+ end
271
316
 
272
317
  @gemfile_options = nil
273
318
 
@@ -295,7 +340,24 @@ module Maven
295
340
  end
296
341
  plugin( 'de.saumya.mojo:gem-maven-plugin:${jruby.plugins.version}',
297
342
  config )
343
+
344
+ deps = nil
345
+ if @inside_gemfile
346
+ profile! @inside_gemfile do
347
+ deps = all_deps( spec )
348
+ end
349
+ else
350
+ deps = all_deps( spec )
351
+ end
298
352
 
353
+ unless deps.java_runtime.empty?
354
+ deps.java_runtime.each do |d|
355
+ dependency Maven::Tools::Artifact.new( *d )
356
+ end
357
+ end
358
+ end
359
+
360
+ def all_deps( spec )
299
361
  deps = Maven::Tools::GemspecDependencies.new( spec )
300
362
  deps.runtime.each do |d|
301
363
  gem d
@@ -307,12 +369,9 @@ module Maven
307
369
  end
308
370
  end
309
371
  end
310
- unless deps.java_runtime.empty?
311
- deps.java_runtime.each do |d|
312
- dependency Maven::Tools::Artifact.new( *d )
313
- end
314
- end
372
+ deps
315
373
  end
374
+ private :all_deps
316
375
 
317
376
  def build( &block )
318
377
  build = @current.build ||= Build.new
@@ -368,29 +427,81 @@ module Maven
368
427
  end
369
428
  end
370
429
 
371
- def site( url = nil, options = {} )
430
+ def site( *args, &block )
372
431
  site = Site.new
373
- options.merge!( :url => url )
432
+ args, options = args_and_options( *args )
433
+ site.id = args[ 0 ]
434
+ site.url = args[ 1 ]
435
+ site.name = args[ 2 ]
374
436
  fill_options( site, options )
437
+ nested_block( :site, site, block) if block
375
438
  @current.site = site
376
439
  end
377
440
 
378
- def source_control( url = nil, options = {} )
441
+ def source_control( *args, &block )
379
442
  scm = Scm.new
380
- options.merge!( :url => url )
443
+ args, options = args_and_options( *args )
444
+ scm.connection = args[ 0 ]
445
+ scm.developer_connection = args[ 1 ]
446
+ scm.url = args[ 2 ]
381
447
  fill_options( scm, options )
448
+ nested_block( :scm, scm, block ) if block
382
449
  @current.scm = scm
383
450
  end
384
451
  alias :scm :source_control
385
452
 
386
- def issue_management( url, system = nil )
453
+ def issue_management( *args, &block )
387
454
  issues = IssueManagement.new
388
- issues.url = url
389
- issues.system = system
455
+ args, options = args_and_options( *args )
456
+ issues.url = args[ 0 ]
457
+ fill_options( issues, options )
458
+ nested_block( :issue_management, issues, block ) if block
390
459
  @current.issue_management = issues
391
- issues
460
+ end
461
+ alias :issues :issue_management
462
+
463
+ def ci_management( *args, &block )
464
+ ci = CiManagement.new
465
+ args, options = args_and_options( *args )
466
+ ci.url = args[ 0 ]
467
+ fill_options( ci, options )
468
+ nested_block( :ci_management, ci, block ) if block
469
+ @current.ci_management = ci
470
+ end
471
+ alias :ci :ci_management
472
+
473
+ def distribution_management( *args, &block )
474
+ di = DistributionManagement.new
475
+ args, options = args_and_options( *args )
476
+ di.status = args[ 0 ]
477
+ di.download_url = args[ 1 ]
478
+ fill_options( di, options )
479
+ nested_block( :distribution_management, di, block ) if block
480
+ @current.distribution_management = di
392
481
  end
393
482
 
483
+ def relocation( *args, &block )
484
+ args, options = args_and_options( *args )
485
+ relocation = fill_gav( Relocation, args.join( ':' ) )
486
+ fill_options( relocation, options )
487
+ nested_block( :relocation, relocation, block ) if block
488
+ @current.relocation = relocation
489
+ end
490
+
491
+ def system( arg )
492
+ @current.system = arg
493
+ end
494
+
495
+ def notifier( *args, &block )
496
+ n = Notifier.new
497
+ args, options = args_and_options( *args )
498
+ n.type = args[ 0 ]
499
+ n.address = args[ 1 ]
500
+ fill_options( n, options )
501
+ nested_block( :notifier, n, block ) if block
502
+ @current.notifiers << n
503
+ n
504
+ end
394
505
  def mailing_list( *args, &block )
395
506
  list = MailingList.new
396
507
  args, options = args_and_options( *args )
@@ -468,16 +579,15 @@ module Maven
468
579
  @current.activation = activation
469
580
  end
470
581
 
471
- def distribution( val = nil, &block )
582
+ def distribution( *args, &block )
472
583
  if @context == :license
473
- @current.distribution = val
584
+ args, options = args_and_options( *args )
585
+ @current.distribution = args[ 0 ]
586
+ fill_options( @current, options )
474
587
  else
475
- dist = DistributionManagement.new
476
- nested_block( :distribution, dist, block ) if block
477
- @current.distribution_management = dist
588
+ distribution_management( *args, &block )
478
589
  end
479
590
  end
480
- alias :distribution_management :distribution
481
591
 
482
592
  def includes( *items )
483
593
  @current.includes = items.flatten
@@ -487,11 +597,12 @@ module Maven
487
597
  @current.excludes = items.flatten
488
598
  end
489
599
 
490
- def test_resource( &block )
600
+ def test_resource( options = {}, &block )
491
601
  # strange behaviour when calling specs from Rakefile
492
602
  return if @current.nil?
493
- resource = Resource.new
494
- nested_block( :resource, resource, block ) if block
603
+ resource = TestResource.new
604
+ fill_options( resource, options )
605
+ nested_block( :test_resource, resource, block ) if block
495
606
  if @context == :project
496
607
  ( @current.build ||= Build.new ).test_resources << resource
497
608
  else
@@ -499,8 +610,9 @@ module Maven
499
610
  end
500
611
  end
501
612
 
502
- def resource( &block )
613
+ def resource( options = {}, &block )
503
614
  resource = Resource.new
615
+ fill_options( resource, options )
504
616
  nested_block( :resource, resource, block ) if block
505
617
  if @context == :project
506
618
  ( @current.build ||= Build.new ).resources << resource
@@ -509,44 +621,59 @@ module Maven
509
621
  end
510
622
  end
511
623
 
512
- def repository( url, options = {}, &block )
513
- do_repository( :repository=, url, options, block )
624
+ def repository( *args, &block )
625
+ do_repository( :repository=, *args, &block )
626
+ end
627
+
628
+ def plugin_repository( *args, &block )
629
+ do_repository( :plugin, *args, &block )
514
630
  end
515
631
 
516
- def plugin_repository( url, options = {}, &block )
517
- do_repository( :plugin, url, options, block )
632
+ def set_policy( key, enable, options )
633
+ return unless options
634
+ if map = options[ key ] || options[ key.to_s ]
635
+ map[ :enabled ] = enable
636
+ else
637
+ options[ key ] = enable
638
+ end
518
639
  end
640
+ private :set_policy
519
641
 
520
- def snapshot_repository( url, options = {}, &block )
521
- unless @current.respond_to? :snapshot_repository=
522
- options[ :releases ] = false unless options.key?( :releases ) || options.key?( 'releases' )
523
- options[ :snapshots ] = true unless options.key?( :snapshots ) || options.key?( 'snapshots' )
642
+ def snapshot_repository( *args, &block )
643
+ unless @current.respond_to?( :snapshot_repository= )
644
+ args, options = args_and_options( *args )
645
+ set_policy( :releases, false, options )
646
+ set_policy( :snapshots, true, options )
647
+ args << options
524
648
  end
525
- do_repository( :snapshot_repository=, url, options, block )
649
+ do_repository( :snapshot_repository=, *args, &block )
526
650
  end
527
651
 
528
- def releases( config )
529
- @current.releases = repository_policy( config )
652
+ def releases( config = nil, &block )
653
+ @current.releases = repository_policy( @current.releases,
654
+ config, &block )
530
655
  end
531
656
 
532
- def snapshots( config )
533
- @current.snapshots = repository_policy( config )
657
+ def snapshots( config = nil, &block)
658
+ @current.snapshots = repository_policy( @current.snapshots,
659
+ config, &block )
534
660
  end
535
661
 
536
- def repository_policy( config )
537
- rp = RepositoryPolicy.new
662
+ def repository_policy( rp, config, &block )
663
+ rp ||= RepositoryPolicy.new
538
664
  case config
539
665
  when Hash
540
- rp.enabled = config[ :enabled ]
541
- rp.update_policy = config[ :update ]
542
- rp.checksum_policy = config[ :checksum ]
666
+ rp.enabled = config[ :enabled ] unless config[ :enabled ].nil?
667
+ rp.update_policy = config[ :update ] || config[ :update_policy ]
668
+ rp.checksum_policy = config[ :checksum ] || config[ :checksum_policy ]
543
669
  when TrueClass
544
670
  rp.enabled = true
545
671
  when FalseClass
546
672
  rp.enabled = false
547
673
  else
548
- rp.enabled = 'true' == config
674
+ rp.enabled = 'true' == config unless config.nil?
549
675
  end
676
+ nested_block( :repository_policy, rp, block ) if block
550
677
  rp
551
678
  end
552
679
 
@@ -594,14 +721,26 @@ module Maven
594
721
  @current.properties
595
722
  end
596
723
 
597
- def extension( *gav )
598
- @current.build ||= Build.new
599
- gav = gav.join( ':' )
600
- ext = fill_gav( Extension, gav)
601
- @current.build.extensions << ext
724
+ def extension( *args )
725
+ build = if @context == :build
726
+ @current
727
+ else
728
+ @current.build ||= Build.new
729
+ end
730
+ args, options = args_and_options( *args )
731
+ ext = fill_gav( Extension, args.join( ':' ) )
732
+ fill_options( ext, options )
733
+ build.extensions << ext
602
734
  ext
603
735
  end
604
736
 
737
+ def exclusion( *gav )
738
+ gav = gav.join( ':' )
739
+ ex = fill_gav( Extension, gav)
740
+ @current.exclusions << ex
741
+ ex
742
+ end
743
+
605
744
  def setup_jruby_plugins_version
606
745
  unless @current.properties.key?( 'jruby.plugins.version' )
607
746
  properties( 'jruby.plugins.version' => VERSIONS[ :jruby_plugins ] )
@@ -706,7 +845,7 @@ module Maven
706
845
  end
707
846
  options[ :taskId ] = options[ :id ] || options[ 'id' ]
708
847
  if @source
709
- options[ :nativePom ] = File.expand_path( @source ).sub( /#{basedir}./, '' )
848
+ options[ :nativePom ] = ::File.expand_path( @source ).sub( /#{basedir}./, '' )
710
849
  end
711
850
 
712
851
  add_execute_task( options, &block )
@@ -766,12 +905,12 @@ module Maven
766
905
  exec
767
906
  end
768
907
 
769
- def dependency( type, *args )
770
- do_dependency( false, type, *args )
908
+ def dependency( type, *args, &block )
909
+ do_dependency( false, type, *args, &block )
771
910
  end
772
911
 
773
- def dependency!( type, *args )
774
- do_dependency( true, type, *args )
912
+ def dependency!( type, *args, &block )
913
+ do_dependency( true, type, *args, &block )
775
914
  end
776
915
 
777
916
  def dependency?( type, *args )
@@ -808,6 +947,7 @@ module Maven
808
947
  type = a[ :type ]
809
948
  options = a
810
949
  else
950
+ args, options = args_and_options( *args )
811
951
  a = ::Maven::Tools::Artifact.from( type, *args )
812
952
  end
813
953
  options ||= {}
@@ -817,6 +957,7 @@ module Maven
817
957
  # TODO maybe copy everything from options ?
818
958
  d.scope = options[ :scope ] if options[ :scope ]
819
959
  d.system_path = options[ :system_path ] if options[ :system_path ]
960
+
820
961
  d
821
962
  end
822
963
 
@@ -824,12 +965,14 @@ module Maven
824
965
  if @context == :overrides
825
966
  @current.dependency_management ||= DependencyManagement.new
826
967
  @current.dependency_management.dependencies
968
+ #elsif @context == :build
969
+ # @current.
827
970
  else
828
971
  @current.dependencies
829
972
  end
830
973
  end
831
974
 
832
- def do_dependency( bang, type, *args )
975
+ def do_dependency( bang, type, *args, &block )
833
976
  d = retrieve_dependency( type, *args )
834
977
  container = dependency_container
835
978
 
@@ -843,10 +986,9 @@ module Maven
843
986
  else
844
987
  container << d
845
988
  end
989
+
990
+ args, options = args_and_options( *args )
846
991
 
847
- if args.last.is_a?( Hash )
848
- options = args.last
849
- end
850
992
  if options || @scope
851
993
  options ||= {}
852
994
  if @scope
@@ -860,7 +1002,10 @@ module Maven
860
1002
  case exclusions
861
1003
  when Array
862
1004
  exclusions.each do |v|
863
- d.exclusions << fill_gav( Exclusion, v )
1005
+ v, opts = args_and_options( v )
1006
+ ex = fill_gav( Exclusion, *v )
1007
+ fill_options( ex, opts )
1008
+ d.exclusions << ex
864
1009
  end
865
1010
  when String
866
1011
  d.exclusions << fill_gav( Exclusion, exclusions )
@@ -870,13 +1015,18 @@ module Maven
870
1015
  d.send( "#{k}=".to_sym, v ) unless d.send( k.to_sym )
871
1016
  end
872
1017
  end
1018
+ nested_block( :dependency, d, block ) if block
873
1019
  d
874
1020
  end
875
1021
 
876
1022
  def scope( name )
877
- @scope = name
878
- yield
879
- @scope = nil
1023
+ if @context == :dependency
1024
+ @current.scope = name
1025
+ else
1026
+ @scope = name
1027
+ yield
1028
+ @scope = nil
1029
+ end
880
1030
  end
881
1031
 
882
1032
  def phase( name )
@@ -885,11 +1035,22 @@ module Maven
885
1035
  @phase = nil
886
1036
  end
887
1037
 
1038
+ def profile!( id, &block )
1039
+ profile = @current.profiles.detect { |p| p.id.to_s == id.to_s }
1040
+ if profile
1041
+ nested_block( :profile, profile, block ) if block
1042
+ profile
1043
+ else
1044
+ profile( id, &block )
1045
+ end
1046
+ end
1047
+
888
1048
  def profile( id, &block )
889
1049
  profile = Profile.new
890
1050
  profile.id = id if id
891
1051
  @current.profiles << profile
892
1052
  nested_block( :profile, profile, block ) if block
1053
+ profile
893
1054
  end
894
1055
 
895
1056
  def report_set( *reports, &block )
@@ -942,12 +1103,7 @@ module Maven
942
1103
  end
943
1104
  if args.last.is_a?(Hash)
944
1105
  options = args.last
945
- elsif @group
946
- options = {}
947
- args << options
948
- end
949
- if options
950
-
1106
+
951
1107
  # on ruby-maven side we ignore the require option
952
1108
  options.delete( :require )
953
1109
  options.delete( 'require' )
@@ -958,15 +1114,15 @@ module Maven
958
1114
  @has_path = true
959
1115
  else
960
1116
  platform = options.delete( :platform ) || options.delete( 'platform' )
961
- group = options.delete( :group ) || options.delete( 'group' ) || @group
962
- if group
1117
+ group = options.delete( :group ) || options.delete( 'group' ) || @group || nil
1118
+ if group
963
1119
  case group.to_sym
964
1120
  when :test
965
1121
  options[ :scope ] = :test
966
1122
  when :development
967
1123
  options[ :scope ] = :provided
968
1124
  end
969
- end
1125
+ end
970
1126
  if platform.nil? || is_jruby_platform( platform )
971
1127
  options[ :version ] = '[0,)' if args.size == 2 && options[ :version ].nil? && options[ 'version' ].nil?
972
1128
  do_dependency( bang, :gem, *args )
@@ -979,7 +1135,7 @@ module Maven
979
1135
  end
980
1136
 
981
1137
  def local( path, options = {} )
982
- path = File.expand_path( path )
1138
+ path = ::File.expand_path( path )
983
1139
  dependency( :jar,
984
1140
  Maven::Tools::Artifact.new_local( path, :jar, options ) )
985
1141
  end
@@ -1016,26 +1172,28 @@ module Maven
1016
1172
  end
1017
1173
  @current
1018
1174
  else
1019
- if ( args.size > 0 &&
1020
- args[0].is_a?( String ) &&
1021
- args[0] =~ /^[${}0-9a-zA-Z._-]+(:[${}0-9a-zA-Z._-]+)+$/ ) ||
1022
- ( args.size == 1 && args[0].is_a?( Hash ) )
1023
- mm = method.to_s
1024
- case mm[ (mm.size - 1)..-1 ]
1175
+ begin
1176
+ # if ( args.size > 0 &&
1177
+ # args[0].is_a?( String ) &&
1178
+ # args[0] =~ /^[${}0-9a-zA-Z._-]+(:[${}0-9a-zA-Z._-]+)+$/ ) ||
1179
+ # ( args.size == 1 && args[0].is_a?( Hash ) )
1180
+ case method.to_s[ -1 ]
1025
1181
  when '?'
1026
- dependency?( method.to_s[0..-2].to_sym, *args )
1182
+ dependency?( method.to_s[0..-2].to_sym, *args, &block )
1027
1183
  when '!'
1028
- dependency!( method.to_s[0..-2].to_sym, *args )
1184
+ dependency!( method.to_s[0..-2].to_sym, *args, &block )
1029
1185
  else
1030
- dependency( method, *args )
1186
+ dependency( method, *args, &block )
1031
1187
  end
1032
1188
  # elsif @current.respond_to? method
1033
1189
  # @current.send( method, *args )
1034
1190
  # @current
1035
- else
1191
+ # else
1192
+ rescue => e
1036
1193
  p @context
1037
1194
  p m
1038
1195
  p args
1196
+ raise e
1039
1197
  end
1040
1198
  end
1041
1199
  else
@@ -1053,7 +1211,8 @@ module Maven
1053
1211
 
1054
1212
  private
1055
1213
 
1056
- def do_repository( method, url = nil, options = {}, block = nil )
1214
+ def do_repository( method, *args, &block )
1215
+ args, options = args_and_options( *args )
1057
1216
  if @current.respond_to?( method )
1058
1217
  r = DeploymentRepository.new
1059
1218
  else
@@ -1061,17 +1220,19 @@ module Maven
1061
1220
  c = options.delete( :snapshots )
1062
1221
  c = options.delete( 'snapshots' ) if c.nil?
1063
1222
  unless c.nil?
1064
- r.snapshots = repository_policy( c )
1223
+ r.snapshots = repository_policy( r.snapshots, c )
1065
1224
  end
1066
1225
  c = options.delete( :releases )
1067
1226
  c = options.delete( 'releases' ) if c.nil?
1068
1227
  unless c.nil?
1069
- r.releases = repository_policy( c )
1228
+ r.releases = repository_policy( r.releases, c )
1070
1229
  end
1071
1230
  end
1072
- nested_block( :repository, r, block ) if block
1073
- options.merge!( :url => url )
1231
+ r.id = args[ 0 ]
1232
+ r.url = args[ 1 ]
1233
+ r.name = args[ 2 ]
1074
1234
  fill_options( r, options )
1235
+ nested_block( :repository, r, block ) if block
1075
1236
  case method
1076
1237
  when :plugin
1077
1238
  @current.plugin_repositories << r