jbundler 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -51,11 +51,13 @@ module JBundler
51
51
  JBundler::Tree.new( config ).show_it
52
52
  end
53
53
 
54
- desc 'executable', 'create an executable jar with a given bootstrap.rb file'
55
- method_option :bootstrap, :type => :string, :aliases => '-b', :required => true, :desc => 'file which will be executed when the jar gets executed'
54
+ desc 'executable', 'create an executable jar with a given bootstrap.rb file\nLIMITATION: only for jruby 1.6.x and newer'
55
+ method_option :bootstrap, :type => :string, :aliases => '-b'#, :required => true, :desc => 'file which will be executed when the jar gets executed'
56
+ method_option :compile, :type => :boolean, :aliases => '-c', :default => false, :desc => 'compile the ruby files from the lib directory'
57
+ method_option :verbose, :type => :boolean, :aliases => '-v', :default => false, :desc => 'more output'
56
58
  method_option :groups, :type => :array, :aliases => '-g', :desc => 'bundler groups to use for determine the gems to include in the jar file'
57
59
  def executable
58
- ex = JBundler::Executable.new( options[ :bootstrap ], config )
60
+ ex = JBundler::Executable.new( options[ 'bootstrap' ], config, options[ 'compile' ], options[ :verbose ], *( options[ 'groups' ] || [:default] ) )
59
61
  ex.packit
60
62
  end
61
63
 
@@ -75,7 +77,6 @@ module JBundler
75
77
  def update
76
78
  if ARGV.size == 1
77
79
  require 'java'
78
- require 'jbundler/config'
79
80
  config = JBundler::Config.new
80
81
  FileUtils.rm_f(config.jarfile_lock)
81
82
 
@@ -2,115 +2,41 @@ require 'maven/tools/jarfile'
2
2
  require 'maven/tools/dsl'
3
3
  require 'maven/ruby/maven'
4
4
  require 'fileutils'
5
+ require 'jbundler/executable_pom'
5
6
  module JBundler
6
7
  class Executable
7
8
 
9
+ class Filter
10
+
11
+ def initialize(a)
12
+ @a = a
13
+ end
14
+ def method_missing(m, *args, &b)
15
+ args[ 0 ].sub!(/^.* - /, '' )
16
+ args[ 0 ] = 'asd'
17
+ @a.send(m,*args, &b)
18
+ end
19
+ end
20
+
8
21
  BOOTSTRAP = 'jar-bootstrap.rb'
9
22
 
10
23
  include Maven::Tools::DSL
11
24
 
12
- def initialize( bootstrap, config )
25
+ def initialize( bootstrap, config, compile, verbose, *groups )
13
26
  raise "file not found: #{bootstrap}" unless File.exists?( bootstrap )
14
- @bootstrap = bootstrap
15
- @config = config
16
- end
17
-
18
- attr_accessor :clean, :groups
19
-
20
- def groups
21
- @groups || []
22
- end
23
-
24
- def setup_jruby( jruby )
25
- if ( jruby < '1.7' )
26
- warn 'jruby version below 1.7 uses jruby-complete'
27
- jar 'org.jruby:jruby-core', jruby
28
- elsif ( jruby < '1.7.5' )
29
- jar 'org.jruby:jruby-core', jruby
30
- else
31
- jar 'org.jruby:jruby', jruby
32
- end
33
- end
34
- private :setup_jruby
35
-
36
- def jruby_home( path )
37
- File.join( 'META-INF/jruby.home/lib/ruby/gems/shared', path )
27
+ @pom = ExecutablePom.new( bootstrap, config, compile, verbose, *groups )
38
28
  end
39
29
 
40
30
  def packit
