Module: Maven::Tools::DSL

Included in:
POM
Defined in:
lib/maven/tools/dsl.rb,
lib/maven/tools/dsl/models.rb,
lib/maven/tools/dsl/gemspec.rb,
lib/maven/tools/dsl/jarfile.rb,
lib/maven/tools/dsl/options.rb,
lib/maven/tools/dsl/jars_lock.rb,
lib/maven/tools/dsl/jruby_dsl.rb,
lib/maven/tools/dsl/gem_support.rb,
lib/maven/tools/dsl/jarfile_lock.rb,
lib/maven/tools/dsl/dependency_dsl.rb,
lib/maven/tools/dsl/exclusions_dsl.rb,
lib/maven/tools/dsl/profile_gemspec.rb,
lib/maven/tools/dsl/project_gemspec.rb

Defined Under Namespace

Modules: GemSupport, Models, Options Classes: DependencyDSL, ExclusionDSL, ExclusionsDSL, Gemspec, JRubyDSL, Jarfile, JarfileLock, JarsLock, ProfileGemspec, ProjectGemspec, RepositoryDSL

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
# File 'lib/maven/tools/dsl.rb', line 1313

def method_missing( method, *args, &block )
  if @context
    m = "#{method}=".to_sym
    if @current.respond_to? m
      if method == :properties && defined? JRUBY_VERSION
        return @current.properties = java.util.Properties.new
      end
      #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
      begin
      # 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 ) )
        case method.to_s[ -1 ]
        when '?'
          _dependency?( method.to_s[0..-2].to_sym, *args, &block )
        when '!'
          _dependency!( method.to_s[0..-2].to_sym, *args, &block  )
        else
          _dependency( method, *args, &block )
        end
        # elsif @current.respond_to? method
        #   @current.send( method, *args )
        #   @current
#            else
      rescue => e
        p @context
        p m
        p args
        raise e
      end
    end
  else
    super
  end
end

Instance Method Details

#_dependency(type, *args, &block) ⇒ Object Also known as: dependency_artifact



1051
1052
1053
# File 'lib/maven/tools/dsl.rb', line 1051

def _dependency( type, *args, &block )
  do_dependency( false, type, *args, &block )
end

#_dependency!(type, *args, &block) ⇒ Object Also known as: dependency_artifact!



1055
1056
1057
# File 'lib/maven/tools/dsl.rb', line 1055

def _dependency!( type, *args, &block )
  do_dependency( true, type, *args, &block )
end

#_dependency?(type, *args) ⇒ Boolean

Returns:

  • (Boolean)


1060
1061
1062
1063
# File 'lib/maven/tools/dsl.rb', line 1060

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

#activation(&block) ⇒ Object



631
632
633
634
635
# File 'lib/maven/tools/dsl.rb', line 631

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



1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'lib/maven/tools/dsl.rb', line 1001

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

#archives(*archives) ⇒ Object



579
580
581
582
# File 'lib/maven/tools/dsl.rb', line 579

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

#args_and_options(*args) ⇒ Object



801
802
803
804
805
806
807
# File 'lib/maven/tools/dsl.rb', line 801

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

#artifact(a) ⇒ Object



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

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



74
75
76
77
78
79
80
81
# File 'lib/maven/tools/dsl.rb', line 74

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



425
426
427
428
429
# File 'lib/maven/tools/dsl.rb', line 425

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

#ci_management(*args, &block) ⇒ Object Also known as: ci



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

def ci_management( *args, &block )
  ci = CiManagement.new
  args, options = args_and_options( *args )
  ci.url = args[ 0 ]
  fill_options( ci, options )
  nested_block( :ci_management, ci, block ) if block
  @current.ci_management = ci
end

#configuration(v) ⇒ Object



1399
1400
1401
1402
1403
1404
1405
# File 'lib/maven/tools/dsl.rb', line 1399

def configuration( v )
  if @context == :notifier
    @current.configuration = v
  else
    set_config( @current, v )
  end
end

#contributor(*args, &block) ⇒ Object



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

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

#currentObject

TODO remove me



62
63
64
# File 'lib/maven/tools/dsl.rb', line 62

def current
  @current
end

#default_goal(val) ⇒ Object



