jar-dependencies 0.1.8 → 0.1.10

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: f607cf0e0acf6dc622b37a829a8adc1322edfbf6
4
- data.tar.gz: 8cf7cc1b6d81ca0f1c664a98b6519586265fa813
3
+ metadata.gz: 8285b7214e47fe153c7757817c250fe9a7752fdc
4
+ data.tar.gz: f99b7597244bdbf340fb945c7cf39a699734b15a
5
5
  SHA512:
6
- metadata.gz: b4bfa3b22e9fd05eee1710cc4859799a7271d6d9779ef86be3925cb08ace83e33e48c3d30bfcd0944995192e4c98414638afe607fe51141c8cbfe9c9d8138fc8
7
- data.tar.gz: 326a5440977b4440e20698680843e1f2da0bfc69abc6e285cac0e0e345f25ebef9455fe1659d6c211bd904f6b376ce859cb04c752a358432686afb90ad6d3423
6
+ metadata.gz: b55db0cfecaaf73eac4d95cc3b7d061d809d112afe815afffd2a8a12b83ed4d3c8beb0cbfb19e27ff2f14ece87068d3267c49e79298dda32d273cbbc69f0284b
7
+ data.tar.gz: 5bcf7abf25d8709a98ff405a94bdba3f219450bf58b8a2c0d6a99b2499f1067f0870277d4f32fd7520a50b3095ec3bb1315616a34606c5d57e88f6695086174b
data/Mavenfile CHANGED
@@ -10,14 +10,12 @@ jruby_plugin( :minitest, :minispecDirectory => "specs/*_spec.rb" ) do
10
10
  gem 'ruby-maven', '3.1.1.0.8'
11
11
  end
12
12
 
13
- #snapshot_repository :jruby, 'http://ci.jruby.org/snapshots/maven'
14
-
15
13
  # (jruby-1.6.8 mode 1.8 produces a lot of yaml errors parsing gemspecs)