41
- require 'bundler'
42
- Bundler.setup( *groups )
43
-
44
- require 'jbundler'
45
- jarfile = ::Maven::Tools::Jarfile.new( @config.jarfile )
46
-
47
- work_dir = File.join( @config.work_dir, 'executable' )
48
- FileUtils.rm_rf( work_dir )
49
- FileUtils.mkdir_p( work_dir )
50
- FileUtils.cp( @bootstrap, File.join( work_dir,
51
- BOOTSTRAP ) )
52
- project = maven do
53
- jarfile.locked.each do |dep|
54
- artifact( dep )
55
- end
56
- build.final_name = model.artifact_id
57
- build.directory = work_dir
58
- resource do
59
- directory work_dir
60
- includes [ BOOTSTRAP ]
61
- end
62
- Gem.loaded_specs.values.each do |s|
63
- resource do
64
- directory s.full_gem_path
65
- target_path File.join( jruby_home( 'gems' ),
66
- File.basename( s.full_gem_path ) )
67
- if s.full_gem_path == File.expand_path( '.' )
68
- excludes [ "**/#{File.basename( @config.work_dir )}/**" ]
69
- end
70
- end
71
- resource do
72
- directory File.dirname( s.loaded_from )
73
- includes [ File.basename( s.loaded_from ) ]
74
- target_path jruby_home( 'specifications' )
75
- end
76
- end
77
-
78
- properties( 'maven.test.skip' => true,
79
- 'project.build.sourceEncoding' => 'utf-8' )
80
-
81
- jarfile.populate_unlocked do |dsl|
82
- setup_jruby( dsl.jruby || '1.7.4' )
83
- local = dsl.artifacts.select do |a|
84
- a[ :system_path ]
85
- end
86
- if local
87
- localrepo = File.join( work_dir, 'localrepo' )
88
- repository( "file:#{localrepo}", :id => 'localrepo' )
89
- local.each do |a|
90
- file = "#{localrepo}/#{a[ :group_id ].gsub( /\./, File::SEPARATOR)}/#{a[ :artifact_id ]}/#{a[ :version ]}/#{a[ :artifact_id ]}-#{a[ :version ]}.#{a[ :type ]}"
91
- FileUtils.mkdir_p( File.dirname( file ) )
92
- FileUtils.cp( a.delete( :system_path ), file )
93
- a.delete( :scope )
94
- jar a
95
- end
96
- end
97
- end
98
-
99
- plugin( :shade, '2.1',
100
- :transformers => [ { '@implementation' => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer',
101
- :mainClass => 'org.jruby.JarBootstrapMain' } ] ) do
102
- execute_goals( 'shade', :phase => 'package' )
103
- end
104
- end
105
-
106
- m = Maven::Ruby::Maven.new( project, '.executable.pom.xml' )
31
+ m = Maven::Ruby::Maven.new( @pom.project, '.executable.pom.xml' )
32
+ m.verbose = @verbose
107
33
  m.package
108
-
34
+
109
35
  FileUtils.rm_f( 'dependency-reduced-pom.xml' )
110
36
  puts
111
37
  puts 'now you can execute your jar like this'
112
38
  puts
113
- puts "\tjava -jar #{work_dir}/#{project.artifact_id}.jar"
39
+ puts "\tjava -jar #{@pom.work_dir}/#{@pom.project.artifact_id}.jar"
114
40
  puts
115
41
  end
116
42
  end
