jar-dependencies 0.4.1 → 0.5.3

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
- SHA1:
3
- metadata.gz: d730f61c3fbec4cbb40c2d2d772dece10891d172
4
- data.tar.gz: cb4aacf3dc32930cfafbc202e128e8a821474a57
2
+ SHA256:
3
+ metadata.gz: 679b43ab08c7a479313003c77557e7bd235df6b6737441b0ad14b5d2e25e465e
4
+ data.tar.gz: db72e55ece4bb54e6ace8e7970e61502dace779a7dac8e4c68f32c8080d4788a
5
5
  SHA512:
6
- metadata.gz: 7f7baa869bd3cc34a27f1604cd205ca7f116ecf6ae86bd7019935950443137850b459d80b31e36d9b8fa8579f243261d2aa336812e53734ed3c1ea7a70df5ce5
7
- data.tar.gz: 894cf492789572bba0e93fc678e7cbfe3ac878340c2c9baa5ff2c65b903ce997ab0e9b328b7645fa3b6843087c4b04ab554194a89c568adeb4e8dca941a42304
6
+ metadata.gz: b2101f641caffb4ac8c2754050c6999c2989ac8b5cd58d414333e6b42961a86f66f8c2ea28068e4ea528daecabf840612f436cb2541f9b6179485bb79c98fb9e
7
+ data.tar.gz: f3bf1d00df6e004d72026d34c819a5d58b475d56e864c30f119c13d82b39520aab8bde682c420b590fe7d20c3f9c3719f73afe96d35bad09d876bbf5039dccc4
data/Mavenfile CHANGED
@@ -1,8 +1,8 @@
1
- #-*- mode: ruby -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  gemfile
4
4
 
5
- plugin_repository id: :maven_gems, url: 'mavengem:https://rubygems.org'
5
+ plugin_repository id: :mavengems, url: 'mavengem:https://rubygems.org'
6
6
 
7
7
  jruby_plugin(:minitest, minispecDirectory: 'specs/*_spec.rb') do
8
8
  execute_goals(:spec)
@@ -17,13 +17,12 @@ ruby_maven = gemfile_profile.dependencies.detect do |d|
17
17
  d.artifact_id == 'ruby-maven'
18
18
  end
19
19
 
