jar-dependencies 0.4.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Mavenfile +6 -10
- data/Rakefile +6 -22
- data/Readme.md +7 -2
- data/{bin → exe}/lock_jars +7 -2
- data/jar-dependencies.gemspec +25 -25
- data/lib/jar-dependencies.rb +2 -0
- data/lib/jar_dependencies.rb +107 -99
- data/lib/jar_install_post_install_hook.rb +2 -0
- data/lib/jars/attach_jars_pom.rb +6 -2
- data/lib/jars/classpath.rb +8 -10
- data/lib/jars/gemspec_artifacts.rb +62 -56
- data/lib/jars/gemspec_pom.rb +8 -2
- data/lib/jars/installer.rb +49 -70
- data/lib/jars/lock.rb +10 -7
- data/lib/jars/lock_down.rb +21 -29
- data/lib/jars/lock_down_pom.rb +9 -4
- data/lib/jars/maven_exec.rb +13 -10
- data/lib/jars/maven_factory.rb +12 -13
- data/lib/jars/maven_settings.rb +21 -27
- data/lib/jars/output_jars_pom.rb +10 -2
- data/lib/jars/post_install_hook.rb +3 -1
- data/lib/jars/setup.rb +2 -0
- data/lib/jars/version.rb +5 -3
- data/lib/rubygems_plugin.rb +2 -0
- metadata +23 -50
- data/lib/jar_installer.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b63d6263197117be1ee5707243d41f077b2b98ad7911d79a34cbd11fc09d738d
|
4
|
+
data.tar.gz: c953c86b1031a278021411fe5a1b7d5d7466db90a0708815bc694d4c4ce9286c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed1812b1173946a18db5448789ad943976eb7d00c791770e718127549e3c7a204620bd3fc3532bb1332d681cb8d85a2f166140750cbe37b9fc3f5a1fc2ea9d12
|
7
|
+
data.tar.gz: 297efd1bc555b7b1e3d823ea829aa94b4891f2b1e8e134d020a9c42f3e25a31c49cc33bf09ea241d10b1136ce29ba2842c9973b71614f5809ed0b2364c1089b5
|
data/Mavenfile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
gemfile
|
4
4
|
|
5
|
-
plugin_repository id: :
|
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' => ['
|
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' => '
|
22
|
+
'bundler.version' => '2.5.11',
|
24
23
|
'ruby-maven.version' => ruby_maven.version,
|
25
|
-
'jruby.version' => '9.
|
26
|
-
'jruby.plugins.version' => '
|
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
|
-
|
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::
|
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.
|
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
|
data/{bin → exe}/lock_jars
RENAMED
@@ -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',
|
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.'
|
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
|
|
data/jar-dependencies.gemspec
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
|
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
|
-
|
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 = '
|
15
|
-
|
16
|
-
s.executables = [LOCK_JARS]
|
15
|
+
s.bindir = 'exe'
|
16
|
+
s.executables = [lock_jars = 'lock_jars']
|
17
17
|
|
18
18
|
s.license = 'MIT'
|
19
19
|
|
20
|
-
s.files =
|
21
|
-
file =~ /^lib\// ||
|
22
|
-
%w[Mavenfile Rakefile].include?(file) ||
|
23
|
-
['Readme.md', 'jar-dependencies.gemspec', 'MIT-LICENSE'].include?(file)
|
24
|
-
end
|
20
|
+
s.files = Dir['{lib}/**/*'] + %w[Mavenfile Rakefile Readme.md jar-dependencies.gemspec MIT-LICENSE]
|
25
21
|
|
26
|
-
s.description =
|
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
|
27
29
|
|
28
|
-
s.
|
29
|
-
s.add_development_dependency 'pry'
|
30
|
-
s.add_development_dependency 'rake', '~> 10.2'
|
31
|
-
RUBY_MAVEN_VERSION = '~> 3.3.11'.freeze
|
32
|
-
s.add_development_dependency 'ruby-maven', RUBY_MAVEN_VERSION
|
30
|
+
s.required_ruby_version = '>= 2.6'
|
33
31
|
|
34
|
-
s.
|
32
|
+
s.add_development_dependency 'minitest', '~> 5.10'
|
33
|
+
s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.9'
|
35
34
|
|
36
|
-
|
35
|
+
s.post_install_message = <<~TEXT
|
37
36
|
|
38
|
-
|
37
|
+
if you want to use the executable #{lock_jars} then install ruby-maven gem before using #{lock_jars}
|
39
38
|
|
40
|
-
|
39
|
+
$ gem install ruby-maven -v '#{ruby_maven_version}'
|
41
40
|
|
42
|
-
|
41
|
+
or add it as a development dependency to your Gemfile
|
43
42
|
|
44
|
-
|
45
|
-
end
|
43
|
+
gem 'ruby-maven', '#{ruby_maven_version}'
|
46
44
|
|
47
|
-
|
45
|
+
TEXT
|
46
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
47
|
+
end
|
data/lib/jar-dependencies.rb
CHANGED
data/lib/jar_dependencies.rb
CHANGED
@@ -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'
|
25
|
-
LOCAL_MAVEN_REPO = 'JARS_LOCAL_MAVEN_REPO'
|
26
|
+
MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'
|
27
|
+
LOCAL_MAVEN_REPO = 'JARS_LOCAL_MAVEN_REPO'
|
26
28
|
# lock file to use
|
27
|
-
LOCK = 'JARS_LOCK'
|
29
|
+
LOCK = 'JARS_LOCK'
|
28
30
|
# where the locally stored jars are search for or stored
|
29
|
-
HOME = 'JARS_HOME'
|
31
|
+
HOME = 'JARS_HOME'
|
30
32
|
# skip the gem post install hook
|
31
|
-
SKIP = 'JARS_SKIP'
|
33
|
+
SKIP = 'JARS_SKIP'
|
32
34
|
# skip Jars.lock mainly to run lock_jars
|
33
|
-
SKIP_LOCK = 'JARS_SKIP_LOCK'
|
35
|
+
SKIP_LOCK = 'JARS_SKIP_LOCK'
|
34
36
|
# do not require any jars if set to false
|
35
|
-
REQUIRE = 'JARS_REQUIRE'
|
37
|
+
REQUIRE = 'JARS_REQUIRE'
|
36
38
|
# @private
|
37
|
-
NO_REQUIRE = 'JARS_NO_REQUIRE'
|
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'
|
43
|
+
QUIET = 'JARS_QUIET'
|
42
44
|
# show maven output
|
43
|
-
VERBOSE = 'JARS_VERBOSE'
|
45
|
+
VERBOSE = 'JARS_VERBOSE'
|
44
46
|
# maven debug
|
45
|
-
DEBUG = 'JARS_DEBUG'
|
47
|
+
DEBUG = 'JARS_DEBUG'
|
46
48
|
# vendor jars inside gem when installing gem
|
47
|
-
VENDOR = 'JARS_VENDOR'
|
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
|
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(
|
64
|
+
Jars::LockDown.new(debug, verbose).lock_down(**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
|
67
|
-
|
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
|
-
|
108
|
+
@quiet = to_boolean(QUIET) if @quiet.nil?
|
109
|
+
@quiet
|
100
110
|
end
|
101
111
|
|
102
|
-
def
|
103
|
-
|
112
|
+
def no_more_warnings
|
113
|
+
@quiet = true
|
104
114
|
end
|
105
115
|
|
106
|
-
|
107
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
151
|
-
|
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
|
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
|
-
|
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
|
-
@
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
-
|
198
|
-
|
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
|
-
|
216
|
-
|
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
|
-
|
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
|
-
@
|
236
|
-
@
|
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
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
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
|
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 = [
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
298
|
-
coordinate = "#{group_id}:#{artifact_id}"
|
303
|
+
coordinate = +"#{group_id}:#{artifact_id}"
|
299
304
|
coordinate << ":#{classifier}" if classifier
|
300
|
-
if
|
301
|
-
if
|
305
|
+
if @jars.key? coordinate
|
306
|
+
if @jars[coordinate] == version
|
302
307
|
false
|
303
308
|
else
|
304
|
-
|
309
|
+
@jars[coordinate] # version of already registered jar
|
305
310
|
end
|
306
311
|
else
|
307
312
|
yield group_id, artifact_id, version, classifier
|
308
|
-
|
309
|
-
|
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(
|
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.
|
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 =
|
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
|
-
|
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
|
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
|
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 << (
|
366
|
-
Jars.warn
|
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
|
data/lib/jars/attach_jars_pom.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# this file is maven DSL
|
2
4
|
|
3
|
-
|
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
|
-
|
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"]
|