Module: Maven::Tools::DSL

Included in:
POM
Defined in:
lib/maven/tools/dsl.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
# File 'lib/maven/tools/dsl.rb', line 975

def method_missing( method, *args, &block )
  if @context
    m = "#{method}=".to_sym
    if @current.respond_to? m
      #p @context
      #p m
      #p args
      begin

        if defined?(JRUBY_VERSION) and
            not RUBY_VERSION =~ /1.8/ and
            args.size > 1

          @current.send( m, args, &block )

        else
          @current.send( m, *args, &block )
        end
      rescue TypeError
        # assume single argument
        @current.send( m, args[0].to_s, &block )              
      rescue ArgumentError
        begin
          @current.send( m, args )
        rescue ArgumentError => e
          if @current.respond_to? method
            @current.send( method, *args )
          end
        end
      end
      @current
    else
      if ( args.size > 0 &&
           args[0].is_a?( String ) &&
           args[0] =~ /^[${}0-9a-zA-Z._-]+(:[${}0-9a-zA-Z._-]+)+$/ ) ||
          ( args.size == 1 && args[0].is_a?( Hash ) )
        mm = method.to_s
        case mm[ (mm.size - 1)..-1 ]
        when '?'
          dependency?( method.to_s[0..-2].to_sym, *args )
        when '!'
          dependency!( method.to_s[0..-2].to_sym, *args )
        else
          dependency( method, *args )
        end
        # elsif @current.respond_to? method
        #   @current.send( method, *args )
        #   @current
      else
        p @context
        p m
        p args
      end
    end
  else
    super
  end
end

Instance Method Details

#activation(&block) ⇒ Object



458
459
460
461
462
# File 'lib/maven/tools/dsl.rb', line 458

def activation( &block )
  activation = Activation.new
  nested_block( :activation, activation, block ) if block
  @current.activation = activation
end

#add_execute_task(options, &block) ⇒ Object

hook for polyglot maven to register those tasks



713
714
715
716
717
718
719
720
721
# File 'lib/maven/tools/dsl.rb', line 713

def add_execute_task( options, &block )
  plugin!( 'io.tesla.polyglot:tesla-polyglot-maven-plugin',
           VERSIONS[ :tesla_version ] ) do
    execute_goal( :execute, options )
    
    jar!( 'io.tesla.polyglot:tesla-polyglot-ruby',
          VERSIONS[ :tesla_version ] )
  end
end

#archives(*archives) ⇒ Object



406
407
408
409
# File 'lib/maven/tools/dsl.rb', line 406

def archives( *archives )
  @current.archive = archives.shift
  @current.other_archives = archives
end

#args_and_options(*args) ⇒ Object



546
547
548
549
550
551
552
# File 'lib/maven/tools/dsl.rb', line 546

def args_and_options( *args )
  if args.last.is_a? Hash
    [ args[0..-2], args.last ]
  else
    [ args, {} ]
  end
end

#artifact(a) ⇒ Object



65
66
67
68
69
70
# File 'lib/maven/tools/dsl.rb', line 65

def artifact( a )
  if a.is_a?( String )
    a = Maven::Tools::Artifact.from_coordinate( a )
  end
  self.send a[:type].to_sym, a
end

#basedir(basedir = nil) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/maven/tools/dsl.rb', line 56

def basedir( basedir = nil )
  @basedir ||= basedir if basedir
  if @source
    @basedir ||= File.directory?( @source ) ? @source : 
      File.dirname( File.expand_path( @source ) )
  end
  @basedir ||= File.expand_path( '.' )
end

#build(&block) ⇒ Object



310
311
312
313
314
# File 'lib/maven/tools/dsl.rb', line 310

def build( &block )
  build = @current.build ||= Build.new
  nested_block( :build, build, block ) if block
  build
end

#contributor(*args, &block) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
# File 'lib/maven/tools/dsl.rb', line 428

def contributor( *args, &block )
  con = Contributor.new
  args, options = args_and_options( *args )
  con.name = args[ 0 ]
  con.url = args[ 1 ]
  con.email = args[ 2 ]
  fill_options( con, options )
  nested_block( :contributor, con, block ) if block
  @current.contributors << con
  con
