jbundler 0.8.0.pre → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ac6a9fb5c574bba0b316c3a86a7779371a334cc
4
- data.tar.gz: 750f10fa9bb8a767a3d0b850318bf57132c9f3cc
3
+ metadata.gz: 4c9e585f4468a32aa458da2a1a78b497aa84af54
4
+ data.tar.gz: 39edf54af322a15bc17822eb8df7bf84cdca9f8a
5
5
  SHA512:
6
- metadata.gz: 55749212e56d0cb339dc95dca63ac6c2454dfbdeb3b5f4f6105e5c5183fc5fdb0218f5e3e08cf1ba0b9255038d1fc29c3e8bce5cfeaa90568f9fb609fb4ea25c
7
- data.tar.gz: ff954ccee92c476835a455150ab6fd84b1aebef43f61c5c153614a537c3fab882e9d32216ba2531af8423ee8a840a9e02b47fe36005c27647a1f6cb04c068b78
6
+ metadata.gz: 506c7136901ba6d97a11309b09aaa2a4e65f2708197d8f07188a2a3d7611251609a830bcba242e185ac70a12249254a80dd41484f4ca4b6f788bb57a1eb4358a
7
+ data.tar.gz: 6ac1b2f582b3222f13ff00431b4a70ddb21165737f42bfeae1ca05c96a82afc16259f5c0200415befd1e11e10f6e754d3bd7853e14dd6ac12d902fad03b14ad0
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jbundler (0.7.3)
4
+ jbundler (0.8.0)
5
5
  bundler (~> 1.5)
6
- jar-dependencies (~> 0.1.11)
7
- maven-tools (~> 1.0.8)
8
- ruby-maven (>= 3.1.1.0.6, < 3.1.2)
6
+ jar-dependencies (~> 0.1.15)
7
+ maven-tools (~> 1.0.10)
8
+ ruby-maven (~> 3.3, >= 3.3.3)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -18,19 +18,18 @@ GEM
18
18
  descendants_tracker (~> 0.0.1)
19
19
  descendants_tracker (0.0.4)
20
20
  thread_safe (~> 0.3, >= 0.3.1)
21
- equalizer (0.0.9)
21
+ equalizer (0.0.11)
22
22
  ice_nine (0.11.1)
23
- jar-dependencies (0.1.11)
24
- maven-tools (1.0.8)
23
+ jar-dependencies (0.1.15)
24
+ maven-tools (1.0.10)
25
25
  virtus (~> 1.0)
26
- minitest (5.5.1)
26
+ minitest (5.7.0)
27
27
  rake (10.4.2)
28
- ruby-maven (3.1.1.0.11)
29
- maven-tools (~> 1.0.8)
30
- ruby-maven-libs (= 3.1.1)
31
- ruby-maven-libs (3.1.1)
28
+ ruby-maven (3.3.3)
29
+ ruby-maven-libs (~> 3.3.1)
30
+ ruby-maven-libs (3.3.3)
32
31
  thread_safe (0.3.5-java)
33
- virtus (1.0.4)
32
+ virtus (1.0.5)
34
33
  axiom-types (~> 0.1)
35
34
  coercible (~> 1.0)
36
35
  descendants_tracker (~> 0.0, >= 0.0.3)
@@ -44,3 +43,6 @@ DEPENDENCIES
44
43
  jbundler!
45
44
  minitest (~> 5.3)
46
45
  rake (~> 10.0)
46
+
47
+ BUNDLED WITH
48
+ 1.10.4
data/Readme.md CHANGED
@@ -7,13 +7,9 @@ manage jar dependencies similar than **bundler** manages gem dependencies.
7
7
  * the DSL mimics the one from bundler
8
8
  * you can use maven like version declaration or rubygems/bundler like version ranges
9
9
  * it locks down the jar versions inside "Jarfile.lock"
10
- * you can declare jar dependency within a gem using the requirements directive of the gem specification. jbundler will include those jar dependencies into its classpath
11
-
12
- the difference to **bundler**
13
-
14
- * it is just a development gem - no need for it during runtime. just add ```Jars.require_jars_lock!``` to your code and for older JRuby add ```gem 'jar-dependencies', '~> 0.1.11'``` as runtime dependency.
15
- * you need to run ```bundle install``` first if any of the gems has jar dependencies.
16
- * all one command ```jbundle```, see ```jbundle --help``` on the possible options and how to update a single jar, etc.
10
+ * you can declare jar dependency within a rubygems using the requirements directive of the gem specification. jbundler will include those jar dependencies into its classpath
11
+ * on the first run everything get resolved, any further run just the setup of classpath is done (without any maven involved)
12
+ * it integrates nicely with bundler when Bundler.require is used (like Rails does it)
17
13
 
