maven-tools 0.33.4 → 0.33.5

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.
@@ -22,7 +22,14 @@ module Maven
22
22
  @model = nil
23
23
  result
24
24
  end
25
- alias :maven :tesla
25
+
26
+ def maven( val = nil, &block )
27
+ if @context == nil
28
+ tesla( &block )
29
+ else
30
+ @current.maven = val
31
+ end
32
+ end
26
33
 
27
34
  def model
28
35
  @model
@@ -208,7 +215,9 @@ module Maven
208
215
  end
209
216
 
210
217
  def gemspec( name = nil, options = @gemfile_options || {} )
211
- properties( 'project.build.sourceEncoding' => 'utf-8' ) unless model.properties.member?( 'project.build.sourceEncoding' )
218
+ unless model.properties.member?( 'project.build.sourceEncoding' )
219
+ properties( 'project.build.sourceEncoding' => 'utf-8' )
220
+ end
212
221
 
213
222
  @gemfile_options = nil
214
223
  if name.is_a? Hash
@@ -271,33 +280,65 @@ module Maven
271
280
  build
272
281
  end
273
282
 
274
- def project( name, url = nil, &block )
275
- raise 'mixed up hierachy' unless @current == model
276
- @current.name = name
277
- @current.url = url
283
+ def organization( *args, &block )
284
+ if @context == :project
285
+ args, options = args_and_options( *args )
286
+ org = ( @current.organization ||= Organization.new )
287
+ org.name = args[ 0 ]
288
+ org.url = args[ 1 ]
289
+ fill_options( org, options )
290
+ nested_block( :organization, org, block ) if block
291
+ org
292
+ else
293
+ @current.organization = args[ 0 ]
294
+ end
295
+ end
278
296
 
279
- nested_block(:project, @current, block)
297
+ def license( *args, &block )
298
+ args, options = args_and_options( *args )
299
+ license = License.new
300
+ license.name = args[ 0 ]
301
+ license.url = args[ 1 ]
302
+ fill_options( license, options )
303
+ nested_block( :license, license, block ) if block
304
+ @current.licenses << license
305
+ license
280
306
  end
281
307
 
282
- def id(*value)
283
- value = value.join( ':' )
308
+ def project( *args, &block )
309
+ raise 'mixed up hierachy' unless @current == model
310
+ args, options = args_and_options( *args )
311
+ @current.name = args[ 0 ]
312
+ @current.url = args[ 1 ]
313
+ fill_options( @current, options )
314
+ nested_block(:project, @current, block) if block
315
+ end
316
+
317
+ def id( *args )
318
+ args, options = args_and_options( *args )
284
319
  if @context == :project
285
- fill_gav(@current, value)
320
+ # reset version + groupId
321
+ @current.version = nil
322
+ @current.group_id = nil
323
+ fill_gav( @current, *args )
324
+ fill_options( @current, options )
286
325
  reduce_id
287
326
  else
288
- @current.id = value
327
+ @current.id = args[ 0 ]
289
328
  end
290
329
  end
291
330
 
292
331
  def site( url = nil, options = {} )
293
332
  site = Site.new
294
- fill_options( site, url, options )
333
+ options.merge!( :url => url )
334
+ fill_options( site, options )
295
335
  @current.site = site
296
336
  end
297
337
 
298
338
  def source_control( url = nil, options = {} )
299
339
  scm = Scm.new
300
- fill_options( scm, url, options )
340
+ options.merge!( :url => url )
341
+ fill_options( scm, options )
301
342
  @current.scm = scm
302
343
  end
303
344
  alias :scm :source_control
@@ -307,13 +348,26 @@ module Maven
307
348
  issues.url = url
308
349
  issues.system = system
309
350
  @current.issue_management = issues
351
+ issues
310
352
  end
311
353
 
312
- def mailing_list( name = nil, &block )
354
+ def mailing_list( *args, &block )
313
355
  list = MailingList.new
314
- list.name = name
315
- nested_block( :mailing_list, list, block )
356
+ args, options = args_and_options( *args )
357
+ list.name = args[ 0 ]
358
+ fill_options( list, options )
359
+ nested_block( :mailing_list, list, block ) if block
316
360
  @current.mailing_lists << list
361
+ list
362
+ end
363
+
364
+ def prerequisites( *args, &block )
365
+ pre = Prerequisites.new
366
+ args, options = args_and_options( *args )
367
+ fill_options( pre, options )
368
+ nested_block( :prerequisites, pre, block ) if block
369
+ @current.prerequisites = pre
370
+ pre
317
371
  end