end

#dependency(type, *args) ⇒ Object



762
763
764
# File 'lib/maven/tools/dsl.rb', line 762

def dependency( type, *args )
  do_dependency( false, type, *args )
end

#dependency!(type, *args) ⇒ Object



766
767
768
# File 'lib/maven/tools/dsl.rb', line 766

def dependency!( type, *args )
  do_dependency( true, type, *args )
end

#dependency?(type, *args) ⇒ Boolean

Returns:

  • (Boolean)


770
771
772
773
# File 'lib/maven/tools/dsl.rb', line 770

def dependency?( type, *args )
  find_dependency( dependency_container,
                   retrieve_dependency( type, *args ) ) != nil
end

#dependency_containerObject



816
817
818
819
820
821
822
823
# File 'lib/maven/tools/dsl.rb', line 816

def dependency_container
  if @context == :overrides
    @current.dependency_management ||= DependencyManagement.new
    @current.dependency_management.dependencies
  else
    @current.dependencies
  end
end

#dependency_set(bang, container, dep) ⇒ Object



781
782
783
784
785
786
787
788
789
790
791
792
# File 'lib/maven/tools/dsl.rb', line 781

def dependency_set( bang, container, dep )
  if bang
    dd = do_dependency?( container, dep )
    if index = container.index( dd )
      container[ index ] = dep
    else
      container << dep
    end
  else
    container << dep
  end
end

#developer(*args, &block) ⇒ Object



415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/maven/tools/dsl.rb', line 415

def developer( *args, &block )
  dev = Developer.new
  args, options = args_and_options( *args )
  dev.id = args[ 0 ]
  dev.name = args[ 1 ]
  dev.url = args[ 2 ]
  dev.email = args[ 3 ]
  fill_options( dev, options )
  nested_block( :developer, dev, block ) if block
  @current.developers << dev
  dev
end

#distribution(val = nil, &block) ⇒ Object Also known as: distribution_management



464
465
466
467
468
469
470
471
472
# File 'lib/maven/tools/dsl.rb', line 464

def distribution( val = nil, &block )
  if @context == :license
    @current.distribution = val
  else
    dist = DistributionManagement.new
    nested_block( :distribution, dist, block ) if block
    @current.distribution_management = dist
  end
end

#do_dependency(bang, type, *args) ⇒ Object



825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# File 'lib/maven/tools/dsl.rb', line 825

def do_dependency( bang, type, *args )
  d = retrieve_dependency( type, *args )
  container = dependency_container

  if bang
    dd = find_dependency( container, d )
    if index = container.index( dd )
      container[ index ] = d
    else
      container << d
    end
  else
    container << d
  end

  if args.last.is_a?( Hash )
    options = args.last
  end
  if options || @scope
    options ||= {}
    if @scope
      if options[ :scope ] || options[ 'scope' ]
        raise "scope block and scope option given"
      end
      options[ :scope ] = @scope
    end
    exclusions = options.delete( :exclusions ) ||
      options.delete( "exclusions" )
    case exclusions
    when Array
      exclusions.each do |v|
        d.exclusions << fill_gav( Exclusion, v )
      end
    when String
      d.exclusions << fill_gav( Exclusion, exclusions )
    end

    options.each do |k,v|
      d.send( "#{k}=".to_sym, v ) unless d.send( k.to_sym )
    end
  end
  d
end

#do_gem(bang, *args) ⇒ Object



930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
# File 'lib/maven/tools/dsl.rb', line 930

def do_gem( bang, *args )
  # in some setup that gem could overload the Kernel gem
  return if @current.nil?
  unless args[ 0 ].match( /:/ )
    args[ 0 ] = "rubygems:#{args[ 0 ] }"
  end
  if args.last.is_a?(Hash)
    options = args.last

    # on ruby-maven side we ignore the require option
    options.delete( :require )
    options.delete( 'require' )

    if options.key?( :git )
      @has_git = true
    elsif options.key?( :path )
      @has_path = true
    else
      platform = options.delete( :platform ) || options.delete( 'platform' )
      group = options.delete( :group ) || options.delete( 'group' ) || @group || nil
       if group
         case group.to_sym
         when :test
           options[ :scope ] = :test 
         when :development
           options[ :scope ] = :provided
         end
       end
      if platform.nil? || is_jruby_platform( platform )
        options[ :version ] = '[0,)' if args.size == 2 && options[ :version ].nil? && options[ 'version' ].nil?
        do_dependency( bang, :gem, *args )
      end
    end
  else
    args << { :version => '[0,)' } if args.size == 1
    do_dependency( bang, :gem, *args )
  end