717
718
719
# File 'lib/maven/tools/dsl.rb', line 717

def default_goal( val )
  build_method( __method__, val )
end

#dependency(*args, &block) ⇒ Object



1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
# File 'lib/maven/tools/dsl.rb', line 1206

def dependency( *args, &block )
  dep = Dependency.new
  args, options = args_and_options( *args )
  dep.group_id = args[ 0 ]
  dep.artifact_id = args[ 1 ]
  dep.version = args[ 2 ]
  dep.type = :jar
  fill_options( dep, options )
  nested_block( :dependency, dep, block ) if block
  dependency_container << dep
  dep
end

#dependency_containerObject



1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
# File 'lib/maven/tools/dsl.rb', line 1108

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

#dependency_set(bang, container, dep) ⇒ Object



1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
# File 'lib/maven/tools/dsl.rb', line 1071

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



588
589
590
591
592
593
594
595
596
597
598
599
# File 'lib/maven/tools/dsl.rb', line 588

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

#directory(val) ⇒ Object



713
714
715
# File 'lib/maven/tools/dsl.rb', line 713

def directory( val )
  build_method( __method__, val )
end

#distribution(*args, &block) ⇒ Object



637
638
639
640
641
642
643
644
645
# File 'lib/maven/tools/dsl.rb', line 637

def distribution( *args, &block )
  if @context == :license
    args, options = args_and_options( *args )
    @current.distribution = args[ 0 ]
    fill_options( @current, options )
  else
    distribution_management( *args, &block )
  end
end

#distribution_management(*args, &block) ⇒ Object



523
524
525
526
527
528
529
530
531
# File 'lib/maven/tools/dsl.rb', line 523

def distribution_management( *args, &block )
  di = DistributionManagement.new
  args, options = args_and_options( *args )
  di.status = args[ 0 ]
  di.download_url = args[ 1 ]
  fill_options( di, options )
  nested_block( :distribution_management, di, block ) if block
  @current.distribution_management = di
end

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



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
# File 'lib/maven/tools/dsl.rb', line 1119

def do_dependency( bang, type, *args, &block )
  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
  
  args, options = args_and_options( *args )

  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|
        v, opts = args_and_options( v )
        ex = fill_gav( Exclusion, *v )
        fill_options( ex, opts )
        d.exclusions << ex
      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
  nested_block( :dependency, d, block ) if block
  d
end

#do_extension(*args) ⇒ Object



851
852
853
854
855
856
857
858
859
860
861
# File 'lib/maven/tools/dsl.rb', line 851

def do_extension( *args )
  build = if @context == :build
            @current
          else
            @current.build ||= Build.new
          end
  args, options = args_and_options( *args )
  ext = fill_gav( Extension, args.join( ':' ) )
  fill_options( ext, options )
  [ ext, build ]
end

#do_gem(bang, *args) ⇒ Object



1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
# File 'lib/maven/tools/dsl.rb', line 1264

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
  elsif @group
    options = {}
    args << options
  end
  if options
    # 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' ) || options.delete( :platforms ) || options.delete( 'platforms' )
      group = options.delete( :groups ) || options.delete( 'groups' ) ||  options.delete( :group ) || options.delete( 'group' ) || @group
      if group
        group = [ group ].flatten.each { |g| g.to_sym }
        if group.member? :development
          options[ :scope ] = :provided
        elsif group.member? :test
          options[ :scope ] = :test 
        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



886
887
888
889
890
891
892
893
# File 'lib/maven/tools/dsl.rb', line 886

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

#enabled(value) ⇒ Object



797
798
799
# File 'lib/maven/tools/dsl.rb', line 797

def enabled( value )
  @current.enabled = ( value.to_s == 'true' )
end

#eval_pom(src, reference_file) ⇒ Object



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

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

#excludes(*items) ⇒ Object



651
652
653
# File 'lib/maven/tools/dsl.rb', line 651

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

#exclusion(*gav) ⇒ Object



871
872
873
874
875
876
# File 'lib/maven/tools/dsl.rb', line 871

def exclusion( *gav )
  gav = gav.join( ':' )
  ex = fill_gav( Exclusion, gav )
  @current.exclusions << ex
  ex
end

#execute(id = nil, phase = nil, options = {}, &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
# File 'lib/maven/tools/dsl.rb', line 975

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