318
372
 
319
373
  def archives( *archives )
@@ -321,13 +375,35 @@ module Maven
321
375
  @current.other_archives = archives
322
376
  end
323
377
 
324
- def developer( id = nil, &block )
325
- dev = Developer.new
326
- dev.id = id
327
- nested_block( :developer, dev, block )
328
- @current.developers << dev
378
+ def other_archives( *archives )
379
+ @current.other_archives = archives
329
380
  end
330
381
 
382
+ def developer( *args, &block )
383
+ dev = Developer.new
384
+ args, options = args_and_options( *args )
385
+ dev.id = args[ 0 ]
386
+ dev.name = args[ 1 ]
387
+ dev.url = args[ 2 ]
388
+ dev.email = args[ 3 ]
389
+ fill_options( dev, options )
390
+ nested_block( :developer, dev, block ) if block
391
+ @current.developers << dev
392
+ dev
393
+ end
394
+
395
+ def contributor( *args, &block )
396
+ con = Contributor.new
397
+ args, options = args_and_options( *args )
398
+ con.name = args[ 0 ]
399
+ con.url = args[ 1 ]
400
+ con.email = args[ 2 ]
401
+ fill_options( con, options )
402
+ nested_block( :contributor, con, block ) if block
403
+ @current.contributors << con
404
+ con
405
+ end
406
+
331
407
  def roles( *roles )
332
408
  @current.roles = roles
333
409
  end
@@ -348,15 +424,20 @@ module Maven
348
424
 
349
425
  def activation( &block )
350
426
  activation = Activation.new
351
- nested_block( :activation, activation, block )
427
+ nested_block( :activation, activation, block ) if block
352
428
  @current.activation = activation
353
429
  end
354
430
 
355
- def distribution( &block )
356
- dist = DistributionManagement.new
357
- nested_block( :distribution, dist, block )
358
- @current.distribution_management = dist
431
+ def distribution( val = nil, &block )
432
+ if @context == :license
433
+ @current.distribution = val
434
+ else
435
+ dist = DistributionManagement.new
436
+ nested_block( :distribution, dist, block ) if block
437
+ @current.distribution_management = dist
438
+ end
359
439
  end
440
+ alias :distribution_management :distribution
360
441
 
361
442
  def includes( *items )
362
443
  @current.includes = items.flatten
@@ -370,7 +451,7 @@ module Maven
370
451
  # strange behaviour when calling specs from Rakefile
371
452
  return if @current.nil?
372
453
  resource = Resource.new
373
- nested_block( :resource, resource, block )
454
+ nested_block( :resource, resource, block ) if block
374
455
  if @context == :project
375
456
  ( @current.build ||= Build.new ).test_resources << resource
376
457
  else
@@ -380,7 +461,7 @@ module Maven
380
461
 
381
462
  def resource( &block )
382
463
  resource = Resource.new
383
- nested_block( :resource, resource, block )
464
+ nested_block( :resource, resource, block ) if block
384
465
  if @context == :project
385
466
  ( @current.build ||= Build.new ).resources << resource
386
467
  else
@@ -425,13 +506,44 @@ module Maven
425
506
  @current.send( method, rp )
426
507
  end
427
508
 
428
- def inherit( *value )
429
- @current.parent = fill_gav( Parent, value.join( ':' ) )
509
+ def args_and_options( *args )
510
+ if args.last.is_a? Hash
511
+ [ args[0..-2], args.last ]
512
+ else
513
+ [ args, {} ]
514
+ end
515
+ end
516
+
517
+ def fill_options( receiver, options )
518
+ options.each do |k,v|
519
+ receiver.send( "#{k}=".to_sym, v )
520
+ end
521
+ end
522
+
523
+ def fill( receiver, method, args )
524
+ receiver.send( "#{method}=".to_sym, args )
525
+ rescue
526
+ begin
527
+ old = @current
528
+ @current = receiver
529
+ # assume v is an array
530
+ send( method, *args )
531
+ ensure
532
+ @current = old
533
+ end
534
+ end
535
+
536
+ def inherit( *args, &block )
537
+ args, options = args_and_options( *args )
538
+ parent = ( @current.parent = fill_gav( Parent, *args ) )
539
+ fill_options( parent, options )
540
+ nested_block( :parent, parent, block ) if block
430
541
  reduce_id
542
+ parent
431
543
  end
432
544
  alias :parent :inherit
433
545
 
434
- def properties(props)
546
+ def properties(props = {})
435
547
  props.each do |k,v|
436
548
  @current.properties[k.to_s] = v.to_s