@@ -0,0 +1,149 @@
1
+ require 'maven/tools/jarfile'
2
+ require 'maven/tools/dsl'
3
+ require 'maven/tools/versions'
4
+ require 'maven/tools/model'
5
+ require 'maven/ruby/maven'
6
+ require 'fileutils'
7
+ module JBundler
8
+ class ExecutablePom
9
+
10
+ BOOTSTRAP = 'jar-bootstrap.rb'
11
+
12
+ include Maven::Tools::DSL
13
+
14
+ def initialize( bootstrap, config, compile, verbose, *groups )
15
+ @bootstrap = bootstrap
16
+ @config = config
17
+ @groups = groups
18
+ @compile = compile
19
+ @verbose = verbose
20
+ end
21
+
22
+ private
23
+
24
+ def setup_jruby( jruby )
25
+ if ( jruby < '1.6' )
26
+ raise 'jruby before 1.6 are not supported'
27
+ elsif ( jruby < '1.7' )
28
+ warn 'jruby version below 1.7 uses jruby-complete'
29
+ jar 'org.jruby:jruby-complete', jruby
30
+ elsif ( jruby < '1.7.5' )
31
+ jar 'org.jruby:jruby-core', jruby
32
+ else
33
+ jar 'org.jruby:jruby', jruby
34
+ end
35
+ end
36
+
37
+ def jruby_home( path )
38
+ File.join( 'META-INF/jruby.home/lib/ruby/gems/shared', path )
39
+ end
40
+
41
+ def bundler_setup
42
+ require 'bundler'
43
+ Bundler.setup( *@groups )
44
+ rescue LoadError
45
+ # ignore- bundler is optional
46
+ end
47
+
48
+ def jarfile
49
+ unless @jarfile
50
+ bundler_setup
51
+
52
+ require 'jbundler'
53
+ @jarfile = ::Maven::Tools::Jarfile.new( @config.jarfile )
54
+ end
55
+ @jarfile
56
+ end
57
+
58
+ def create_project
59
+ maven do
60
+ jarfile.locked.each do |dep|
61
+ artifact( dep )
62
+ end
63
+ build.final_name = model.artifact_id
64
+ build.directory = work_dir
65
+ resource do
66
+ directory work_dir
67
+ includes [ BOOTSTRAP ]
68
+ end
69
+ Gem.loaded_specs.values.each do |s|
70
+ resource do
71
+ directory s.full_gem_path
72
+ target_path File.join( jruby_home( 'gems' ),
73
+ File.basename( s.full_gem_path ) )
74
+ if s.full_gem_path == File.expand_path( '.' )
75
+ excludes [ "**/#{File.basename( @config.work_dir )}/**" ]
76
+ end
77
+ end
78
+ resource do
79
+ directory File.dirname( s.loaded_from )
80
+ includes [ File.basename( s.loaded_from ) ]
81
+ target_path jruby_home( 'specifications' )
82
+ end
83
+ end
84
+
85
+ properties( 'maven.test.skip' => true,
86
+ 'project.build.sourceEncoding' => 'utf-8' )
87
+
88
+ jarfile.populate_unlocked do |dsl|
89
+ setup_jruby( dsl.jruby || JRUBY_VERSION )
90
+ local = dsl.artifacts.select do |a|
91
+ a[ :system_path ]
92
+ end
93
+ if local
94
+ localrepo = File.join( work_dir, 'localrepo' )
95
+ repository( "file:#{localrepo}", :id => 'localrepo' )
96
+ local.each do |a|
97
+ file = "#{localrepo}/#{a[ :group_id ].gsub( /\./, File::SEPARATOR)}/#{a[ :artifact_id ]}/#{a[ :version ]}/#{a[ :artifact_id ]}-#{a[ :version ]}.#{a[ :type ]}"
98
+ FileUtils.mkdir_p( File.dirname( file ) )
99
+ FileUtils.cp( a.delete( :system_path ), file )
100
+ a.delete( :scope )
101
+ jar a
102
+ end
103
+ end
104
+ end
105
+
106
+ if @compile
107
+
108
+ properties 'jruby.plugins.version' => Maven::Tools::VERSIONS[ :jruby_plugins ]
109
+ plugin( 'de.saumya.mojo:jruby-maven-plugin', '${jruby.plugins.version}' ) do
110
+ execute_goal( :compile,
111
+ :rubySourceDirectory => 'lib',
112
+ :jrubycVerbose => @verbose)
113
+ end
114
+
115
+ else
116
+
117
+ resource do
118
+ directory '${basedir}/lib'
119
+ includes [ '**/*.rb' ]
120
+ end
121
+
122
+ end
123
+
124
+ plugin( :shade, '2.1',
125
+ :transformers => [ { '@implementation' => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer',
126
+ :mainClass => 'org.jruby.JarBootstrapMain' } ] ) do
127
+ execute_goals( 'shade', :phase => 'package' )
128
+ end
129
+ end
130
+ end
131
+
132
+ public
133
+
134
+ def work_dir
135
+ unless @work_dir
136
+ @work_dir = File.join( @config.work_dir, 'executable' )
137
+ FileUtils.rm_rf( @work_dir )
138
+ FileUtils.mkdir_p( @work_dir )
139
+ FileUtils.cp( @bootstrap, File.join( @work_dir,
140
+ BOOTSTRAP ) )
141
+ end
142
+ @work_dir
143
+ end
144
+
145
+ def project
146
+ @project ||= create_project
147
+ end
148
+ end
149
+ end
@@ -0,0 +1 @@
1
+ jar 'junit:junit', '4.11'
@@ -0,0 +1 @@
1
+ require 'app'
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec', '<3.0'
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.4)
5
+ rspec (2.14.1)
6
+ rspec-core (~> 2.14.0)
7
+ rspec-expectations (~> 2.14.0)
8
+ rspec-mocks (~> 2.14.0)
9
+ rspec-core (2.14.5)
10
+ rspec-expectations (2.14.2)
11
+ diff-lcs (>= 1.1.3, < 2.0)
12
+ rspec-mocks (2.14.3)
13
+
14
+ PLATFORMS
15
+ java
16
+
17
+ DEPENDENCIES
18
+ rspec (< 3.0)
@@ -0,0 +1 @@
1
+ jar 'junit:junit', '4.11'
@@ -0,0 +1,2 @@
1
+ junit:junit:jar:4.11
2
+ org.hamcrest:hamcrest-core:jar:1.3
@@ -0,0 +1 @@
1
+ require 'app'
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec', '<3.0'
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.4)
5
+ rspec (2.14.1)
6
+ rspec-core (~> 2.14.0)
7
+ rspec-expectations (~> 2.14.0)
8
+ rspec-mocks (~> 2.14.0)
9
+ rspec-core (2.14.5)
10
+ rspec-expectations (2.14.2)
11
+ diff-lcs (>= 1.1.3, < 2.0)
12
+ rspec-mocks (2.14.3)
13
+
14
+ PLATFORMS
15
+ java
16
+
17
+ DEPENDENCIES
18
+ rspec (< 3.0)
@@ -0,0 +1,2 @@
1
+ junit:junit:jar:4.11
2
+ org.hamcrest:hamcrest-core:jar:1.3
@@ -1,3 +1,4 @@
1
+ require 'java' #for jruby before 1.7.x
1
2
  import 'org.junit.runner.JUnitCore'