1024
1025
1026
1027
1028
1029
1030
# File 'lib/maven/tools/dsl.rb', line 1024

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



1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/maven/tools/dsl.rb', line 1032

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(*args) ⇒ Object



845
846
847
848
849
# File 'lib/maven/tools/dsl.rb', line 845

def extension( *args )
  ext, build = do_extension( *args )
  build.extensions << ext
  ext
end

#extension!(*args) ⇒ Object



863
864
865
866
867
868
869
# File 'lib/maven/tools/dsl.rb', line 863

def extension!( *args )
  ext, build = do_extension( *args )
  old = build.extensions.detect { |e| e.group_id == ext.group_id && e.artifact_id == ext.artifact_id }
  build.extensions.remove( old ) if old
  build.extensions << ext
  ext
end

#extensions(*args) ⇒ Object



417
418
419
420
421
422
423
# File 'lib/maven/tools/dsl.rb', line 417

def extensions(*args)
  if @context == :plugin || @context == :report_plugin
    @current.extensions = args[0]
  else
    yield
  end
end

#file(options) ⇒ Object



624
625
626
627
628
629
# File 'lib/maven/tools/dsl.rb', line 624

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



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

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



809
810
811
812
813
# File 'lib/maven/tools/dsl.rb', line 809

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

#final_name(val) ⇒ Object



709
710
711
# File 'lib/maven/tools/dsl.rb', line 709

def final_name( val )
  build_method( __method__, val )
end

#find_dependency(container, dep) ⇒ Object



1065
1066
1067
1068
1069
# File 'lib/maven/tools/dsl.rb', line 1065

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



1255
1256
1257
# File 'lib/maven/tools/dsl.rb', line 1255

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

#gem!(*args) ⇒ Object

TODO useful ?



1260
1261
1262
# File 'lib/maven/tools/dsl.rb', line 1260

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

#gem?(name) ⇒ Boolean

Returns:

  • (Boolean)


1245
1246
1247
1248
1249
# File 'lib/maven/tools/dsl.rb', line 1245

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



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
# File 'lib/maven/tools/dsl.rb', line 136