20
- properties('jruby.versions' => ['1.7.12', '1.7.25', '${jruby.version}'].join(','),
21
- 'jruby.modes' => ['1.9', '2.0', '2.2'].join(','),
20
+ properties('jruby.versions' => ['${jruby.version}'].join(','),
22
21
  # just lock the version
23
- 'bundler.version' => '1.10.6',
22
+ 'bundler.version' => '2.5.11',
24
23
  'ruby-maven.version' => ruby_maven.version,
25
- 'jruby.version' => '9.0.5.0',
26
- 'jruby.plugins.version' => '1.1.3',
24
+ 'jruby.version' => '9.4.8.0',
25
+ 'jruby.plugins.version' => '3.0.2',
27
26
  'push.skip' => true)
28
27
 
29
28
  plugin :invoker, '1.8' do
@@ -37,7 +36,6 @@ plugin :invoker, '1.8' do
37
36
  cloneProjectsTo: '${project.build.directory}',
38
37
  properties: { 'jar-dependencies.version' => '${project.version}',
39
38
  # use an old jruby with old ruby-maven here
40
- 'jruby.old-version' => '1.7.20',
41
39
  'jruby.version' => '${jruby.version}',
42
40
  'jruby.plugins.version' => '${jruby.plugins.version}',
43
41
  'bundler.version' => '${bundler.version}',
@@ -59,5 +57,3 @@ profile id: :release do
59
57
  default_goal :deploy
60
58
  end
61
59
  end
62
-
63
- # vim: syntax=Ruby
data/Rakefile CHANGED
@@ -1,7 +1,12 @@
1
- #-*- mode: ruby -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  task default: [:specs]
4
4
 
5
+ require 'bundler/gem_tasks'
6
+ require 'rubocop/rake_task'
7
+
8
+ RuboCop::RakeTask.new
9
+
5
10
  desc 'run specs'
6
11
  task :specs do
7
12
  $LOAD_PATH << 'specs'
@@ -10,24 +15,3 @@ task :specs do
10
15
  require File.basename(f.sub(/.rb$/, ''))
11
16
  end
12
17
  end
13
-
14
- task :headers do
15
- require 'copyright_header'
16
-
17
- s = Gem::Specification.load(Dir['*gemspec'].first)
18
-
19
- args = {
20
- license: s.license,
21
- copyright_software: s.name,
22
- copyright_software_description: s.description,
23
- copyright_holders: s.authors,
24
- copyright_years: [Time.now.year],
25
- add_path: 'lib',
26
- output_dir: './'
27
- }
28
-
29
- command_line = CopyrightHeader::CommandLine.new(args)
30
- command_line.execute
31
- end
32
-
33
- # vim: syntax=Ruby
data/Readme.md CHANGED
@@ -47,7 +47,7 @@ during installation.
47
47
 
48
48
  If you do not want to vendor jars into a gem then **jar-dependency** gem can vendor
49
49
  them when you install the gem. In that case do not use
50
- `Jars::JarInstaller.install_jars` from the above rake tasks.
50
+ `Jars::Installer.install_jars` from the above rake tasks.
51
51
 
52
52
  **NOTE**: Recent JRuby comes with **jar-dependencies** as default gem, for older
53
53
  versions for the feature to work you need to gem install **jar-dependencies** first
@@ -172,7 +172,7 @@ Or, with maven debug enabled
172
172
  JARS_DEBUG=true bundle install
173
173
  JARS_DEBUG=true gem install some_gem
174
174
 
175
- The maven command line which gets printed needs maven-3.3.x and the
175
+ The maven command line which gets printed needs maven-3.9.x and the
176
176
  ruby DSL extension for maven:
177
177
  [https://github.com/takari/polyglot-maven#configuration](polyglot-maven
178
178
  configuration) where ```${maven.multiModuleProjectDirectory}``` is
@@ -216,3 +216,8 @@ Or a few days ago an issue for rake-compile [https://github.com/luislavena/rake-
216
216
 
217
217
  With JRuby 9000 it is the right time to get jar dependencies "right" - the current situation is like the time before bundler for gems.
218
218
 
219
+ # Developing
220
+
221
+ You must have the latest ruby-maven installed in your local JRuby.
222
+
223
+ ./mvnw install will build the gem and run integration tests
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'jar_dependencies'
3
5
  require 'optparse'
4
6
  options = {}
@@ -25,11 +27,14 @@ optparse = OptionParser.new do |opts|
25
27
  options[:tree] = t
26
28
  end
27
29
 
28
- opts.on('-u', '--update JAR_COORDINATE', 'Resolves given dependency and use latest version. JAR_COORDINATE is either artifact_id or group_id:artifact_id') do |u|
30
+ opts.on('-u', '--update JAR_COORDINATE',
31
+ 'Resolves given dependency and use latest version. ' \
32
+ 'JAR_COORDINATE is either artifact_id or group_id:artifact_id') do |u|
29
33
  options[:update] = u
30
34
  end
31
35
 
32
- 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|
36
+ opts.on('--vendor-dir DIRECTORY', 'Vendor directory where to copy the installed jars.' \
37
+ 'add this directory to $LOAD_PATH or set JARS_HOME respectively.') do |dir|
33
38
  options[:vendor_dir] = dir
34
39
  end
35
40
 
@@ -46,4 +51,4 @@ optparse = OptionParser.new do |opts|
46
51
  end
47
52
  optparse.parse!
48
53
 
49
- Jars.lock_down(options[:debug], options[:verbose], options)
54
+ Jars.lock_down(debug: options.delete(:debug), verbose: options.delete(:verbose), **options)
@@ -1,44 +1,47 @@
1
- #-*- mode: ruby -*-
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/jars/version'
2
4
 
3
5
  Gem::Specification.new do |s|
4
6
  s.name = 'jar-dependencies'
5
7
 
6
- path = File.expand_path('lib/jars/version.rb', File.dirname(__FILE__))
7
- s.version = File.read(path).match(/\s*VERSION\s*=\s*['"](.*)['"]/)[1]
8
+ s.version = Jars::VERSION
8
9
 
9
10
  s.author = 'christian meier'
10
11
  s.email = ['mkristian@web.de']
11
12
  s.summary = 'manage jar dependencies for gems'
12
13
  s.homepage = 'https://github.com/mkristian/jar-dependencies'
13
14
 
14
- s.bindir = 'bin'
15
- s.executables = [lock_jars = 'lock_jars'.freeze]
15
+ s.bindir = 'exe'
16
+ s.executables = [lock_jars = 'lock_jars']
16
17
 
17
18
  s.license = 'MIT'
18
19
 
19
- s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR).select do |file|
20
- file =~ /^lib\// ||
21
- %w[Mavenfile Rakefile].include?(file) ||
22
- ['Readme.md', 'jar-dependencies.gemspec', 'MIT-LICENSE'].include?(file)
23
- end
20
+ s.files = Dir['{lib}/**/*'] + %w[Mavenfile Rakefile Readme.md jar-dependencies.gemspec MIT-LICENSE]
24
21
 
25
- s.description = 'manage jar dependencies for gems and keep track which jar was already loaded using maven artifact coordinates. it warns on version conflicts and loads only ONE jar assuming the first one is compatible to the second one otherwise your project needs to lock down the right version by providing a Jars.lock file.'
22
+ s.description = <<~TEXT
23
+ manage jar dependencies for gems and keep track which jar was already
24
+ loaded using maven artifact coordinates. it warns on version conflicts and
25
+ loads only ONE jar assuming the first one is compatible to the second one
26
+ otherwise your project needs to lock down the right version by providing a
27
+ Jars.lock file.
28
+ TEXT
26
29
 
27
- s.add_development_dependency 'minitest', '~> 5.10.0'
28
- s.add_development_dependency 'rake', '~> 10.2'
29
- s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.3.11'.freeze
30
+ s.required_ruby_version = '>= 2.6'
30
31
 
31
- s.post_install_message = <<EOF
32
+ s.add_development_dependency 'minitest', '~> 5.10'
33
+ s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.9'
32
34
 
33
- if you want to use the executable #{lock_jars} then install ruby-maven gem before using #{lock_jars}
35
+ s.post_install_message = <<~TEXT
34
36
 
35
- $ gem install ruby-maven -v '#{ruby_maven_version}'
37
+ if you want to use the executable #{lock_jars} then install ruby-maven gem before using #{lock_jars}
36
38
 
37
- or add it as a development dependency to your Gemfile
39
+ $ gem install ruby-maven -v '#{ruby_maven_version}'
38
40
 
39
- gem 'ruby-maven', '#{ruby_maven_version}'
41
+ or add it as a development dependency to your Gemfile
40
42
 
41
- EOF
42
- end
43
+ gem 'ruby-maven', '#{ruby_maven_version}'
43
44
 
44
- # vim: syntax=Ruby
45
+ TEXT
46
+ s.metadata['rubygems_mfa_required'] = 'true'
47
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (C) 2014 Christian Meier
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (C) 2014 Christian Meier
3
5
  #
@@ -21,41 +23,45 @@
21
23
 
22
24
  module Jars
23
25
  unless defined? Jars::SKIP_LOCK
24
- MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'.freeze
25
- LOCAL_MAVEN_REPO = 'JARS_LOCAL_MAVEN_REPO'.freeze
26
+ MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'
27
+ LOCAL_MAVEN_REPO = 'JARS_LOCAL_MAVEN_REPO'
26
28
  # lock file to use
27
- LOCK = 'JARS_LOCK'.freeze
29
+ LOCK = 'JARS_LOCK'
28
30
  # where the locally stored jars are search for or stored
29
- HOME = 'JARS_HOME'.freeze
31
+ HOME = 'JARS_HOME'
30
32
  # skip the gem post install hook
31
- SKIP = 'JARS_SKIP'.freeze
33
+ SKIP = 'JARS_SKIP'
32
34
  # skip Jars.lock mainly to run lock_jars
33
- SKIP_LOCK = 'JARS_SKIP_LOCK'.freeze
35
+ SKIP_LOCK = 'JARS_SKIP_LOCK'
34
36
  # do not require any jars if set to false
35
- REQUIRE = 'JARS_REQUIRE'.freeze
37
+ REQUIRE = 'JARS_REQUIRE'
36
38
  # @private
37
- NO_REQUIRE = 'JARS_NO_REQUIRE'.freeze
39
+ NO_REQUIRE = 'JARS_NO_REQUIRE'
38
40
  # no more warnings on conflict. this still requires jars but will
39
41
  # not warn. it is needed to load jars from (default) gems which
40
42
  # do contribute to any dependency manager (maven, gradle, jbundler)
41
- QUIET = 'JARS_QUIET'.freeze
43
+ QUIET = 'JARS_QUIET'
42
44
  # show maven output
43
- VERBOSE = 'JARS_VERBOSE'.freeze
45
+ VERBOSE = 'JARS_VERBOSE'
44
46
  # maven debug
45
- DEBUG = 'JARS_DEBUG'.freeze
47
+ DEBUG = 'JARS_DEBUG'
46
48
  # vendor jars inside gem when installing gem
47
- VENDOR = 'JARS_VENDOR'.freeze
49
+ VENDOR = 'JARS_VENDOR'
48
50
  # string used when the version is unknown
49
51
  UNKNOWN = 'unknown'
50
52
  end
51
53
 
52
54
  autoload :MavenSettings, 'jars/maven_settings'
55
+ autoload :Classpath, 'jars/classpath'
56
+
57
+ @jars_lock = false
58
+ @jars = {}
53
59
 
54
60
  class << self
55
- def lock_down(debug = false, verbose = false, options = {})
61
+ def lock_down(debug: false, verbose: false, **kwargs)
56
62
  ENV[SKIP_LOCK] = 'true'
57
63
  require 'jars/lock_down' # do this lazy to keep things clean
58
- Jars::LockDown.new(debug, verbose).lock_down(options)
64
+ Jars::LockDown.new(debug, verbose).lock_down(kwargs.delete(:vendor_dir), **kwargs)
59
65
  ensure
60
66
  ENV[SKIP_LOCK] = nil
61
67
  end
@@ -63,8 +69,11 @@ module Jars
63
69
  if defined? JRUBY_VERSION
64
70
  def to_prop(key)
65
71
  key = key.tr('_', '.')
66
- ENV_JAVA[(key.downcase!; key)] ||
67
- ENV[(key.tr!('.', '_'); key.upcase!; key)]
72
+ ENV_JAVA[(key.downcase!
73
+ key)] ||
74
+ ENV[(key.tr!('.', '_')
75
+ key.upcase!
76
+ key)]
68
77
  end
69
78
  else
70
79
  def to_prop(key)
@@ -74,6 +83,7 @@ module Jars
74
83
 
75
84
  def to_boolean(key)
76
85
  return nil if (prop = to_prop(key)).nil?
86
+
77
87
  prop.empty? || prop.eql?('true')
78
88
  end
79
89
 
@@ -82,7 +92,6 @@ module Jars
82
92
  end
83
93
 
84
94
  def require?
85
- @require = nil unless instance_variable_defined?(:@require)
86
95
  if @require.nil?
87
96
  if (require = to_boolean(REQUIRE)).nil?
88
97
  no_require = to_boolean(NO_REQUIRE)
@@ -96,16 +105,16 @@ module Jars
96
105
  attr_writer :require
97
106
 
98
107
  def quiet?
99
- (@silent ||= false) || to_boolean(QUIET)
108
+ @quiet = to_boolean(QUIET) if @quiet.nil?
109
+ @quiet
100
110
  end
101
111
 
102
- def jarfile
103
- ENV['JARFILE'] || ENV_JAVA['jarfile'] || ENV['JBUNDLER_JARFILE'] || ENV_JAVA['jbundler.jarfile'] || 'Jarfile'
112
+ def no_more_warnings
113
+ @quiet = true
104
114
  end
105
115
 
106
- # @deprecated
107
- def no_require?
108
- !require?
116
+ def jarfile
117
+ ENV['JARFILE'] || ENV_JAVA['jarfile'] || ENV['JBUNDLER_JARFILE'] || ENV_JAVA['jbundler.jarfile'] || 'Jarfile'
109
118
  end
110
119
 
111
120
  def verbose?
@@ -120,10 +129,6 @@ module Jars
120
129
  to_boolean(VENDOR)
121
130
  end
122
131
 
123
- def no_more_warnings
124
- @silent = true
125
- end
126
-
127
132
  def freeze_loading
128
133
  self.require = false
129
134
  end
@@ -133,22 +138,23 @@ module Jars
133
138
  end
134
139
 
135
140
  def lock
136
- to_prop(LOCK) || 'Jars.lock'
141
+ @lock ||= to_prop(LOCK) || 'Jars.lock'
137
142
  end
138
143
 
139
144
  def jars_lock_from_class_loader
140
- if to_prop(LOCK).nil? && defined?(JRUBY_VERSION)
141
- if JRuby::Util.respond_to?(:class_loader_resources)
142
- JRuby::Util.class_loader_resources('Jars.lock')
143
- else; require 'jruby'
144
- JRuby.runtime.jruby_class_loader.get_resources('Jars.lock').collect(&:to_s)
145
- end
145
+ return unless defined?(JRUBY_VERSION)
146
+
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)
146
152
  end
147
153
  end
148
154
 
149
155
  def lock_path(basedir = nil)
150
- deps = lock
151
- return deps if File.exist?(deps)
156
+ return lock if File.exist?(lock)
157
+
152
158
  basedir ||= '.'
153
159
  ['.', 'jars', 'vendor/jars'].each do |dir|
154
160
  file = File.join(basedir, dir, lock)
@@ -158,9 +164,13 @@ module Jars
158
164
  end
159
165
 
160
166
  def reset
161
- instance_variables.each { |var| instance_variable_set(var, nil) }
167
+ instance_variables.each do |var|
168
+ next if var == :@jars_lock
169
+
170
+ instance_variable_set(var, nil)
171
+ end
162
172
  Jars::MavenSettings.reset
163
- (@@jars ||= {}).clear
173
+ @jars = {}
164
174
  end
165
175
 
166
176
  def maven_local_settings
@@ -180,49 +190,44 @@ module Jars
180
190
  end
181
191
 
182
192
  def local_maven_repo
183
- @_local_maven_repo ||= absolute(to_prop(LOCAL_MAVEN_REPO)) ||
184
- detect_local_repository(maven_local_settings) ||
185
- detect_local_repository(maven_user_settings) ||
186
- detect_local_repository(maven_global_settings) ||
187
- File.join(user_home, '.m2', 'repository')
193
+ @local_maven_repo ||= absolute(to_prop(LOCAL_MAVEN_REPO)) ||
194
+ detect_local_repository(maven_local_settings) ||
195
+ detect_local_repository(maven_user_settings) ||
196
+ detect_local_repository(maven_global_settings) ||
197
+ File.join(user_home, '.m2', 'repository')
188
198
  end
189
199
 
190
200
  def home
191
- absolute(to_prop(HOME)) || local_maven_repo
201
+ @home ||= absolute(to_prop(HOME)) || local_maven_repo
192
202
  end
193
203
 
194
204
  def require_jars_lock!(scope = :runtime)
195
- urls = jars_lock_from_class_loader
205
+ urls = jars_lock_from_class_loader if to_prop(LOCK).nil?
196
206
  if urls && !urls.empty?
197
- @@jars_lock = true
198
- # funny error during spec where it tries to load it again
199
- # and finds it as gem instead of the LOAD_PATH
200
- require 'jars/classpath' unless defined? Jars::Classpath
207
+ @jars_lock = true
208
+
201
209
  done = []
202
210
  while done != urls
203
211
  urls.each do |url|
204
212
  next if done.member?(url)
213
+
205
214
  Jars.debug { "--- load jars from uri #{url}" }
206
215
  classpath = Jars::Classpath.new(nil, "uri:#{url}")
207
216
  classpath.require(scope)
208
217
  done << url
209
218
  end
210
- urls = jars_lock_from_class_loader
211
219
  end
212
220
  no_more_warnings
213
- elsif jars_lock = Jars.lock_path
221
+ elsif (jars_lock = Jars.lock_path)
214
222
  Jars.debug { "--- load jars from #{jars_lock}" }
215
- @@jars_lock = jars_lock
216
- # funny error during spec where it tries to load it again
217
- # and finds it as gem instead of the LOAD_PATH
218
- require 'jars/classpath' unless defined? Jars::Classpath
223
+ @jars_lock = jars_lock
224
+
219
225
  classpath = Jars::Classpath.new(nil, jars_lock)
220
226
  classpath.require(scope)
221
227
  no_more_warnings
222
228
  end
223
229
  Jars.debug do
224
- @@jars ||= {}
225
- loaded = @@jars.collect { |k, v| "#{k}:#{v}" }
230
+ loaded = @jars.collect { |k, v| "#{k}:#{v}" }
226
231
  "--- loaded jars ---\n\t#{loaded.join("\n\t")}"
227
232
  end
228
233
  end
@@ -232,8 +237,8 @@ module Jars
232
237
  when Symbol
233
238
  require_jars_lock!(options)
234
239
  when Hash
235
- @_jars_home = options[:jars_home]
236
- @_jars_lock = options[:jars_lock]
240
+ @home = options[:jars_home]
241
+ @lock = options[:jars_lock]
237
242
  require_jars_lock!(options[:scope] || :runtime)
238
243
  else
239
244
  require_jars_lock!
@@ -241,25 +246,23 @@ module Jars
241
246
  end
242
247
 
243
248
  def require_jars_lock
244
- @@jars_lock ||= false
245
- unless @@jars_lock
246
- require_jars_lock!
247
- @@jars_lock ||= true
248
- end
249
+ return if @jars_lock
250
+
251
+ require_jars_lock!
252
+ @jars_lock ||= true # rubocop:disable Naming/MemoizedInstanceVariableName
249
253
  end
250
254
 
251
255
  def mark_as_required(group_id, artifact_id, *classifier_version)
252
256
  require_jar_with_block(group_id, artifact_id, *classifier_version) do
257
+ # ignore
253
258
  end
254
259
  end
255
260
 
256
- def require_jar(group_id, artifact_id, *classifier_version, &block)
261
+ def require_jar(group_id, artifact_id, *classifier_version)
257
262
  require_jars_lock unless skip_lock?
258
263
  if classifier_version.empty? && block_given?
259
- classifier_version = [block.call].compact
260
- if classifier_version.empty?
261
- return mark_as_required(group_id, artifact_id, UNKNOWN) || false
262
- end
264
+ classifier_version = [yield].compact
265
+ return mark_as_required(group_id, artifact_id, UNKNOWN) || false if classifier_version.empty?
263
266
  end
264
267
  require_jar_with_block(group_id, artifact_id, *classifier_version) do |gid, aid, version, classifier|
265
268
  do_require(gid, aid, version, classifier)
@@ -267,11 +270,16 @@ module Jars
267
270
  end
268
271
 
269
272
  def warn(msg = nil)
270
- Kernel.warn(msg || yield) unless quiet? && !verbose?
273
+ return if (verbose? == nil && quiet?) || (verbose? == false && !debug?)
274
+
275
+ Kernel.warn(msg || yield)
271
276
  end
272
277
 
273
278
  def debug(msg = nil)
274
- Kernel.warn(msg || yield) if verbose?
279
+ return unless debug?
280
+
281
+ msg = "#{msg.inspect}\n\t#{(msg.backtrace || []).join("\n\t")}" if msg.is_a?(Exception)
282
+ Kernel.warn(msg || yield)
275
283
  end
276
284
 
277
285
  def absolute(file)
@@ -281,9 +289,7 @@ module Jars
281
289
  def user_home
282
290
  ENV['HOME'] || begin
283
291
  user_home = Dir.home if Dir.respond_to?(:home)
284
- unless user_home
285
- user_home = ENV_JAVA['user.home'] if Object.const_defined?(:ENV_JAVA)
286
- end
292
+ user_home = ENV_JAVA['user.home'] if !user_home && Object.const_defined?(:ENV_JAVA)
287
293
  user_home
288
294
  end
289
295
  end
@@ -294,19 +300,18 @@ module Jars
294
300
  version = classifier_version[-1]
295
301
  classifier = classifier_version[-2]
296
302
 
297
- @@jars ||= {}
298
- coordinate = "#{group_id}:#{artifact_id}"
303
+ coordinate = +"#{group_id}:#{artifact_id}"
299
304
  coordinate << ":#{classifier}" if classifier
300
- if @@jars.key? coordinate
301
- if @@jars[coordinate] == version
305
+ if @jars.key? coordinate
306
+ if @jars[coordinate] == version
302
307
  false
303
308
  else
304
- @@jars[coordinate] # version of already registered jar
309
+ @jars[coordinate] # version of already registered jar
305
310
  end
306
311
  else
307
312
  yield group_id, artifact_id, version, classifier
308
- @@jars[coordinate] = version
309
- return true
313
+ @jars[coordinate] = version
314
+ true
310
315
  end
311
316
  end
312
317
 
@@ -315,20 +320,21 @@ module Jars
315
320
 
316
321
  doc = File.read(settings)
317
322
  # TODO: filter out xml comments
318
- local_repo = doc.sub(/<\/localRepository>.*/m, '').sub(/.*<localRepository>/m, '')
323
+ local_repo = doc.sub(%r{</localRepository>.*}m, '').sub(/.*<localRepository>/m, '')
319
324
  # replace maven like system properties embedded into the string
320
325
  local_repo.gsub!(/\$\{[a-zA-Z.]+\}/) do |a|
321
326
  ENV_JAVA[a[2..-2]] || a
322
327
  end
323
328
  local_repo = nil if local_repo.empty? || !File.exist?(local_repo)
324
329
  local_repo
325
- rescue
326
- Jars.warn { "error reading or parsing #{settings}" }
330
+ rescue => e
331
+ Jars.debug(e)
332
+ Jars.warn "error reading or parsing local settings from: #{settings}"
327
333
  nil
328
334
  end
329
335
 
330
336
  def to_jar(group_id, artifact_id, version, classifier = nil)
331
- file = String.new("#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}")
337
+ file = +"#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}"
332
338
  file << "-#{classifier}" if classifier
333
339
  file << '.jar'
334
340
  file
@@ -336,34 +342,36 @@ module Jars
336
342
 
337
343
  def do_require(*args)
338
344
  jar = to_jar(*args)
339
- local = File.join(Dir.pwd, 'jars', jar)
340
- vendor = File.join(Dir.pwd, 'vendor', 'jars', jar)
341
- file = File.join(home, jar)
342
- # use jar from local repository if exists
343
- if File.exist?(file)
344
- require file
345
- # use jar from PWD/jars if exists
346
- elsif File.exist?(local)
347
- require local
348
345
  # use jar from PWD/vendor/jars if exists
349
- elsif File.exist?(vendor)
346
+ if File.exist?(vendor = File.join(Dir.pwd, 'vendor', 'jars', jar))
350
347
  require vendor
348
+ # use jar from PWD/jars if exists
349
+ elsif File.exist?(local = File.join(Dir.pwd, 'jars', jar))
350
+ require local
351
+ # use jar from local repository if exists
352
+ elsif File.exist?(file = File.join(home, jar))
353
+ require file
351
354
  else
352
355
  # otherwise try to find it on the load path
353
356
  require jar
354
357
  end
355
358
  rescue LoadError => e
356
- raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar or in case there is Jars.lock then resolve the jars with `lock_jars` command\n\n" + e.message + ' (LoadError)'
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)"
357
362
  end
358
- end # class << self
363
+ end
359
364
  end
360
365
 
361
366
  def require_jar(*args, &block)
362
367
  return nil unless Jars.require?
368
+
363
369
  result = Jars.require_jar(*args, &block)
364
370
  if result.is_a? String
365
- args << (block.call || Jars::UNKNOWN) if args.size == 2 && block_given?
366
- Jars.warn { "--- jar coordinate #{args[0..-2].join(':')} already loaded with version #{result} - omit version #{args[-1]}" }
371
+ args << (yield || Jars::UNKNOWN) if args.size == 2 && block
372
+ Jars.warn do
373
+ "--- jar coordinate #{args[0..-2].join(':')} already loaded with version #{result} - omit version #{args[-1]}"
374
+ end
367
375
  Jars.debug { " try to load from #{caller.join("\n\t")}" }
368
376
  return false
369
377
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (C) 2014 Christian Meier
3
5
  #
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this file is maven DSL
2
4
 
3
- (0..10_000).each do |i|
5
+ 10_000.times do |i|
4
6
  coord = ENV_JAVA["jars.#{i}"]
5
7
  break unless coord
8
+
6
9
  artifact = Maven::Tools::Artifact.from_coordinate(coord)
7
10
  exclusions = []
8
- (0..10_000).each do |j|
11
+ 10_000.times do |j|
9
12
  exclusion = ENV_JAVA["jars.#{i}.exclusions.#{j}"]
10
13
  break unless exclusion
14
+
11
15
  exclusions << exclusion
12
16
  end
13
17
  scope = ENV_JAVA["jars.#{i}.scope"]