jar-dependencies 0.5.7 → 0.6.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f808b45045d68ee8f676ae6a217eab596d8f5636e61113b453ee0b6b190f75f
4
- data.tar.gz: 5dcec69751d4ebc168be6059e56da74a8c033bff73d895f5cf06051e15fc716d
3
+ metadata.gz: 47fc2eba6a111bc981e2c73b3762afaa096e9e8e81b6aa9ac062198cb8eb3694
4
+ data.tar.gz: a67771296a97cbdc4596ea245e72bfde22ebb319c772d37fc0b9e4f210a77568
5
5
  SHA512:
6
- metadata.gz: 413d8136a728211c7cfe8bffa455f4ac17b4d3eb5cb4eb44e1a08642a56805d3d81698f26be3cb0ee76b972aed0ff748e0f4d1b42fa7030d47e12e676b37fa7b
7
- data.tar.gz: f9558c6a6804622b02546b70320709cb945701524e72d1d1e40829af8cdb5e4fa345fa4888f924794d55b46cf1aa508490f06e70345da2a3c6170ebe516854f8
6
+ metadata.gz: 987de7a7960c938380ff580e629508bcfa35b1e01d843e99e3e98c1f0667eabbd09cd6e05e9668fe0abdb59eacd750c2d69592b637b81af912b1af71989cb69d
7
+ data.tar.gz: af48da8fd323c6babf5a11ddd28df1fed578a18691fc4cd023be0d1fb84cef8042887c8d6fd18ab830b9435f63df36ca5bdfae6d7a757a1f93a7f930ba0e7c1e
data/Rakefile CHANGED
@@ -4,6 +4,7 @@ task default: [:specs]
4
4
 
5
5
  require 'bundler/gem_tasks'
6
6
  require 'rubocop/rake_task'
7
+ require 'rake/clean'
7
8
 
8
9
  RuboCop::RakeTask.new
9
10
 
@@ -15,3 +16,47 @@ task :specs do
15
16
  require File.basename(f.sub(/.rb$/, ''))
16
17
  end
17
18
  end
19
+
20
+ require_relative 'lib/jars/mima/version'
21
+
22
+ MIMA_VERSION = Jars::Mima::MIMA_VERSION
23
+ SLF4J_VERSION = Jars::Mima::SLF4J_VERSION
24
+ MIMA_JARS = Jars::Mima::JARS
25
+ MIMA_DIR = Jars::Mima::MIMA_DIR
26
+
27
+ MIMA_JARS.each_key { |jar| CLEAN.include(File.join(MIMA_DIR, jar)) }
28
+
29
+ desc 'download Mima (and dependent SLF4J) jars'
30
+ task :download_jars do
31
+ require 'fileutils'
32
+ require 'open-uri'
33
+ require 'digest/sha1'
34
+
35
+ FileUtils.mkdir_p(MIMA_DIR)
36
+
37
+ MIMA_JARS.each do |filename, info|
38
+ target = File.join(MIMA_DIR, filename)
39
+ if File.exist?(target)
40
+ verify_checksum(target, info[:sha1])
41
+ puts " exists: #{target}"
42
+ next
43
+ end
44
+
45
+ puts " downloading #{filename}..."
46
+ URI.open(info[:url]) do |remote| # rubocop:disable Security/Open
47
+ File.open(target, 'wb') { |f| f.write(remote.read) }
48
+ end
49
+ verify_checksum(target, info[:sha1])
50
+ puts " saved: #{target}"
51
+ end
52
+ end
53
+
54
+ def verify_checksum(path, expected_sha1)
55
+ actual = Digest::SHA1.file(path).hexdigest
56
+ return if actual == expected_sha1
57
+
58
+ File.delete(path)
59
+ raise "SHA-1 mismatch for #{path}:\n" \
60
+ " expected: #{expected_sha1}\n" \
61
+ " actual: #{actual}"
62
+ end
data/Readme.md CHANGED
@@ -166,8 +166,8 @@ xalan/xerces libraries used by those gems are popular ones in the Java world.
166
166
 
167
167
  # Troubleshooting
168
168
 
169
- Since maven is used under the hood it is possible to get more insight
170
- what maven is doing. Show the regular maven output:
169
+ Jar dependency resolution uses the bundled Mima resolver. To get more
170
+ insight into jar-dependencies progress and warnings, enable verbose output:
171
171
 