18
14
  ## get started
19
15
 
@@ -23,28 +19,91 @@ install JBundler with
23
19
 
24
20
  first create a **Jarfile**, something like
25
21
 
26
- jar 'org.yaml:snakeyaml', '1.14'
22
+ jar 'org.yaml:snakeyaml'
27
23
  jar 'org.slf4j:slf4j-simple', '>1.1'
28
24
 
25
+ ### together with Bundler
26
+
27
+ just add it as **first** entry in your *Gemfile*
28
+
29
+ ```gem 'jbundler'```
30
+
31
+ and now install the bundle both **gems and jars**
32
+
33
+ jbundle install
34
+
35
+ #### Building
36
+
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 ;)
50
+
51
+ #### Gemfile and Jarfile
52
+
53
+ if there is only a **Gemfile** and no Jarfile **jbundler** handles all the declared [jar dependencies of gems](https://github.com/mkristian/jbundler/wiki/Build) as well all the jars from the Jarfile. it will only look into gems which bundler loaded.
54
+
55
+ ### without Bundler - Jarfile only
56
+
57
+ requiring **jbundler** will trigger the classpath setup
58
+
59
+ ```require 'jbundler'```
60
+
61
+ this you can use with **rubygems** or **isolate** or . . .
62
+
29
63
  ### Jarfile
30
64
 
31
65
  more info about the **[Jarfile](https://github.com/torquebox/maven-tools/wiki/Jarfile)** and about [versions](https://github.com/torquebox/maven-tools/wiki/Versions).
32
66
 
33
67
  for adding a maven repository see [Jarfile](https://github.com/torquebox/maven-tools/wiki/Jarfile).
68
+
69
+ ## console ##
70
+
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:
34
72
 
35
- # Building the jbundler gem
73
+ jbundle console
36
74
 
37
- running the integration test
75
+ further it adds two methods to the root level:
38
76
 
39
- ./mvnw verify
77
+ > jars
40
78
 
41
- building the gem (see ./pkg)
79
+ to list the loaded jars and
42
80
 
43
- ./mvnw package -Dinvoker.skip
81
+ > jar 'org.yaml:snakeyaml'
44
82
 
45
- or just
83
+ using the same syntax as use in the **Jarfile**. there are limitations with such a lazy jar loading but it is very convenient when trying out things.
46
84
 
47
- gem build jbundler.gemspec
85
+ ## lazy jar loading ##
86
+
87
+ require 'jbundler/lazy'
88
+ include JBundler::Lazy
89
+
90
+ will offer the same `jar`/`jars` method than you have inside the console.
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.
48
107
 
49
108
  ## example ##
50
109
 
@@ -58,8 +117,37 @@ execute *src/example/my_project/info.rb* to see it in action:
58
117
 
59
118
  ## limitations ##
60
119
 
120
+ update of single artifacts is not possible.
121
+
61
122
  since the version resolution happens in two steps - first the gems then the jars/poms - it is possible in case of a failure that there is a valid gems/jars version resolution which satisfies all version contraints. so there is plenty of space for improvements (like maven could resolve the gems as well, etc)
62
123
 
124
+ **Jarfile** is **not** a DSL but it could use a ruby DSL to read the data (any contribution welcome).
125
+
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 ```jbundle tree``` and ```jbundle executable```
133
+
134
+ ## running tests ##
135
+
136
+ * ```rake``` will execute all tests without integration tests
137
+ * ```rake all``` will execute all tests
138
+ * ```rake minitest``` runs the minitest specs
139
+ * ```rake integration``` runs the integration tests where poms are used (might fail due to hardcoded absolute paths)
140
+ * ```rake junit``` runs the junit java tests
141
+ * ```jruby spec/abc_spec.rb``` runs that given tests (just use the right file)
142
+ * ```mvn test``` will also run all tests
143
+ * ```rmvn test`` same as ```mvn test```
144
+
145
+ ## update ##
146
+
147
+ update of a single artifact is not possible (yet). but to update the whole set of artifacts just delete the lockfile *Jarfile.lock*
148
+
149
+ if jbundler sees that **Gemfile.lock** or **Jarfile** is newer then the **.jbundler/classpath.rb** file then jbundler tries to gracefully upgrade towards the changes.
150
+
63
151
  # special thanks #
64
152
 
65
153
  the whole project actually started with a controversial discussion on a [pull request on bundler](https://github.com/carlhuda/bundler/pull/1683). this very same pull request were the starting point of that project here. probably by now there is no much left of the original code but many thanks to [ANithian](https://github.com/ANithian) for given the seed of that project.
data/bin/jbundle CHANGED
@@ -1,51 +1,51 @@
1
1
  #!/usr/bin/env ruby
2
- require 'jbundler'
3
- require 'optparse'
4
- options = {}
5
- optparse = OptionParser.new do|opts|
6
-
7
- opts.banner = "Usage: jbundle [options]"
8
-
9
- opts.separator ''
10
- opts.separator '* load jars: `Jars.require_jars_lock!`'
11
- opts.separator '* classpath features: see `Jars::Classpath'
12
- opts.separator ''
13
- opts.separator 'NOTE: JBundler is not need during runtime !'
14
- opts.separator ''
15
- opts.separator 'Options:'
16
- opts.separator ''
17
-
18
- opts.on( '-v', '--verbose', 'Output more information' ) do |t|
19
- options[:verbose] = t
20
- end
2
+ if ARGV[0] == 'help'
21
3
 
22
- opts.on( '-d', '--debug', 'Output debug information' ) do |t|
23
- options[:debug] = t
24
- end
4
+ # ensure we use the right version
5
+ gem 'ruby-maven', '>=3.3.3'
25
6
 
26
- opts.on( '-f', '--force', 'Force creation of Jars.lock' ) do |t|
27
- options[:force] = t
28
- end
7
+ require 'jbundler/cli'
29
8
 
30
- opts.on( '-t', '--tree', 'Show dependency tree' ) do |t|
31
- options[:tree] = t
32
- end
9
+ JBundler::Cli.start
33
10
 
34
- opts.on( '-u', '--update JAR_COORDINATE', 'Resolves given dependency and use latest version' ) do |u|
35
- options[:update] = u
36
- end
11
+ else
37
12
 
38
- opts.on( '--vendor-dir DIRECTORY', 'Vendor directory where to copy the installed jars.', 'add this directory to $LOAD_PATH or set JARS_HOME respectively.' ) do |dir|
39
- options[:vendor_dir] = dir
13
+ if ARGV == [] || ARGV.all?{ |a| a.match( /^-/ ) }
14
+ ARGV.unshift 'install'
40
15
  end
41
16
 
42
- opts.on( '-h', '--help', 'Display this screen' ) do
43
- puts opts
44
- exit
17
+ if ARGV[0] == 'console'
18
+ # ensure we use the right version
19
+ gem 'ruby-maven', '>=3.3.3'
20
+
21
+ require 'irb'
22
+ require 'jbundler'
23
+ require 'jbundler/lazy'
24
+ include JBundler::Lazy
25
+
26
+ ARGV.shift
27
+ require 'jbundler'
28
+ if defined? JBUNDLER_CLASSPATH
29
+ warn 'Jarfile dependencies loaded'
30
+ else
31
+ warn 'Could not locate a Jarfile'
32
+ end
33
+
34
+ if defined? JBUNDLER_CLASSPATH
35
+ warn 'Jarfile dependencies loaded'
36
+ else
37
+ warn 'Could not locate a Jarfile'
38
+ end
39
+
40
+ IRB.start
41
+
42
+ else
43
+ # ensure we use the right version
44
+ gem 'ruby-maven', '>=3.3.3'
45
+
46
+ require 'jbundler/cli'
47
+ JBundler::Cli.start
45
48
  end
49
+
46
50
  end
47
- optparse.parse!
48
51
 
49
- require 'jbundler/executor'
50
- mvn = JBundler::Executor.new( options[:debug], options[:verbose] )
51
- mvn.lock_down( options )
data/lib/jbundler.rb CHANGED
@@ -18,14 +18,56 @@
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
- require 'jbundler/executor'
21
+
22
+ require 'jbundler/context'
23
+ require 'jbundler/lock_down'
24
+
22
25
  module JBundler
23
26
 
24
- def self.install( debug = false, verbose = false, options = {} )
25
- JBundler::Executor.new( debug, verbose ).lock_down( options )
27
+ def self.context
28
+ @context ||= JBundler::Context.new
29
+ end
30
+
31
+ def self.setup_test
32
+ context.classpath.require_test_classpath
33
+ context.config
26
34
  end
27
35
 
28
- def self.jarfile
29
- ENV[ 'JBUNDLER_JARFILE' ] || ENV_JAVA[ 'jbundler.jarfile' ] || 'Jarfile'
36
+ def self.require_jars
37
+ if context.vendor.vendored?
38
+ jars = context.vendor.require_jars
39
+ if context.config.verbose
40
+ warn "jbundler classpath:"
41
+ jars.each do |path|
42
+ warn "\t#{path}"
43
+ end
44
+ end
45
+ elsif context.classpath.exists? && context.jarfile.exists_lock?
46
+ require 'java'
47
+ context.classpath.require_classpath
48
+ if context.config.verbose
49
+ warn "jbundler classpath:"
50
+ JBUNDLER_CLASSPATH.each do |path|
51
+ warn "\t#{path}"
52
+ end
53
+ end
54
+ Jars.no_more_warnings
55
+ end
56
+ end
57
+
58
+ def self.install( debug = false, verbose = false )
59
+ jbundler = JBundler::LockDown.new( context.config )
60
+ msg = jbundler.lock_down( false, debug, verbose )
61
+ puts msg if msg
62
+ end
63
+
64
+ def self.setup
65
+ if context.config.skip
66
+ warn "skip jbundler setup" if context.config.verbose
67
+ else
68
+ require_jars
69
+ end
30
70
  end
31
71
  end
72
+
73
+ JBundler.setup
@@ -0,0 +1,139 @@
1
+ #
2
+ # Copyright (C) 2013 Christian Meier
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'yaml'
22
+ require 'jbundler/config'
23
+ require 'maven/ruby'
24
+
25
+ module JBundler
26
+
27
+ class AetherRuby
28
+
29
+ def self.setup_classloader
30
+ require 'java'
31
+
32
+ Dir.glob( File.join( Maven.lib, '*.jar' ) ).each do |path|
33
+ require path
34
+ end
35
+ begin
36
+ require 'jbundler.jar'
37
+ rescue LoadError
38
+ # allow the classes already be added to the classloader
39
+ begin
40
+ java_import 'jbundler.Aether'
41
+ rescue NameError
42
+ # assume this happens only when working on the git clone
43
+ raise "jbundler.jar is missing - maybe you need to build it first ? use\n$ rmvn prepare-package -Dmaven.test.skip\n"
44
+ end
45
+ end
46
+ java_import 'jbundler.Aether'
47
+ end
48
+
49
+ def initialize( config = Config.new )
50
+ unless defined? Aether
51
+ self.class.setup_classloader
52
+ end
53
+ @aether = Aether.new( config.verbose )
54
+ @aether.add_proxy( config.proxy ) if config.proxy
55
+ @aether.add_mirror( config.mirror ) if config.mirror
56
+ @aether.offline = config.offline
57
+ if config.settings
58
+ @aether.user_settings = java.io.File.new( config.settings )
59
+ end
60
+ if config.local_repository
61
+ @aether.local_repository = java.io.File.new(config.local_repository)
62
+ end
63
+ rescue NativeException => e
64
+ e.cause.print_stack_trace
65
+ raise e
66
+ end
67
+
68
+ def local_jars
69
+ @local_jars ||= []
70
+ end
71
+
72
+ def add_local_jar( path )
73
+ local_jars << File.expand_path( path )
74
+ end
75
+
76
+ def add_artifact(coordinate, extension = nil)
77
+ if extension
78
+ coord = coordinate.split(/:/)
79
+ coord.insert(2, extension)
80
+ @aether.add_artifact(coord.join(":"))
81
+ else
82
+ @aether.add_artifact(coordinate)
83
+ end
84
+ end
85
+
86
+ def add_repository(name, url)
87
+ @aether.add_repository(name, url)
88
+ end
89
+
90
+ def add_snapshot_repository(name, url)
91
+ @aether.add_snapshot_repository(name, url)
92
+ end
93
+
94
+ def resolve
95
+ @aether.resolve unless artifacts.empty?
96
+ rescue NativeException => e
97
+ e.cause.print_stack_trace
98
+ raise e
99
+ end
100
+
101
+ def classpath
102
+ if artifacts.empty? and local_jars.empty?
103
+ ''
104
+ else
105
+ path = [ @aether.classpath ]
106
+ path = path + @local_jars if @local_jars
107
+ path.join( File::PATH_SEPARATOR )
108
+ end
109
+ end
110
+
111
+ def classpath_array
112
+ classpath.split(/#{File::PATH_SEPARATOR}/)
113
+ end
114
+
115
+ def repositories
116
+ @aether.repositories
117
+ end
118
+
119
+ def artifacts
120
+ @aether.artifacts
121
+ end
122
+
123
+ def resolved_coordinates
124
+ if @aether.artifacts.empty?
125
+ []
126
+ else
127
+ @aether.resolved_coordinates
128
+ end
129
+ end
130
+
131
+ def install(coordinate, file)
132
+ @aether.install(coordinate, file)
133
+ rescue NativeException => e
134
+ e.cause.print_stack_trace
135
+ raise e
136
+ end
137
+
138
+ end
139
+ end