end

#do_jruby_plugin(method, *gav, &block) ⇒ Object



604
605
606
607
608
609
610
611
# File 'lib/maven/tools/dsl.rb', line 604

def do_jruby_plugin( method, *gav, &block )
  gav[ 0 ] = "de.saumya.mojo:#{gav[ 0 ]}-maven-plugin"
  if gav.size == 1 || gav[ 1 ].is_a?( Hash )
    setup_jruby_plugins_version
    gav.insert( 1, '${jruby.plugins.version}' )
  end
  send( method, *gav, &block )
end

#eval_pom(src, reference_file = '.') ⇒ Object



48
49
50
51
52
53
54
# File 'lib/maven/tools/dsl.rb', line 48

def eval_pom( src, reference_file = '.' )
  @source = reference_file
  eval( src )
ensure
  @source = nil
  @basedir = nil
end

#excludes(*items) ⇒ Object



479
480
481
# File 'lib/maven/tools/dsl.rb', line 479

def excludes( *items )
  @current.excludes = items.flatten
end

#execute(id = nil, phase = nil, options = {}, &block) ⇒ Object



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'lib/maven/tools/dsl.rb', line 687

def execute( id = nil, phase = nil, options = {}, &block )
  if block
    raise 'can not be inside a plugin' if @current == :plugin
    if phase.is_a? Hash
      options = phase
    else
      options[ :phase ] = phase
    end
    if id.is_a? Hash
      options = id
    else
      options[ :id ] = id
    end
    options[ :taskId ] = options[ :id ] || options[ 'id' ]
    if @source
      options[ :nativePom ] = File.expand_path( @source ).sub( /#{basedir}./, '' )
    end
	  
    add_execute_task( options, &block )
  else
    # just act like execute_goals
    execute_goals( id )
  end
end

#execute_goal(goal, options = {}, &block) ⇒ Object



735
736
737
738
739
740
741
# File 'lib/maven/tools/dsl.rb', line 735

def execute_goal( goal, options = {}, &block )
  if goal.is_a? Hash
    execute_goals( goal, &block )
  else
    execute_goals( goal, options, &block )
  end
end

#execute_goals(*goals, &block) ⇒ Object



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
# File 'lib/maven/tools/dsl.rb', line 743

def execute_goals( *goals, &block )
  if goals.last.is_a? Hash
    options = goals.last
    goals = goals[ 0..-2 ]
  else
    options = {}
  end
  exec = Execution.new
  # keep the original default of id
  id = options.delete( :id ) || options.delete( 'id' )
  exec.id = id if id
  exec.phase = retrieve_phase( options )
  exec.goals = goals.collect { |g| g.to_s }
  set_config( exec, options )
  @current.executions << exec
  nested_block(:execution, exec, block) if block
  exec
end

#extension(*gav) ⇒ Object



590
591
592
593
594
595
596
# File 'lib/maven/tools/dsl.rb', line 590

def extension( *gav )
  @current.build ||= Build.new
  gav = gav.join( ':' )
  ext = fill_gav( Extension, gav)
  @current.build.extensions << ext
  ext
end

#file(options) ⇒ Object



451
452
453
454
455
456
# File 'lib/maven/tools/dsl.rb', line 451

def file( options )
  file = ActivationFile.new
  file.missing = options[ :missing ] || options[ 'missing' ]
  file.exists = options[ :exists ] || options[ 'exists' ]
  @current.file = file
end

#fill(receiver, method, args) ⇒ Object



560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/maven/tools/dsl.rb', line 560

def fill( receiver, method, args )
  receiver.send( "#{method}=".to_sym, args )
rescue
  begin
    old = @current
    @current = receiver
    # assume v is an array
    send( method, *args )
  ensure
    @current = old
  end
end

#fill_options(receiver, options) ⇒ Object



554
555
556
557
558
# File 'lib/maven/tools/dsl.rb', line 554

def fill_options( receiver, options )
  options.each do |k,v|
    receiver.send( "#{k}=".to_sym, v )
  end
end

#find_dependency(container, dep) ⇒ Object



775
776
777
778
779
# File 'lib/maven/tools/dsl.rb', line 775

def find_dependency( container, dep )
  container.detect do |d|
    dep.group_id == d.group_id && dep.artifact_id == d.artifact_id && dep.classifier == d.classifier
  end
end

#gem(*args) ⇒ Object



921
922
923
# File 'lib/maven/tools/dsl.rb', line 921

def gem( *args )
  do_gem( false, *args )
end

#gem!(*args) ⇒ Object

TODO useful ?



926
927
928
# File 'lib/maven/tools/dsl.rb', line 926

def gem!( *args )
  do_gem( true, *args )
end

#gem?(name) ⇒ Boolean

Returns:

  • (Boolean)


911
912
913
914
915
# File 'lib/maven/tools/dsl.rb', line 911

def gem?( name )
  @current.dependencies.detect do |d|
    d.group_id == 'rubygems' && d.artifact_id == name && d.type == :gem
  end
end

#gemfile(name = 'Gemfile', options = {}) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/maven/tools/dsl.rb', line 106

def gemfile( name = 'Gemfile', options = {} )
  if name.is_a? Hash
    options = name
    name = 'Gemfile'
  end
  name = File.join( basedir, name ) unless File.exists?( name )
  basedir = File.dirname( name ) unless basedir

  @gemfile_options = options
  FileUtils.cd( basedir ) do
    eval( File.read( File.expand_path( name ) ) )
  end

  if @gemfile_options
    @gemfile_options = nil
    setup_gem_support( options )
  end

  if @has_path or @has_git
    gem 'bundler', :scope => :provided unless gem? 'bundler'
    jruby_plugin :gem do
      execute_goal :exec, :filename => 'bundle', :args => 'install'
    end
  end
ensure
  @has_path = nil
  @has_git = nil
end

#gemspec(name = nil, options = @gemfile_options || {}) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/maven/tools/dsl.rb', line 232

def gemspec( name = nil, options = @gemfile_options || {} )
  if name.is_a? Hash
    options = name
    name = nil
  end
  if name
    name = File.join( basedir, name )
  else name
    gemspecs = Dir[ File.join( basedir, "*.gemspec" ) ]
    raise "more then one gemspec file found" if gemspecs.size > 1
    raise "no gemspec file found" if gemspecs.size == 0
    name = gemspecs.first
  end
  spec = nil
  spec_file = File.read( File.expand_path( name ) )
  begin
    FileUtils.cd( basedir ) do
      # TODO jruby java user.dir
      spec = eval( spec_file )
    end
  rescue
    spec = Gem::Specification.from_yaml( spec_file )
  end
  
  self.spec( spec, name, options )
end

#git(*args) ⇒ Object



84
85
86
# File 'lib/maven/tools/dsl.rb', line 84

def git( *args )
  warn 'git block not implemented'
end

#group(*args) ⇒ Object



99
100
101
102
103
104
# File 'lib/maven/tools/dsl.rb', line 99

def group( *args )
  @group = args[ 0 ]
  yield
ensure
  @group = nil
end

#id(*args) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/maven/tools/dsl.rb', line 350

def id( *args )
  args, options = args_and_options( *args )
  if @context == :project
    # reset version + groupId
    @current.version = nil
    @current.group_id = nil
    fill_gav( @current, *args )
    fill_options( @current, options )
    reduce_id
  else
    @current.id = args[ 0 ]
  end
end

#includes(*items) ⇒ Object



475
476
477
# File 'lib/maven/tools/dsl.rb', line 475

def includes( *items )
  @current.includes = items.flatten
end

#inherit(*args, &block) ⇒ Object Also known as: parent



573
574
575
576
577
578
579
580
# File 'lib/maven/tools/dsl.rb', line 573

def inherit( *args, &block )
  args, options = args_and_options( *args )
  parent = ( @current.parent = fill_gav( Parent, *args ) )
  fill_options( parent, options )
  nested_block( :parent, parent, block ) if block
  reduce_id
  parent
end

#issue_management(url, system = nil) ⇒ Object



379
380
381
382
383
384
385
# File 'lib/maven/tools/dsl.rb', line 379

def issue_management( url, system = nil )
  issues = IssueManagement.new
  issues.url = url
  issues.system = system
  @current.issue_management = issues
  issues
end

#jar!(*args) ⇒ Object



917
918
919
# File 'lib/maven/tools/dsl.rb', line 917

def jar!( *args )
  dependency!( :jar, *args )
end

#jarfile(file = 'Jarfile', options = {}) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/maven/tools/dsl.rb', line 201

def jarfile( file = 'Jarfile', options = {} )
  if file.is_a? Hash 
    options = file
    file = 'Jarfile'
  end
  unless file.is_a?( Maven::Tools::Jarfile )
    file = Maven::Tools::Jarfile.new( File.expand_path( file ) )
  end

  if options[ :skip_locked ] or not file.exists_lock?
    file.populate_unlocked do |dsl|
      setup_jruby( dsl.jruby )
      dsl.artifacts.each do |a|
        dependency a
      end
    end
  else
    file.locked.each do |dep|
      artifact( dep )
    end
    file.populate_unlocked do |dsl|
      setup_jruby( dsl.jruby )
      dsl.artifacts.each do |a|
        if a[ :system_path ]
          dependeny a
        end
      end
    end
  end
end

#jruby_plugin(*gav, &block) ⇒ Object



613
614
615
# File 'lib/maven/tools/dsl.rb', line 613

def jruby_plugin( *gav, &block )
  do_jruby_plugin( :plugin, *gav, &block )
end

#jruby_plugin!(*gav, &block) ⇒ Object



617
618
619
# File 'lib/maven/tools/dsl.rb', line 617

def jruby_plugin!( *gav, &block )
  do_jruby_plugin( :plugin!, *gav, &block )
end

#license(*args, &block) ⇒ Object



330
331
332
333
334
335
336
337
338
339
# File 'lib/maven/tools/dsl.rb', line 330

def license( *args, &block )
  args, options = args_and_options( *args )
  license = License.new
  license.name = args[ 0 ]
  license.url = args[ 1 ]
  fill_options( license, options )
  nested_block( :license, license, block ) if block
  @current.licenses << license
  license
end

#local(path, options = {}) ⇒ Object



969
970
971
972
973
# File 'lib/maven/tools/dsl.rb', line 969

def local( path, options = {} )
  path = File.expand_path( path )
  dependency( :jar,
              Maven::Tools::Artifact.new_local( path, :jar, options ) )
end

#mailing_list(*args, &block) ⇒ Object



387
388
389
390
391
392
393
394
395
# File 'lib/maven/tools/dsl.rb', line 387

def mailing_list( *args, &block )
  list = MailingList.new
  args, options = args_and_options( *args )
  list.name = args[ 0 ]
  fill_options( list, options )
  nested_block( :mailing_list, list, block ) if block
  @current.mailing_lists <<  list
  list
end

#maven(val = nil, &block) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/maven/tools/dsl.rb', line 36

def maven( val = nil, &block )
  if @context == nil
    tesla( &block )
  else
    @current.maven = val
  end
end

#modelObject



44
45
46
# File 'lib/maven/tools/dsl.rb', line 44

def model
  @model
end

#organization(*args, &block) ⇒ Object



316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/maven/tools/dsl.rb', line 316

def organization( *args, &block )
  if @context == :project
    args, options = args_and_options( *args )
    org = ( @current.organization ||= Organization.new )
    org.name = args[ 0 ]
    org.url = args[ 1 ]
    fill_options( org, options )
    nested_block( :organization, org, block ) if block
    org
  else
    @current.organization = args[ 0 ]
  end
end

#other_archives(*archives) ⇒ Object



411
412
413
# File 'lib/maven/tools/dsl.rb', line 411

def other_archives( *archives )
  @current.other_archives = archives
end

#overrides(&block) ⇒ Object Also known as: plugin_management, dependency_management



681
682
683
# File 'lib/maven/tools/dsl.rb', line 681

def overrides(&block)
  nested_block(:overrides, @current, block) if block
end

#path(*args) ⇒ Object



80
81
82
# File 'lib/maven/tools/dsl.rb', line 80

def path( *args )
  warn 'path block not implemented'
end

#phase(name) ⇒ Object



875
876
877
878
879
# File 'lib/maven/tools/dsl.rb', line 875

def phase( name )
  @phase = name
  yield
  @phase = nil
end

#platforms(*args) ⇒ Object



93
94
95
96
97
# File 'lib/maven/tools/dsl.rb', line 93

def platforms( *args )
  if is_jruby_platform( *args )
    yield
  end
end

#plugin(*gav, &block) ⇒ Object



665
666
667
668
669
670
671
# File 'lib/maven/tools/dsl.rb', line 665

def plugin( *gav, &block )
  gav, options = plugin_gav( *gav )
  plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin,
                     gav)

  do_plugin( true, plugin, options, &block )