def gemfile( name = 'Gemfile', options = {} )
  if name.is_a? Hash
    options = name
    name = 'Gemfile'
  end
  name = ::File.join( basedir, name ) unless ::File.exists?( name )
  if @context == :project
    build do
      extension! 'org.torquebox.mojo:mavengem-wagon', '${mavengem.wagon.version}'
      directory '${basedir}/pkg'
    end
  end
  @inside_gemfile = true
  # the eval might need those options for gemspec declaration
  lockfile = ::File.expand_path( name + '.lock' )
  if File.exists? lockfile
    pr = profile :gemfile do
      activation do
        file( :missing => name.sub(/#{basedir}./, '') + '.lock' )
      end
      
      FileUtils.cd( basedir ) do
        f = ::File.expand_path( name )
        eval( ::File.read( f ), nil, f )
      end
    end
    @inside_gemfile = :gemfile
  else
    FileUtils.cd( basedir ) do
      f = ::File.expand_path( name )
      eval( ::File.read( f ), nil, f )
    end 
    @inside_gemfile = false
  end

  if @gemspec_args
    case @gemspec_args[ 0 ]
    when Hash
      gemspec( @gemspec_args[ 0 ].merge( options ) )
    when NilClass
      gemspec( @gemspec_args[ 0 ], options )
    else
      @gemspec_args[ 1 ].merge!( options ) 
      gemspec( *@gemspec_args )
    end
  else
    setup_gem_support( options )
    
    jruby_plugin!( :gem ) do
      execute_goal :initialize, :id => 'install gems'
    end
  end

  if pr && pr.dependencies.empty?
    if @current.profiles.respond_to? :delete
      @current.profiles.delete( pr )
    else
      @current.profiles.remove( pr )
    end
  end

  if pr && !pr.dependencies.empty?
    locked = GemfileLock.new( lockfile )
    has_bundler = gem?( 'bundler' )
    profile :gemfile_lock do
      activation do
        file( :exists => name.sub(/#{basedir}./, '') + '.lock' )
      end
      done = add_scoped_hull( locked, pr.dependencies )
      done += add_scoped_hull( locked, pr.dependencies,
                                  done, :provided )
      add_scoped_hull( locked, pr.dependencies, done, :test )
      if locked['bundler'] && !  has_bundler
        gem( 'bundler', locked['bundler'].version )
      end
    end
  end

  if @has_path or @has_git
    gem 'bundler', VERSIONS[ :bundler_version ], :scope => :provided unless gem? 'bundler'
    jruby_plugin! :gem do
      execute_goal( :exec,
                    :id => 'bundle install', 
                    :filename => 'bundle',
                    :args => 'install' )
    end
  end
  DSL::JarsLock.new(self)
ensure
  @inside_gemfile = nil
  @gemspec_args = nil
  @has_path = nil
  @has_git = nil
end

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



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/maven/tools/dsl.rb', line 377

def gemspec( name = nil, options = {} )
  if @inside_gemfile == true
    @gemspec_args = [ name, options ]
    return
  end
  if @context == :project
    if @inside_gemfile.is_a? Symbol
      options[ :profile ] = @inside_gemfile
    end
    options[ :no_gems ] = gemspec_without_gem_dependencies?
    require 'maven/tools/dsl/project_gemspec'
    DSL::ProjectGemspec.new( self, name, options )
  else
    require 'maven/tools/dsl/profile_gemspec'
    DSL::ProfileGemspec.new( self, name, options )
  end
end

#gemspec_without_gem_dependencies?Boolean

TODO remove this hack to get jar-dependencies to work

Returns:

  • (Boolean)


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

def gemspec_without_gem_dependencies?
  gems = GemspecDependencies.new( Gem::Specification.new )
  gems.runtime << 123
  deps = gems.send( :_deps, :runtime )
  deps.size == 0
end

#git(*args) ⇒ Object



114
115
116
# File 'lib/maven/tools/dsl.rb', line 114

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

#group(*args) ⇒ Object



129
130
131
132
133
134
# File 'lib/maven/tools/dsl.rb', line 129

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

#id(*args) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/maven/tools/dsl.rb', line 465

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



647
648
649
# File 'lib/maven/tools/dsl.rb', line 647

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

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



828
829
830
831
832
833
834
835
# File 'lib/maven/tools/dsl.rb', line 828

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(*args, &block) ⇒ Object Also known as: issues



502
503
504
505
506
507
508
509
510
# File 'lib/maven/tools/dsl.rb', line 502

def issue_management( *args, &block )
  issues = IssueManagement.new
  args, options = args_and_options( *args )
  issues.url = args[ 0 ]
  issues.system = args[ 1 ]
  fill_options( issues, options )
  nested_block( :issue_management, issues, block ) if block
  @current.issue_management = issues
end

#jar!(*args) ⇒ Object



1251
1252
1253
# File 'lib/maven/tools/dsl.rb', line 1251

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

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



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

def jarfile( file = 'Jarfile', options = {} )
  if file.is_a? Hash 
    options = file
    file = 'Jarfile'
  end
  if file.is_a?( Maven::Tools::Jarfile )
    warn "DEPRECATED use filename instead"
    file = jfile.file
  end
  file = ::File.join( basedir, file ) unless ::File.exists?( file )
  dsl = Maven::Tools::DSL::Jarfile.new( @current, file, options[ :skip_lock ] )

  # TODO this setup should be part of DSL::Jarfile
  jarfile_dsl( dsl )
end

#jruby_plugin(*gav, &block) ⇒ Object



895
896
897
# File 'lib/maven/tools/dsl.rb', line 895

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

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



899
900
901
# File 'lib/maven/tools/dsl.rb', line 899

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

#license(*args, &block) ⇒ Object



445
446
447
448
449
450
451
452
453
454
# File 'lib/maven/tools/dsl.rb', line 445

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

#licensesObject Also known as: developers, contributors, mailing_lists, notifiers, dependencies, repositories, plugin_repositories, resources, testResources, plugins



403
404
405
# File 'lib/maven/tools/dsl.rb', line 403

def licenses
  yield
end

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



1307
1308
1309
1310
1311
# File 'lib/maven/tools/dsl.rb', line 1307

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



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

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



45
46
47
48
49
50
51
# File 'lib/maven/tools/dsl.rb', line 45

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

#modelObject



53
54
55
# File 'lib/maven/tools/dsl.rb', line 53

def model
  @model
end

#needs_torquebox=(t) ⇒ Object

TODO remove me



58
59
60
# File 'lib/maven/tools/dsl.rb', line 58

def needs_torquebox= t
  @needs_torquebox = t
end

#notifier(*args, &block) ⇒ Object



549
550
551
552
553
554
555
556
557
558
# File 'lib/maven/tools/dsl.rb', line 549

def notifier( *args, &block )
  n = Notifier.new
  args, options = args_and_options( *args )
  n.type = args[ 0 ]
  n.address = args[ 1 ]
  fill_options( n, options )
  nested_block( :notifier, n, block ) if block
  @current.notifiers <<  n
  n
end

#organization(*args, &block) ⇒ Object



431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/maven/tools/dsl.rb', line 431

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



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

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

#output_directory(val) ⇒ Object



721
722
723
# File 'lib/maven/tools/dsl.rb', line 721

def output_directory( val )
  build_method( __method__, val )
end

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



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

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

#packaging(val) ⇒ Object



685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/maven/tools/dsl.rb', line 685

def packaging( val )
  @current.packaging = val
  if val =~ /jruby[WJ]ar/
    if not @current.properties.key?( 'jruby9.plugins.version' ) and
     not (@context == :profile and model.properties.key?( 'jruby9.plugins.version' ) )
      properties( 'jruby9.plugins.version' => VERSIONS[ :jruby9_plugins ] )
    end
    extension 'org.torquebox.mojo', 'jruby9-extensions', '${jruby9.plugins.version}'
    build do
      directory '${basedir}/pkg'
    end
  end
end

#path(*args) ⇒ Object



110
111
112
# File 'lib/maven/tools/dsl.rb', line 110

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

#phase(name, &block) ⇒ Object



1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'lib/maven/tools/dsl.rb', line 1176

def phase( name, &block )
  if @context != :plugin && block
    @phase = name
    yield
    @phase = nil
  else
    @current.phase = name
  end
end

#platforms(*args) ⇒ Object



123
124
125
126
127
# File 'lib/maven/tools/dsl.rb', line 123

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

#plugin(*gav, &block) ⇒ Object



953
954
955
956
957
958
959
# File 'lib/maven/tools/dsl.rb', line 953

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



903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
# File 'lib/maven/tools/dsl.rb', line 903

def plugin!( *gav, &block )
  gav, options = plugin_gav( *gav )
  ga = gav.sub( /:[^:]*$/, '' )
  pl = plugins.detect do |p|
    "#{p.group_id}:#{p.artifact_id}" == ga
  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(*args, &block) ⇒ Object



745
746
747
# File 'lib/maven/tools/dsl.rb', line 745

def plugin_repository( *args, &block )
  do_repository( :plugin, *args, &block )
end

#prepare_config(receiver, options) ⇒ Object



1384
1385
1386
1387
1388
1389
1390
1391
1392
# File 'lib/maven/tools/dsl.rb', line 1384

def prepare_config( receiver, options )
  return unless options
  inh = options.delete( 'inherited' )
  inh = options.delete( :inherited ) if inh.nil?
  receiver.inherited = inh unless inh.nil?
  ext = options.delete( 'extensions' )
  ext = options.delete( :extensions ) if ext.nil?
  receiver.extensions = ext unless ext.nil?
end

#prerequisites(*args, &block) ⇒ Object



570
571
572
573
574
575
576
577
# File 'lib/maven/tools/dsl.rb', line 570

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(*args, &block) ⇒ Object



1196
1197
1198
1199
1200
1201
1202
1203
1204
# File 'lib/maven/tools/dsl.rb', line 1196

def profile( *args, &block )
  profile = Profile.new
  args, options = args_and_options( *args )
  profile.id = args[ 0 ]
  fill_options( profile, options )
  @current.profiles << profile
  nested_block( :profile, profile, block ) if block
  profile
end

#profile!(id, &block) ⇒ Object



1186
1187
1188
1189
1190
1191
1192
1193
1194
# File 'lib/maven/tools/dsl.rb', line 1186

def profile!( id, &block )
  profile = @current.profiles.detect { |p| p.id.to_s == id.to_s }
  if profile
    nested_block( :profile, profile, block ) if block
    profile
  else
    profile( id, &block )
  end
end

#project(*args, &block) ⇒ Object



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

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



838
839
840
841
842
843
# File 'lib/maven/tools/dsl.rb', line 838

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

#property(options) ⇒ Object



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

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

#releases(config = nil, &block) ⇒ Object



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

def releases( config = nil, &block )
  @current.releases = repository_policy( @current.releases,
                                         config, &block )
end

#relocation(*args, &block) ⇒ Object



533
534
535
536
537
538
539
# File 'lib/maven/tools/dsl.rb', line 533

def relocation( *args, &block )
  args, options = args_and_options( *args )
  relocation = fill_gav( Relocation, args.join( ':' ) )
  fill_options( relocation, options )
  nested_block( :relocation, relocation, block ) if block
  @current.relocation = relocation
end

#report_set(*reports, &block) ⇒ Object



1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
# File 'lib/maven/tools/dsl.rb', line 1219

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 )
    inherited = options.delete( 'inherited' ) if inherited.nil?
    set.inherited = inherited unless inherited.nil?
    extensions = options.delete( :extensions )
    extensions = options.delete( 'extensions' ) if extensions.nil?
    set.extensions = extensions unless extensions.nil?
  end
  set_config( set, options )
  set.reports = reports#.to_java
  @current.report_sets << set
end

#reporting(&block) ⇒ Object



1239
1240
1241
1242
1243
# File 'lib/maven/tools/dsl.rb', line 1239

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

#repository(*args, &block) ⇒ Object



741
742
743
# File 'lib/maven/tools/dsl.rb', line 741

def repository( *args, &block )
  do_repository( :repository=, *args, &block )
end

#repository_policy(rp, config, &block) ⇒ Object



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

def repository_policy( rp, config, &block )
  rp ||= RepositoryPolicy.new
  case config
  when Hash
    rp.enabled = config[ :enabled ] unless config[ :enabled ].nil?
    rp.update_policy = config[ :update ] || config[ :update_policy ] 
    rp.checksum_policy = config[ :checksum ] || config[ :checksum_policy ]
  when TrueClass
    rp.enabled = true
  when FalseClass
    rp.enabled = false
  else
    rp.enabled = 'true' == config unless config.nil?
  end
  nested_block( :repository_policy, rp, block ) if block
  rp
end

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



671
672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/maven/tools/dsl.rb', line 671

def resource( options = {}, &block )
  resource = Resource.new
  fill_options( resource, options )
  nested_block( :resource, resource, block ) if block
  unless resource.directory
    resource.directory = '${basedir}'
  end
  if @context == :project
    ( @current.build ||= Build.new ).resources << resource
  else
    @current.resources << resource
  end
end

#retrieve_dependency(type, *args) ⇒ Object



1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'lib/maven/tools/dsl.rb', line 1084

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
    args, options = args_and_options( *args )
    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



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

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

#ruby(*args) ⇒ Object



106
107
108
# File 'lib/maven/tools/dsl.rb', line 106

def ruby( *args )
  # ignore
end

#scope(name) ⇒ Object



1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'lib/maven/tools/dsl.rb', line 1166

def scope( name )
  if @context == :dependency
    @current.scope = name
  else
    @scope = name
    yield
    @scope = nil
  end
end

#script_source_directory(val) ⇒ Object



733
734
735
# File 'lib/maven/tools/dsl.rb', line 733

def script_source_directory( val )
  build_method( __method__, val )
end

#set_config(receiver, options) ⇒ Object



1394
1395
1396
1397
# File 'lib/maven/tools/dsl.rb', line 1394

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

#setup_jruby_plugins_versionObject



878
879
880
881
882
883
884
# File 'lib/maven/tools/dsl.rb', line 878

def setup_jruby_plugins_version
  if not @current.properties.key?( 'jruby.plugins.version' ) and
     not (@context == :profile and model.properties.key?( 'jruby.plugins.version' ) )
    properties( 'jruby.plugins.version' => VERSIONS[ :jruby_plugins ] )
    properties( 'mavengem.wagon.version' => VERSIONS[ :mavengem_wagon ] )
  end
end

#site(*args, &block) ⇒ Object



479
480
481
482
483
484
485
486
487
488
# File 'lib/maven/tools/dsl.rb', line 479

def site( *args, &block )
  site = Site.new
  args, options = args_and_options( *args )
  site.id = args[ 0 ]
  site.url = args[ 1 ]
  site.name = args[ 2 ]
  fill_options( site, options )
  nested_block( :site, site, block) if block
  @current.site = site
end

#snapshot_repository(*args, &block) ⇒ Object



759
760
761
762
763
764
765
766
767
# File 'lib/maven/tools/dsl.rb', line 759

def snapshot_repository( *args, &block )
  unless @current.respond_to?( :snapshot_repository= )
    args, options = args_and_options( *args )
    set_policy( :releases, false, options )
    set_policy( :snapshots, true, options )
    args << options
  end
  do_repository( :snapshot_repository=, *args, &block )
end

#snapshots(config = nil, &block) ⇒ Object



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

def snapshots( config = nil, &block)
  @current.snapshots = repository_policy( @current.snapshots,
                                          config, &block )
end

#source(*args) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/maven/tools/dsl.rb', line 90

def source(*args)
  url = args[0].to_s
  url = 'https://rubygems.org' if url == :rubygems
  id = url.gsub( /[\/:"<>|?*]/, '_').gsub(/_+/, '_') unless url == 'https://rubygems.org'

  # we need to add the repo at project level
  if @context == :profile
    current = @current
    @current = @model
  end

  repository :id => id || 'mavengems', :url => "mavengem:#{url}"
  extension! 'org.torquebox.mojo:mavengem-wagon', '${mavengem.wagon.version}'
  @current = current if current
end

#source_control(*args, &block) ⇒ Object Also known as: scm



490
491
492
493
494
495
496
497
498
499
# File 'lib/maven/tools/dsl.rb', line 490

def source_control( *args, &block )
  scm = Scm.new
  args, options = args_and_options( *args )
  scm.connection = args[ 0 ]
  scm.developer_connection = args[ 1 ]
  scm.url = args[ 2 ]
  fill_options( scm, options )
  nested_block( :scm, scm, block ) if block
  @current.scm = scm
end

#source_directory(val) ⇒ Object



729
730
731
# File 'lib/maven/tools/dsl.rb', line 729

def source_directory( val )
  build_method( __method__, val )
end

#system(*args) ⇒ Object



541
542
543
544
545
546
547
# File 'lib/maven/tools/dsl.rb', line 541

def system( *args )
  if @current && @current.respond_to?( :system )
    @current.system = args[ 0 ]
  else
    Kernel.system( *args )
  end
end

#tesla(&block) ⇒ Object



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

def tesla( &block )
  @model = Model.new
  @model.model_version = '4.0.0'
  @model.name = ::File.basename( basedir )
  @model.group_id = 'no_group_id_given'
  @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( /-SNAPSHOT/ ) }
      
      @current = @model
      snapshot_repository(  'rubygems-prereleases',
                            'http://rubygems-proxy.torquebox.org/prereleases' )
      @current = nil
    end
    @needs_torquebox = nil
  end
  result = @model
  @context = nil
  @model = nil
  result
end

#test_output_directory(val) ⇒ Object



725
726
727
# File 'lib/maven/tools/dsl.rb', line 725

def test_output_directory( val )
  build_method( __method__, val )
end

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



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/maven/tools/dsl.rb', line 655

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

#test_source_directory(val) ⇒ Object



737
738
739
# File 'lib/maven/tools/dsl.rb', line 737

def test_source_directory( val )
  build_method( __method__, val )
end

#use(plugin, version = nil, &block) ⇒ Object



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

def use( plugin, version = nil, &block )
  Kernel.gem( plugin.to_s, version ) if version
  require plugin.to_s
  const = plugin.to_s.split( /_/ ).collect{ |a| a.capitalize }.join
  Object.const_get( const ).send( :maven, self, &block )
end

#xml(xml) ⇒ Object



1377
1378
1379
1380
1381
1382
# File 'lib/maven/tools/dsl.rb', line 1377

def xml( xml )
  def xml.to_xml
    self
  end
  xml
end