437
549
  end
@@ -443,6 +555,7 @@ module Maven
443
555
  gav = gav.join( ':' )
444
556
  ext = fill_gav( Extension, gav)
445
557
  @current.build.extensions << ext
558
+ ext
446
559
  end
447
560
 
448
561
  def setup_jruby_plugins_version
@@ -460,7 +573,22 @@ module Maven
460
573
  plugin( *gav, &block )
461
574
  end
462
575
 
463
- def plugin( *gav, &block )
576
+ def plugin!( *gav, &block )
577
+ gav, options = plugin_gav( *gav )
578
+ pl = plugins.detect do |p|
579
+ "#{p.group_id}:#{p.artifact_id}:#{p.version}" == gav
580
+ end
581
+ if pl
582
+ do_plugin( false, pl, options, &block )
583
+ else
584
+ plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin,
585
+ gav)
586
+
587
+ do_plugin( true, plugin, options, &block )
588
+ end
589
+ end
590
+
591
+ def plugin_gav( *gav )
464
592
  if gav.last.is_a? Hash
465
593
  options = gav.last
466
594
  gav = gav[ 0..-2 ]
@@ -470,44 +598,104 @@ module Maven
470
598
  unless gav.first.match( /:/ )
471
599
  gav[ 0 ] = "org.apache.maven.plugins:maven-#{gav.first}-plugin"
472
600
  end
473
- gav = gav.join( ':' )
474
- plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin,
475
- gav)
476
- set_config( plugin, options )
601
+ [ gav.join( ':' ), options ]
602
+ end
603
+ private :plugin_gav
604
+
605
+ def plugins
477
606
  if @current.respond_to? :build
478
607
  @current.build ||= Build.new
479
608
  if @context == :overrides
480
609
  @current.build.plugin_management ||= PluginManagement.new
481
- @current.build.plugin_management.plugins << plugin
610
+ @current.build.plugin_management.plugins
482
611
  else
483
- @current.build.plugins << plugin
612
+ @current.build.plugins
484
613
  end
485
614
  else
486
- @current.plugins << plugin
615
+ @current.plugins
487
616
  end
617
+ end
618
+ private :plugins
619
+
620
+ def plugin( *gav, &block )
621
+ gav, options = plugin_gav( *gav )
622
+ plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin,
623
+ gav)
624
+
625
+ do_plugin( true, plugin, options, &block )
626
+ end
627
+
628
+ def do_plugin( add_plugin, plugin, options, &block )
629
+ set_config( plugin, options )
630
+ plugins << plugin if add_plugin
488
631
  nested_block(:plugin, plugin, block) if block
489
632
  plugin
490
633
  end
634
+ private :do_plugin
491
635
 
492
636
  def overrides(&block)
493
- nested_block(:overrides, @current, block)
637
+ nested_block(:overrides, @current, block) if block
494
638
  end
495
639
  alias :plugin_management :overrides
496
640
  alias :dependency_management :overrides
497
641
 