end

#plugin!(*gav, &block) ⇒ Object



621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/maven/tools/dsl.rb', line 621

def plugin!( *gav, &block )
  gav, options = plugin_gav( *gav )
  pl = plugins.detect do |p|
    "#{p.group_id}:#{p.artifact_id}:#{p.version}" == gav
  end
  if pl
    do_plugin( false, pl, options, &block )
  else
    plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin,
                       gav)

    do_plugin( true, plugin, options, &block )
  end
end

#plugin_repository(url, options = {}, &block) ⇒ Object



509
510
511
# File 'lib/maven/tools/dsl.rb', line 509

def plugin_repository( url, options = {}, &block )
  do_repository( :plugin, url, options, block )
end

#prerequisites(*args, &block) ⇒ Object



397
398
399
400
401
402
403
404
# File 'lib/maven/tools/dsl.rb', line 397

def prerequisites( *args, &block )
  pre = Prerequisites.new
  args, options = args_and_options( *args )
  fill_options( pre, options )
  nested_block( :prerequisites, pre, block ) if block
  @current.prerequisites = pre
  pre
end

#profile(id, &block) ⇒ Object



881
882
883
884
885
886
# File 'lib/maven/tools/dsl.rb', line 881

def profile( id, &block )
  profile = Profile.new
  profile.id = id if id
  @current.profiles << profile
  nested_block( :profile, profile, block ) if block
