jbundler 0.4.3 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem 'jruby-openssl', '0.8.2', :platform => 'jruby'
4
+ # needed for some specs
5
+ gem 'rspec', '<3.0', :group => :test
@@ -1,45 +1,44 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jbundler (0.4.1)
5
- maven-tools (~> 0.32.1)
6
- ruby-maven (~> 3.0.4)
4
+ jbundler (0.5.1)
5
+ bundler (~> 1.2)
6
+ ruby-maven (>= 3.1.0.0.1, < 3.1.1)
7
7
 
8
8
  GEM
9
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- bouncy-castle-java (1.5.0146.1)
12
- builder (3.1.4)
13
- copyright-header (1.0.7)
14
- cucumber (1.1.9)
15
- builder (>= 2.1.2)
16
- diff-lcs (>= 1.1.2)
17
- gherkin (~> 2.9.0)
18
- json (>= 1.4.6)
19
- term-ansicolor (>= 1.0.6)
20
- diff-lcs (1.2.0)
21
- gherkin (2.9.3-java)
22
- json (>= 1.4.6)
23
- jruby-openssl (0.8.2)
24
- bouncy-castle-java (>= 1.5.0146.1)
25
- json (1.7.6-java)
26
- maven-tools (0.32.1)
27
- minitest (4.5.0)
28
- rake (10.0.3)
29
- ruby-maven (3.0.4.1.3)
30
- maven-tools (~> 0.32.1)
31
- thor (>= 0.14.6, < 2.0)
32
- term-ansicolor (1.0.7)
11
+ backports (3.3.4)
12
+ descendants_tracker (0.0.1)
13
+ diff-lcs (1.2.4)
14
+ maven-tools (0.33.2)
15
+ virtus (~> 0.5)
16
+ minitest (4.7.5)
17
+ rake (10.1.0)
18
+ rspec (2.14.1)
19
+ rspec-core (~> 2.14.0)
20
+ rspec-expectations (~> 2.14.0)
21
+ rspec-mocks (~> 2.14.0)
22
+ rspec-core (2.14.5)
23
+ rspec-expectations (2.14.2)
24
+ diff-lcs (>= 1.1.3, < 2.0)
25
+ rspec-mocks (2.14.3)
26
+ ruby-maven (3.1.0.0.1)
27
+ maven-tools (~> 0.33)
28
+ ruby-maven-libs (= 3.1.0)
29
+ ruby-maven-libs (3.1.0)
33
30
  thor (0.15.4)
31
+ virtus (0.5.5)
32
+ backports (~> 3.3)
33
+ descendants_tracker (~> 0.0.1)
34
34
 
35
35
  PLATFORMS
36
36
  java
37
+ ruby
37
38
 
38
39
  DEPENDENCIES
39
- copyright-header (~> 1.0.7)
40
- cucumber (~> 1.1.9)
41
40
  jbundler!
42
- jruby-openssl (= 0.8.2)
43
- minitest (~> 4.3)
44
- rake (~> 10.0.3)
41
+ minitest (~> 4.0)
42
+ rake (~> 10.0)
43
+ rspec (< 3.0)
45
44
  thor (> 0.14.0, < 0.16.0)
@@ -1,42 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jbundler (0.3.2)
5
- ruby-maven (= 3.0.4.1)
4
+ jbundler (0.5.0)
5
+ bundler (~> 1.2)
6
+ ruby-maven (~> 3.1.0.0)
6
7
 
7
8
  GEM
8
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
9
10
  specs:
10
- builder (3.0.0)
11
- cucumber (1.1.9)
12
- builder (>= 2.1.2)
13
- diff-lcs (>= 1.1.2)
14
- gherkin (~> 2.9.0)
15
- json (>= 1.4.6)
16
- term-ansicolor (>= 1.0.6)
17
- diff-lcs (1.1.3)
18
- gherkin (2.9.3)
19
- json (>= 1.4.6)
20
- gherkin (2.9.3-java)
21
- json (>= 1.4.6)
22
- json (1.7.5)
23
- json (1.7.5-java)
24
- maven-tools (0.29.3)
25
- minitest (2.10.1)
26
- rake (0.9.2.2)
27
- ruby-maven (3.0.4.1)
28
- maven-tools (~> 0.29.1)
29
- thor (>= 0.14.6, < 2.0)
30
- term-ansicolor (1.0.7)
11
+ backports (3.3.3)
12
+ descendants_tracker (0.0.1)
13
+ maven-tools (0.33.1)
14
+ virtus (~> 0.5)
15
+ minitest (4.7.5)
16
+ rake (10.1.0)
17
+ ruby-maven (3.1.0.0.1)
18
+ maven-tools (~> 0.33)
19
+ ruby-maven-libs (= 3.1.0)
20
+ ruby-maven-libs (3.1.0)
31
21
  thor (0.15.4)
22
+ virtus (0.5.5)
23
+ backports (~> 3.3)
24
+ descendants_tracker (~> 0.0.1)
32
25
 
33
26
  PLATFORMS
34
27
  java
35
- ruby
36
28
 
37
29
  DEPENDENCIES
38
- cucumber (~> 1.1.9)
39
30
  jbundler!
40
- minitest (~> 2.10.0)
41
- rake (= 0.9.2.2)
31
+ minitest (~> 4.0)
32
+ rake (~> 10.0)
42
33
  thor (> 0.14.0, < 0.16.0)
data/Readme.md CHANGED
@@ -32,9 +32,21 @@ and now install the bundle both **gems and jars**
32
32
 
33
33
  jbundle install
34
34
 
35
- #### Gemfile only
35
+ #### Building
36
36
 
37
- if there is only a **Gemfile** and no Jarfile **jbundler** just handles all the declared [jar dependencies of gems](https://github.com/mkristian/jbundler/wiki/Build). it will only look into gems which bundler loaded.
37
+ building the jar
38
+ ```rake jar```
39
+
40
+ building the gem
41
+ ```rake build```
42
+
43
+ running the junit test
44
+ ```rake junit```
45
+
46
+ running the minitest
47
+ ```rake minitest```
48
+
49
+ make sure you use jruby ;)
38
50
 
39
51
  #### Gemfile and Jarfile
40
52
 
@@ -58,7 +70,7 @@ for adding a maven repository see [Jarfile](https://github.com/torquebox/maven-t
58
70
 
59
71
  like bundler there is a console which sets up the gems (if there is Gemfile otherwise that part get skipped) and sets up the classloader:
60
72
 
61
- jbundler console
73
+ jbundle console
62
74
 
63
75
  further it adds two methods to the root level:
64
76
 
@@ -77,6 +89,22 @@ using the same syntax as use in the **Jarfile**. there are limitations with such
77
89
 
78
90
  will offer the same `jar`/`jars` method than you have inside the console.
79
91
 
92
+ # extra commands
93
+
94
+ ## jbundler tree
95
+
96
+ shows the dependency tree - without the locked version. i.e. an install or update would result in the shown version.
97
+
98
+ with locked down versions that tree is more hint then a real picture of the situation !!
99
+
100
+ ## jruby executable -b start.rb
101
+
102
+ will create an executable jar file using the given ruby script as bootstrap script. it will include the comple jruby and all the dependent jars as well all the gems packed into it as well. the
103
+
104
+ jruby '1.7.4'
105
+
106
+ declaration in the *Jarfile* will determinate the jruby version to use for the executable jar.
107
+
80
108
  ## example ##
81
109
 
82
110
  *src/example/my_project* has a Gemfile which uses a gem which depends on jar dependency. see *src/example/gem_with_jar/gem_with_jar.gemspec* how the jar gets declared.
@@ -95,8 +123,23 @@ since the version resolution happens in two steps - first the gems then the jars
95
123
 
96
124
  **Jarfile** is **not** a DSL but it could use a ruby DSL to read the data (any contribution welcome).
97
125
 
98
- jbundler does not yet obey the **$HOME/.m2/settings.xml** from maven where you usually declare proxies, mirrors, etc.
99
-
126
+ jbundler does not completely obey the **$HOME/.m2/settings.xml** from maven where you usually declare proxies, mirrors, etc. see [jbundler configuration](https://github.com/mkristian/jbundler/wiki/Configuration) for what is already possible.
127
+
128
+ ## RVM and/or rubygems-bundler ##
129
+
130
+ some tests did not work with RVM and/or rubygems-bundler - there are some weird classloader issue popping up. there is a problem with the way the classloader gets setup. but a manual jruby installion or using rbenv is just working fine.
131
+
132
+ those issue might pop up with ```jbunle tree``` and ```jbundle executable```
133
+
134
+ ## running tests ##
135
+
136
+ * ```rake``` will just execute all tests (skips some with rvm)
137
+ * ```rake minitest``` runs the minitest specs
138
+ * ```rake junit``` runs the junit java tests
139
+ * ```jruby spec/abc_spec.rb``` runs that given tests (just use the right file)
140
+ * ```mvn test``` will also run all tests (skips some)
141
+ * ```rmvn test`` same as ```mvn test```
142
+
100
143
  ## update ##
101
144
 
102
145
  update of a single artifact is not possible (yet). but to update the whole set of artifacts just delete the lockfile *Jarfile.lock*
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
+ # ensure we use the right version
4
+ gem 'ruby-maven', '>=3.1.0'
3
5
 
4
6
  if ARGV[0] == 'help'
5
7
 
@@ -19,50 +21,57 @@ else
19
21
 
20
22
  require 'jbundler/config'
21
23
  config = JBundler::Config.new
22
- begin
23
- require 'yaml'
24
- bundle_config = YAML.load_file( File.join( ENV['HOME'],
25
- '.bundle',
26
- 'config' ) )
27
- mirrors = bundle_config.select { |k,v| nil != (k =~ /BUNDLE_MIRROR__/) }
28
- if config.rubygems_mirror || mirrors.size > 0
29
- mirrors.each do |k,v|
30
- ENV[ k ] = v
31
- end
32
- if config.rubygems_mirror
33
- ENV['BUNDLE_MIRROR__HTTP://RUBYGEMS.ORG'] = config.rubygems_mirror
34
- ENV['BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG'] = config.rubygems_mirror
35
- end
36
24
 
37
- begin
38
- load Gem.bin_path('nexus', 'nbundle')
39
- rescue Gem::GemNotFoundException
40
- warn ''
41
- warn 'to use a rubygems mirror you need to install the nexus gem'
42
- warn ' $ gem install nexus'
43
- warn ''
44
- warn 'rubygems mirror ignored !'
25
+ if ['install', 'update', 'show', 'console'].member?( ARGV[0] )
26
+ begin
27
+ file = File.join( ENV['HOME'], '.bundle', 'config' )
28
+ if File.exists?( file )
29
+ require 'yaml'
30
+ bundle_config = YAML.load_file( file )
31
+ mirrors = bundle_config.select { |k,v| nil != (k =~ /BUNDLE_MIRROR__/) }
32
+ if config.rubygems_mirror || mirrors.size > 0
33
+ mirrors.each do |k,v|
34
+ ENV[ k ] = v
35
+ end
36
+ if config.rubygems_mirror
37
+ ENV['BUNDLE_MIRROR__HTTP://RUBYGEMS.ORG'] = config.rubygems_mirror
38
+ ENV['BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG'] = config.rubygems_mirror
39
+ end
40
+
41
+ begin
42
+ load Gem.bin_path('nexus', 'nbundle')
43
+ rescue Gem::GemNotFoundException
44
+ warn ''
45
+ warn 'to use a rubygems mirror you need to install the nexus gem'
46
+ warn ' $ gem install nexus'
47
+ warn ''
48
+ warn 'rubygems mirror ignored !'
49
+ end
50
+ else
51
+ load Gem.bin_path('bundler', 'bundle')
52
+ end
53
+ else
54
+ load Gem.bin_path('bundler', 'bundle')
45
55
  end
46
- else
47
- load Gem.bin_path('bundler', 'bundle')
48
- end
49
- rescue Exception
50
- if ARGV[0] == 'console'
51
- ARGV.shift
52
- require 'jbundler'
53
- if defined? JBUNDLER_CLASSPATH
54
- warn 'Jarfile dependencies loaded'
56
+ require 'jbundler/cli'
57
+ JBundler::Cli.start
58
+ rescue Exception => e
59
+ if ARGV[0] == 'console'
60
+ ARGV.shift
61
+ require 'jbundler'
62
+ if defined? JBUNDLER_CLASSPATH
63
+ warn 'Jarfile dependencies loaded'
64
+ else
65
+ warn 'Could not locate Jarfile'
66
+
67
+ end
68
+ IRB.start
55
69
  else
56
- warn 'Could not locate Jarfile'
57
-
70
+ raise e
58
71
  end
59
- IRB.start
60
72
  end
61
- end
62
-
63
- if ARGV[0] && ['install', 'update', 'show'].member?(ARGV[0])
73
+ else
64
74
  require 'jbundler/cli'
65
-
66
75
  JBundler::Cli.start
67
76
  end
68
77
 
Binary file
@@ -20,6 +20,7 @@
20
20
  #
21
21
  require 'yaml'
22
22
  require 'jbundler/config'
23
+ require 'maven'
23
24
 
24
25
  module JBundler
25
26
 
@@ -28,10 +29,9 @@ module JBundler
28
29
  def self.setup_classloader
29
30
  require 'java'
30
31
 
31
- maven_home = File.dirname(File.dirname(Gem.bin_path('ruby-maven',
32
- 'rmvn')))
33
- # TODO reduce to the libs which are really needed
34
- Dir.glob(File.join(maven_home, 'lib', "*jar")).each {|path| require path }
32
+ Dir.glob( File.join( Maven.lib, '*.jar' ) ).each do |path|
33
+ require path
34
+ end
35
35
  begin
36
36
  require 'jbundler.jar'
37
37
  rescue LoadError
@@ -61,6 +61,14 @@ module JBundler
61
61
  raise e
62
62
  end
63
63
 
64
+ def local_jars
65
+ @local_jars ||= []
66
+ end
67
+
68
+ def add_local_jar( path )
69
+ local_jars << File.expand_path( path )
70
+ end
71
+
64
72
  def add_artifact(coordinate, extension = nil)
65
73
  if extension
66
74
  coord = coordinate.split(/:/)
@@ -75,6 +83,10 @@ module JBundler
75
83
  @aether.add_repository(name, url)
76
84
  end
77
85
 
86
+ def add_snapshot_repository(name, url)
87
+ @aether.add_snapshot_repository(name, url)
88
+ end
89
+
78
90
  def resolve
79
91
  @aether.resolve unless artifacts.empty?
80
92
  rescue NativeException => e
@@ -83,10 +95,12 @@ module JBundler
83
95
  end
84
96
 
85
97
  def classpath
86
- if artifacts.empty?
98
+ if artifacts.empty? and local_jars.empty?
87
99
  ''
88
100
  else
89
- @aether.classpath
101
+ path = [ @aether.classpath ]
102
+ path = path + @local_jars if @local_jars
103
+ path.join( File::PATH_SEPARATOR )
90
104
  end
91
105
  end
92
106
 
@@ -103,7 +117,7 @@ module JBundler
103
117
  end
104
118
 
105
119
  def resolved_coordinates
106
- if artifacts.empty?
120
+ if @aether.artifacts.empty?
107
121
  []
108
122
  else
109
123
  @aether.resolved_coordinates
@@ -56,4 +56,4 @@ module JBundler
56
56
  end
57
57
 
58
58
  end
59
- end
59
+ end
@@ -19,18 +19,19 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  require 'thor'
22
+ require 'jbundler/config'
23
+ require 'jbundler/executable'
24
+ require 'jbundler/tree'
22
25
  module JBundler
23
26
  class Cli < Thor
24
27
  no_tasks do
25
- def mvn
26
- @mvn ||= Maven::Ruby::Maven.new
28
+ def config
29
+ @config ||= JBundler::Config.new
27
30
  end
28
31
 
29
32
  def do_show
30
33
  require 'java'
31
- require 'jbundler/config'
32
34
  require 'jbundler/classpath_file'
33
- config = JBundler::Config.new
34
35
  classpath_file = JBundler::ClasspathFile.new(config.classpath_file)
35
36
  if classpath_file.exists?
36
37
  classpath_file.require_classpath unless defined? JBUNDLER_CLASSPATH
@@ -43,7 +44,21 @@ module JBundler
43
44
  end
44
45
  end
45
46
  end
46
-
47
+
48
+ desc 'tree', 'display a graphical representation of the dependency tree'
49
+ #method_option :details, :type => :boolean, :default => false
50
+ def tree
51
+ JBundler::Tree.new( config ).show_it
52
+ end
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'
56
+ method_option :groups, :type => :array, :aliases => '-g', :desc => 'bundler groups to use for determine the gems to include in the jar file'
57
+ def executable
58
+ ex = JBundler::Executable.new( options[ :bootstrap ], config )
59
+ ex.packit
60
+ end
61
+
47
62
  desc 'console', 'irb session with gems and/or jars and with lazy jar loading.'
48
63
  def console
49
64
  # dummy - never executed !!!
@@ -78,4 +93,4 @@ module JBundler
78
93
  end
79
94
  end
80
95
  end
81
- end
96
+ end
@@ -25,7 +25,7 @@ module JBundler
25
25
  # allow yaml config in $HOME/.jbundlerrc and $PWD/.jbundlerrc
26
26
  class Config
27
27
 
28
- attr_accessor :verbose, :local_repository, :jarfile, :gemfile, :skip, :settings, :offline
28
+ attr_accessor :verbose, :local_repository, :jarfile, :gemfile, :skip, :settings, :offline, :work_dir
29
29
 
30
30
  def initialize
31
31
  file = '.jbundlerrc'
@@ -37,11 +37,11 @@ module JBundler
37
37
 
38
38
  if defined? JRUBY_VERSION
39
39
  def jbundler_env(key)
40
- ENV[key.upcase.gsub(/[.]/, '_')] || java.lang.System.getProperty(key.downcase.gsub(/_/, '.')) || @config[key.downcase.sub(/^j?bundler/, '').sub(/[.]/, '_')]
40
+ @config[key.downcase.sub(/^j?bundle_/, '').sub(/[.]/, '_')] || java.lang.System.getProperty(key.downcase.gsub(/_/, '.')) || ENV[key.upcase.gsub(/[.]/, '_')]
41
41
  end
42
42
  else
43
43
  def jbundler_env(key)
44
- ENV[key.upcase.gsub(/[.]/, '_')] || @config[key.downcase.sub(/^j?bundler/, '').sub(/[.]/, '_')]
44
+ @config[key.downcase.sub(/^j?bundler/, '').sub(/[.]/, '_')] || ENV[key.upcase.gsub(/[.]/, '_')]
45
45
  end
46
46
  end
47
47
  private :jbundler_env
@@ -102,7 +102,7 @@ module JBundler
102
102
 
103
103
  def mirror
104
104
  @mirror ||= jbundler_env('JBUNDLE_MIRROR')
105
- # nce to have no leading slash
105
+ # nice to have no leading slash
106
106
  @mirror.sub!( /\/$/, '' ) if @mirror
107
107
  @mirror
108
108
  end
@@ -113,5 +113,10 @@ module JBundler
113
113
  @rubygems_mirror.sub!( /([^\/])$/ , "\\1/" ) if @rubygems_mirror
114
114
  @rubygems_mirror
115
115
  end
116
+
117
+ def work_dir
118
+ @work_dir ||= jbundler_env('JBUNDLE_WORK_DIR') || 'target'
119
+ end
120
+
116
121
  end
117
- end
122
+ end
@@ -0,0 +1,117 @@
1
+ require 'maven/tools/jarfile'
2
+ require 'maven/tools/dsl'
3
+ require 'maven/ruby/maven'
4
+ require 'fileutils'
5
+ module JBundler
6
+ class Executable
7
+
8
+ BOOTSTRAP = 'jar-bootstrap.rb'
9
+
10
+ include Maven::Tools::DSL
11
+
12
+ def initialize( bootstrap, config )
13
+ 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 )
38
+ end
39
+
40
+ 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' )
107
+ m.package
108
+
109
+ FileUtils.rm_f( 'dependency-reduced-pom.xml' )
110
+ puts
111
+ puts 'now you can execute your jar like this'
112
+ puts
113
+ puts "\tjava -jar #{work_dir}/#{project.artifact_id}.jar"
114
+ puts
115
+ end
116
+ end
117
+ end
@@ -42,12 +42,12 @@ module JBundler
42
42
  def populate_dependencies(aether)
43
43
  if @lockfile
44
44
  # assuming we run in Bundler context here
45
- # at we have a Gemfile.lock :)
45
+ # since we have a Gemfile.lock :)
46
46
  Bundler.load.specs.each do |spec|
47
47
  jars = []
48
48
  spec.requirements.each do |rr|
49
49
  rr.split(/\n/).each do |r|
50
- jars << r if r =~ /^jar\s/
50
+ jars << r if r =~ /^\s*(jar|pom)\s/
51
51
  end
52
52
  end
53
53
  unless jars.empty?
@@ -62,4 +62,4 @@ module JBundler
62
62
  end
63
63
  end
64
64
 
65
- end
65
+ end
@@ -0,0 +1,27 @@
1
+ require 'maven/ruby/maven'
2
+ require 'maven/tools/visitor'
3
+ module JBundler
4
+ # mimic the new maven class - prepare for upgrade
5
+ class MavenNG
6
+
7
+ def initialize( project, temp_pom = nil )
8
+ f = File.expand_path( File.join( temp_pom || '.pom.xml' ) )
9
+ v = ::Maven::Tools::Visitor.new( File.open( f, 'w' ) )
10
+ # parse block and write out pom4rake.xml file
11
+ v.accept_project( project )
12
+ # tell maven to use the generated file
13
+ @rmvn = ::Maven::Ruby::Maven.new
14
+ @rmvn.options[ '-f' ] = f
15
+ @rmvn.options[ '-B' ] = nil
16
+ end
17
+
18
+ def exec( *args )
19
+ @rmvn.exec_in( File.expand_path( '.' ), *args )
20
+ end
21
+
22
+ def method_missing( method, *args )
23
+ @rmvn.exec( [ method ] + args )
24
+ end
25
+ end
26
+ end
27
+
@@ -21,6 +21,7 @@
21
21
  require 'fileutils'
22
22
  require 'tempfile'
23
23
  require 'maven/tools/coordinate'
24
+ require 'securerandom'
24
25
  require 'java'
25
26
 
26
27
  module JBundler
@@ -34,9 +35,11 @@ module JBundler
34
35
  def temp_dir
35
36
  @temp_dir ||=
36
37
  begin
37
- d = Dir.mktmpdir
38
+ # on travis the mktmpdir failed
39
+ d = Dir.mktmpdir rescue FileUtils.mkdir( ".tmp" + SecureRandom.hex( 12) ).first
38
40
  at_exit { FileUtils.rm_rf(d.dup) }
39
- d
41
+ # for jruby-1.7.4 1.8 mode add expand_path
42
+ File.expand_path( d )
40
43
  end
41
44
  end
42
45
 
@@ -125,4 +128,4 @@ module JBundler
125
128
  end
126
129
 
127
130
  end
128
- end
131
+ end
@@ -0,0 +1,54 @@
1
+ require 'maven/tools/jarfile'
2
+ require 'maven/tools/dsl'
3
+ require 'maven/tools/model'
4
+ require 'maven/ruby/maven'
5
+ require 'fileutils'
6
+ module JBundler
7
+ class Tree
8
+
9
+ include Maven::Tools::DSL
10
+
11
+ def initialize( config )
12
+ @config = config
13
+ end
14
+
15
+ def show_it( debug = false )
16
+ require 'jbundler'
17
+ jfile = ::Maven::Tools::Jarfile.new( @config.jarfile )
18
+ project = maven do
19
+ basedir( File.dirname( @config.jarfile ) )
20
+
21
+ gemfile( @config.gemfile ) if File.exists? @config.gemfile
22
+
23
+ jarfile :skip_locked => true
24
+
25
+ build.directory = @config.work_dir if @config.work_dir != 'target'
26
+
27
+ properties( 'project.build.sourceEncoding' => 'utf-8' )
28
+ end
29
+
30
+ output = java.io.ByteArrayOutputStream.new
31
+ out = java.io.PrintStream.new( output )
32
+ old = java.lang.System.err
33
+ java.lang.System.err = out
34
+
35
+ m = Maven::Ruby::Maven.new( project, '.tree.pom.xml' )
36
+ m.exec( 'org.apache.maven.plugins:maven-dependency-plugin:2.8:tree' )
37
+ result = output.to_string( 'utf-8' ).split( "\n" )
38
+ result = result.each do |line|
39
+ line.gsub!( /\[[^ ]+\] /, '' )
40
+ end
41
+ unless debug
42
+ result = result.select do |line|
43
+ line =~ /^[INFO].*/
44
+ end
45
+ end
46
+ result = result.each do |line|
47
+ line.gsub!( /^.* - /, '' )
48
+ end
49
+ $stdout.puts result.join( "\n" )#.gsub( /^.* - /, '' )#.gsub( /\n\n\n/, "\n" )
50
+ ensure
51
+ java.lang.System.err = old
52
+ end
53
+ end
54
+ end
@@ -1,17 +1,18 @@
1
- #TODO get 'spec' into $LOAD by minispec-maven-plugin
2
1
  load File.expand_path(File.join('spec', 'setup.rb'))
3
2
  require 'maven/tools/jarfile'
4
3
  require 'jbundler/aether'
4
+ require 'fileutils'
5
5
 
6
6
  describe JBundler::AetherRuby do
7
7
 
8
- let(:workdir) { 'target' }
8
+ let(:workdir) { 'pkg' }
9
9
  let(:jfile) { File.join(workdir, 'tmp-jarfile') }
10
10
  let(:jfile_lock) { jfile + ".lock"}
11
11
  let(:jarfile) { Maven::Tools::Jarfile.new(jfile) }
12
12
  subject { JBundler::AetherRuby.new }
13
13
 
14
14
  before do
15
+ FileUtils.mkdir_p( workdir )
15
16
  Dir[File.join(workdir, "tmp*")].each { |f| FileUtils.rm_f f }
16
17
  end
17
18
 
@@ -28,6 +29,24 @@ EOF
28
29
  subject.repositories[0].id.must_equal "central"
29
30
  subject.repositories[1].id.must_equal "first"
30
31
  subject.repositories[2].id.must_equal "second"
32
+ subject.repositories[0].get_policy( false ).is_enabled.must_equal true
33
+ subject.repositories[0].get_policy( true ).is_enabled.must_equal true
34
+ subject.repositories[1].get_policy( true ).is_enabled.must_equal false
35
+ subject.repositories[2].get_policy( true ).is_enabled.must_equal false
36
+ end
37
+
38
+ it 'snapshot repositories' do
39
+ File.open(jfile, 'w') do |f|
40
+ f.write <<-EOF
41
+ snapshot_repository :snap, "http://example.com/repo"
42
+ EOF
43
+ end
44
+ jarfile.populate_unlocked subject
45
+ subject.repositories.size.must_equal 2
46
+ subject.artifacts.size.must_equal 0
47
+ subject.repositories[0].id.must_equal "central"
48
+ subject.repositories[1].id.must_equal "snap"
49
+ subject.repositories[1].get_policy( true ).is_enabled.must_equal true
31
50
  end
32
51
 
33
52
  it 'artifacts without locked' do
@@ -1,4 +1,3 @@
1
- #TODO get 'spec' into $LOAD by minispec-maven-plugin
2
1
  load File.expand_path(File.join('spec', 'setup.rb'))
3
2
  require 'jbundler/classpath_file'
4
3
  require 'maven/tools/jarfile'
@@ -6,7 +5,7 @@ require 'jbundler/gemfile_lock'
6
5
 
7
6
  describe JBundler::ClasspathFile do
8
7
 
9
- let(:workdir) { File.join('target', 'tmp') }
8
+ let(:workdir) { File.join('pkg', 'tmp') }
10
9
  let(:jfile) { File.join(workdir, 'jarfile') }
11
10
  let(:gfile_lock) { File.join(workdir, 'gemfile.lock') }
12
11
  let(:jfile_lock) { jfile + ".lock"}
@@ -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,3 @@
1
+ # provide non https as well for travis
2
+ repository 'central', 'http://repo.maven.apache.org/maven2/'
3
+ 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,5 @@
1
+ import 'org.junit.runner.JUnitCore'
2
+ import 'test.AppTest'
3
+
4
+ java.lang.System.set_property( 'WORLD', 'world' )
5
+ JUnitCore.run_classes( AppTest.java_class )
@@ -0,0 +1,27 @@
1
+ load File.expand_path(File.join( File.dirname( __FILE__ ), 'setup.rb'))
2
+ require 'jbundler/executable'
3
+ require 'jbundler/config'
4
+ require 'fileutils'
5
+
6
+ describe JBundler::Executable do
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
21
+
22
+ `java -jar target/executable/executable.jar`.must_equal 'hello world'
23
+ end
24
+
25
+ end
26
+
27
+ FileUtils.rm_rf( File.join( File.expand_path( __FILE__ ).sub( /_spec.rb/, '' ), 'target' ) )
@@ -1,4 +1,3 @@
1
- #TODO get 'spec' into $LOAD by minispec-maven-plugin
2
1
  load File.expand_path(File.join('spec', 'setup.rb'))
3
2
  require 'jbundler/pom'
4
3
 
@@ -1,3 +1,9 @@
1
- require 'fileutils'
1
+ # single spec setup
2
+ $LOAD_PATH.unshift File.join( File.dirname( File.expand_path( File.dirname( __FILE__ ) ) ),
3
+ 'lib' )
2
4
 
3
- FileUtils.mkdir_p 'target'
5
+ begin
6
+ require 'minitest'
7
+ rescue LoadError
8
+ end
9
+ require 'minitest/autorun'
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec', '<3.0'
@@ -0,0 +1,5 @@
1
+ # provide non https as well for travis
2
+ repository 'central', 'http://repo.maven.apache.org/maven2/'
3
+ jar 'junit:junit', '4.11'
4
+
5
+ local './myfirst.jar'
@@ -0,0 +1,2 @@
1
+ junit:junit:jar:4.11
2
+ org.hamcrest:hamcrest-core:jar:1.3
Binary file
@@ -0,0 +1,27 @@
1
+ +- rubygems:rspec:gem:2.14.1:compile
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])
4
+ | | \- rubygems:diff-lcs:gem:1.2.4:compile (version selected from constraint [1.1.3,2.0))
5
+ | \- rubygems:rspec-mocks:gem:2.14.3:compile (version selected from constraint [2.14.0,2.14.99999])
6
+ +- org.jruby:jruby-core:jar:1.7.4:provided
7
+ | +- org.jruby:jruby-stdlib:jar:1.7.4:provided
8
+ | +- org.jruby.joni:joni:jar:2.0.0:provided
9
+ | +- com.github.jnr:jnr-netdb:jar:1.1.2:provided
10
+ | +- com.github.jnr:jnr-enxio:jar:0.4:provided
11
+ | +- com.github.jnr:jnr-unixsocket:jar:0.3:provided
12
+ | +- com.github.jnr:jnr-posix:jar:2.5.2:provided
13
+ | +- org.jruby.extras:bytelist:jar:1.0.10:provided
14
+ | +- com.github.jnr:jnr-constants:jar:0.8.4:provided
15
+ | +- org.jruby.jcodings:jcodings:jar:1.0.10:provided
16
+ | +- com.github.jnr:jffi:jar:1.2.5:provided
17
+ | +- org.yaml:snakeyaml:jar:1.11:provided
18
+ | +- jline:jline:jar:2.7:provided
19
+ | +- joda-time:joda-time:jar:2.1:provided
20
+ | +- com.jcraft:jzlib:jar:1.1.2:provided
21
+ | +- com.headius:invokebinder:jar:1.2:provided
22
+ | \- com.github.jnr:jnr-ffi:jar:1.0.4:provided
23
+ | +- com.github.jnr:jffi:jar:native:1.2.7:provided (version selected from constraint [1.2.1,1.3.0))
24
+ | \- com.github.jnr:jnr-x86asm:jar:1.0.2:provided (version selected from constraint [1.0.2,))
25
+ +- junit:junit:jar:4.11:compile
26
+ | \- org.hamcrest:hamcrest-core:jar:1.3:compile
27
+ \- ruby.maven-tools.jar:myfirst:jar:0:system
@@ -0,0 +1,33 @@
1
+ load File.expand_path(File.join( File.dirname( __FILE__ ), 'setup.rb'))
2
+ require 'jbundler/tree'
3
+ require 'jbundler/config'
4
+ require 'stringio'
5
+
6
+ describe JBundler::Tree do
7
+
8
+ it 'should show dependency tree' do
9
+
10
+ skip 'that spec does not execute properly with maven' if java.lang.System.get_property( 'jruby.script' ) == nil
11
+
12
+ skip 'rvm is not working properly' if ENV[ 'rvm_version' ]
13
+
14
+ dir = File.join( File.dirname( __FILE__ ), 'tree' )
15
+ java.lang.System.set_property( 'user.dir', dir )
16
+ FileUtils.cd( dir ) do
17
+ exec = JBundler::Tree.new( JBundler::Config.new )
18
+ output = StringIO.new
19
+ $stdout = output
20
+ exec.show_it( true )
21
+ $stdout = STDOUT
22
+ lines = output.string.split( /\n/ )
23
+ lines = lines.select do |line|
24
+ line =~ /:.+:.+:.+:/
25
+ end
26
+ lines.join( "\n" ).must_equal File.read( 'ref.txt' ).strip
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ FileUtils.rm_rf( File.join( File.expand_path( __FILE__ ).sub( /_spec.rb/, '' ), 'target' ) )
metadata CHANGED
@@ -1,45 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbundler
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.5.1
4
5
  prerelease:
5
- version: 0.4.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christian Meier
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-10 00:00:00.000000000 Z
12
+ date: 2013-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-maven
16
16
  version_requirements: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - '>='
19
19
  - !ruby/object:Gem::Version
20
- version: 3.0.4
20
+ version: 3.1.0.0.1
21
+ - - <
22
+ - !ruby/object:Gem::Version
23
+ version: 3.1.1
21
24
  none: false
22
25
  requirement: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0.0.1
30
+ - - <
25
31
  - !ruby/object:Gem::Version
26
- version: 3.0.4
32
+ version: 3.1.1
27
33
  none: false
28
34
  prerelease: false
29
35
  type: :runtime
30
36
  - !ruby/object:Gem::Dependency
31
- name: maven-tools
37
+ name: bundler
32
38
  version_requirements: !ruby/object:Gem::Requirement
33
39
  requirements:
34
- - - "~>"
40
+ - - ~>
35
41
  - !ruby/object:Gem::Version
36
- version: 0.32.1
42
+ version: '1.2'
37
43
  none: false
38
44
  requirement: !ruby/object:Gem::Requirement
39
45
  requirements:
40
- - - "~>"
46
+ - - ~>
41
47
  - !ruby/object:Gem::Version
42
- version: 0.32.1
48
+ version: '1.2'
43
49
  none: false
44
50
  prerelease: false
45
51
  type: :runtime
@@ -47,15 +53,15 @@ dependencies:
47
53
  name: rake
48
54
  version_requirements: !ruby/object:Gem::Requirement
49
55
  requirements:
50
- - - "~>"
56
+ - - ~>
51
57
  - !ruby/object:Gem::Version
52
- version: 10.0.3
58
+ version: '10.0'
53
59
  none: false
54
60
  requirement: !ruby/object:Gem::Requirement
55
61
  requirements:
56
- - - "~>"
62
+ - - ~>
57
63
  - !ruby/object:Gem::Version
58
- version: 10.0.3
64
+ version: '10.0'
59
65
  none: false
60
66
  prerelease: false
61
67
  type: :development
@@ -63,73 +69,37 @@ dependencies:
63
69
  name: thor
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - !binary |-
67
- PA==
72
+ - - <
68
73
  - !ruby/object:Gem::Version
69
74
  version: 0.16.0
70
- - - !binary |-
71
- Pg==
75
+ - - '>'
72
76
  - !ruby/object:Gem::Version
73
77
  version: 0.14.0
74
78
  none: false
75
79
  requirement: !ruby/object:Gem::Requirement
76
80
  requirements:
77
- - - !binary |-
78
- PA==
81
+ - - <
79
82
  - !ruby/object:Gem::Version
80
83
  version: 0.16.0
81
- - - !binary |-
82
- Pg==
84
+ - - '>'
83
85
  - !ruby/object:Gem::Version
84
86
  version: 0.14.0
85
87
  none: false
86
88
  prerelease: false
87
89
  type: :development
88
- - !ruby/object:Gem::Dependency
89
- name: cucumber
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - "~>"
93
- - !ruby/object:Gem::Version
94
- version: 1.1.9
95
- none: false
96
- requirement: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - "~>"
99
- - !ruby/object:Gem::Version
100
- version: 1.1.9
101
- none: false
102
- prerelease: false
103
- type: :development
104
90
  - !ruby/object:Gem::Dependency
105
91
  name: minitest
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '4.3'
111
- none: false
112
- requirement: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '4.3'
117
- none: false
118
- prerelease: false
119
- type: :development
120
- - !ruby/object:Gem::Dependency
121
- name: copyright-header
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - '='
94
+ - - ~>
125
95
  - !ruby/object:Gem::Version
126
- version: 1.0.8
96
+ version: '4.0'
127
97
  none: false
128
98
  requirement: !ruby/object:Gem::Requirement
129
99
  requirements:
130
- - - '='
100
+ - - ~>
131
101
  - !ruby/object:Gem::Version
132
- version: 1.0.8
102
+ version: '4.0'
133
103
  none: false
134
104
  prerelease: false
135
105
  type: :development
@@ -143,24 +113,39 @@ extensions: []
143
113
  extra_rdoc_files: []
144
114
  files:
145
115
  - bin/jbundle
146
- - lib/jbundler.jar
147
116
  - lib/jbundler.rb
148
- - lib/jbundler/lazy.rb
149
- - lib/jbundler/pom.rb
150
- - lib/jbundler/gemfile_lock.rb
151
- - lib/jbundler/config.rb
152
117
  - lib/jbundler/aether.rb
153
118
  - lib/jbundler/classpath_file.rb
119
+ - lib/jbundler/tree.rb
120
+ - lib/jbundler/gemfile_lock.rb
154
121
  - lib/jbundler/cli.rb
155
- - spec/classpath_file_spec.rb
122
+ - lib/jbundler/config.rb
123
+ - lib/jbundler/pom.rb
124
+ - lib/jbundler/maven.rb
125
+ - lib/jbundler/lazy.rb
126
+ - lib/jbundler/executable.rb
127
+ - lib/jbundler.jar
128
+ - spec/executable_spec.rb
129
+ - spec/tree_spec.rb
130
+ - spec/pom_spec.rb
156
131
  - spec/setup.rb
157
132
  - spec/aether_spec.rb
158
- - spec/pom_spec.rb
133
+ - spec/classpath_file_spec.rb
134
+ - spec/tree/myfirst.jar
135
+ - spec/tree/Jarfile
136
+ - spec/tree/Jarfile.lock
137
+ - spec/tree/Gemfile
138
+ - 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
159
144
  - MIT-LICENSE
160
145
  - Readme.md
161
- - Gemfile.lock~
162
- - Gemfile
163
146
  - Gemfile.lock
147
+ - Gemfile
148
+ - Gemfile.lock~
164
149
  homepage: https://github.com/mkristian/jbundler
165
150
  licenses:
166
151
  - MIT
@@ -170,17 +155,15 @@ require_paths:
170
155
  - lib
171
156
  required_ruby_version: !ruby/object:Gem::Requirement
172
157
  requirements:
173
- - - ">="
158
+ - - '>='
174
159
  - !ruby/object:Gem::Version
175
- version: !binary |-
176
- MA==
160
+ version: '0'
177
161
  none: false
178
162
  required_rubygems_version: !ruby/object:Gem::Requirement
179
163
  requirements:
180
- - - ">="
164
+ - - '>='
181
165
  - !ruby/object:Gem::Version
182
- version: !binary |-
183
- MA==
166
+ version: '0'
184
167
  none: false
185
168
  requirements: []
186
169
  rubyforge_project:
@@ -189,6 +172,8 @@ signing_key:
189
172
  specification_version: 3
190
173
  summary: managing jar dependencies
191
174
  test_files:
192
- - spec/classpath_file_spec.rb
193
- - spec/aether_spec.rb
175
+ - spec/executable_spec.rb
176
+ - spec/tree_spec.rb
194
177
  - spec/pom_spec.rb
178
+ - spec/aether_spec.rb
179
+ - spec/classpath_file_spec.rb