498
- def execute( options )
499
- execute_goals( options )
642
+ def execute( id = nil, phase = nil, options = {}, &block )
643
+ if block
644
+ raise 'can not be inside a plugin' if @current == :plugin
645
+ if phase.is_a? Hash
646
+ options = phase
647
+ else
648
+ options[ :phase ] = phase
649
+ end
650
+ if id.is_a? Hash
651
+ options = id
652
+ else
653
+ options[ :id ] = id
654
+ end
655
+ options[ :taskId ] = options[ :id ] || options[ 'id' ]
656
+ if @source
657
+ options[ :nativePom ] = File.expand_path( @source ).sub( /#{basedir}./, '' )
658
+ end
659
+
660
+ add_execute_task( options, &block )
661
+ else
662
+ # just act like execute_goals
663
+ execute_goals( id )
664
+ end
665
+ end
666
+
667
+ # hook for polyglot maven to register those tasks
668
+ def add_execute_task( options, &block )
669
+ plugin!( 'io.tesla.polyglot:tesla-polyglot-maven-plugin',
670
+ VERSIONS[ :tesla_version ] ) do
671
+ execute_goal( :execute, options )
672
+
673
+ jar!( 'io.tesla.polyglot:tesla-polyglot-ruby',
674
+ VERSIONS[ :tesla_version ] )
675
+ end
676
+ end
677
+
678
+ def retrieve_phase( options )
679
+ if @phase
680
+ if options[ :phase ] || options[ 'phase' ]
681
+ raise 'inside phase block and phase option given'
682
+ end
683
+ @phase
684
+ else
685
+ options.delete( :phase ) || options.delete( 'phase' )
686
+ end
500
687
  end
688
+ private :retrieve_phase
501
689
 
502
- def execute_goal( goal, options = {} )
690
+ def execute_goal( goal, options = {}, &block )
503
691
  if goal.is_a? Hash
504
- execute_goals( goal )
692
+ execute_goals( goal, &block )
505
693
  else
506
- execute_goals( goal, options )
694
+ execute_goals( goal, options, &block )
507
695
  end
508
696
  end
509
697
 
510
- def execute_goals( *goals )
698
+ def execute_goals( *goals, &block )
511
699
  if goals.last.is_a? Hash
512
700
  options = goals.last
513
701
  goals = goals[ 0..-2 ]
@@ -518,18 +706,11 @@ module Maven
518
706
  # keep the original default of id
519
707
  id = options.delete( :id ) || options.delete( 'id' )
520
708
  exec.id = id if id
521
- if @phase
522
- if options[ :phase ] || options[ 'phase' ]
523
- raise 'inside phase block and phase option given'
524
- end
525
- exec.phase = @phase
526
- else
527
- exec.phase = options.delete( :phase ) || options.delete( 'phase' )
528
- end
709
+ exec.phase = retrieve_phase( options )
529
710
  exec.goals = goals.collect { |g| g.to_s }
530
711
  set_config( exec, options )
531
712
  @current.executions << exec
532
- # nested_block(:execution, exec, block) if block
713
+ nested_block(:execution, exec, block) if block
533
714
  exec
534
715
  end
535
716
 
@@ -537,7 +718,16 @@ module Maven
537
718
  do_dependency( false, type, *args )
538
719
  end
539
720
 
540
- def dependency?( container, dep )
721
+ def dependency!( type, *args )
722
+ do_dependency( true, type, *args )
723
+ end
724
+
725
+ def dependency?( type, *args )
726
+ find_dependency( dependency_container,
727
+ retrieve_dependency( type, *args ) ) != nil
728
+ end
729
+
730
+ def find_dependency( container, dep )
541
731
  container.detect do |d|
542
732
  dep.group_id == d.group_id && dep.artifact_id == d.artifact_id && dep.classifier == d.classifier
543
733
  end
@@ -545,7 +735,7 @@ module Maven
545
735
 
546
736
  def dependency_set( bang, container, dep )
547
737
  if bang
548
- dd = dependency?( container, dep )
738
+ dd = do_dependency?( container, dep )
549
739
  if index = container.index( dd )
550
740
  container[ index ] = dep
551
741
  else
@@ -556,7 +746,7 @@ module Maven
556
746
  end
557
747
  end
558
748
 
559
- def do_dependency( bang, type, *args )
749
+ def retrieve_dependency( type, *args )
560
750
  if args.empty?
561
751
  a = type
562
752
  type = a[ :type ]
@@ -571,16 +761,33 @@ module Maven
571
761
  d = fill_gav( Dependency,
572
762
  a ? a.gav : args.join( ':' ) )
573
763
  d.type = type.to_s
764
+ d
765
+ end
766
+
767
+ def dependency_container
574
768
  if @context == :overrides
575
769
  @current.dependency_management ||= DependencyManagement.new
576
- dependency_set( bang,
577
- @current.dependency_management.dependencies,
578
- d )
770
+ @current.dependency_management.dependencies
771
+ else
772
+ @current.dependencies
773
+ end
774
+ end
775
+
776
+ def do_dependency( bang, type, *args )
777
+ d = retrieve_dependency( type, *args )
778
+ container = dependency_container
779
+
780
+ if bang
781
+ dd = find_dependency( container, d )
782
+ if index = container.index( dd )
783
+ container[ index ] = d
784
+ else
785
+ container << d
786
+ end
579
787
  else
580
- dependency_set( bang,
581
- @current.dependencies,
582
- d )
788
+ container << d
583
789
  end
790
+
584
791
  if args.last.is_a?( Hash )
585
792
  options = args.last
586
793
  end
@@ -625,7 +832,7 @@ module Maven
625
832
  profile = Profile.new
626
833
  profile.id = id if id
627
834
  @current.profiles << profile
628
- nested_block( :profile, profile, block )
835
+ nested_block( :profile, profile, block ) if block
629
836
  end
630
837
 
631
838
  def report_set( *reports, &block )
@@ -648,15 +855,19 @@ module Maven
648
855
  def reporting( &block )
649
856
  reporting = Reporting.new
650
857
  @current.reporting = reporting
651
- nested_block( :reporting, reporting, block )
858
+ nested_block( :reporting, reporting, block ) if block
652
859
  end
653
860
 
654
861
  def gem?( name )
655
862
  @current.dependencies.detect do |d|
656
- d.artifact_id == name && d.type == :gem
863
+ d.group_id == 'rubygems' && d.artifact_id == name && d.type == :gem
657
864
  end
658
865
  end
659
866
 
867
+ def jar!( *args )
868
+ dependency!( :jar, *args )
869
+ end
870
+
660
871
  def gem( *args )
661
872
  do_gem( false, *args )
662
873
  end
@@ -714,10 +925,26 @@ module Maven
714
925
  #p m
715
926
  #p args
716
927
  begin
717
- @current.send( m, *args )
928
+
929
+ if defined?(JRUBY_VERSION) and
930
+ not RUBY_VERSION =~ /1.8/ and
931
+ args.size > 1
932
+
933
+ @current.send( m, args, &block )
934
+
935
+ else
936
+ @current.send( m, *args, &block )
937
+ end
938
+ rescue TypeError
939
+ # assume single argument
940
+ @current.send( m, args[0].to_s, &block )
718
941
  rescue ArgumentError
719
- if @current.respond_to? method
720
- @current.send( method, *args )
942
+ begin
943
+ @current.send( m, args )
944
+ rescue ArgumentError => e
945
+ if @current.respond_to? method
946
+ @current.send( method, *args )
947
+ end
721
948
  end
722
949
  end
723
950
  @current
@@ -726,7 +953,15 @@ module Maven
726
953
  args[0].is_a?( String ) &&
727
954
  args[0] =~ /^[${}0-9a-zA-Z._-]+(:[${}0-9a-zA-Z._-]+)+$/ ) ||
