jar-dependencies 0.0.5 → 0.0.6

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: 9af7f3df159b3a9eb53f8af55f533107b73bc88d
4
- data.tar.gz: bac89ca7cf7f7db5d2e2c5f14c153100dd8eb87f
3
+ metadata.gz: 1ef94c824badc66c5d18e6e2795e59cde096da4b
4
+ data.tar.gz: 399a2d77b39d6f58304d1b341566efd493b1f883
5
5
  SHA512:
6
- metadata.gz: 8a3e4898522d92e63d8088ffdd32e5e4143061078ab7feef26f3c98281f6f3a0a3f72c4bdce6c5c39e34e7ffce14a954ea0a44422aa74e5decd854ffe0c0cce9
7
- data.tar.gz: 47b2c9bf2e6a8fda74c3a6baeadd96284d022da54dbc36cbf1477e4017f4a899b8fa3553d69162810cd55cd640cd202a341d5033c74899f6ffb009c6238ba8f7
6
+ metadata.gz: aca337598e947a4d0c95b25f2b10378e9472aef02bd86c881d6a88b3166fd56b93bf61e902065dbeec19b32dedb1cc92110efafb279c23f7d722420003befbaa
7
+ data.tar.gz: def85fcc93e6fbc41ec7837941842f083d8c43266438dda1d8d375b038e5a2add5bac0ec068cfcd0451142adb8c50620864ce0308d568c3a8ca09974e145fed1
data/Readme.md CHANGED
@@ -5,22 +5,50 @@
5
5
 
6
6
  add gem dependencies for jar files to ruby gems.
7
7
 
8
- ## features ##
8
+ ## getting control back over your jar ##
9
9
 