end

#project(*args, &block) ⇒ Object



341
342
343
344
345
346
347
348
# File 'lib/maven/tools/dsl.rb', line 341

def project( *args, &block )
  raise 'mixed up hierachy' unless @current == model
  args, options = args_and_options( *args )
  @current.name = args[ 0 ]
  @current.url = args[ 1 ]
  fill_options( @current, options )
  nested_block(:project, @current, block) if block
end

#properties(props = {}) ⇒ Object



583
584
585
586
587
588
# File 'lib/maven/tools/dsl.rb', line 583

def properties(props = {})
  props.each do |k,v|
    @current.properties[k.to_s] = v.to_s
  end
  @current.properties
end

#property(options) ⇒ Object



444
445
446
447
448
449
# File 'lib/maven/tools/dsl.rb', line 444

def property( options )
  prop = ActivationProperty.new
  prop.name = options[ :name ] || options[ 'name' ]
  prop.value = options[ :value ] || options[ 'value' ]
  @current.property = prop
end

#releases(config) ⇒ Object



521
522
523
# File 'lib/maven/tools/dsl.rb', line 521

def releases( config )
  @current.releases = repository_policy( config )
end

#report_set(*reports, &block) ⇒ Object



888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
# File 'lib/maven/tools/dsl.rb', line 888

