lib/maven/tools/dsl.rb in maven-tools-0.33.4 vs lib/maven/tools/dsl.rb in maven-tools-0.33.5

- old
+ new

@@ -20,11 +20,18 @@ result = @model @context = nil @model = nil result end - alias :maven :tesla + + def maven( val = nil, &block ) + if @context == nil + tesla( &block ) + else + @current.maven = val + end + end def model @model end @@ -206,11 +213,13 @@ end end end def gemspec( name = nil, options = @gemfile_options || {} ) - properties( 'project.build.sourceEncoding' => 'utf-8' ) unless model.properties.member?( 'project.build.sourceEncoding' ) + unless model.properties.member?( 'project.build.sourceEncoding' ) + properties( 'project.build.sourceEncoding' => 'utf-8' ) + end @gemfile_options = nil if name.is_a? Hash options = name name = nil @@ -269,67 +278,134 @@ build = @current.build ||= Build.new nested_block( :build, build, block ) if block build end - def project( name, url = nil, &block ) - raise 'mixed up hierachy' unless @current == model - @current.name = name - @current.url = url + 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 - nested_block(:project, @current, block) + 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 - def id(*value) - value = value.join( ':' ) + 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 + + def id( *args ) + args, options = args_and_options( *args ) if @context == :project - fill_gav(@current, value) + # reset version + groupId + @current.version = nil + @current.group_id = nil + fill_gav( @current, *args ) + fill_options( @current, options ) reduce_id else - @current.id = value + @current.id = args[ 0 ] end end def site( url = nil, options = {} ) site = Site.new - fill_options( site, url, options ) + options.merge!( :url => url ) + fill_options( site, options ) @current.site = site end def source_control( url = nil, options = {} ) scm = Scm.new - fill_options( scm, url, options ) + options.merge!( :url => url ) + fill_options( scm, options ) @current.scm = scm end alias :scm :source_control def issue_management( url, system = nil ) issues = IssueManagement.new issues.url = url issues.system = system @current.issue_management = issues + issues end - def mailing_list( name = nil, &block ) + def mailing_list( *args, &block ) list = MailingList.new - list.name = name - nested_block( :mailing_list, list, block ) + 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 + 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 + def archives( *archives ) @current.archive = archives.shift @current.other_archives = archives end - def developer( id = nil, &block ) + def other_archives( *archives ) + @current.other_archives = archives + end + + def developer( *args, &block ) dev = Developer.new - dev.id = id - nested_block( :developer, dev, block ) - @current.developers << dev + 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 + 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 + def roles( *roles ) @current.roles = roles end def property( options ) @@ -346,19 +422,24 @@ @current.file = file end def activation( &block ) activation = Activation.new - nested_block( :activation, activation, block ) + nested_block( :activation, activation, block ) if block @current.activation = activation end - def distribution( &block ) - dist = DistributionManagement.new - nested_block( :distribution, dist, block ) - @current.distribution_management = dist + 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 + alias :distribution_management :distribution def includes( *items ) @current.includes = items.flatten end @@ -368,21 +449,21 @@ def test_resource( &block ) # strange behaviour when calling specs from Rakefile return if @current.nil? resource = Resource.new - nested_block( :resource, resource, block ) + nested_block( :resource, resource, block ) if block if @context == :project ( @current.build ||= Build.new ).test_resources << resource else @current.test_resources << resource end end def resource( &block ) resource = Resource.new - nested_block( :resource, resource, block ) + nested_block( :resource, resource, block ) if block if @context == :project ( @current.build ||= Build.new ).resources << resource else @current.resources << resource end @@ -423,17 +504,48 @@ rp.enabled = 'true' == config end @current.send( method, rp ) end - def inherit( *value ) - @current.parent = fill_gav( Parent, value.join( ':' ) ) + def args_and_options( *args ) + if args.last.is_a? Hash + [ args[0..-2], args.last ] + else + [ args, {} ] + end + end + + def fill_options( receiver, options ) + options.each do |k,v| + receiver.send( "#{k}=".to_sym, v ) + end + end + + 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 + + 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 alias :parent :inherit - def properties(props) + def properties(props = {}) props.each do |k,v| @current.properties[k.to_s] = v.to_s end @current.properties end @@ -441,10 +553,11 @@ def extension( *gav ) @current.build ||= Build.new gav = gav.join( ':' ) ext = fill_gav( Extension, gav) @current.build.extensions << ext + ext end def setup_jruby_plugins_version unless @current.properties.key?( 'jruby.plugins.version' ) properties( 'jruby.plugins.version' => VERSIONS[ :jruby_plugins ] ) @@ -458,107 +571,184 @@ gav.insert( 1, '${jruby.plugins.version}' ) end plugin( *gav, &block ) end - def plugin( *gav, &block ) + 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 + + def plugin_gav( *gav ) if gav.last.is_a? Hash options = gav.last gav = gav[ 0..-2 ] else options = {} end unless gav.first.match( /:/ ) gav[ 0 ] = "org.apache.maven.plugins:maven-#{gav.first}-plugin" end - gav = gav.join( ':' ) - plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin, - gav) - set_config( plugin, options ) + [ gav.join( ':' ), options ] + end + private :plugin_gav + + def plugins if @current.respond_to? :build @current.build ||= Build.new if @context == :overrides @current.build.plugin_management ||= PluginManagement.new - @current.build.plugin_management.plugins << plugin + @current.build.plugin_management.plugins else - @current.build.plugins << plugin + @current.build.plugins end else - @current.plugins << plugin + @current.plugins end + end + private :plugins + + def plugin( *gav, &block ) + gav, options = plugin_gav( *gav ) + plugin = fill_gav( @context == :reporting ? ReportPlugin : Plugin, + gav) + + do_plugin( true, plugin, options, &block ) + end + + def do_plugin( add_plugin, plugin, options, &block ) + set_config( plugin, options ) + plugins << plugin if add_plugin nested_block(:plugin, plugin, block) if block plugin end + private :do_plugin def overrides(&block) - nested_block(:overrides, @current, block) + nested_block(:overrides, @current, block) if block end alias :plugin_management :overrides alias :dependency_management :overrides - def execute( options ) - execute_goals( options ) + 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 - def execute_goal( goal, options = {} ) + # hook for polyglot maven to register those tasks + 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 + + def retrieve_phase( options ) + if @phase + if options[ :phase ] || options[ 'phase' ] + raise 'inside phase block and phase option given' + end + @phase + else + options.delete( :phase ) || options.delete( 'phase' ) + end + end + private :retrieve_phase + + def execute_goal( goal, options = {}, &block ) if goal.is_a? Hash - execute_goals( goal ) + execute_goals( goal, &block ) else - execute_goals( goal, options ) + execute_goals( goal, options, &block ) end end - def execute_goals( *goals ) + 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 - if @phase - if options[ :phase ] || options[ 'phase' ] - raise 'inside phase block and phase option given' - end - exec.phase = @phase - else - exec.phase = options.delete( :phase ) || options.delete( 'phase' ) - end + 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 + nested_block(:execution, exec, block) if block exec end def dependency( type, *args ) do_dependency( false, type, *args ) end - def dependency?( container, dep ) + def dependency!( type, *args ) + do_dependency( true, type, *args ) + end + + def dependency?( type, *args ) + find_dependency( dependency_container, + retrieve_dependency( type, *args ) ) != nil + end + + 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 def dependency_set( bang, container, dep ) if bang - dd = dependency?( container, dep ) + dd = do_dependency?( container, dep ) if index = container.index( dd ) container[ index ] = dep else container << dep end else container << dep end end - def do_dependency( bang, type, *args ) + def retrieve_dependency( type, *args ) if args.empty? a = type type = a[ :type ] options = a elsif args[ 0 ].is_a?( ::Maven::Tools::Artifact ) @@ -569,20 +759,37 @@ a = ::Maven::Tools::Artifact.from( type, *args ) end d = fill_gav( Dependency, a ? a.gav : args.join( ':' ) ) d.type = type.to_s + d + end + + def dependency_container if @context == :overrides @current.dependency_management ||= DependencyManagement.new - dependency_set( bang, - @current.dependency_management.dependencies, - d ) + @current.dependency_management.dependencies else - dependency_set( bang, - @current.dependencies, - d ) + @current.dependencies end + end + + 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 ||= {} @@ -623,11 +830,11 @@ def profile( id, &block ) profile = Profile.new profile.id = id if id @current.profiles << profile - nested_block( :profile, profile, block ) + nested_block( :profile, profile, block ) if block end def report_set( *reports, &block ) set = ReportSet.new case reports.last @@ -646,19 +853,23 @@ end def reporting( &block ) reporting = Reporting.new @current.reporting = reporting - nested_block( :reporting, reporting, block ) + nested_block( :reporting, reporting, block ) if block end def gem?( name ) @current.dependencies.detect do |d| - d.artifact_id == name && d.type == :gem + d.group_id == 'rubygems' && d.artifact_id == name && d.type == :gem end end + def jar!( *args ) + dependency!( :jar, *args ) + end + def gem( *args ) do_gem( false, *args ) end # TODO useful ? @@ -712,23 +923,47 @@ if @current.respond_to? m #p @context #p m #p args begin - @current.send( m, *args ) + + 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 - if @current.respond_to? method - @current.send( method, *args ) + 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 ) ) - dependency( method, *args ) + 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 @@ -764,11 +999,12 @@ # if config = ( options.delete( :release ) || # options.delete( 'release' ) ) # r.snapshot( repository_policy( config ) ) # end nested_block( :repository, r, block ) if block - fill_options( r, url, options ) + options.merge!( :url => url ) + fill_options( r, options ) case method when :plugin @current.plugin_repositories << r else if @current.respond_to?( method ) @@ -777,18 +1013,10 @@ @current.repositories << r end end end - def fill_options( receiver, url, options ) - url ||= options.delete( :url ) || options.delete( 'url' ) - options.each do |k,v| - receiver.send "#{k}=".to_sym, v - end - receiver.url = url - end - def reduce_id if parent = @current.parent @current.version = nil if parent.version == @current.version @current.group_id = nil if parent.group_id == @current.group_id end @@ -805,22 +1033,27 @@ @current = old @context = old_ctx end - def fill_gav(receiver, gav) - if gav - if receiver.is_a? Class - receiver = receiver.new - end - gav = gav.split(':') + def fill_gav(receiver, *gav) + if receiver.is_a? Class + receiver = receiver.new + end + if gav.size > 0 + gav = gav[0].split(':') if gav.size == 1 case gav.size when 0 # do nothing - will be filled later when 1 receiver.artifact_id = gav[0] when 2 - receiver.group_id, receiver.artifact_id = gav + if gav[ 0 ] =~ /:/ + receiver.group_id, receiver.artifact_id = gav[ 0 ].split /:/ + receiver.version = gav[ 1 ] + else + receiver.group_id, receiver.artifact_id = gav + end when 3 receiver.group_id, receiver.artifact_id, receiver.version = gav when 4 receiver.group_id, receiver.artifact_id, receiver.version, receiver.classifier = gav else