728
955
  ( args.size == 1 && args[0].is_a?( Hash ) )
729
- dependency( method, *args )
956
+ mm = method.to_s
957
+ case mm[ (mm.size - 1)..-1 ]
958
+ when '?'
959
+ dependency?( method.to_s[0..-2].to_sym, *args )
960
+ when '!'
961
+ dependency!( method.to_s[0..-2].to_sym, *args )
962
+ else
963
+ dependency( method, *args )
964
+ end
730
965
  # elsif @current.respond_to? method
731
966
  # @current.send( method, *args )
732
967
  # @current
@@ -766,7 +1001,8 @@ module Maven
766
1001
  # r.snapshot( repository_policy( config ) )
767
1002
  # end
768
1003
  nested_block( :repository, r, block ) if block
769
- fill_options( r, url, options )
1004
+ options.merge!( :url => url )
1005
+ fill_options( r, options )
770
1006
  case method
771
1007
  when :plugin
772
1008
  @current.plugin_repositories << r
@@ -779,14 +1015,6 @@ module Maven
779
1015
  end
780
1016
  end
781
1017
 
782
- def fill_options( receiver, url, options )
783
- url ||= options.delete( :url ) || options.delete( 'url' )
784
- options.each do |k,v|
785
- receiver.send "#{k}=".to_sym, v
786
- end
787
- receiver.url = url
788
- end
789
-
790
1018
  def reduce_id
791
1019
  if parent = @current.parent
792
1020
  @current.version = nil if parent.version == @current.version
@@ -807,19 +1035,24 @@ module Maven
807
1035
  @context = old_ctx
808
1036
  end
809
1037
 
810
- def fill_gav(receiver, gav)
811
- if gav
812
- if receiver.is_a? Class
813
- receiver = receiver.new
814
- end
815
- gav = gav.split(':')
1038
+ def fill_gav(receiver, *gav)
1039
+ if receiver.is_a? Class
1040
+ receiver = receiver.new
1041
+ end
1042
+ if gav.size > 0
1043
+ gav = gav[0].split(':') if gav.size == 1
816
1044
  case gav.size
817
1045
  when 0
818
1046
  # do nothing - will be filled later
819
1047
  when 1
820
1048
  receiver.artifact_id = gav[0]
821
1049
  when 2
822
- receiver.group_id, receiver.artifact_id = gav
1050
+ if gav[ 0 ] =~ /:/
1051
+ receiver.group_id, receiver.artifact_id = gav[ 0 ].split /:/
1052
+ receiver.version = gav[ 1 ]
1053
+ else
1054
+ receiver.group_id, receiver.artifact_id = gav
1055
+ end
823
1056
  when 3
824
1057
  receiver.group_id, receiver.artifact_id, receiver.version = gav
825
1058
  when 4