def report_set( *reports, &block )
  set = ReportSet.new
  case reports.last
  when Hash
    options = reports.last
    reports = reports[ 0..-2 ]
    id = options.delete( :id ) || options.delete( 'id' )
    set.id = id if id
    inherited = options.delete( :inherited ) ||
      options.delete( 'inherited' )
    set.inherited = inherited if inherited
  end
  set_config( set, options )
  set.reports = reports#.to_java
  @current.report_sets << set
end

#reporting(&block) ⇒ Object



905
906
907
908
909
# File 'lib/maven/tools/dsl.rb', line 905

def reporting( &block )
  reporting = Reporting.new
  @current.reporting = reporting
  nested_block( :reporting, reporting, block ) if block
end

#repository(url, options = {}, &block) ⇒ Object



505
506
507
# File 'lib/maven/tools/dsl.rb', line 505

def repository( url, options = {}, &block )
  do_repository( :repository=, url, options, block )
end

#repository_policy(config) ⇒ Object



529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/maven/tools/dsl.rb', line 529

def repository_policy( config )
  rp = RepositoryPolicy.new
  case config
  when Hash
    rp.enabled = config[ :enabled ]
    rp.update_policy = config[ :update ]
    rp.checksum_policy = config[ :checksum ]
  when TrueClass
    rp.enabled = true
  when FalseClass
    rp.enabled = false
  else
    rp.enabled = 'true' == config
  end
  rp
end

#resource(&block) ⇒ Object



495
496
497
498
499
500
501
502
503
# File 'lib/maven/tools/dsl.rb', line 495

def resource( &block )
  resource = Resource.new
  nested_block( :resource, resource, block ) if block
  if @context == :project
    ( @current.build ||= Build.new ).resources << resource
  else
    @current.resources << resource
  end
end

#retrieve_dependency(type, *args) ⇒ Object



794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
# File 'lib/maven/tools/dsl.rb', line 794

def retrieve_dependency( type, *args )
  if args.empty?
    a = type
    type = a[ :type ]
    options = a
  elsif args[ 0 ].is_a?( ::Maven::Tools::Artifact )
    a = args[ 0 ]
    type = a[ :type ]
    options = a
  else
    a = ::Maven::Tools::Artifact.from( type, *args )
  end
  options ||= {}
  d = fill_gav( Dependency, 
                a ? a.gav : args.join( ':' ) )
  d.type = type.to_s
  # TODO maybe copy everything from options ?
  d.scope = options[ :scope ] if options[ :scope ]
  d.system_path = options[ :system_path ] if options[ :system_path ]
  d
end

#roles(*roles) ⇒ Object



440
441
442
# File 'lib/maven/tools/dsl.rb', line 440

def roles( *roles )
  @current.roles = roles
end

#ruby(*args) ⇒ Object



76
77
78
# File 'lib/maven/tools/dsl.rb', line 76

def ruby( *args )
  # ignore
end

#scope(name) ⇒ Object



869
870
871
872
873
# File 'lib/maven/tools/dsl.rb', line 869

def scope( name )
  @scope = name
  yield
  @scope = nil
end

#set_config(receiver, options) ⇒ Object



1038
1039
1040
# File 'lib/maven/tools/dsl.rb', line 1038

def set_config(  receiver, options )
  receiver.configuration = options
end

#setup_jruby_plugins_versionObject



598
599
600
601
602
# File 'lib/maven/tools/dsl.rb', line 598

def setup_jruby_plugins_version
  unless @current.properties.key?( 'jruby.plugins.version' )
    properties( 'jruby.plugins.version' => VERSIONS[ :jruby_plugins ] )
  end
end

#site(url = nil, options = {}) ⇒ Object



364
365
366
367
368
369
# File 'lib/maven/tools/dsl.rb', line 364

def site( url = nil, options = {} )
  site = Site.new
  options.merge!( :url => url )
  fill_options( site, options )
  @current.site = site
end

#snapshot_repository(url, options = {}, &block) ⇒ Object



513
514
515
516
517
518
519
# File 'lib/maven/tools/dsl.rb', line 513

def snapshot_repository( url, options = {}, &block )
  unless @current.respond_to? :snapshot_repository=
      options[ :releases ] = false unless options.key?( :releases ) || options.key?( 'releases' )
    options[ :snapshots ] = true unless options.key?( :snapshots ) || options.key?( 'snapshots' )
  end
  do_repository( :snapshot_repository=, url, options, block )
end

#snapshots(config) ⇒ Object



525
526
527
# File 'lib/maven/tools/dsl.rb', line 525

def snapshots( config )
  @current.snapshots = repository_policy( config )
end

#source(*args) ⇒ Object



72
73
74
# File 'lib/maven/tools/dsl.rb', line 72

def source(*args)
  warn "ignore source #{args}" if !(args[0].to_s =~ /^https?:\/\/rubygems.org/) && args[0] != :rubygems
end

#source_control(url = nil, options = {}) ⇒ Object Also known as: scm



371
372
373
374
375
376
# File 'lib/maven/tools/dsl.rb', line 371

def source_control( url = nil, options = {} )
  scm = Scm.new
  options.merge!( :url => url )
  fill_options( scm, options )
  @current.scm = scm
end

#spec(spec, name = nil, options = {}) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/maven/tools/dsl.rb', line 259

def spec( spec, name = nil, options = {} )
  name ||= "#{spec.name}-#{spec.version}.gemspec"
  unless model.properties.member?( 'project.build.sourceEncoding' )
    properties( 'project.build.sourceEncoding' => 'utf-8' ) 
  end

  @gemfile_options = nil

  if @context == :project
    build.directory = '${basedir}/pkg'
    version = spec.version.to_s
    version += '-SNAPSHOT' if spec.version.prerelease?
    id "rubygems:#{spec.name}:#{version}"
    name( spec.summary || spec.name )
    description spec.description
    url spec.homepage
    unless options[ :only_metadata ]
      packaging 'gem'
      extension 'de.saumya.mojo:gem-extension:${jruby.plugins.version}'
    end
  end

  setup_gem_support( options, spec )
  
  return if options[ :only_metadata ]

  config = { :gemspec => name.sub( /^#{basedir}\/?/, '' ) }
  if options[ :include_jars ] || options[ 'include_jars' ] 
    config[ :includeDependencies ] = true
  end
  plugin( 'de.saumya.mojo:gem-maven-plugin:${jruby.plugins.version}',
          config )
  
  deps = Maven::Tools::GemspecDependencies.new( spec )
  deps.runtime.each do |d|
    gem d
  end
  unless deps.development.empty?
    scope :test do
      deps.development.each do |d|
        gem d
      end          
    end
  end
  unless deps.java_runtime.empty?
    deps.java_runtime.each do |d|
      dependency Maven::Tools::Artifact.new( *d )
    end
  end
end

#tesla(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/maven/tools/dsl.rb', line 11

def tesla( &block )
  @model = Model.new
  @model.model_version = '4.0.0'
  @model.name = File.basename( basedir )
  @model.group_id = 'dummy'
  @model.artifact_id = model.name
  @model.version = '0.0.0'
  @context = :project
  nested_block( :project, @model, block ) if block
  if @needs_torquebox
    if ! @model.repositories.detect { |r| r.id == 'rubygems-prereleases' }  && @model.dependencies.detect { |d| d.group_id == 'rubygems' && d.version.match( /[a-zA-Z]/ ) }
      
      @current = @model
      snapshot_repository( 'http://rubygems-proxy.torquebox.org/prereleases',
                           :id => 'rubygems-prereleases' )
      @current = nil
    end
    @needs_torquebox = nil
  end
  result = @model
  @context = nil
  @model = nil
  result
end

#test_resource(&block) ⇒ Object



483
484
485
486
487
488
489
490
491
492
493
# File 'lib/maven/tools/dsl.rb', line 483

def test_resource( &block )
  # strange behaviour when calling specs from Rakefile
  return if @current.nil?
  resource = Resource.new
  nested_block( :resource, resource, block ) if block
  if @context == :project
    ( @current.build ||= Build.new ).test_resources << resource
  else
    @current.test_resources << resource
  end
end

#xml(xml) ⇒ Object



1034
1035
1036
# File 'lib/maven/tools/dsl.rb', line 1034

def xml( xml )
  raise  'Xpp3DomBuilder.build( java.io.StringReader.new( xml ) )'
end