2
3
  import 'test.AppTest'
3
4
 
@@ -5,23 +5,39 @@ require 'fileutils'
5
5
 
6
6
  describe JBundler::Executable do
7
7
 
8
- before do
9
- dir = File.join( File.dirname( __FILE__ ), 'executable' )
10
- java.lang.System.set_property( 'user.dir', dir )
11
- FileUtils.rm_rf( File.join( dir, 'target' ) )
12
- Dir.chdir( dir )
13
- end
14
-
15
- it 'should create executable jar' do
16
- skip 'rvm is not working properly' if ENV[ 'rvm_version' ]
17
- exec = JBundler::Executable.new( 'start.rb',
18
- JBundler::Config.new )
19
- exec.groups = [:default]
20
- exec.packit
8
+ [
9
+ 'executable_only_java_sources',
10
+ 'executable_compile',
11
+ 'executable_no_compile'
12
+ ].each do |exec_dir|
21
13
 
22
- `java -jar target/executable/executable.jar`.must_equal 'hello world'
23
- end
14
+ let( exec_dir.to_sym ) do
15
+ dir = File.join( File.dirname( File.expand_path( __FILE__ ) ),
16
+ exec_dir )
17
+ java.lang.System.set_property( 'user.dir', dir )
18
+ FileUtils.rm_rf( File.join( dir, 'target' ) )
19
+ dir
20
+ end
24
21
 
