lib/maven/tools/dsl.rb in maven-tools-1.0.0.rc2 vs lib/maven/tools/dsl.rb in maven-tools-1.0.0.rc3
- old
+ new
@@ -17,11 +17,11 @@
@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]/ ) }
+ 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
@@ -44,12 +44,12 @@
def model
@model
end
- def eval_pom( src, reference_file = '.' )
- @source = reference_file
+ def eval_pom( src, reference_file )
+ @source = reference_file || '.'
eval( src, nil, ::File.expand_path( @source ) )
ensure
@source = nil
@basedir = nil
end
@@ -108,27 +108,35 @@
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
-
- @inside_gemfile = true
+
+ @inside_gemfile = true
# the eval might need those options for gemspec declaration
- pr = profile :gemfile do
- activation do
- file( :missing => name + '.lock' )
+ lockfile = ::File.expand_path( name + '.lock' )
+ if File.exists? lockfile
+ pr = profile :gemfile do
+ activation do
+ file( :missing => name + '.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
+ end
+ @inside_gemfile = false
end
if @gemspec_args
- @inside_gemfile = :gemfile
case @gemspec_args[ 0 ]
when Hash
gemspec( @gemspec_args[ 0 ].merge( options ) )
when NilClass
gemspec( @gemspec_args[ 0 ], options )
@@ -138,29 +146,28 @@
end
else
setup_gem_support( options )
end
- if pr.dependencies.empty?
+ if pr && pr.dependencies.empty?
@current.profiles.delete( pr )
end
- lockfile = ::File.expand_path( name + '.lock' )
- if File.exists? lockfile
+ if pr && !pr.dependencies.empty?
profile :gemfile_lock do
activation do
file( :exists => name + '.lock' )
end
locked = GemfileLock.new( lockfile )
- locked.hull.each do |name, version|
- gem name, version unless model.artifact_id == name && model.group_id == 'rubygems'
- end
+ add_scoped_hull( locked, pr.dependencies )
+ add_scoped_hull( locked, pr.dependencies, :provided )
+ add_scoped_hull( locked, pr.dependencies, :test )
end
end
if @has_path or @has_git
- gem 'bundler', :scope => :provided unless gem? 'bundler'
+ gem 'bundler', VERSIONS[ :bundler_version ], :scope => :provided unless gem? 'bundler'
jruby_plugin :gem do
execute_goal :exec, :filename => 'bundle', :args => 'install'
end
end
ensure
@@ -168,22 +175,41 @@
@gemspec_args = nil
@has_path = nil
@has_git = nil
end
+ def add_scoped_hull( locked, deps, scope = nil )
+ options = {}
+ options[ :scope ] = scope if scope
+ scope ||= "compile runtime default"
+ scope = scope.to_s
+ names = deps.select do |d|
+ sc = d.scope || 'default'
+ scope.match /#{sc}/
+ end.collect { |d| d.artifact_id }
+ locked.dependency_hull( names ).each do |name, version|
+ gem name, version, options unless model.artifact_id == name && model.group_id == 'rubygems'
+ end
+ end
+ private :add_scoped_hull
+
def setup_gem_support( options, spec = nil, config = {} )
+ unless model.properties.member?( 'project.build.sourceEncoding' )
+ properties( 'project.build.sourceEncoding' => 'utf-8' )
+ end
if spec.nil?
require_path = '.'
name = ::File.basename( ::File.expand_path( '.' ) )
else
require_path = spec.require_path
name = spec.name
end
unless options[ :only_metadata ]
- unless model.repositories.detect { |r| r.id == 'rubygems-releases' }
+ if ( nil == model.repositories.detect { |r| r.id == 'rubygems-releases' } && options[ :no_rubygems_repo ] != true )
+
repository( 'rubygems-releases',
'http://rubygems-proxy.torquebox.org/releases' )
end
@needs_torquebox = true
@@ -206,11 +232,11 @@
build do
source_directory source
end
end
if jar && ( source ||
- ::File.exists?( ::File.join( basedir, 'src', 'main', 'java' ) ) )
+ ::File.exists?( ::File.join( basedir, 'src', 'main', 'java' ) ) ) && spec.platform.to_s.match( /java|jruby/ )
plugin( :jar, VERSIONS[ :jar_plugin ],
:outputDirectory => output,
:finalName => jar ) do
execute_goals :jar, :phase => 'prepare-package'
end
@@ -296,11 +322,11 @@
spec = nil
f = ::File.expand_path( name )
spec_file = ::File.read( f )
begin
spec = Gem::Specification.from_yaml( spec_file )
- rescue Gem::Exception
+ rescue
FileUtils.cd( basedir ) do
# TODO jruby java user.dir
spec = eval( spec_file, nil, f )
end
end
@@ -308,24 +334,34 @@
self.spec( spec, name, options )
end
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?
+ if options[ :snapshot ] && spec.version.prerelease?
+ version += '-SNAPSHOT'
+ end
id "rubygems:#{spec.name}:#{version}"
name( spec.summary || spec.name )
description spec.description
url spec.homepage
+ if spec.homepage && spec.homepage.match( /github.com/ )
+ con = spec.homepage.sub( /http:/, 'https:' ).sub( /\/?$/, ".git" )
+ scm :url => spec.homepage, :connection => con
+ end
+
+ spec.licenses.each do |l|
+ license( l )
+ end
+ spec.authors.zip( spec.email || [] ).each do |d|
+ developer( :name => d[0], :email => d[1] )
+ end
unless options[ :only_metadata ]
packaging 'gem'
extension 'de.saumya.mojo:gem-extension:${jruby.plugins.version}'
end
end
@@ -340,11 +376,11 @@
end
plugin( 'de.saumya.mojo:gem-maven-plugin:${jruby.plugins.version}',
config )
deps = nil
- if @inside_gemfile
+ if @inside_gemfile.is_a? Symbol
profile! @inside_gemfile do
deps = all_deps( spec )
end
else
deps = all_deps( spec )
@@ -452,10 +488,11 @@
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
alias :issues :issue_management
@@ -500,10 +537,11 @@
fill_options( n, options )
nested_block( :notifier, n, block ) if block
@current.notifiers << n
n
end
+
def mailing_list( *args, &block )
list = MailingList.new
args, options = args_and_options( *args )
list.name = args[ 0 ]
fill_options( list, options )
@@ -598,11 +636,11 @@
end
def test_resource( options = {}, &block )
# strange behaviour when calling specs from Rakefile
return if @current.nil?
- resource = TestResource.new
+ resource = Resource.new
fill_options( resource, options )
nested_block( :test_resource, resource, block ) if block
if @context == :project
( @current.build ||= Build.new ).test_resources << resource
else
@@ -675,10 +713,14 @@
end
nested_block( :repository_policy, rp, block ) if block
rp
end
+ def enabled( value )
+ @current.enabled = ( value.to_s == 'true' )
+ end
+
def args_and_options( *args )
if args.last.is_a? Hash
[ args[0..-2], args.last ]
else
[ args, {} ]
@@ -734,11 +776,11 @@
ext
end
def exclusion( *gav )
gav = gav.join( ':' )
- ex = fill_gav( Extension, gav)
+ ex = fill_gav( Exclusion, gav )
@current.exclusions << ex
ex
end
def setup_jruby_plugins_version
@@ -801,11 +843,16 @@
@current.build.plugin_management.plugins
else
@current.build.plugins
end
else
- @current.plugins
+ if @context == :overrides
+ @current.plugin_management ||= PluginManagement.new
+ @current.plugin_management.plugins
+ else
+ @current.plugins
+ end
end
end
private :plugins
def plugin( *gav, &block )
@@ -855,16 +902,17 @@
end
end
# hook for polyglot maven to register those tasks
def add_execute_task( options, &block )
+ @model.properties[ 'tesla.version' ] = VERSIONS[ :tesla_version ]
plugin!( 'io.tesla.polyglot:tesla-polyglot-maven-plugin',
- VERSIONS[ :tesla_version ] ) do
+ '${tesla.version}' ) do
execute_goal( :execute, options )
jar!( 'io.tesla.polyglot:tesla-polyglot-ruby',
- VERSIONS[ :tesla_version ] )
+ '${tesla.version}' )
end
end
def retrieve_phase( options )
if @phase
@@ -1027,14 +1075,18 @@
yield
@scope = nil
end
end
- def phase( name )
- @phase = name
- yield
- @phase = nil
+ def phase( name, &block )
+ if @context != :plugin && block
+ @phase = name
+ yield
+ @phase = nil
+ else
+ @current.phase = name
+ end
end
def profile!( id, &block )
profile = @current.profiles.detect { |p| p.id.to_s == id.to_s }
if profile
@@ -1101,30 +1153,34 @@
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' )
- group = options.delete( :group ) || options.delete( 'group' ) || @group || nil
- if group
+ group = options.delete( :group ) || options.delete( 'group' ) || @group
+ if group
case group.to_sym
when :test
options[ :scope ] = :test
when :development
options[ :scope ] = :provided
end
- 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
@@ -1200,14 +1256,32 @@
super
end
end
def xml( xml )
- raise 'Xpp3DomBuilder.build( java.io.StringReader.new( xml ) )'
+ def xml.to_xml
+ self
+ end
+ xml
end
- def set_config( receiver, options )
+ def prepare_config( receiver, options )
+ return unless options
+ inherited = options.delete( 'inherited' ) || options.delete( :inherited )
+ receiver.inherited = inherited if inherited
+ end
+
+ def set_config( receiver, options )
+ prepare_config( receiver, options )
receiver.configuration = options
+ end
+
+ def configuration( v )
+ if @context == :notifier
+ @current.configuration = v
+ else
+ set_config( @current, v )
+ end
end
private
def do_repository( method, *args, &block )