Class: JBundler::Executable
- Inherits:
-
Object
- Object
- JBundler::Executable
- Includes:
- Maven::Tools::DSL
- Defined in:
- lib/jbundler/executable.rb
Constant Summary collapse
- BOOTSTRAP =
'jar-bootstrap.rb'
Instance Attribute Summary collapse
-
#clean ⇒ Object
Returns the value of attribute clean.
-
#groups ⇒ Object
Returns the value of attribute groups.
Instance Method Summary collapse
-
#initialize(bootstrap, config) ⇒ Executable
constructor
A new instance of Executable.
- #jruby_home(path) ⇒ Object
- #packit ⇒ Object
Constructor Details
#initialize(bootstrap, config) ⇒ Executable
Returns a new instance of Executable.
12 13 14 15 16 |
# File 'lib/jbundler/executable.rb', line 12 def initialize( bootstrap, config ) raise "file not found: #{bootstrap}" unless File.exists?( bootstrap ) @bootstrap = bootstrap @config = config end |
Instance Attribute Details
#clean ⇒ Object
Returns the value of attribute clean.
18 19 20 |
# File 'lib/jbundler/executable.rb', line 18 def clean @clean end |
#groups ⇒ Object
Returns the value of attribute groups.
18 19 20 |
# File 'lib/jbundler/executable.rb', line 18 def groups @groups end |
Instance Method Details
#jruby_home(path) ⇒ Object
36 37 38 |
# File 'lib/jbundler/executable.rb', line 36 def jruby_home( path ) File.join( 'META-INF/jruby.home/lib/ruby/gems/shared', path ) end |
#packit ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/jbundler/executable.rb', line 40 def packit require 'bundler' Bundler.setup( *groups ) require 'jbundler' jarfile = ::Maven::Tools::Jarfile.new( @config.jarfile ) 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 ) ) 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.( '.' ) 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' ) jarfile.populate_unlocked do |dsl| setup_jruby( dsl.jruby || '1.7.4' ) 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 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 m = Maven::Ruby::Maven.new( project, '.executable.pom.xml' ) m.package FileUtils.rm_f( 'dependency-reduced-pom.xml' ) puts puts 'now you can execute your jar like this' puts puts "\tjava -jar #{work_dir}/#{project.artifact_id}.jar" puts end |