16
- properties( 'jruby.versions' => ['1.6.8', '1.7.12', '1.7.19', '9.0.0.0.pre1'
14
+ properties( 'jruby.versions' => ['1.6.8', '1.7.12', '${jruby.version}', '9.0.0.0.pre1'
17
15
  ].join(','),
18
16
  'jruby.modes' => ['1.9', '2.0', '2.1'].join(','),
19
17
  # just lock the version
20
- 'jruby.version' => '1.7.13',
18
+ 'jruby.version' => '1.7.19',
21
19
  'tesla.dump.pom' => 'pom.xml',
22
20
  'tesla.dump.readonly' => true )
23
21
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jar-dependencies'
5
- s.version = "0.1.8"
5
+ s.version = "0.1.10"
6
6
  s.author = 'christian meier'
7
7
  s.email = [ 'mkristian@web.de' ]
8
8
  s.summary = 'manage jar dependencies for gems'
@@ -21,16 +21,25 @@
21
21
 
22
22
  module Jars
23
23
  unless defined? Jars::MAVEN_SETTINGS
24
- HOME = 'JARS_HOME'.freeze
25
24
  MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'.freeze
25
+ # where the locally stored jars are search for or stored
26
+ HOME = 'JARS_HOME'.freeze
26
27
  # skip the gem post install hook
27
28
  SKIP = 'JARS_SKIP'.freeze
28
29
  # just do not require any jars
29
30
  NO_REQUIRE = 'JARS_NO_REQUIRE'.freeze
31
+ # no more warnings on conflict. this still requires jars but will
32
+ # not warn. it is needed to load jars from (default) gems which
33
+ # do contribute to any dependency manager (maven, gradle, jbundler)
30
34
  QUIET = 'JARS_QUIET'.freeze
35
+ # show maven output
31
36
  VERBOSE = 'JARS_VERBOSE'.freeze
37
+ # maven debug
32
38
  DEBUG = 'JARS_DEBUG'.freeze
39
+ # vendor jars inside gem when installing gem
33
40
  VENDOR = 'JARS_VENDOR'.freeze
41
+ # resolve jars from Jars.lock
42
+ RESOLVE = 'JARS_RESOLVE'.freeze
34
43
  end
35
44
 
36
45
  class << self
@@ -48,9 +57,6 @@ module Jars
48
57
 
49
58
  def to_boolean( key )
50
59
  prop = to_prop( key )
51
- # prop == nil => false
52
- # prop == 'false' => false
53
- # anything else => true
54
60
  prop == '' or prop == 'true'
55
61
  end
56
62
 
@@ -78,6 +84,10 @@ module Jars
78
84
  to_boolean( VENDOR )
79
85
  end
80
86
 
87
+ def resolve?
88
+ to_boolean( RESOLVE )
89
+ end
90
+
81
91
  def no_more_warnings
82
92
  @silent = true
83
93
  end
@@ -141,7 +151,24 @@ module Jars
141
151
  @_jars_home_
142
152
  end
143
153
 
154
+ def require_jars_lock
155
+ @@jars_lock ||= false
156
+ unless @@jars_lock
157
+ # be lazy and only load if there are jar dependencies
158
+ require 'jars/classpath'
159
+ classpath = Jars::Classpath.new
160
+ if @@jars_lock = classpath.jars_lock
161
+ classpath.require
162
+ self.no_more_warnings
163
+ else
164
+ @@jars_lock = true
165
+ end
166
+ end
167
+ end
168
+
144
169
  def require_jar( group_id, artifact_id, *classifier_version )
170
+ require_jars_lock
171
+
145
172
  version = classifier_version[ -1 ]
146
173
  classifier = classifier_version[ -2 ]
147
174
 
@@ -210,7 +237,7 @@ module Jars
210
237
  require jar
211
238
  end
212
239
  rescue LoadError => e
213
- raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar\n\n" + e.message + " (LoadError)"
240
+ raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar or in case there is Jars.lock then JARS_RESOLVE=true will install the missing jars\n\n" + e.message + " (LoadError)"
214
241
  end
215
242
 
216
243
  end # class << self
@@ -18,14 +18,4 @@
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
-
22
- if defined?( JRUBY_VERSION ) && Gem.post_install_hooks.empty?
23
- Gem.post_install do |gem_installer|
24
- unless (ENV['JARS_SKIP'] || ENV_JAVA['jars.skip']) == 'true'
25
- require 'jar_installer'
26
- jars = Jars::JarInstaller.new( gem_installer.spec )
27
- jars.ruby_maven_install_options = gem_installer.options || {}
28
- jars.vendor_jars
29
- end
30
- end
31
- end
21
+ require 'jars/post_install_hook'
data/lib/jar_installer.rb CHANGED
@@ -1,295 +1 @@
1
- require 'jar_dependencies'
2
- require 'uri'
3
- module Jars
4
- class JarInstaller
5
-
6
- class Dependency
7
-
8
- attr_reader :path, :file, :gav, :scope, :type, :coord
9
-
10
- def self.new( line )
11
- if line.match /:jar:|:pom:/
12
- super
13
- end
14
- end
15
-
16
- def setup_type( line )
17
- if line.match /:pom:/
18
- @type = :pom
19
- elsif line.match /:jar:/
20
- @type = :jar
21
- end
22
- end
23
- private :setup_type
24
-
25
- def setup_scope( line )
26
- @scope =
27
- case line
28
- when /:provided:/
29
- :provided
30
- when /:test:/
31
- :test
32
- else
33
- :runtime
34
- end
35
- end
36
- private :setup_scope
37
-
38
- def initialize( line )
39
- setup_type( line )
40
-
41
- line.sub!( /^\s+/, '' )
42
- @coord = line.sub( /:[^:]+:([A-Z]:\\)?[^:]+$/, '' )
43
- first, second = @coord.split( /:#{type}:/ )
44
- group_id, artifact_id = first.split( /:/ )
45
- parts = group_id.split( '.' )
46
- parts << artifact_id
47
- parts << second.split( /:/ )[ -1 ]
48
- parts << File.basename( line.sub /.:/, '' )
49
- @path = File.join( parts ).strip
50
-
51
- setup_scope( line )
52
-
53
- reg = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/
54
- @file = line.slice(@coord.length, line.length).sub(reg, '').strip
55
- @system = nil != (line =~ /:system:/)
56
- @gav = @coord.sub(reg, ':')
57
- end
58
-
59
- def system?
60
- @system
61
- end
62
- end
63
-
64
- def self.install_jars( write_require_file = false )
65
- new.install_jars( write_require_file )
66
- end
67
-
68
- def self.vendor_jars( write_require_file = false )
69
- new.vendor_jars( write_require_file )
70
- end
71
-
72
- def self.load_from_maven( file )
73
- result = []
74
- File.read( file ).each_line do |line|
75
- dep = Dependency.new( line )
76
- result << dep if dep
77
- end
78
- result
79
- end
80
-
81
- def self.write_require_file( require_filename )
82
- FileUtils.mkdir_p( File.dirname( require_filename ) )
83
- comment = '# this is a generated file, to avoid over-writing it just delete this comment'
84
- if ! File.exists?( require_filename ) || File.read( require_filename ).match( comment )
85
- f = File.open( require_filename, 'w' )
86
- f.puts comment
87
- f.puts "require 'jar_dependencies'"
88
- f.puts
89
- f
90
- end
91
- end
92
-
93
- def self.vendor_file( dir, dep )
94
- vendored = File.join( dir, dep.path )
95
- FileUtils.mkdir_p( File.dirname( vendored ) )
96
- FileUtils.cp( dep.file, vendored ) unless dep.system?
97
- end
98
-
99
- def self.write_dep( file, dir, dep, vendor )
100
- return if dep.type != :jar || dep.scope != :runtime
101
- if dep.system?
102
- file.puts( "require( '#{dep.file}' )" ) if file
103
- elsif dep.scope == :runtime
104
- vendor_file( dir, dep ) if vendor
105
- file.puts( "require_jar( '#{dep.gav.gsub( /:/, "', '" )}' )" ) if file
106
- end
107
- end
108
-
109
- def self.install_deps( deps, dir, require_filename, vendor )
110
- f = write_require_file( require_filename ) if require_filename
111
- deps.each do |dep|
112
- write_dep( f, dir, dep, vendor )
113
- end
114
- yield f if block_given? and f
115
- ensure
116
- f.close if f
117
- end
118
-
119
- def find_spec( allow_no_file )
120
- specs = Dir[ '*.gemspec' ]
121
- case specs.size
122
- when 0
123
- raise 'no gemspec found' unless allow_no_file
124
- when 1
125
- specs.first
126
- else
127
- raise 'more then one gemspec found. please specify a specfile' unless allow_no_file
128
- end
129
- end
130
- private :find_spec
131
-
132
- def initialize( spec = nil )
133
- setup( spec )
134
- end
135
-
136
- def setup( spec = nil, allow_no_file = false )
137
- spec ||= find_spec( allow_no_file )
138
-
139
- case spec
140
- when String
141
- @specfile = File.expand_path( spec )
142
- @basedir = File.dirname( @specfile )
143
- spec = eval( File.read( spec ) )
144
- when Gem::Specification
145
- if File.exists?( spec.spec_file )
146
- @basedir = spec.gem_dir
147
- @specfile = spec.spec_file
148
- else
149
- # this happens with bundle and local gems
150
- # there the spec_file is "not installed" but inside
151
- # the gem_dir directory
152
- Dir.chdir( spec.gem_dir ) do
153
- setup( nil, true )
154
- end
155
- end
156
- when NilClass
157
- else
158
- raise 'spec must be either String or Gem::Specification'
159
- end
160
-
161
- @spec = spec
162
- rescue
163
- # for all those strange gemspec we skip looking for jar-dependencies
164
- end
165
-
166
- def ruby_maven_install_options=( options )
167
- @options = options.dup
168
- @options.delete( :ignore_dependencies )
169
- end
170
-
171
- def vendor_jars( write_require_file = true )
172
- return unless has_jars?
173
- case Jars.to_prop( Jars::VENDOR )
174
- when 'true'
175
- do_vendor = true
176
- when 'false'
177
- do_vendor = false
178
- else
179
- # if the spec_file does not exists this means it is a local gem
180
- # coming via bundle :path or :git
181
- do_vendor = File.exists?( @spec.spec_file )
182
- end
183
- do_install( do_vendor, write_require_file )
184
- end
185
-
186
- def install_jars( write_require_file = true )
187
- return unless has_jars?
188
- do_install( false, write_require_file )
189
- end
190
-
191
- private
192
-
193
- def has_jars?
194
- # first look if there are any requirements in the spec
195
- # and then if gem depends on jar-dependencies
196
- # only then install the jars declared in the requirements
197
- ! @spec.requirements.empty? && @spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime }
198
- end
199
-
200
- def do_install( vendor, write_require_file )
201
- vendor_dir = File.join( @basedir, @spec.require_path )
202
- jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" )
203
-
204
- # write out new jars_file it write_require_file is true or
205
- # check timestamps:
206
- # do not generate file if specfile is older then the generated file
207
- if ! write_require_file &&
208
- File.exists?( jars_file ) &&
209
- File.mtime( @specfile ) < File.mtime( jars_file )
210
- # leave jars_file as is
211
- jars_file = nil
212
- end
213
- self.class.install_deps( install_dependencies, vendor_dir,
214
- jars_file, vendor )
215
- end
216
-
217
- def setup_arguments( deps )
218
- args = [ 'dependency:list',
219
- "-DoutputFile=#{deps}",
220
- '-DoutputAbsoluteArtifactFilename=true',
221
- '-DincludeTypes=jar',
222
- '-DoutputScope=true',
223
- '-f', File.dirname( __FILE__ ) + '/jars/jar_pom.rb',
224
- "-Djars.specfile=#{@specfile}" ]
225
-
226
- if Jars.debug?
227
- args << '-X'
228
- elsif not Jars.verbose?
229
- args << '--quiet'
230
- end
231
-
232
- if Jars.maven_user_settings.nil? && (proxy = Gem.configuration[ :proxy ]).is_a?( String )
233
- uri = URI.parse( proxy )
234
- args << "-DproxySet=true"
235
- args << "-DproxyHost=#{uri.host}"
236
- args << "-DproxyPort=#{uri.port}"
237
- end
238
-
239
- if defined? JRUBY_VERSION
240
- args << "-Dmaven.repo.local=#{java.io.File.new( Jars.home ).absolute_path}"
241
- else
242
- args << "-Dmaven.repo.local=#{File.expand_path( Jars.home )}"
243
- end
244
-
245
- args
246
- end
247
-
248
- def lazy_load_maven
249
- require 'maven/ruby/maven'
250
- rescue LoadError
251
- install_ruby_maven
252
- require 'maven/ruby/maven'
253
- end
254
-
255
- def install_ruby_maven
256
- require 'rubygems/dependency_installer'
257
- jars = Gem.loaded_specs[ 'jar-dependencies' ]
258
- dep = jars.dependencies.detect { |d| d.name == 'ruby-maven' }
259
- req = dep.nil? ? Gem::Requirement.create( '>0' ) : dep.requirement
260
- inst = Gem::DependencyInstaller.new( @options || {} )
261
- inst.install 'ruby-maven', req
262
- rescue => e
263
- warn e.backtrace.join( "\n" ) if Jars.verbose?
264
- raise "there was an error installing 'ruby-maven'. please install it manually: #{e.inspect}"
265
- end
266
-
267
- def monkey_patch_gem_dependencies
268
- # monkey patch to NOT include gem dependencies
269
- require 'maven/tools/gemspec_dependencies'
270
- eval <<EOF
271
- class ::Maven::Tools::GemspecDependencies
272
- def runtime; []; end
273
- def development; []; end
274
- end
275
- EOF
276
- end
277
-
278
- def install_dependencies
279
- lazy_load_maven
280
-
281
- monkey_patch_gem_dependencies
282
-
283
- deps = File.join( @basedir, 'deps.lst' )
284
-
285
- maven = Maven::Ruby::Maven.new
286
- maven.verbose = Jars.verbose?
287
- puts " jar dependencies for #{@spec.spec_name} . . ." unless Jars.quiet?
288
- maven.exec( *setup_arguments( deps ) )
289
-
290
- self.class.load_from_maven( deps )
291
- ensure
292
- FileUtils.rm_f( deps ) if deps
293
- end
294
- end
295
- end
1
+ require 'jars/installer'
@@ -0,0 +1,73 @@
1
+ require 'jars/maven_exec'
2
+ require 'jars/lock'
3
+ require 'fileutils'
4
+
5
+ module Jars
6
+
7
+ class Classpath
8
+
9
+ def initialize( spec = nil )
10
+ @mvn = MavenExec.new( spec )
11
+ end
12
+
13
+ def workdir( dirname )
14
+ dir = File.join( @mvn.basedir, dirname )
15
+ dir if File.directory?( dir )
16
+ end
17
+
18
+ def jars_lock
19
+ deps = File.join( @mvn.basedir || '.', 'Jars.lock' )
20
+ deps if File.exists?( deps )
21
+ end
22
+
23
+ def dependencies_list
24
+ deps = jars_lock
25
+ if deps and File.exists?( deps )
26
+ @mvn.resolve_dependencies( deps ) if Jars.resolve?
27
+ deps
28
+ else
29
+ resolve_dependencies
30
+ end
31
+ end
32
+ private :dependencies_list
33
+
34
+ DEPENDENCY_LIST = 'dependencies.list'
35
+ def resolve_dependencies
36
+ basedir = workdir( 'pkg' ) || workdir( 'target' ) || workdir( '' )
37
+ deps = File.join( basedir, DEPENDENCY_LIST )
38
+ @mvn.resolve_dependencies( deps )
39
+ deps
40
+ end
41
+ private :resolve_dependencies
42
+
43
+ def require( scope = nil )
44
+ process( scope ) do |jar|
45
+ if jar.scope == :system
46
+ Kernel.require jar.path
47
+ else
48
+ require_jar( *jar.gacv )
49
+ end
50
+ end
51
+ end
52
+
53
+ def classpath( scope = nil )
54
+ classpath = []
55
+ process( scope ) do |jar|
56
+ classpath << jar.file
57
+ end
58
+ classpath
59
+ end
60
+
61
+ def process( scope, &block )
62
+ deps = dependencies_list
63
+ Lock.new( deps ).process( scope, &block )
64
+ ensure
65
+ FileUtils.rm_f( DEPENDENCY_LIST ) if deps
66
+ end
67
+ private :process
68
+
69
+ def classpath_string( scope = nil )
70
+ classpath( scope ).join( File::PATH_SEPARATOR )
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,187 @@
1
+ require 'jar_dependencies'
2
+ require 'jars/maven_exec'
3
+ require 'uri'
4
+ module Jars
5
+ class Installer
6
+
7
+ class Dependency
8
+
9
+ attr_reader :path, :file, :gav, :scope, :type, :coord
10
+
11
+ def self.new( line )
12
+ if line.match /:jar:|:pom:/
13
+ super
14
+ end
15
+ end
16
+
17
+ def setup_type( line )
18
+ if line.match /:pom:/
19
+ @type = :pom
20
+ elsif line.match /:jar:/
21
+ @type = :jar
22
+ end
23
+ end
24
+ private :setup_type
25
+
26
+ def setup_scope( line )
27
+ @scope =
28
+ case line
29
+ when /:provided:/
30
+ :provided
31
+ when /:test:/
32
+ :test
33
+ else
34
+ :runtime
35
+ end
36
+ end
37
+ private :setup_scope
38
+
39
+ def initialize( line )
40
+ setup_type( line )
41
+
42
+ line.sub!( /^\s+/, '' )
43
+ @coord = line.sub( /:[^:]+:([A-Z]:\\)?[^:]+$/, '' )
44
+ first, second = @coord.split( /:#{type}:/ )
45
+ group_id, artifact_id = first.split( /:/ )
46
+ parts = group_id.split( '.' )
47
+ parts << artifact_id
48
+ parts << second.split( /:/ )[ -1 ]
49
+ parts << File.basename( line.sub /.:/, '' )
50
+ @path = File.join( parts ).strip
51
+
52
+ setup_scope( line )
53
+
54
+ reg = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/
55
+ @file = line.slice(@coord.length, line.length).sub(reg, '').strip
56
+ @system = nil != (line =~ /:system:/)
57
+ @gav = @coord.sub(reg, ':')
58
+ end
59
+
60
+ def system?
61
+ @system
62
+ end
63
+ end
64
+
65
+ def self.install_jars( write_require_file = false )
66
+ new.install_jars( write_require_file )
67
+ end
68
+
69
+ def self.vendor_jars( write_require_file = false )
70
+ new.vendor_jars( write_require_file )
71
+ end
72
+
73
+ def self.load_from_maven( file )
74
+ result = []
75
+ File.read( file ).each_line do |line|
76
+ dep = Dependency.new( line )
77
+ result << dep if dep && dep.scope == :runtime
78
+ end
79
+ result
80
+ end
81
+
82
+ def self.write_require_file( require_filename )
83
+ FileUtils.mkdir_p( File.dirname( require_filename ) )
84
+ comment = '# this is a generated file, to avoid over-writing it just delete this comment'
85
+ if ! File.exists?( require_filename ) || File.read( require_filename ).match( comment )
86
+ f = File.open( require_filename, 'w' )
87
+ f.puts comment
88
+ f.puts "require 'jar_dependencies'"
89
+ f.puts
90
+ f
91
+ end
92
+ end
93
+
94
+ def self.vendor_file( dir, dep )
95
+ vendored = File.join( dir, dep.path )
96
+ FileUtils.mkdir_p( File.dirname( vendored ) )
97
+ FileUtils.cp( dep.file, vendored ) unless dep.system?
98
+ end
99
+
100
+ def self.write_dep( file, dir, dep, vendor )
101
+ return if dep.type != :jar || dep.scope != :runtime
102
+ if dep.system?
103
+ file.puts( "require( '#{dep.file}' )" ) if file
104
+ elsif dep.scope == :runtime
105
+ vendor_file( dir, dep ) if vendor
106
+ file.puts( "require_jar( '#{dep.gav.gsub( /:/, "', '" )}' )" ) if file
107
+ end
108
+ end
109
+
110
+ def self.install_deps( deps, dir, require_filename, vendor )
111
+ f = write_require_file( require_filename ) if require_filename
112
+ deps.each do |dep|
113
+ write_dep( f, dir, dep, vendor )
114
+ end
115
+ yield f if block_given? and f
116
+ ensure
117
+ f.close if f
118
+ end
119
+
120
+ def vendor_jars( write_require_file = true )
121
+ return unless has_jars?
122
+ case Jars.to_prop( Jars::VENDOR )
123
+ when 'true'
124
+ do_vendor = true
125
+ when 'false'
126
+ do_vendor = false
127
+ else
128
+ # if the spec_file does not exists this means it is a local gem
129
+ # coming via bundle :path or :git
130
+ do_vendor = File.exists?( @mvn.spec.spec_file )
131
+ end
132
+ do_install( do_vendor, write_require_file )
133
+ end
134
+
135
+ def install_jars( write_require_file = true )
136
+ return unless has_jars?
137
+ do_install( false, write_require_file )
138
+ end
139
+
140
+ def initialize( spec = nil )
141
+ @mvn = MavenExec.new( spec )
142
+ end
143
+
144
+ def ruby_maven_install_options=( options )
145
+ @mvn.ruby_maven_install_options=( options )
146
+ end
147
+
148
+ private
149
+
150
+ def has_jars?
151
+ # first look if there are any requirements in the spec
152
+ # and then if gem depends on jar-dependencies
153
+ # only then install the jars declared in the requirements
154
+ @mvn.spec != nil && ! @mvn.spec.requirements.empty? && @mvn.spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime }
155
+ end
156
+
157
+ def do_install( vendor, write_require_file )
158
+ vendor_dir = File.join( @mvn.basedir, @mvn.spec.require_path )
159
+ jars_file = File.join( vendor_dir, "#{@mvn.spec.name}_jars.rb" )
160
+
161
+ # write out new jars_file it write_require_file is true or
162
+ # check timestamps:
163
+ # do not generate file if specfile is older then the generated file
164
+ if ! write_require_file &&
165
+ File.exists?( jars_file ) &&
166
+ File.mtime( @mvn.specfile ) < File.mtime( jars_file )
167
+ # leave jars_file as is
168
+ jars_file = nil
169
+ end
170
+ self.class.install_deps( install_dependencies, vendor_dir,
171
+ jars_file, vendor )
172
+ end
173
+
174
+ def install_dependencies
175
+ deps = File.join( @mvn.basedir, 'deps.lst' )
176
+
177
+ puts " jar dependencies for #{@mvn.spec.spec_name} . . ." unless Jars.quiet?
178
+ @mvn.resolve_dependencies( deps )
179
+
180
+ self.class.load_from_maven( deps )
181
+ ensure
182
+ FileUtils.rm_f( deps ) if deps
183
+ end
184
+ end
185
+ # to stay backward compatible
186
+ JarInstaller = Installer
187
+ end
data/lib/jars/jar_pom.rb CHANGED
@@ -1,14 +1,18 @@
1
- # this file is maven DSL and used by maven via jar_installer.rb
1
+ # this file is maven DSL and used by maven via jars/maven_exec.rb
2
2
 
3
3
  specfile = java.lang.System.getProperty('jars.specfile')
4
4
 
5
5
  # needed since the gemspec does not allow absolute files
6
6
  basedir( File.dirname( specfile ) )
7
7
 
8
+ # add jruby for compilation
9
+ jar 'org.jruby:jruby-core', JRUBY_VERSION, :scope => :provided
10
+
8
11
  # get ALL depenedencies from the specfile
9
12
  gemspec File.basename( specfile )
10
13
 
11
- # we do not want those gem dependencies
14
+ # we do not want those gem dependencies, each gem takes care of its
15
+ # own jar dependencies
12
16
  gems = model.dependencies.select do |d|
13
17
  d.group_id == 'rubygems'
14
18
  end
@@ -18,5 +22,5 @@ end
18
22
 
19
23
  # some output
20
24
  model.dependencies.each do |d|
21
- puts " " + d.group_id + ':' + d.artifact_id + (d.classifier ? ":" + d.classifier : "" ) + ":" + d.version
25
+ puts " " + d.group_id + ':' + d.artifact_id + (d.classifier ? ":" + d.classifier : "" ) + ":" + d.version unless d.artifact_id == 'jruby-core'
22
26
  end
@@ -0,0 +1,18 @@
1
+ # this file is maven DSL and used by maven via jars/maven_exec.rb
2
+
3
+ require_relative 'lock'
4
+ require_relative '../jar_dependencies'
5
+
6
+ lock = Jars::Lock.new( java.lang.System.getProperty('outputFile') )
7
+
8
+ lock.process( :all ) do |coord|
9
+
10
+ options = { :scope => coord.scope }
11
+ options[ :systemPath ] = coord[ -1 ] if coord.scope == :system
12
+ options[ :classifier ] = coord.classifier
13
+
14
+ jar coord.group_id, coord.artifact_id, coord.version, options
15
+
16
+ end
17
+
18
+ properties :excludeTransitive => true
data/lib/jars/lock.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'jars/maven_exec'
2
+
3
+ module Jars
4
+ class JarDetails < Array
5
+
6
+ def scope
7
+ self[ -2 ].to_sym
8
+ end
9
+
10
+ def file
11
+ f = self[ -1 ].strip
12
+ if f.empty?
13
+ path
14
+ else
15
+ f
16
+ end
17
+ end
18
+
19
+ def group_id
20
+ self[ 0 ]
21
+ end
22
+
23
+ def artifact_id
24
+ self[ 1 ]
25
+ end
26
+
27
+ def version
28
+ self[ -3 ]
29
+ end
30
+
31
+ def classifier
32
+ size == 5 ? nil : self[ 2 ]
33
+ end
34
+
35
+ def gacv
36
+ classifier ? self[ 0..3 ] : self[ 0..2 ]
37
+ end
38
+
39
+ def path
40
+ if scope == :system
41
+ # replace maven like system properties embedded into the string
42
+ self[ -1 ].gsub( /\$\{[a-zA-Z.]+\}/ ) do |a|
43
+ ENV_JAVA[ a[2..-2] ] || a
44
+ end
45
+ else
46
+ File.join( Jars.home, group_id.gsub(/[.]/, '/'), artifact_id, version, gacv[ 1..-1 ].join( '-' ) + '.jar' )
47
+ end
48
+ end
49
+ end
50
+
51
+ class Lock
52
+
53
+ def initialize( file )
54
+ @file = file
55
+ end
56
+
57
+ def process( scope )
58
+ scope ||= :compile
59
+ File.read( @file ).each_line do |line|
60
+ next if not line =~ /:.+:/
61
+ jar = JarDetails.new( line.strip
62
+ .sub( /:jar:/, ':' )
63
+ .sub( /:$/, ': ' ).split( /:/ ) )
64
+ case scope
65
+ when :all
66
+ yield jar
67
+ when :compile
68
+ yield jar if jar.scope != :test
69
+ when :runtime
70
+ yield jar if jar.scope != :test and jar.scope != :provided
71
+ when :test
72
+ yield jar if jar.scope != :runtime
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,129 @@
1
+ require 'jar_dependencies'
2
+ require 'uri'
3
+ module Jars
4
+ class MavenExec
5
+
6
+ def find_spec( allow_no_file )
7
+ specs = Dir[ '*.gemspec' ]
8
+ case specs.size
9
+ when 0
10
+ raise 'no gemspec found' unless allow_no_file
11
+ when 1
12
+ specs.first
13
+ else
14
+ raise 'more then one gemspec found. please specify a specfile' unless allow_no_file
15
+ end
16
+ end
17
+ private :find_spec
18
+
19
+ attr_reader :basedir, :spec, :specfile
20
+
21
+ def initialize( spec = nil )
22
+ setup( spec )
23
+ end
24
+
25
+ def setup( spec = nil, allow_no_file = false )
26
+ spec ||= find_spec( allow_no_file )
27
+
28
+ case spec
29
+ when String
30
+ @specfile = File.expand_path( spec )
31
+ @basedir = File.dirname( @specfile )
32
+ spec = eval( File.read( spec ) )
33
+ when Gem::Specification
34
+ if File.exists?( spec.spec_file )
35
+ @basedir = spec.gem_dir
36
+ @specfile = spec.spec_file
37
+ else
38
+ # this happens with bundle and local gems
39
+ # there the spec_file is "not installed" but inside
40
+ # the gem_dir directory
41
+ Dir.chdir( spec.gem_dir ) do
42
+ setup( nil, true )
43
+ end
44
+ end
45
+ when NilClass
46
+ else
47
+ raise 'spec must be either String or Gem::Specification'
48
+ end
49
+
50
+ @spec = spec
51
+ rescue
52
+ # for all those strange gemspec we skip looking for jar-dependencies
53
+ end
54
+
55
+ def ruby_maven_install_options=( options )
56
+ @options = options.dup
57
+ @options.delete( :ignore_dependencies )
58
+ end
59
+
60
+ def resolve_dependencies( file )
61
+ lazy_load_maven
62
+
63
+ maven = Maven::Ruby::Maven.new
64
+ maven.verbose = Jars.verbose?
65
+ maven.exec( *setup_arguments( file ) )
66
+ end
67
+
68
+ private
69
+
70
+ def setup_arguments( deps )
71
+ if File.basename( deps ) == 'Jars.lock'
72
+ pom = 'jars_lock_pom.rb'
73
+ goals = [ 'dependency:copy-dependencies' ]
74
+ else
75
+ pom = 'jar_pom.rb'
76
+ goals = [ 'dependency:copy-dependencies', 'dependency:list' ]
77
+ end
78
+ args = [ *goals,
79
+ "-DoutputFile=#{deps}",
80
+ '-DoutputAbsoluteArtifactFilename=true',
81
+ '-DincludeTypes=jar',
82
+ '-DoutputScope=true',
83
+ '-DuseRepositoryLayout=true',
84
+ "-DoutputDirectory=#{Jars.home}",
85
+ '-f', File.dirname( __FILE__ ) + '/' + pom,
86
+ "-Djars.specfile=#{@specfile}" ]
87
+
88
+ if Jars.debug?
89
+ args << '-X'
90
+ elsif not Jars.verbose?
91
+ args << '--quiet'
92
+ end
93
+
94
+ if Jars.maven_user_settings.nil? && (proxy = Gem.configuration[ :proxy ]).is_a?( String )
95
+ uri = URI.parse( proxy )
96
+ args << "-DproxySet=true"
97
+ args << "-DproxyHost=#{uri.host}"
98
+ args << "-DproxyPort=#{uri.port}"
99
+ end
100
+
101
+ if defined? JRUBY_VERSION
102
+ args << "-Dmaven.repo.local=#{java.io.File.new( Jars.home ).absolute_path}"
103
+ else
104
+ args << "-Dmaven.repo.local=#{File.expand_path( Jars.home )}"
105
+ end
106
+
107
+ args
108
+ end
109
+
110
+ def lazy_load_maven
111
+ require 'maven/ruby/maven'
112
+ rescue LoadError
113
+ install_ruby_maven
114
+ require 'maven/ruby/maven'
115
+ end
116
+
117
+ def install_ruby_maven
118
+ require 'rubygems/dependency_installer'
119
+ jars = Gem.loaded_specs[ 'jar-dependencies' ]
120
+ dep = jars.dependencies.detect { |d| d.name == 'ruby-maven' }
121
+ req = dep.nil? ? Gem::Requirement.create( '>0' ) : dep.requirement
122
+ inst = Gem::DependencyInstaller.new( @options || {} )
123
+ inst.install 'ruby-maven', req
124
+ rescue => e
125
+ warn e.backtrace.join( "\n" ) if Jars.verbose?
126
+ raise "there was an error installing 'ruby-maven'. please install it manually: #{e.inspect}"
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # Copyright (C) 2014 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
+
22
+ if defined?( JRUBY_VERSION ) && Gem.post_install_hooks.empty?
23
+ Gem.post_install do |gem_installer|
24
+ unless (ENV['JARS_SKIP'] || ENV_JAVA['jars.skip']) == 'true'
25
+ require 'jars/installer'
26
+ jars = Jars::Installer.new( gem_installer.spec )
27
+ jars.ruby_maven_install_options = gem_installer.options || {}
28
+ jars.vendor_jars
29
+ end
30
+ end
31
+ end
@@ -18,4 +18,4 @@
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 'jar_install_post_install_hook'
21
+ require 'jars/post_install_hook'
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.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian meier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -66,6 +66,12 @@ files:
66
66
  - lib/jar-dependencies.rb
67
67
  - lib/rubygems_plugin.rb
68
68
  - lib/jars/jar_pom.rb
69
+ - lib/jars/jars_lock_pom.rb
70
+ - lib/jars/installer.rb
71
+ - lib/jars/lock.rb
72
+ - lib/jars/maven_exec.rb
73
+ - lib/jars/classpath.rb
74
+ - lib/jars/post_install_hook.rb
69
75
  - bin/bundle-with-jars
70
76
  - Rakefile
71
77
  - Mavenfile