172
172
  ```shell
173
173
  JARS_VERBOSE=true bundle install
@@ -175,19 +175,14 @@ JARS_VERBOSE=true gem install some_gem
175
175
  ```
176
176
 
177
177
 
178
- Or, with maven debug enabled
178
+ For Ruby-side debug diagnostics, including backtraces for suppressed setup
179
+ errors and jar loading decisions, enable debug output:
179
180
 
180
181
  ```shell
181
182
  JARS_DEBUG=true bundle install
182
183
  JARS_DEBUG=true gem install some_gem
183
184
  ```
184
185
 
185
- The maven command line which gets printed needs maven-3.9.x and the
186
- ruby DSL extension for maven:
187
- [polyglot-maven
188
- configuration](https://github.com/takari/polyglot-maven#configuration) where `${maven.multiModuleProjectDirectory}` is
189
- your current directory.
190
-
191
186
  # Configuration
192
187
 
193
188
  <table border='1'>
@@ -195,10 +190,10 @@ your current directory.
195
190
  <td>ENV</td><td>java system property</td><td>default</td><td>description</td>
196
191
  </tr>
197
192
  <tr>
198
- <td><tt>JARS_DEBUG</tt></td><td>jars.debug</td><td>false</td><td>if set to true it will produce lots of debug out (maven -X switch)</td>
193
+ <td><tt>JARS_DEBUG</tt></td><td>jars.debug</td><td>false</td><td>if set to true it will produce Ruby-side debug diagnostics and implies verbose output</td>
199
194
  </tr>
200
195
  <tr>
201
- <td><tt>JARS_VERBOSE</tt></td><td>jars.verbose</td><td>false</td><td>if set to true it will produce some extra output</td>
196
+ <td><tt>JARS_VERBOSE</tt></td><td>jars.verbose</td><td>false</td><td>if set to true it will produce some extra resolver output</td>
202
197
  </tr>
203
198
  <tr>
204
199
  <td><tt>JARS_HOME</tt></td><td>jars.home</td><td>$HOME/.m2/repository</td><td>filesystem location where to store the jar files and some metadata</td>
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'lib/jars/version'
4
+ require_relative 'lib/jars/mima/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
7
  s.name = 'jar-dependencies'
@@ -13,11 +14,13 @@ Gem::Specification.new do |s|
13
14
  s.homepage = 'https://github.com/jruby/jar-dependencies'
14
15
 
15
16
  s.bindir = 'exe'
16
- s.executables = [lock_jars = 'lock_jars']
17
+ s.executables = ['lock_jars']
17
18
 
18
19
  s.license = 'MIT'
19
20
 
20
21
  s.files = Dir['{lib}/**/*'] + %w[Mavenfile Rakefile Readme.md jar-dependencies.gemspec MIT-LICENSE]
22
+ # explicitly require the jars
23
+ s.files += Jars::Mima::JARS.each_key.map {File.join(Jars::Mima::MIMA_DIR, _1)}
21
24
 
22
25
  s.description = <<~TEXT
23
26
  manage jar dependencies for gems and keep track which jar was already
@@ -30,18 +33,6 @@ Gem::Specification.new do |s|
30
33
  s.required_ruby_version = '>= 2.6'
31
34
 
32
35
  s.add_development_dependency 'minitest', '~> 5.10'
33
- s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.9'
34
36
 
35
- s.post_install_message = <<~TEXT
36
-
37
- if you want to use the executable #{lock_jars} then install ruby-maven gem before using #{lock_jars}
38
-
39
- $ gem install ruby-maven -v '#{ruby_maven_version}'
40
-
41
- or add it as a development dependency to your Gemfile
42
-
43
- gem 'ruby-maven', '#{ruby_maven_version}'
44
-
45
- TEXT
46
37
  s.metadata['rubygems_mfa_required'] = 'true'
47
38
  end
@@ -22,48 +22,58 @@
22
22
  #
23
23
 
24
24
  module Jars
25
- unless defined? Jars::SKIP_LOCK
26
- MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'
27
- LOCAL_MAVEN_REPO = 'JARS_LOCAL_MAVEN_REPO'
28
- # lock file to use
29
- LOCK = 'JARS_LOCK'
30
- # where the locally stored jars are search for or stored
31
- HOME = 'JARS_HOME'
32
- # skip the gem post install hook
33
- SKIP = 'JARS_SKIP'
34
- # skip Jars.lock mainly to run lock_jars
35
- SKIP_LOCK = 'JARS_SKIP_LOCK'
36
- # do not require any jars if set to false
37
- REQUIRE = 'JARS_REQUIRE'
38
- # @private
39
- NO_REQUIRE = 'JARS_NO_REQUIRE'
40
- # no more warnings on conflict. this still requires jars but will
41
- # not warn. it is needed to load jars from (default) gems which
42
- # do contribute to any dependency manager (maven, gradle, jbundler)
43
- QUIET = 'JARS_QUIET'
44
- # show maven output
45
- VERBOSE = 'JARS_VERBOSE'
46
- # maven debug
47
- DEBUG = 'JARS_DEBUG'
48
- # vendor jars inside gem when installing gem
49
- VENDOR = 'JARS_VENDOR'
50
- # string used when the version is unknown
51
- UNKNOWN = 'unknown'
52
- end
25
+ # rubocop:disable Style/RedundantFreeze
26
+ MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'.freeze
27
+ LOCAL_MAVEN_REPO = 'JARS_LOCAL_MAVEN_REPO'.freeze
28
+ # lock file to use
29
+ LOCK = 'JARS_LOCK'.freeze
30
+ # where the locally stored jars are search for or stored
31
+ HOME = 'JARS_HOME'.freeze
32
+ # skip the gem post install hook
33
+ SKIP = 'JARS_SKIP'.freeze
34
+ # skip Jars.lock mainly to run lock_jars
35
+ SKIP_LOCK = 'JARS_SKIP_LOCK'.freeze
36
+ # do not require any jars if set to false
37
+ REQUIRE = 'JARS_REQUIRE'.freeze
38
+ # @private
39
+ NO_REQUIRE = 'JARS_NO_REQUIRE'.freeze
40
+ # no more warnings on conflict. this still requires jars but will
41
+ # not warn. it is needed to load jars from (default) gems which
42
+ # do contribute to any dependency manager (maven, gradle, jbundler)
43
+ QUIET = 'JARS_QUIET'.freeze
44
+ # show resolver output
45
+ VERBOSE = 'JARS_VERBOSE'.freeze
46
+ # show jar-dependencies debug output
47
+ DEBUG = 'JARS_DEBUG'.freeze
48
+ # vendor jars inside gem when installing gem
49
+ VENDOR = 'JARS_VENDOR'.freeze
50
+ # string used when the version is unknown
51
+ UNKNOWN = 'unknown'.freeze
52
+ # rubocop:enable Style/RedundantFreeze
53
53
 
54
- autoload :MavenSettings, 'jars/maven_settings'
55
54
  autoload :Classpath, 'jars/classpath'
55
+ autoload :MavenSettings, 'jars/maven_settings'
56
+ autoload :Mima, 'jars/mima'
56
57
 
57
58
  @jars_lock = false
58
59
  @jars = {}
59
60
 
61
+ class JarLoadError < LoadError; end
62
+
60
63
  class << self
61
- def lock_down(debug: false, verbose: false, **kwargs)
64
+ def lock_down(debug: nil, verbose: nil, **kwargs)
65
+ previous_debug = ENV[DEBUG]
66
+ previous_verbose = ENV[VERBOSE]
67
+ previous_skip_lock = ENV[SKIP_LOCK]
68
+ ENV[DEBUG] = debug.to_s unless debug.nil?
69
+ ENV[VERBOSE] = verbose.to_s unless verbose.nil?
62
70
  ENV[SKIP_LOCK] = 'true'
63
71
  require 'jars/lock_down' # do this lazy to keep things clean
64
- Jars::LockDown.new(debug, verbose).lock_down(kwargs.delete(:vendor_dir), **kwargs)
72
+ Jars::LockDown.new.lock_down(kwargs.delete(:vendor_dir), **kwargs)
65
73
  ensure
66
- ENV[SKIP_LOCK] = nil
74
+ ENV[DEBUG] = previous_debug unless debug.nil?
75
+ ENV[VERBOSE] = previous_verbose unless verbose.nil?
76
+ ENV[SKIP_LOCK] = previous_skip_lock
67
77
  end
68
78
 
69
79
  if defined? JRUBY_VERSION
@@ -95,7 +105,7 @@ module Jars
95
105
  if @require.nil?
96
106
  if (require = to_boolean(REQUIRE)).nil?
97
107
  no_require = to_boolean(NO_REQUIRE)
98
- @require = no_require.nil? ? true : !no_require
108
+ @require = no_require.nil? || !no_require
99
109
  else
100
110
  @require = require
101
111
  end
@@ -118,7 +128,8 @@ module Jars
118
128
  end
119
129
 
120
130
  def verbose?
121
- to_boolean(VERBOSE)
131
+ verbose = to_boolean(VERBOSE)
132
+ verbose.nil? ? debug? : (verbose || !!debug?)
122
133
  end
123
134
 
124
135
  def debug?
@@ -144,12 +155,7 @@ module Jars
144
155
  def jars_lock_from_class_loader
145
156
  return unless defined?(JRUBY_VERSION)
146
157
 
147
- if JRuby::Util.respond_to?(:class_loader_resources)
148
- JRuby::Util.class_loader_resources('Jars.lock')
149
- else
150
- require 'jruby'
151
- JRuby.runtime.jruby_class_loader.get_resources('Jars.lock').collect(&:to_s)
152
- end
158
+ JRuby::Util.class_loader_resources('Jars.lock')
153
159
  end
154
160
 
155
161
  def lock_path(basedir = nil)
@@ -270,7 +276,7 @@ module Jars
270
276
  end
271
277
 
272
278
  def warn(msg = nil)
273
- return if (verbose? == nil && quiet?) || (verbose? == false && !debug?)
279
+ return if quiet? && !debug?
274
280
 
275
281
  Kernel.warn(msg || yield)
276
282
  end
@@ -328,8 +334,8 @@ module Jars
328
334
  local_repo = nil if local_repo.empty? || !File.exist?(local_repo)
329
335
  local_repo
330
336
  rescue => e
331
- Jars.debug(e)
332
337
  Jars.warn "error reading or parsing local settings from: #{settings}"
338
+ Jars.debug(e)
333
339
  nil
334
340
  end
335
341
 
@@ -356,25 +362,26 @@ module Jars
356
362
  require jar
357
363
  end
358
364
  rescue LoadError => e
359
- raise "\n\n\tyou might need to reinstall the gem which depends on the " \
360
- 'missing jar or in case there is Jars.lock then resolve the jars with ' \
361
- "`lock_jars` command\n\n#{e.message} (LoadError)"
365
+ Jars.warn "failed to load jar: #{jar} (#{e.message})"
366
+ Jars.debug(e)
367
+ raise JarLoadError, "failed to load jar: #{jar}; run `lock_jars` or reinstall the gem"
362
368
  end
363
369
  end
364
370
  end
365
371
 
366
372
  def require_jar(*args, &block)
367
- return nil unless Jars.require?
373
+ return unless Jars.require?
368
374
 
369
375
  result = Jars.require_jar(*args, &block)
370
376
  if result.is_a? String
371
377
  args << (yield || Jars::UNKNOWN) if args.size == 2 && block
372
378
  Jars.warn do
373
- "--- jar coordinate #{args[0..-2].join(':')} already loaded with version #{result} - omit version #{args[-1]}"
379
+ "jar conflict: #{args[0..-2].join(':')} already loaded with version #{result}; " \
380
+ "skipping requested version #{args[-1]}"
374
381
  end
375
- Jars.debug { " try to load from #{caller.join("\n\t")}" }
382
+ Jars.debug("\n\t#{caller.join("\n\t")}") if Jars.debug?
376
383
  return false
377
384
  end
378
- Jars.debug { " register #{args.inspect} - #{result == true}" }
385
+ Jars.debug { "jar registration: #{args.inspect}; loaded=#{result == true}" }
379
386
  result
380
387
  end
@@ -12,7 +12,7 @@ module Jars
12
12
  if low == high
13
13
  low
14
14
  else
15
- super "#{low || '[0'},#{high || ')'}"
15
+ super("#{low || '[0'},#{high || ')'}")
16
16
  end
17
17
  end
18
18
  end
@@ -26,17 +26,17 @@ module Jars
26
26
  ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"]
27
27
  elsif arg.include?('>=')
28
28
  val = arg.sub(/>=\s*/, '')
29
- ["[#{snapshot_version(val)}", (nil || high)]
29
+ ["[#{snapshot_version(val)}", high]
30
30
  elsif arg.include?('<=')
31
31
  val = arg.sub(/<=\s*/, '')
32
- [(nil || low), "#{snapshot_version(val)}]"]
33
- # treat '!' the same way as '>' since maven can not describe such range
32
+ [low, "#{snapshot_version(val)}]"]
33
+ # treat '!' the same way as '>' since maven cannot describe such range
34
34
  elsif /[!>]/.match?(arg)
35
35
  val = arg.sub(/[!>]\s*/, '')
36
- ["(#{snapshot_version(val)}", (nil || high)]
36
+ ["(#{snapshot_version(val)}", high]
37
37
  elsif arg.include?('<')
38
38
  val = arg.sub(/<\s*/, '')
39
- [(nil || low), "#{snapshot_version(val)})"]
39
+ [low, "#{snapshot_version(val)})"]
40
40
  elsif arg.include?('=')
41
41
  val = arg.sub(/=\s*/, '')
42
42
  # for prereleased version pick the maven version (no version range)
@@ -133,12 +133,12 @@ module Jars
133
133
 
134
134
  if /[\[()\]]/.match?(line)
135
135
  index = line.index(/[\[(].+$/)
136
- version = line[index..].sub(/:/, ', ')
137
- line = line[0..index - 1].strip.sub(/:$/, '')
136
+ version = line[index..].sub(':', ', ')
137
+ line = line[0..(index - 1)].strip.sub(/:$/, '')
138
138
  else
139
139
  index = line.index(/:[^:]+$/)
140
- version = line[index + 1..]
141
- line = line[0..index - 1].strip
140
+ version = line[(index + 1)..]
141
+ line = line[0..(index - 1)].strip
142
142
  end
143
143
 
144
144
  case line.count(':')
@@ -171,17 +171,18 @@ module Jars
171
171
  end
172
172
 
173
173
  def ruby_maven_install_options=(options)
174
- @mvn.ruby_maven_install_options = options
174
+ # no-op: kept for backward compatibility with post_install_hook
175
175
  end
176
176
 
177
177
  def jars?
178
178
  # first look if there are any requirements in the spec
179
179
  # and then if gem depends on jar-dependencies for runtime.
180
180
  # only then install the jars declared in the requirements
181
- result = (spec = self.spec) && !spec.requirements.empty? &&
181
+ spec = self.spec
182
+ result = spec && !spec.requirements.empty? &&
182
183
  spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime }
183
184
  if result && spec.platform.to_s != 'java'
184
- Jars.warn "\njar dependencies found on non-java platform gem - do not install jars\n"
185
+ Jars.warn "jar-dependencies found on non-java platform gem; skipping jar installation"
185
186
  false
186
187
  else
187
188
  result
@@ -191,21 +192,18 @@ module Jars
191
192
  private
192
193
 
193
194
  def do_install(vendor_dir, write_require_file)
194
- if !spec.require_paths.include?(vendor_dir) && vendor_dir
195
- raise "vendor dir #{vendor_dir} not in require_paths of gemspec #{spec.require_paths}"
195
+ require_paths = spec.require_paths
196
+ if vendor_dir && !require_paths.include?(vendor_dir)
197
+ raise "vendor dir #{vendor_dir} not in require_paths of gemspec #{require_paths}"
196
198
  end
197
199
 
198
200
  target_dir = File.join(@mvn.basedir, vendor_dir || spec.require_path)
199
201
  jars_file = File.join(target_dir, "#{spec.name}_jars.rb")
200
202
 
201
- # write out new jars_file it write_require_file is true or
202
- # check timestamps:
203
- # do not generate file if specfile is older then the generated file
204
- if !write_require_file &&
205
- File.exist?(jars_file) &&
206
- File.mtime(@mvn.specfile) < File.mtime(jars_file)
207
- # leave jars_file as is
208
- jars_file = nil
203
+ # write out new jars_file if write_require_file is true or check timestamps:
204
+ # do not generate file if specfile is older than the generated file
205
+ if !write_require_file && File.exist?(jars_file) && File.mtime(@mvn.specfile) < File.mtime(jars_file)
206
+ jars_file = nil # leave jars_file as is
209
207
  end
210
208
  deps = install_dependencies
211
209
  self.class.write_require_jars(deps, jars_file)
data/lib/jars/lock.rb CHANGED
@@ -57,7 +57,7 @@ module Jars
57
57
  File.read(@file).each_line do |line|
58
58
  next unless /:.+:/.match?(line)
59
59
 
60
- jar = JarDetails.new(line.strip.sub(/:jar:/, ':').sub(/:$/, ': ').split(':'))
60
+ jar = JarDetails.new(line.strip.sub(':jar:', ':').sub(/:$/, ': ').split(':'))
61
61
  case scope
62
62
  when :all, :test
63
63
  yield jar
@@ -1,101 +1,132 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fileutils'
4
3
  require 'jar_dependencies'
5
4
  require 'jars/version'
6
- require 'jars/maven_factory'
7
5
  require 'jars/gemspec_artifacts'
8
6
 
9
7
  module Jars
10
8
  class LockDown
11
- attr_reader :debug, :verbose
12
-
13
- def initialize(debug, verbose)
14
- @debug = debug
15
- @verbose = verbose
9
+ def basedir
10
+ File.expand_path('.')
16
11
  end
17
12
 
18
- def maven_new
19
- factory = MavenFactory.new({}, @debug, @verbose)
20
- pom = File.expand_path('lock_down_pom.rb', __dir__)
21
- m = factory.maven_new(pom)
22
- m['jruby.plugins.version'] = Jars::JRUBY_PLUGINS_VERSION
23
- m['dependency.plugin.version'] = Jars::DEPENDENCY_PLUGIN_VERSION
24
- m['jars.basedir'] = File.expand_path(basedir)
25
- jarfile = File.expand_path(Jars.jarfile)
26
- m['jars.jarfile'] = jarfile if File.exist?(jarfile)
27
- attach_jar_coordinates_from_bundler_dependencies(m)
28
- m
29
- end
30
- private :maven_new
13
+ def collect_artifacts
14
+ artifacts = []
15
+ done = []
31
16
 
32
- def maven
33
- @maven ||= maven_new
34
- end
17
+ attach_jar_coordinates_from_bundler_dependencies(artifacts, done)
35
18
 
36
- def basedir
37
- File.expand_path('.')
19
+ # Also collect from local gemspec if present
20
+ specs = Dir['*.gemspec']
21
+ if specs.size == 1
22
+ spec = eval(File.read(specs.first), TOPLEVEL_BINDING, specs.first) # rubocop:disable Security/Eval
23
+ ga = GemspecArtifacts.new(spec)
24
+ ga.artifacts.each do |a|
25
+ unless done.include?(a.key)
26
+ artifacts << a
27
+ done << a.key
28
+ end
29
+ end
30
+ end
31
+
32
+ artifacts
38
33
  end
34
+ private :collect_artifacts
39
35
 
40
- def attach_jar_coordinates_from_bundler_dependencies(maven)
36
+ def attach_jar_coordinates_from_bundler_dependencies(artifacts, done)
41
37
  load_path = $LOAD_PATH.dup
42
38
  require 'bundler'
43
39
  # TODO: make this group a commandline option
44
40
  Bundler.setup('default')
45
- maven.property('jars.bundler', true)
46
41
  cwd = File.expand_path('.')
47
- Gem.loaded_specs.each do |_name, spec|
48
- # if gemspec is local then include all dependencies
49
- maven.attach_jars(spec, all_dependencies: cwd == spec.full_gem_path)
42
+ Gem.loaded_specs.each_value do |spec|
43
+ all = cwd == spec.full_gem_path # if gemspec is local then include all dependencies
44
+ ga = GemspecArtifacts.new(spec)
45
+ ga.artifacts.each do |a|
46
+ next if done.include?(a.key)
47
+ next unless all || (a.scope != 'provided' && a.scope != 'test')
48
+
49
+ artifacts << a
50
+ done << a.key
51
+ end
50
52
  end
51
53
  rescue LoadError => e
52
- if Jars.verbose?
53
- warn e.message
54
- warn 'no bundler found - ignore Gemfile if exists'
55
- end
54
+ Jars.warn "bundler unavailable (#{e.message}); skipping dependency discovery" if Jars.verbose?
56
55
  rescue Bundler::GemfileNotFound
57
- # do nothing then as we have bundler but no Gemfile
56
+ # bundler is available, but there is no Gemfile to inspect
58
57
  rescue Bundler::GemNotFound
59
- warn "can not setup bundler with #{Bundler.default_lockfile}"
58
+ Jars.warn "cannot set up bundler with #{Bundler.default_lockfile}"
60
59
  raise
61
60
  ensure
62
61
  $LOAD_PATH.replace(load_path)
63
62
  end
64
63
 
65
- def lock_down(vendor_dir = nil, force: false, update: false, tree: nil)
66
- out = File.expand_path('.jars.output')
67
- tree_provided = tree
68
- tree ||= File.expand_path('.jars.tree')
69
- maven.property('jars.outputFile', out)
70
- maven.property('maven.repo.local', Jars.local_maven_repo)
71
- maven.property('jars.home', File.expand_path(vendor_dir)) if vendor_dir
72
- maven.property('jars.lock', File.expand_path(Jars.lock))
73
- maven.property('jars.force', force)
74
- maven.property('jars.update', update) if update
75
- # tell not to use Jars.lock as part of POM when running mvn
76
- maven.property('jars.skip.lock', true)
77
-
78
- args = ['gem:jars-lock']
79
- args += ['dependency:tree', '-P -gemfile.lock', "-DoutputFile=#{tree}"] if tree_provided
64
+ def lock_down(vendor_dir = nil, force: false, update: false, tree: nil) # rubocop:disable Lint/UnusedMethodArgument
65
+ lock_file = File.expand_path(Jars.lock)
66
+
67
+ if !force && File.exist?(lock_file)
68
+ puts 'Jars.lock already exists, use --force to overwrite'
69
+ return
70
+ end
71
+
72
+ artifacts = collect_artifacts
73
+
74
+ if artifacts.empty?
75
+ puts 'no jar dependencies found'
76
+ return
77
+ end
80
78
 
81
79
  puts
82
80
  puts '-- jar root dependencies --'
83
81
  puts
84
- status = maven.exec(*args)
85
- exit 1 unless status
86
- if File.exist?(tree)
82
+ artifacts.each do |a|
83
+ puts " #{a.to_gacv}:#{a.scope || 'compile'}"
84
+ puts " exclusions: #{a.exclusions}" if a.exclusions && !a.exclusions.empty?
85
+ end
86
+
87
+ context = Jars::Mima.create_context
88
+ begin
89
+ resolved = Jars::Mima.resolve_with_context(context, artifacts, all_dependencies: true)
90
+ ensure
91
+ context.close
92
+ end
93
+
94
+ # Write Jars.lock
95
+ File.open(lock_file, 'w') do |f|
96
+ resolved.each do |dep|
97
+ next unless dep.type == 'jar'
98
+
99
+ f.puts dep.to_lock_entry
100
+ end
101
+ end
102
+
103
+ # Optionally vendor jars
104
+ if vendor_dir
105
+ require 'fileutils'
106
+ vendor_path = File.expand_path(vendor_dir)
107
+ resolved.each do |dep|
108
+ next unless dep.type == 'jar' && dep.runtime? && !dep.system?
109
+
110
+ target = File.join(vendor_path, dep.jar_path)
111
+ FileUtils.mkdir_p(File.dirname(target))
112
+ FileUtils.cp(dep.file, target)
113
+ end
114
+ end
115
+
116
+ if tree
87
117
  puts
88
118
  puts '-- jar dependency tree --'
89
119
  puts
90
- puts File.read(tree)
120
+ resolved.each do |dep|
121
+ prefix = dep.classifier ? "#{dep.classifier}:" : ''
122
+ puts " #{dep.group_id}:#{dep.artifact_id}:#{prefix}#{dep.version}:#{dep.scope}"
123
+ end
91
124
  puts
92
125
  end
126
+
93
127
  puts
94
- puts File.read(out).gsub("#{File.dirname(out)}/", '')
128
+ puts File.read(lock_file)
95
129
  puts
96
- ensure
97
- FileUtils.rm_f out
98
- FileUtils.rm_f tree
99
130
  end
100
131
  end
101
132
  end