10
- * vendors jar dependencies during installion of the gem
11
- * jar dependencies are declared in the gemspec of the gem
12
- * jar declaration uses the same notation as jbundler
13
- * transitive jar dependencies will be resolved as well using (ruby-)maven
14
- * when there are two gems with different versions of the same jar dependency an warning will be given and the first version wins, i.e. **only one** version of the a library inside the jruby-classloader
15
- * it hooks into gem, i.e. once the jar-dependency gem is installed the feature can be used by any gem
16
- * offer 'bundle-with-jars' command which hooks the jar_installer into rubytems before delegating all arguments to bundler
17
- * it integrates with an existing maven local repository and obeys the maven setup in ~/.m2/settings.xml, like mirrors, proxieds, etc
10
+ jar dependencies are declared in the gemspec of the gem using the same notation as <https://github.com/mkristian/jbundler>.
11
+
12
+ when using ```require_jar``` to load the jar into JRuby's classloader then an version conflict will be detected and only **ONE** jar gets loaded. jbundler allows to select the version suitable for you application.
13
+
14
+ most maven-artifact do **NOT** use versions ranges but depends pick a version. then jbundler can always **overwrite** any such version.
15
+
16
+ ## vendoring your jars before packing the jar ##
17
+
18
+ add to your Rakefile following:
19
+
20
+ require 'jar_installer'
21
+ task :install_jars do
22
+ Jars::JarInstaller.vendor_jars
23
+ end
24
+
25
+ which will install download the dependent jars into **JARS_HOME** and creats a file **lib/my_gem_jars.rb** which is just an enumeration of ```require_jars``` statements to load all the jars. the **vendor_jars** will copy them into the **lib** directory of the gem.
26
+
27
+ the location where jars are cached is per default **$HOME/.m2/repository** the same default as maven has to cache the jar-artifacts. it respects **$HOME/.m2/settings.xml** from maven with all its mirror and other settings or the environment variable **JARS_HOME**.
28
+
29
+ IMPORTANT: make sure that jar-dependencies is only a **development dependency** of your gem. if it is a runtime dependencies the require_jars file will be overwritten during installation.
30
+
31
+ ## reduce the download and reuse the jars from maven local repository ##
32
+
33
+ if you do not vendor the jars into gem then the **jar-dependency** gem can vendor them when you install the gem. just skip use **Jars::JarInstaller.install_jars** from the above rake tasks.
34
+
35
+ until JRuby itself comes with this jar-dependencies as default gem, for this feature to work you need to install the **jar-dependencies** gem first and for bundler you need to use the **bundle-with-jars** command :(
36
+
37
+ IMPORTANT: make sure that jar-dependencies is a **runtime dependency** of your gem so the require_jars file will be overwritten during installation with the "correct" versions of the jars.
38
+
39
+ ## for development you do not need to vendor the jars at all ##
40
+
41
+ just set an environment variable
42
+
43
+ export JARS_VENDOR=false
44
+
45
+ this tells the jar_installer not vendor any jars but only create the file with the ```require_jar``` statements. this ```require_jars``` method will find the jar inside the maven local repository and loads it from there.
18
46
 
19
47
  ## some drawbacks ##
20
48
 
21
49
  * first you need to install the jar-dependency gem with its development dependencies installed (then ruby-maven gets installed as well)
22
- * bundler does not install the jar-dependencies
23
- * gems need an extra dependency on jar-dependencies during runtime and for development and installation you need ruby-maven installed as well (which you get via the development dependencies)
50
+ * bundler does not install the jar-dependencies (unless JRuby adds the gem as default gem)
51
+ * you need ruby-maven doing the job of dependency resolution and downloading them. gems not part of <http://rubygems.org> will not work currently
24
52
 
25
53
  ## just look at the example ##
26
54
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jar-dependencies'
5
- s.version = "0.0.5"
5
+ s.version = "0.0.6"
6
6
  s.author = 'christian meier'
7
7
  s.email = [ 'mkristian@web.de' ]
8
8
  s.summary = 'manage jar dependencies for gems'
@@ -55,8 +55,12 @@ module Jars
55
55
  end
56
56
  end
57
57
 
58
- def self.install_jars
59
- new.install_jars
58
+ def self.install_jars( write_require_file = false )
59
+ new.install_jars( write_require_file )
60
+ end
61
+
62
+ def self.vendor_jars( write_require_file = false )
63
+ new.vendor_jars( write_require_file )
60
64
  end
61
65
 
62
66
  def self.load_from_maven( file )
@@ -113,20 +117,31 @@ module Jars
113
117
  private :find_spec
114
118
 
115
119
  def initialize( spec = nil )
120
+ setup( spec )
121
+ end
122
+
123
+ def setup( spec = nil )
116
124
  spec ||= find_spec
117
125
 
118
126
  case spec
119
127
  when String
120
- @basedir = File.dirname( File.expand_path( spec ) )
121
- @specfile = spec
128
+ @specfile = File.expand_path( spec )
129
+ @basedir = File.dirname( @specfile )
122
130
  spec = eval( File.read( spec ) )
123
- when
131
+ when Gem::Specification
124
132
  if File.exists?( spec.spec_file )
125
133
  @basedir = spec.gem_dir
126
134
  @specfile = spec.spec_file
127
135
  else
128
- initialize( nil )
136
+ # this happens with bundle and local gems
137
+ # there the spec_file is "not installed" but inside
138
+ # the gem_dir directory
139
+ Dir.chdir( spec.gem_dir ) do
140
+ setup( nil )
141
+ end
129
142
  end
143
+ else
144
+ raise 'spec must be either String or Gem::Specification'
130
145
  end
131
146
 
132
147
  @spec = spec
@@ -136,15 +151,15 @@ module Jars
136
151
  @options = options.dup
137
152
  end
138
153
 
139
- def vendor_jars
154
+ def vendor_jars( write_require_file = true )
140
155
  return unless has_jars?
141
156
  # do not vendor only if set explicitly via ENV/system-properties
142
- do_install( Jars.to_prop( Jars::VENDOR ) != 'false', false )
157
+ do_install( Jars.to_prop( Jars::VENDOR ) != 'false', write_require_file )
143
158
  end
144
159
 
145
- def install_jars
160
+ def install_jars( write_require_file = true )
146
161
  return unless has_jars?
147
- do_install( false, true )
162
+ do_install( false, write_require_file )
148
163
  end
149
164
 
150
165
  private
@@ -158,14 +173,16 @@ module Jars
158
173
 
159
174
  def do_install( vendor, write_require_file )
160
175
  vendor_dir = File.join( @basedir, @spec.require_path )
161
- if write_require_file
162
- jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" )
163
-
164
- # do not generate file if specfile is older then the generated file
165
- if File.exists?( jars_file ) &&
166
- File.mtime( @specfile ) < File.mtime( jars_file )
167
- jars_file = nil
168
- end
176
+ jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" )
177
+
178
+ # write out new jars_file it write_require_file is true or
179
+ # check timestamps:
180
+ # do not generate file if specfile is older then the generated file
181
+ if ! write_require_file &&
182
+ File.exists?( jars_file ) &&
183
+ File.mtime( @specfile ) < File.mtime( jars_file )
184
+ # leave jars_file as is
185
+ jars_file = nil
169
186
  end
170
187
  self.class.install_deps( install_dependencies, vendor_dir,
171
188
  jars_file, vendor )
@@ -23,7 +23,7 @@ if defined?( JRUBY_VERSION ) && Gem.post_install_hooks.empty?
23
23
  Gem.post_install do |gem_installer|
24
24
  require 'jar_installer'
25
25
  jars = Jars::JarInstaller.new( gem_installer.spec )
26
- jars.ruby_maven_install_options = gem_installer.options
26
+ jars.ruby_maven_install_options = gem_installer.options || {}
27
27
  jars.vendor_jars
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jar-dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian meier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest