lib/jbundler/executable_pom.rb in jbundler-0.5.3 vs lib/jbundler/executable_pom.rb in jbundler-0.5.4

- old
+ new

@@ -1,149 +1,110 @@ -require 'maven/tools/jarfile' -require 'maven/tools/dsl' -require 'maven/tools/versions' -require 'maven/tools/model' -require 'maven/ruby/maven' -require 'fileutils' -module JBundler - class ExecutablePom +begin + groups = java.lang.System.getProperty( "jbundler.groups" ) || '' + require 'bundler' + Bundler.setup( *groups.split( /,/ ) ) +rescue LoadError + # ignore- bundler is optional +end - BOOTSTRAP = 'jar-bootstrap.rb' +jfile = ::Maven::Tools::Jarfile.new( java.lang.System.getProperty( "jbundler.jarfile" ) ) - include Maven::Tools::DSL +workdir = java.lang.System.getProperty( "jbundler.workdir" ) +jworkdir = File.join( workdir, 'executable' ) +FileUtils.rm_rf( jworkdir ) +FileUtils.mkdir_p( jworkdir ) - def initialize( bootstrap, config, compile, verbose, *groups ) - @bootstrap = bootstrap - @config = config - @groups = groups - @compile = compile - @verbose = verbose - end +BOOTSTRAP = 'jar-bootstrap.rb' unless defined? BOOTSTRAP - private +FileUtils.cp( java.lang.System.getProperty( 'jbundler.bootstrap'), + File.join( jworkdir, BOOTSTRAP ) ) - def setup_jruby( jruby ) - if ( jruby < '1.6' ) - raise 'jruby before 1.6 are not supported' - elsif ( jruby < '1.7' ) - warn 'jruby version below 1.7 uses jruby-complete' - jar 'org.jruby:jruby-complete', jruby - elsif ( jruby < '1.7.5' ) - jar 'org.jruby:jruby-core', jruby - else - jar 'org.jruby:jruby', jruby - end - end +def jruby_home( path ) + File.join( 'META-INF/jruby.home/lib/ruby/gems/shared', path ) +end - def jruby_home( path ) - File.join( 'META-INF/jruby.home/lib/ruby/gems/shared', path ) + +jfile.locked.each do |dep| + artifact( dep ) +end +build.final_name = model.artifact_id +build.directory = jworkdir +resource do + directory jworkdir + includes [ BOOTSTRAP ] +end +Gem.loaded_specs.values.each do |s| + resource do + directory s.full_gem_path + target_path File.join( jruby_home( 'gems' ), + File.basename( s.full_gem_path ) ) + if s.full_gem_path == File.expand_path( '.' ) + excludes [ "**/#{workdir}/**" ] end + end + resource do + directory File.dirname( s.loaded_from ) + includes [ File.basename( s.loaded_from ) ] + target_path jruby_home( 'specifications' ) + end +end - def bundler_setup - require 'bundler' - Bundler.setup( *@groups ) - rescue LoadError - # ignore- bundler is optional - end - - def jarfile - unless @jarfile - bundler_setup - - require 'jbundler' - @jarfile = ::Maven::Tools::Jarfile.new( @config.jarfile ) - end - @jarfile - end +properties( 'maven.test.skip' => true, + 'project.build.sourceEncoding' => 'utf-8' ) - def create_project - maven do - jarfile.locked.each do |dep| - artifact( dep ) - end - build.final_name = model.artifact_id - build.directory = work_dir - resource do - directory work_dir - includes [ BOOTSTRAP ] - end - Gem.loaded_specs.values.each do |s| - resource do - directory s.full_gem_path - target_path File.join( jruby_home( 'gems' ), - File.basename( s.full_gem_path ) ) - if s.full_gem_path == File.expand_path( '.' ) - excludes [ "**/#{File.basename( @config.work_dir )}/**" ] - end - end - resource do - directory File.dirname( s.loaded_from ) - includes [ File.basename( s.loaded_from ) ] - target_path jruby_home( 'specifications' ) - end - end - - properties( 'maven.test.skip' => true, - 'project.build.sourceEncoding' => 'utf-8' ) +jfile.populate_unlocked do |dsl| + + # setup jruby version + jruby_version = dsl.jruby || JRUBY_VERSION + if ( jruby_version < '1.6' ) + raise 'jruby before 1.6 are not supported' + elsif ( jruby_version < '1.7' ) + warn 'jruby version below 1.7 uses jruby-complete' + jar 'org.jruby:jruby-complete', jruby_version + elsif ( jruby_version < '1.7.5' ) + jar 'org.jruby:jruby-core', jruby_version + else + jar 'org.jruby:jruby', jruby_version + end - jarfile.populate_unlocked do |dsl| - setup_jruby( dsl.jruby || JRUBY_VERSION ) - local = dsl.artifacts.select do |a| - a[ :system_path ] - end - if local - localrepo = File.join( work_dir, 'localrepo' ) - repository( "file:#{localrepo}", :id => 'localrepo' ) - local.each do |a| - file = "#{localrepo}/#{a[ :group_id ].gsub( /\./, File::SEPARATOR)}/#{a[ :artifact_id ]}/#{a[ :version ]}/#{a[ :artifact_id ]}-#{a[ :version ]}.#{a[ :type ]}" - FileUtils.mkdir_p( File.dirname( file ) ) - FileUtils.cp( a.delete( :system_path ), file ) - a.delete( :scope ) - jar a - end - end - end - - if @compile - - properties 'jruby.plugins.version' => Maven::Tools::VERSIONS[ :jruby_plugins ] - plugin( 'de.saumya.mojo:jruby-maven-plugin', '${jruby.plugins.version}' ) do - execute_goal( :compile, - :rubySourceDirectory => 'lib', - :jrubycVerbose => @verbose) - end - - else + local = dsl.artifacts.select do |a| + a[ :system_path ] + end - resource do - directory '${basedir}/lib' - includes [ '**/*.rb' ] - end - - end - - plugin( :shade, '2.1', - :transformers => [ { '@implementation' => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer', - :mainClass => 'org.jruby.JarBootstrapMain' } ] ) do - execute_goals( 'shade', :phase => 'package' ) - end - end + # setup a localrepo for the local jars if needed + if local + localrepo = File.join( jworkdir, 'localrepo' ) + repository( "file:#{localrepo}", :id => 'localrepo' ) + local.each do |a| + file = "#{localrepo}/#{a[ :group_id ].gsub( /\./, File::SEPARATOR)}/#{a[ :artifact_id ]}/#{a[ :version ]}/#{a[ :artifact_id ]}-#{a[ :version ]}.#{a[ :type ]}" + FileUtils.mkdir_p( File.dirname( file ) ) + FileUtils.cp( a.delete( :system_path ), file ) + a.delete( :scope ) + jar a end + end +end - public +profile :compile do + + properties 'jruby.plugins.version' => Maven::Tools::VERSIONS[ :jruby_plugins ] + plugin( 'de.saumya.mojo:jruby-maven-plugin', '${jruby.plugins.version}' ) do + execute_goal( :compile, + :rubySourceDirectory => 'lib', + :jrubycVerbose => @verbose) + end +end - def work_dir - unless @work_dir - @work_dir = File.join( @config.work_dir, 'executable' ) - FileUtils.rm_rf( @work_dir ) - FileUtils.mkdir_p( @work_dir ) - FileUtils.cp( @bootstrap, File.join( @work_dir, - BOOTSTRAP ) ) - end - @work_dir - end - - def project - @project ||= create_project - end +profile :no_compile do + build do + resource do + directory '${basedir}/lib' + includes [ '**/*.rb' ] end + end +end + +plugin( :shade, '2.1', + :transformers => [ { '@implementation' => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer', + :mainClass => 'org.jruby.JarBootstrapMain' } ] ) do + execute_goals( 'shade', :phase => 'package' ) end