maven-tools 0.32.5 → 0.33.2

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.
@@ -0,0 +1,142 @@
1
+ #
2
+ # Copyright (C) 2013 Christian Meier
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'maven/tools/coordinate'
22
+ module Maven
23
+ module Tools
24
+ class Artifact < Hash
25
+
26
+ class Helper
27
+ include Coordinate
28
+ end
29
+
30
+ def self.new_local( path, type, options = {} )
31
+ name = File.basename( path ).sub( /.#{type}$/, '' )
32
+ if ind = name.rindex( '-' )
33
+ version = name[ind + 1..-1]
34
+ name = name[0..ind - 1]
35
+ else
36
+ version = '0'
37
+ end
38
+ self.new( "ruby.maven-tools.#{type}", name, type,
39
+ nil, version, nil,
40
+ options.merge( { :system_path => path,
41
+ :scope => :system } ) )
42
+ end
43
+
44
+ def self.from( type, *args )
45
+ if args.last.is_a? Hash
46
+ options = args.last.dup
47
+ args = args[0..-2]
48
+ end
49
+ helper = Helper.new
50
+ case args.size
51
+ when 1
52
+ # jar "asd:Asd:123
53
+ # jar "asd:Asd:123:test"
54
+ # jar "asd:Asd:123:[dsa:rew,fe:fer]"
55
+ # jar "asd:Asd:123:test:[dsa:rew,fe:fer]"
56
+ group_id, artifact_id, version, classifier, exclusions = args[0].split( /:/ )
57
+ self.new( group_id, artifact_id, type,
58
+ version, classifier, exclusions,
59
+ options )
60
+ when 2
61
+ # jar "asd:Asd", 123
62
+ # jar "asd:Asd:test", 123
63
+ # jar "asd:Asd:[dsa:rew,fe:fer]", 123
64
+ # jar "asd:Asd:test:[dsa:rew,fe:fer]", 123
65
+ group_id, artifact_id, classifier, exclusions = args[0].split( /:/ )
66
+ self.new( group_id, artifact_id, type,
67
+ helper.to_version( args[ 1 ] ),
68
+ classifier, exclusions,
69
+ options )
70
+ when 3
71
+ # jar "asd:Asd",'>123', '<345'
72
+ # jar "asd:Asd:test",'>123', '<345'
73
+ # jar "asd:Asd:[dsa:rew,fe:fer]",'>123', '<345'
74
+ # jar "asd:Asd:test:[dsa:rew,fe:fer]",'>123', '<345'
75
+ # jar "asd:Asd:test:[dsa:rew,fe:fer]", '123', 'source'
76
+ v = helper.to_version( *args[1..-1] )
77
+ case v
78
+ when String
79
+ group_id, artifact_id, classifier, exclusions = args[0].split( /:/ )
80
+ self.new( group_id, artifact_id, type,
81
+ v, classifier, exclusions,
82
+ options )
83
+ else
84
+ group_id, artifact_id = args[0].split( /:/ )
85
+ self.new( group_id, artifact_id, type,
86
+ args[1], args[2], nil,
87
+ options )
88
+ end
89
+ else
90
+ nil
91
+ end
92
+ end
93
+
94
+ def self.from_coordinate( coord )
95
+ args = coord.split( /:/ )
96
+ new( *args )
97
+ end
98
+
99
+ def initialize( group_id, artifact_id, type,
100
+ version = nil, classifier = nil, exclusions = nil,
101
+ options = {} )
102
+ if exclusions.nil?
103
+ if version.nil? and !classifier.nil?
104
+ version = classifier
105
+ classifier = nil
106
+ elsif classifier.is_a?( Array )
107
+ exclusions = classifier#version
108
+ #version = classifier
109
+ classifier = nil
110
+ end
111
+ end
112
+ self[ :type ] = type
113
+ self[ :group_id ] = group_id
114
+ self[ :artifact_id ] = artifact_id
115
+ self[ :version ] = version
116
+ self[ :classifier ] = classifier if classifier
117
+ self[ :exclusions ] = exclusions if exclusions
118
+ if options
119
+ self[ :group_id ] ||= options[ :group_id ]
120
+ self[ :artifact_id ] ||= options[ :artifact_id ]
121
+ self[ :version ] ||= options[ :version ]
122
+ self[ :classifier ] ||= options[ :classifier ] if options[ :classifier ]
123
+ self[ :exclusions ] ||= options[ :exclusions ] if options[ :exclusions ]
124
+ options.delete( :group_id )
125
+ options.delete( :artifact_id )
126
+ options.delete( :version )
127
+ options.delete( :classifier )
128
+ options.delete( :exclusions )
129
+ self.merge!( options )
130
+ end
131
+ end
132
+
133
+ def gav
134
+ [ self[:group_id], self[:artifact_id], self[:version], self[:classifier] ].select { |o| o }.join( ':' )
135
+ end
136
+
137
+ def to_s
138
+ [ self[:group_id], self[:artifact_id], self[:type], self[:classifier], self[:version], key?( :exclusions )? self[:exclusions].inspect.gsub( /[" ]/, '' ) : nil ].select { |o| o }.join( ':' )
139
+ end
140
+ end
141
+ end
142
+ end
@@ -21,25 +21,64 @@
21
21
  module Maven
22
22
  module Tools
23
23
  module Coordinate
24
-
25
- def to_coordinate(line)
24
+ def to_split_coordinate( line )
26
25
  if line =~ /^\s*(jar|pom)\s/
27
26
  packaging = line.strip.sub(/\s+.*/, '')
28
27
 
29
28
  # Remove packaging, comments and whitespaces
30
29
  sanitized_line = line.sub(/\s*[a-z]+\s+/, '').sub(/#.*/,'').gsub(/\s+/,'')
31
30
 
32
- # Remove version(s) and quotes to find the group id, artifact id and classifier
33
- group_id, artifact_id, classifier = sanitized_line.split(',')[0].gsub(/['"]/, '').split(/:/)
34
31
 
35
- # Remove the group id, artifact id and classifier to find the version(s)
36
- version, second_version = sanitized_line.split(',')[1..-1].join(',').gsub(/['"],/, ':').gsub(/['"]/, '').split(/:/)
37
- mversion = second_version ? to_version(version, second_version) : to_version(version)
32
+ exclusions = nil
33
+ sanitized_line.gsub!( /[,:](\[.+:.+\]|'\[.+:.+\]'|"\[.+:.+\]")/ ) do |match|
34
+ exclusions = match.gsub( /['"]/, '' )[2..-2].split( /,\s*/ )
35
+ nil
36
+ end
38
37
 
39
- classifier ? "#{group_id}:#{artifact_id}:#{packaging}:#{classifier}:#{mversion}" : "#{group_id}:#{artifact_id}:#{packaging}:#{mversion}"
38
+ # split to compartments
39
+ parts = sanitized_line.split( /[,]/ ).collect{|o| o.gsub( /['"]/, '' ) }
40
+ # fix no version on one argument
41
+ if parts.size == 1
42
+ parts << '[0,)'
43
+ end
44
+
45
+ # split first argument
46
+ parts[ 0 ] = parts[ 0 ].split( /:/ )
47
+ parts.flatten!
48
+
49
+ # convert ruby version to maven version
50
+ versions = parts.select { |i| i.match( /[~><=!]/ ) }
51
+ if ! versions.empty?
52
+ version = to_version( *versions )
53
+ parts = parts - versions
54
+ parts << version
55
+ else
56
+ # concat maven version ranges
57
+ versions = parts.select { |i| i.match( /[\[\]()]/ ) }
58
+ if ! versions.empty?
59
+ version = versions.join( ',' )
60
+ parts = parts - versions
61
+ parts << version
62
+ end
63
+ end
64
+
65
+ # insert packing and exclusion
66
+ parts.insert( 2, packaging )
67
+ parts << exclusions
68
+
69
+ # make sure there are not nils
70
+ parts.select { |o| !o.nil? }
40
71
  end
41
72
  end
42
73
 
74
+ def to_coordinate( line )
75
+ result = to_split_coordinate( line )
76
+ if result
77
+ exclusion = result.last.inspect.gsub( /[" ]/, '' )
78
+ ( result[0..-2] + [ exclusion ] ).join( ':' )
79
+ end
80
+ end
81
+
43
82
  def group_artifact(*args)
44
83
  case args.size
45
84
  when 1
@@ -109,4 +148,4 @@ module Maven
109
148
  end
110
149
  end
111
150
  end
112
- end
151
+ end
@@ -0,0 +1,757 @@
1
+ require 'fileutils'
2
+ require 'maven/tools/gemspec_dependencies'
3
+ require 'maven/tools/artifact'
4
+ require 'maven/tools/jarfile'
5
+ require 'maven/tools/versions'
6
+
7
+ module Maven
8
+ module Tools
9
+ module DSL
10
+
11
+ def tesla( &block )
12
+ @model = Model.new
13
+ @model.model_version = '4.0.0'
14
+ @model.name = File.basename( basedir )
15
+ @model.group_id = 'dummy'
16
+ @model.artifact_id = model.name
17
+ @model.version = '0.0.0'
18
+ @context = :project
19
+ nested_block( :project, @model, block ) if block
20
+ result = @model
21
+ @context = nil
22
+ @model = nil
23
+ result
24
+ end
25
+ alias :maven :tesla
26
+
27
+ def model
28
+ @model
29
+ end
30
+
31
+ def eval_pom( src, reference_file = '.' )
32
+ @source = reference_file
33
+ eval( src )
34
+ ensure
35
+ @source = nil
36
+ @basedir = nil
37
+ end
38
+
39
+ def basedir( basedir = nil )
40
+ @basedir ||= basedir if basedir
41
+ if @source
42
+ @basedir ||= File.directory?( @source ) ? @source :
43
+ File.dirname( File.expand_path( @source ) )
44
+ end
45
+ @basedir ||= File.expand_path( '.' )
46
+ end
47
+
48
+ def artifact( a )
49
+ if a.is_a?( String )
50
+ a = Maven::Tools::Artifact.from_coordinate( a )
51
+ end
52
+ self.send a[:type].to_sym, a
53
+ end
54
+
55
+ def source(*args)
56
+ warn "ignore source #{args}" if !(args[0].to_s =~ /^https?:\/\/rubygems.org/) && args[0] != :rubygems
57
+ end
58
+
59
+ def ruby( *args )
60
+ # ignore
61
+ end
62
+
63
+ def path( *args )
64
+ warn 'path block not implemented'
65
+ end
66
+
67
+ def git( *args )
68
+ warn 'git block not implemented'
69
+ end
70
+
71
+ def is_jruby_platform( *args )
72
+ args.detect { |a| :jruby == a.to_sym }
73
+ end
74
+ private :is_jruby_platform
75
+
76
+ def platforms( *args )
77
+ if is_jruby_platform( *args )
78
+ yield
79
+ end
80
+ end
81
+
82
+ def group( *args )
83
+ yield
84
+ end
85
+
86
+ def gemfile( name = 'Gemfile', options = {} )
87
+ if name.is_a? Hash
88
+ options = name
89
+ name = 'Gemfile'
90
+ end
91
+ name = File.join( basedir, name ) unless File.exists?( name )
92
+ basedir = File.dirname( name ) unless basedir
93
+
94
+ @gemfile_options = options
95
+ FileUtils.cd( basedir ) do
96
+ eval( File.read( File.expand_path( name ) ) )
97
+ end
98
+
99
+ if @gemfile_options
100
+ @gemfile_options = nil
101
+ setup_gem_support( options )
102
+ end
103
+ end
104
+
105
+ def setup_gem_support( options, spec = nil, config = {} )
106
+ if spec.nil?
107
+ require_path = '.'
108
+ name = File.basename( File.expand_path( '.' ) )
109
+ else
110
+ require_path = spec.require_path
111
+ name = spec.name
112
+ end
113
+
114
+ unless model.repositories.detect { |r| r.id == 'rubygems-releases' }
115
+ repository( 'http://rubygems-proxy.torquebox.org/releases',
116
+ :id => 'rubygems-releases' )
117
+ end
118
+
119
+ properties( 'jruby.plugins.version' => VERSIONS[ :jruby_plugins ] )
120
+
121
+ if options.key?( :jar ) || options.key?( 'jar' )
122
+ jarpath = options[ :jar ] || options[ 'jar' ]
123
+ if jarpath
124
+ jar = File.basename( jarpath ).sub( /.jar$/, '' )
125
+ output = "#{require_path}/#{jarpath.sub( /#{jar}/, '' )}".sub( /\/$/, '' )
126
+ end
127
+ else
128
+ jar = "#{name}"
129
+ output = "#{require_path}"
130
+ end
131
+ if options.key?( :source ) || options.key?( 'source' )
132
+ source = options[ :source ] || options[ 'source' ]
133
+ build do
134
+ source_directory source
135
+ end
136
+ end
137
+ if jar && ( source ||
138
+ File.exists?( File.join( basedir, 'src', 'main', 'java' ) ) )
139
+ plugin( :jar, VERSIONS[ :jar_plugin ],
140
+ :outputDirectory => output,
141
+ :finalName => jar ) do
142
+ execute_goals :jar, :phase => 'prepare-package'
143
+ end
144
+ plugin( :clean, VERSIONS[ :clean_plugin ],
145
+ :filesets => [ { :directory => output,
146
+ :includes => [ "#{jar}.jar" ] } ] )
147
+ end
148
+ end
149
+ private :setup_gem_support
150
+
151
+ def setup_jruby( jruby, jruby_scope = :provided )
152
+ jruby ||= VERSIONS[ :jruby_version ]
153
+ scope( jruby_scope ) do
154
+ if ( jruby < '1.7' )
155
+ warn 'jruby version below 1.7 uses jruby-complete'
156
+ jar 'org.jruby:jruby-core', jruby
157
+ elsif ( jruby < '1.7.5' )
158
+ jar 'org.jruby:jruby-core', jruby
159
+ else
160
+ jar 'org.jruby:jruby', jruby
161
+ end
162
+ end
163
+ end
164
+ private :setup_jruby
165
+
166
+ def jarfile( file = 'Jarfile', options = {} )
167
+ if file.is_a? Hash
168
+ options = file
169
+ file = 'Jarfile'
170
+ end
171
+ unless file.is_a?( Maven::Tools::Jarfile )
172
+ file = Maven::Tools::Jarfile.new( File.expand_path( file ) )
173
+ end
174
+
175
+ if options[ :skip_locked ] or not file.exists_lock?
176
+ file.populate_unlocked do |dsl|
177
+ setup_jruby( dsl.jruby )
178
+ dsl.artifacts.each do |a|
179
+ dependency a
180
+ end
181
+ end
182
+ else
183
+ file.locked.each do |dep|
184
+ artifact( dep )
185
+ end
186
+ file.populate_unlocked do |dsl|
187
+ setup_jruby( dsl.jruby )
188
+ dsl.artifacts.each do |a|
189
+ if a[ :system_path ]
190
+ dependeny a
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+
197
+ def gemspec( name = nil, options = @gemfile_options || {} )
198
+ properties( 'project.build.sourceEncoding' => 'utf-8' ) unless model.properties.member?( 'project.build.sourceEncoding' )
199
+
200
+ @gemfile_options = nil
201
+ if name.is_a? Hash
202
+ options = name
203
+ name = nil
204
+ end
205
+ if name
206
+ name = File.join( basedir, name )
207
+ else name
208
+ gemspecs = Dir[ File.join( basedir, "*.gemspec" ) ]
209
+ raise "more then one gemspec file found" if gemspecs.size > 1
210
+ raise "no gemspec file found" if gemspecs.size == 0
211
+ name = gemspecs.first
212
+ end
213
+ spec = nil
214
+ FileUtils.cd( basedir ) do
215
+ spec = eval( File.read( File.expand_path( name ) ) )
216
+ end
217
+
218
+ if @context == :project
219
+ build.directory = '${basedir}/pkg'
220
+ id "rubygems:#{spec.name}:#{spec.version}"
221
+ name( spec.summary || spec.name )
222
+ description spec.description
223
+ packaging 'gem'
224
+ url spec.homepage
225
+ extension 'de.saumya.mojo:gem-extension:${jruby.plugins.version}'
226
+ end
227
+
228
+ setup_gem_support( options, spec )
229
+
230
+ config = { :gemspec => name.sub( /^#{basedir}\/?/, '' ) }
231
+ if options[ :include_jars ] || options[ 'include_jars' ]
232
+ config[ :includeDependencies ] = true
233
+ end
234
+ plugin( 'de.saumya.mojo:gem-maven-plugin:${jruby.plugins.version}',
235
+ config )
236
+
237
+ deps = Maven::Tools::GemspecDependencies.new( spec )
238
+ deps.runtime.each do |d|
239
+ gem d
240
+ end
241
+ unless deps.development.empty?
242
+ scope :test do
243
+ deps.development.each do |d|
244
+ gem d
245
+ end
246
+ end
247
+ end
248
+ unless deps.java_runtime.empty?
249
+ deps.java_runtime.each do |d|
250
+ dependency Maven::Tools::Artifact.new( *d )
251
+ end
252
+ end
253
+ end
254
+
255
+ def build( &block )
256
+ build = @current.build ||= Build.new
257
+ nested_block( :build, build, block ) if block
258
+ build
259
+ end
260
+
261
+ def project( name, url = nil, &block )
262
+ raise 'mixed up hierachy' unless @current == model
263
+ @current.name = name
264
+ @current.url = url
265
+
266
+ nested_block(:project, @current, block)
267
+ end
268
+
269
+ def id(*value)
270
+ value = value.join( ':' )
271
+ if @context == :project
272
+ fill_gav(@current, value)
273
+ reduce_id
274
+ else
275
+ @current.id = value
276
+ end
277
+ end
278
+
279
+ def site( url = nil, options = {} )
280
+ site = Site.new
281
+ fill_options( site, url, options )
282
+ @current.site = site
283
+ end
284
+
285
+ def source_control( url = nil, options = {} )
286
+ scm = Scm.new
287
+ fill_options( scm, url, options )
288
+ @current.scm = scm
289
+ end
290
+ alias :scm :source_control
291
+
292
+ def issue_management( url, system = nil )
293
+ issues = IssueManagement.new
294
+ issues.url = url
295
+ issues.system = system
296
+ @current.issue_management = issues
297
+ end
298
+
299
+ def mailing_list( name = nil, &block )
300
+ list = MailingList.new
301
+ list.name = name
302
+ nested_block( :mailing_list, list, block )
303
+ @current.mailing_lists << list
304
+ end
305
+
306
+ def archives( *archives )
307
+ @current.archive = archives.shift
308
+ @current.other_archives = archives
309
+ end
310
+
311
+ def developer( id = nil, &block )
312
+ dev = Developer.new
313
+ dev.id = id
314
+ nested_block( :developer, dev, block )
315
+ @current.developers << dev
316
+ end
317
+
318
+ def roles( *roles )
319
+ @current.roles = roles
320
+ end
321
+
322
+ def property( options )
323
+ prop = ActivationProperty.new
324
+ prop.name = options[ :name ] || options[ 'name' ]
325
+ prop.value = options[ :value ] || options[ 'value' ]
326
+ @current.property = prop
327
+ end
328
+
329
+ def file( options )
330
+ file = ActivationFile.new
331
+ file.missing = options[ :missing ] || options[ 'missing' ]
332
+ file.exists = options[ :exists ] || options[ 'exists' ]
333
+ @current.file = file
334
+ end
335
+
336
+ def activation( &block )
337
+ activation = Activation.new
338
+ nested_block( :activation, activation, block )
339
+ @current.activation = activation
340
+ end
341
+
342
+ def distribution( &block )
343
+ dist = DistributionManagement.new
344
+ nested_block( :distribution, dist, block )
345
+ @current.distribution_management = dist
346
+ end
347
+
348
+ def includes( *items )
349
+ @current.includes = items.flatten
350
+ end
351
+
352
+ def excludes( *items )
353
+ @current.excludes = items.flatten
354
+ end
355
+
356
+ def test_resource( &block )
357
+ # strange behaviour when calling specs from Rakefile
358
+ return if @current.nil?
359
+ resource = Resource.new
360
+ nested_block( :resource, resource, block )
361
+ if @context == :project
362
+ ( @current.build ||= Build.new ).test_resources << resource
363
+ else
364
+ @current.test_resources << resource
365
+ end
366
+ end
367
+
368
+ def resource( &block )
369
+ resource = Resource.new
370
+ nested_block( :resource, resource, block )
371
+ if @context == :project
372
+ ( @current.build ||= Build.new ).resources << resource
373
+ else
374
+ @current.resources << resource
375
+ end
376
+ end
377
+
378
+ def repository( url, options = {}, &block )
379
+ do_repository( :repository=, url, options, block )
380
+ end
381
+
382
+ def plugin_repository( url, options = {}, &block )
383
+ do_repository( :plugin, url, options, block )
384
+ end
385
+
386
+ def snapshot_repository( url, options = {}, &block )
387
+ do_repository( :snapshot_repository=, url, options, block )
388
+ end
389
+
390
+ def releases( config )
391
+ respository_policy( :releases=, config )
392
+ end
393
+
394
+ def snapshots( config )
395
+ respository_policy( :snapshots=, config )
396
+ end
397
+
398
+ def respository_policy( method, config )
399
+ rp = RepositoryPolicy.new
400
+ case config
401
+ when Hash
402
+ rp.enabled = snapshot[ :enabled ]
403
+ rp.update_policy = snapshot[ :update ]
404
+ rp.checksum_policy = snapshot[ :checksum ]
405
+ when TrueClass
406
+ rp.enabled = true
407
+ when FalseClass
408
+ rp.enabled = false
409
+ else
410
+ rp.enabled = 'true' == config
411
+ end
412
+ @current.send( method, rp )
413
+ end
414
+
415
+ def inherit( *value )
416
+ @current.parent = fill_gav( Parent, value.join( ':' ) )
417
+ reduce_id
418
+ end
419
+ alias :parent :inherit
420
+
421
+ def properties(props)
422
+ props.each do |k,v|
423
+ @current.properties[k.to_s] = v.to_s
424
+ end
425
+ @current.properties
426
+ end
427
+
428
+ def extension( *gav )
429
+ @current.build ||= Build.new
430
+ gav = gav.join( ':' )
431
+ ext = fill_gav( Extension, gav)
432
+ @current.build.extensions << ext
433
+ end
434
+
435
+ def plugin( *gav, &block )
436
+ if gav.last.is_a? Hash
437
+ options = gav.last
438
+ gav = gav[ 0..-2 ]
439
+ else
440
+ options = {}
441
+ end
442
+ unless gav.first.match( /:/ )
443
+ gav[ 0 ] = "org.apache.maven.plugins:maven-#{gav.first}-plugin"
444
+ end
445
+ gav = gav.join( ':' )
446
+ plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin,
447
+ gav)
448
+ set_config( plugin, options )
449
+ if @current.respond_to? :build
450
+ @current.build ||= Build.new
451
+ if @context == :overrides
452
+ @current.build.plugin_management ||= PluginManagement.new
453
+ @current.build.plugin_management.plugins << plugin
454
+ else
455
+ @current.build.plugins << plugin
456
+ end
457
+ else
458
+ @current.plugins << plugin
459
+ end
460
+ nested_block(:plugin, plugin, block) if block
461
+ plugin
462
+ end
463
+
464
+ def overrides(&block)
465
+ nested_block(:overrides, @current, block)
466
+ end
467
+ alias :plugin_management :overrides
468
+ alias :dependency_management :overrides
469
+
470
+ def execute( options )
471
+ execute_goals( options )
472
+ end
473
+
474
+ def execute_goal( goal, options = {} )
475
+ if goal.is_a? Hash
476
+ execute_goals( goal )
477
+ else
478
+ execute_goals( goal, options )
479
+ end
480
+ end
481
+
482
+ def execute_goals( *goals )
483
+ if goals.last.is_a? Hash
484
+ options = goals.last
485
+ goals = goals[ 0..-2 ]
486
+ else
487
+ options = {}
488
+ end
489
+ exec = Execution.new
490
+ # keep the original default of id
491
+ id = options.delete( :id ) || options.delete( 'id' )
492
+ exec.id = id if id
493
+ if @phase
494
+ if options[ :phase ] || options[ 'phase' ]
495
+ raise 'inside phase block and phase option given'
496
+ end
497
+ exec.phase = @phase
498
+ else
499
+ exec.phase = options.delete( :phase ) || options.delete( 'phase' )
500
+ end
501
+ exec.goals = goals.collect { |g| g.to_s }
502
+ set_config( exec, options )
503
+ @current.executions << exec
504
+ # nested_block(:execution, exec, block) if block
505
+ exec
506
+ end
507
+
508
+ def dependency( type, *args )
509
+ if args.empty?
510
+ a = type
511
+ type = a[ :type ]
512
+ options = a
513
+ elsif args[ 0 ].is_a?( ::Maven::Tools::Artifact )
514
+ a = args[ 0 ]
515
+ type = a[ :type ]
516
+ options = a
517
+ else
518
+ a = ::Maven::Tools::Artifact.from( type, *args )
519
+ end
520
+ d = fill_gav( Dependency,
521
+ a ? a.gav : args.join( ':' ) )
522
+ d.type = type.to_s
523
+ if @context == :overrides
524
+ @current.dependency_management ||= DependencyManagement.new
525
+ @current.dependency_management.dependencies << d
526
+ else
527
+ @current.dependencies << d
528
+ end
529
+ if args.last.is_a?( Hash )
530
+ options = args.last
531
+ end
532
+ if options || @scope
533
+ options ||= {}
534
+ if @scope
535
+ if options[ :scope ] || options[ 'scope' ]
536
+ raise "scope block and scope option given"
537
+ end
538
+ options[ :scope ] = @scope
539
+ end
540
+ exclusions = options.delete( :exclusions ) ||
541
+ options.delete( "exclusions" )
542
+ case exclusions
543
+ when Array
544
+ exclusions.each do |v|
545
+ d.exclusions << fill_gav( Exclusion, v )
546
+ end
547
+ when String
548
+ d.exclusions << fill_gav( Exclusion, exclusions )
549
+ end
550
+ options.each do |k,v|
551
+ d.send( "#{k}=".to_sym, v ) unless d.send( k.to_sym )
552
+ end
553
+ end
554
+ d
555
+ end
556
+
557
+ def scope( name )
558
+ @scope = name
559
+ yield
560
+ @scope = nil
561
+ end
562
+
563
+ def phase( name )
564
+ @phase = name
565
+ yield
566
+ @phase = nil
567
+ end
568
+
569
+ def profile( id, &block )
570
+ profile = Profile.new
571
+ profile.id = id if id
572
+ @current.profiles << profile
573
+ nested_block( :profile, profile, block )
574
+ end
575
+
576
+ def report_set( *reports, &block )
577
+ set = ReportSet.new
578
+ case reports.last
579
+ when Hash
580
+ options = reports.last
581
+ reports = reports[ 0..-2 ]
582
+ id = options.delete( :id ) || options.delete( 'id' )
583
+ set.id = id if id
584
+ inherited = options.delete( :inherited ) ||
585
+ options.delete( 'inherited' )
586
+ set.inherited = inherited if inherited
587
+ end
588
+ set_config( set, options )
589
+ set.reports = reports#.to_java
590
+ @current.report_sets << set
591
+ end
592
+
593
+ def reporting( &block )
594
+ reporting = Reporting.new
595
+ @current.reporting = reporting
596
+ nested_block( :reporting, reporting, block )
597
+ end
598
+
599
+ def gem( *args )
600
+ # in some setup that gem could overload the Kernel gem
601
+ return if @current.nil?
602
+ unless args[ 0 ].match( /:/ )
603
+ args[ 0 ] = "rubygems:#{args[ 0 ] }"
604
+ end
605
+ if args.last.is_a?(Hash)
606
+ options = args.last
607
+ unless options.key?(:git) || options.key?(:path)
608
+ platform = options.delete( :platforms ) || options.delete( 'platforms' )
609
+ group = options.delete( :group ) || options.delete( 'group' )
610
+ if group.to_sym == :test
611
+ options[ :scope ] = :test
612
+ else
613
+ warn "TODO implement groups"
614
+ end
615
+ if platform.nil? || is_jruby_platform( platform )
616
+ dependency( :gem, *args )
617
+ end
618
+ end
619
+ else
620
+ #args = args + [ { :group_id => 'rubygems', :version => '[0,)' } ]
621
+ dependency( :gem, *args )
622
+ end
623
+ end
624
+
625
+ def local( path, options = {} )
626
+ path = File.expand_path( path )
627
+ dependency( :jar,
628
+ Maven::Tools::Artifact.new_local( path, :jar, options ) )
629
+ end
630
+
631
+ def method_missing( method, *args, &block )
632
+ if @context
633
+ m = "#{method}=".to_sym
634
+ if @current.respond_to? m
635
+ #p @context
636
+ #p m
637
+ #p args
638
+ begin
639
+ @current.send( m, *args )
640
+ rescue ArgumentError
641
+ if @current.respond_to? method
642
+ @current.send( method, *args )
643
+ end
644
+ end
645
+ @current
646
+ else
647
+ if ( args.size > 0 &&
648
+ args[0].is_a?( String ) &&
649
+ args[0] =~ /^[${}0-9a-zA-Z._-]+(:[${}0-9a-zA-Z._-]+)+$/ ) ||
650
+ ( args.size == 1 && args[0].is_a?( Hash ) )
651
+ dependency( method, *args )
652
+ # elsif @current.respond_to? method
653
+ # @current.send( method, *args )
654
+ # @current
655
+ else
656
+ p @context
657
+ p m
658
+ p args
659
+ end
660
+ end
661
+ else
662
+ super
663
+ end
664
+ end
665
+
666
+ def xml( xml )
667
+ raise 'Xpp3DomBuilder.build( java.io.StringReader.new( xml ) )'
668
+ end
669
+
670
+ def set_config( receiver, options )
671
+ receiver.configuration = options
672
+ end
673
+
674
+ private
675
+
676
+ def do_repository( method, url = nil, options = {}, block = nil )
677
+ if @current.respond_to?( method )
678
+ r = DeploymentRepository.new
679
+ else
680
+ r = Repository.new
681
+ end
682
+ # if config = ( options.delete( :snapshot ) ||
683
+ # options.delete( 'snapshot' ) )
684
+ # r.snapshot( repository_policy( config ) )
685
+ # end
686
+ # if config = ( options.delete( :release ) ||
687
+ # options.delete( 'release' ) )
688
+ # r.snapshot( repository_policy( config ) )
689
+ # end
690
+ nested_block( :repository, r, block ) if block
691
+ fill_options( r, url, options )
692
+ case method
693
+ when :plugin
694
+ @current.plugin_repositories << r
695
+ else
696
+ if @current.respond_to?( method )
697
+ @current.send method, r
698
+ else
699
+ @current.repositories << r
700
+ end
701
+ end
702
+ end
703
+
704
+ def fill_options( receiver, url, options )
705
+ url ||= options.delete( :url ) || options.delete( 'url' )
706
+ options.each do |k,v|
707
+ receiver.send "#{k}=".to_sym, v
708
+ end
709
+ receiver.url = url
710
+ end
711
+
712
+ def reduce_id
713
+ if parent = @current.parent
714
+ @current.version = nil if parent.version == @current.version
715
+ @current.group_id = nil if parent.group_id == @current.group_id
716
+ end
717
+ end
718
+
719
+ def nested_block(context, receiver, block)
720
+ old_ctx = @context
721
+ old = @current
722
+
723
+ @context = context
724
+ @current = receiver
725
+
726
+ block.call
727
+
728
+ @current = old
729
+ @context = old_ctx
730
+ end
731
+
732
+ def fill_gav(receiver, gav)
733
+ if gav
734
+ if receiver.is_a? Class
735
+ receiver = receiver.new
736
+ end
737
+ gav = gav.split(':')
738
+ case gav.size
739
+ when 0
740
+ # do nothing - will be filled later
741
+ when 1
742
+ receiver.artifact_id = gav[0]
743
+ when 2
744
+ receiver.group_id, receiver.artifact_id = gav
745
+ when 3
746
+ receiver.group_id, receiver.artifact_id, receiver.version = gav
747
+ when 4
748
+ receiver.group_id, receiver.artifact_id, receiver.version, receiver.classifier = gav
749
+ else
750
+ raise "can not assign such an array #{gav.inspect}"
751
+ end
752
+ end
753
+ receiver
754
+ end
755
+ end
756
+ end
757
+ end