22
+ it "should create #{exec_dir} jar" do
23
+ skip 'rvm is not working properly' if ENV[ 'rvm_version' ]
24
+ skip "jruby #{JRUBY_VERSION}" if JRUBY_VERSION < '1.6.'
25
+ dir = eval "#{exec_dir}"
26
+
27
+ FileUtils.chdir( dir ) do
28
+ exec = JBundler::Executable.new( 'start.rb',
29
+ JBundler::Config.new,
30
+ File.basename( dir ) == 'executable_compile',
31
+ false,
32
+ :default )
33
+ exec.packit
34
+
35
+ `java -jar target/executable/#{exec_dir}.jar`.must_equal 'hello world'
36
+
37
+ FileUtils.rm_rf( 'target' ) if ENV[ 'KEEP' ].nil?
38
+ end
39
+ end
40
+ end
25
41
  end
26
42
 
27
- FileUtils.rm_rf( File.join( File.expand_path( __FILE__ ).sub( /_spec.rb/, '' ), 'target' ) )
43
+ #FileUtils.rm_rf( File.join( File.expand_path( __FILE__ ).sub( /_spec.rb/, '' ), 'target' ) )
@@ -2,6 +2,9 @@
2
2
  $LOAD_PATH.unshift File.join( File.dirname( File.expand_path( File.dirname( __FILE__ ) ) ),
3
3
  'lib' )
4
4
 
5
+ # TODO somehow needed here for executable_spec
6
+ require 'maven/tools/coordinate'
7
+
5
8
  begin
6
9
  require 'minitest'
7
10
  rescue LoadError
@@ -1,6 +1,6 @@
1
1
  +- rubygems:rspec:gem:2.14.1:compile
2
2
  | +- rubygems:rspec-core:gem:2.14.5:compile (version selected from constraint [2.14.0,2.14.99999])
3
- | +- rubygems:rspec-expectations:gem:2.14.2:compile (version selected from constraint [2.14.0,2.14.99999])
3
+ | +- rubygems:rspec-expectations:gem:2.14.3:compile (version selected from constraint [2.14.0,2.14.99999])
4
4
  | | \- rubygems:diff-lcs:gem:1.2.4:compile (version selected from constraint [1.1.3,2.0))
5
5
  | \- rubygems:rspec-mocks:gem:2.14.3:compile (version selected from constraint [2.14.0,2.14.99999])
6
6
  +- org.jruby:jruby-core:jar:1.7.4:provided
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
12
+ date: 2013-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-maven
@@ -118,6 +118,7 @@ files:
118
118
  - lib/jbundler/classpath_file.rb
119
119
  - lib/jbundler/tree.rb
120
120
  - lib/jbundler/gemfile_lock.rb
121
+ - lib/jbundler/executable_pom.rb
121
122
  - lib/jbundler/cli.rb
122
123
  - lib/jbundler/config.rb
123
124
  - lib/jbundler/pom.rb
@@ -136,11 +137,21 @@ files:
136
137
  - spec/tree/Jarfile.lock
137
138
  - spec/tree/Gemfile
138
139
  - spec/tree/ref.txt
139
- - spec/executable/Jarfile
140
- - spec/executable/Jarfile.lock
141
- - spec/executable/Gemfile.lock
142
- - spec/executable/Gemfile
143
- - spec/executable/start.rb
140
+ - spec/executable_only_java_sources/Jarfile
141
+ - spec/executable_only_java_sources/Jarfile.lock
142
+ - spec/executable_only_java_sources/Gemfile.lock
143
+ - spec/executable_only_java_sources/Gemfile
144
+ - spec/executable_only_java_sources/start.rb
145
+ - spec/executable_no_compile/Jarfile
146
+ - spec/executable_no_compile/Jarfile.lock
147
+ - spec/executable_no_compile/Gemfile.lock
148
+ - spec/executable_no_compile/Gemfile
149
+ - spec/executable_no_compile/start.rb
150
+ - spec/executable_compile/Jarfile
151
+ - spec/executable_compile/Jarfile.lock
152
+ - spec/executable_compile/Gemfile.lock
153
+ - spec/executable_compile/Gemfile
154
+ - spec/executable_compile/start.rb
144
155
  - MIT-LICENSE
145
156
  - Readme.md
146
157
  - Gemfile.lock