jar-dependencies 0.3.9 → 0.4.1
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 +4 -4
- data/Mavenfile +29 -33
- data/Rakefile +13 -13
- data/Readme.md +79 -79
- data/bin/lock_jars +17 -17
- data/jar-dependencies.gemspec +13 -15
- data/lib/jar_dependencies.rb +107 -98
- data/lib/jars/attach_jars_pom.rb +8 -8
- data/lib/jars/classpath.rb +31 -33
- data/lib/jars/gemspec_artifacts.rb +30 -38
- data/lib/jars/gemspec_pom.rb +2 -2
- data/lib/jars/installer.rb +87 -91
- data/lib/jars/lock.rb +16 -18
- data/lib/jars/lock_down.rb +38 -39
- data/lib/jars/lock_down_pom.rb +14 -11
- data/lib/jars/maven_exec.rb +32 -32
- data/lib/jars/maven_factory.rb +49 -56
- data/lib/jars/maven_settings.rb +16 -24
- data/lib/jars/output_jars_pom.rb +2 -2
- data/lib/jars/post_install_hook.rb +2 -2
- data/lib/jars/setup.rb +1 -1
- data/lib/jars/version.rb +1 -1
- metadata +19 -10
data/jar-dependencies.gemspec
CHANGED
@@ -4,41 +4,39 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'jar-dependencies'
|
5
5
|
|
6
6
|
path = File.expand_path('lib/jars/version.rb', File.dirname(__FILE__))
|
7
|
-
s.version = File.read(path).match(
|
8
|
-
|
7
|
+
s.version = File.read(path).match(/\s*VERSION\s*=\s*['"](.*)['"]/)[1]
|
8
|
+
|
9
9
|
s.author = 'christian meier'
|
10
|
-
s.email = [
|
10
|
+
s.email = ['mkristian@web.de']
|
11
11
|
s.summary = 'manage jar dependencies for gems'
|
12
12
|
s.homepage = 'https://github.com/mkristian/jar-dependencies'
|
13
13
|
|
14
|
-
s.bindir =
|
15
|
-
|
16
|
-
s.executables = [LOCK_JARS]
|
14
|
+
s.bindir = 'bin'
|
15
|
+
s.executables = [lock_jars = 'lock_jars'.freeze]
|
17
16
|
|
18
17
|
s.license = 'MIT'
|
19
18
|
|
20
|
-
s.files = `git ls-files`.split(
|
19
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR).select do |file|
|
21
20
|
file =~ /^lib\// ||
|
22
|
-
|
23
|
-
|
21
|
+
%w[Mavenfile Rakefile].include?(file) ||
|
22
|
+
['Readme.md', 'jar-dependencies.gemspec', 'MIT-LICENSE'].include?(file)
|
24
23
|
end
|
25
24
|
|
26
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.'
|
27
26
|
|
28
|
-
s.add_development_dependency 'minitest', '~> 5.
|
27
|
+
s.add_development_dependency 'minitest', '~> 5.10.0'
|
29
28
|
s.add_development_dependency 'rake', '~> 10.2'
|
30
|
-
|
31
|
-
s.add_development_dependency 'ruby-maven', RUBY_MAVEN_VERSION
|
29
|
+
s.add_development_dependency 'ruby-maven', ruby_maven_version = '~> 3.3.11'.freeze
|
32
30
|
|
33
31
|
s.post_install_message = <<EOF
|
34
32
|
|
35
|
-
if you want to use the executable #{
|
33
|
+
if you want to use the executable #{lock_jars} then install ruby-maven gem before using #{lock_jars}
|
36
34
|
|
37
|
-
|
35
|
+
$ gem install ruby-maven -v '#{ruby_maven_version}'
|
38
36
|
|
39
37
|
or add it as a development dependency to your Gemfile
|
40
38
|
|
41
|
-
gem 'ruby-maven', '#{
|
39
|
+
gem 'ruby-maven', '#{ruby_maven_version}'
|
42
40
|
|
43
41
|
EOF
|
44
42
|
end
|
data/lib/jar_dependencies.rb
CHANGED
@@ -18,7 +18,7 @@
|
|
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
|
-
|
21
|
+
|
22
22
|
module Jars
|
23
23
|
unless defined? Jars::SKIP_LOCK
|
24
24
|
MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'.freeze
|
@@ -45,45 +45,48 @@ module Jars
|
|
45
45
|
DEBUG = 'JARS_DEBUG'.freeze
|
46
46
|
# vendor jars inside gem when installing gem
|
47
47
|
VENDOR = 'JARS_VENDOR'.freeze
|
48
|
+
# string used when the version is unknown
|
49
|
+
UNKNOWN = 'unknown'
|
48
50
|
end
|
49
51
|
|
50
|
-
|
52
|
+
autoload :MavenSettings, 'jars/maven_settings'
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
+
class << self
|
55
|
+
def lock_down(debug = false, verbose = false, options = {})
|
56
|
+
ENV[SKIP_LOCK] = 'true'
|
54
57
|
require 'jars/lock_down' # do this lazy to keep things clean
|
55
|
-
Jars::LockDown.new(
|
58
|
+
Jars::LockDown.new(debug, verbose).lock_down(options)
|
56
59
|
ensure
|
57
|
-
ENV[
|
60
|
+
ENV[SKIP_LOCK] = nil
|
58
61
|
end
|
59
62
|
|
60
63
|
if defined? JRUBY_VERSION
|
61
|
-
def to_prop(
|
62
|
-
key = key.
|
63
|
-
ENV_JAVA[
|
64
|
-
ENV[
|
64
|
+
def to_prop(key)
|
65
|
+
key = key.tr('_', '.')
|
66
|
+
ENV_JAVA[(key.downcase!; key)] ||
|
67
|
+
ENV[(key.tr!('.', '_'); key.upcase!; key)]
|
65
68
|
end
|
66
69
|
else
|
67
|
-
def to_prop(
|
68
|
-
ENV[
|
70
|
+
def to_prop(key)
|
71
|
+
ENV[key.tr('.', '_').upcase]
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
def to_boolean(
|
73
|
-
return nil if (
|
75
|
+
def to_boolean(key)
|
76
|
+
return nil if (prop = to_prop(key)).nil?
|
74
77
|
prop.empty? || prop.eql?('true')
|
75
78
|
end
|
76
79
|
|
77
80
|
def skip?
|
78
|
-
to_boolean(
|
81
|
+
to_boolean(SKIP)
|
79
82
|
end
|
80
83
|
|
81
84
|
def require?
|
82
85
|
@require = nil unless instance_variable_defined?(:@require)
|
83
86
|
if @require.nil?
|
84
|
-
if (
|
85
|
-
no_require = to_boolean(
|
86
|
-
@require = no_require.nil? ? true : !
|
87
|
+
if (require = to_boolean(REQUIRE)).nil?
|
88
|
+
no_require = to_boolean(NO_REQUIRE)
|
89
|
+
@require = no_require.nil? ? true : !no_require
|
87
90
|
else
|
88
91
|
@require = require
|
89
92
|
end
|
@@ -93,26 +96,28 @@ module Jars
|
|
93
96
|
attr_writer :require
|
94
97
|
|
95
98
|
def quiet?
|
96
|
-
(
|
99
|
+
(@silent ||= false) || to_boolean(QUIET)
|
97
100
|
end
|
98
101
|
|
99
102
|
def jarfile
|
100
|
-
ENV[
|
103
|
+
ENV['JARFILE'] || ENV_JAVA['jarfile'] || ENV['JBUNDLER_JARFILE'] || ENV_JAVA['jbundler.jarfile'] || 'Jarfile'
|
101
104
|
end
|
102
105
|
|
103
106
|
# @deprecated
|
104
|
-
def no_require
|
107
|
+
def no_require?
|
108
|
+
!require?
|
109
|
+
end
|
105
110
|
|
106
111
|
def verbose?
|
107
|
-
to_boolean(
|
112
|
+
to_boolean(VERBOSE)
|
108
113
|
end
|
109
114
|
|
110
115
|
def debug?
|
111
|
-
to_boolean(
|
116
|
+
to_boolean(DEBUG)
|
112
117
|
end
|
113
118
|
|
114
119
|
def vendor?
|
115
|
-
to_boolean(
|
120
|
+
to_boolean(VENDOR)
|
116
121
|
end
|
117
122
|
|
118
123
|
def no_more_warnings
|
@@ -124,28 +129,30 @@ module Jars
|
|
124
129
|
end
|
125
130
|
|
126
131
|
def skip_lock?
|
127
|
-
to_prop(
|
132
|
+
to_prop(SKIP_LOCK) || false
|
128
133
|
end
|
129
134
|
|
130
135
|
def lock
|
131
|
-
to_prop(
|
136
|
+
to_prop(LOCK) || 'Jars.lock'
|
132
137
|
end
|
133
138
|
|
134
139
|
def jars_lock_from_class_loader
|
135
|
-
if to_prop(
|
136
|
-
JRuby.
|
137
|
-
|
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)
|
138
145
|
end
|
139
146
|
end
|
140
147
|
end
|
141
148
|
|
142
|
-
def lock_path(
|
143
|
-
deps =
|
144
|
-
return deps if File.
|
149
|
+
def lock_path(basedir = nil)
|
150
|
+
deps = lock
|
151
|
+
return deps if File.exist?(deps)
|
145
152
|
basedir ||= '.'
|
146
|
-
[
|
147
|
-
file = File.join(
|
148
|
-
return file if File.
|
153
|
+
['.', 'jars', 'vendor/jars'].each do |dir|
|
154
|
+
file = File.join(basedir, dir, lock)
|
155
|
+
return file if File.exist?(file)
|
149
156
|
end
|
150
157
|
nil
|
151
158
|
end
|
@@ -153,7 +160,7 @@ module Jars
|
|
153
160
|
def reset
|
154
161
|
instance_variables.each { |var| instance_variable_set(var, nil) }
|
155
162
|
Jars::MavenSettings.reset
|
156
|
-
(
|
163
|
+
(@@jars ||= {}).clear
|
157
164
|
end
|
158
165
|
|
159
166
|
def maven_local_settings
|
@@ -177,29 +184,28 @@ module Jars
|
|
177
184
|
detect_local_repository(maven_local_settings) ||
|
178
185
|
detect_local_repository(maven_user_settings) ||
|
179
186
|
detect_local_repository(maven_global_settings) ||
|
180
|
-
File.join(
|
187
|
+
File.join(user_home, '.m2', 'repository')
|
181
188
|
end
|
182
189
|
|
183
190
|
def home
|
184
|
-
|
191
|
+
absolute(to_prop(HOME)) || local_maven_repo
|
185
192
|
end
|
186
193
|
|
187
|
-
def require_jars_lock!(
|
194
|
+
def require_jars_lock!(scope = :runtime)
|
188
195
|
urls = jars_lock_from_class_loader
|
189
|
-
if urls
|
196
|
+
if urls && !urls.empty?
|
190
197
|
@@jars_lock = true
|
191
198
|
# funny error during spec where it tries to load it again
|
192
199
|
# and finds it as gem instead of the LOAD_PATH
|
193
200
|
require 'jars/classpath' unless defined? Jars::Classpath
|
194
201
|
done = []
|
195
|
-
while done != urls
|
202
|
+
while done != urls
|
196
203
|
urls.each do |url|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
end
|
204
|
+
next if done.member?(url)
|
205
|
+
Jars.debug { "--- load jars from uri #{url}" }
|
206
|
+
classpath = Jars::Classpath.new(nil, "uri:#{url}")
|
207
|
+
classpath.require(scope)
|
208
|
+
done << url
|
203
209
|
end
|
204
210
|
urls = jars_lock_from_class_loader
|
205
211
|
end
|
@@ -210,25 +216,25 @@ module Jars
|
|
210
216
|
# funny error during spec where it tries to load it again
|
211
217
|
# and finds it as gem instead of the LOAD_PATH
|
212
218
|
require 'jars/classpath' unless defined? Jars::Classpath
|
213
|
-
classpath = Jars::Classpath.new(
|
214
|
-
classpath.require(
|
219
|
+
classpath = Jars::Classpath.new(nil, jars_lock)
|
220
|
+
classpath.require(scope)
|
215
221
|
no_more_warnings
|
216
222
|
end
|
217
|
-
Jars.debug
|
223
|
+
Jars.debug do
|
218
224
|
@@jars ||= {}
|
219
|
-
loaded = @@jars.collect{ |k,v| "#{k}:#{v}" }
|
225
|
+
loaded = @@jars.collect { |k, v| "#{k}:#{v}" }
|
220
226
|
"--- loaded jars ---\n\t#{loaded.join("\n\t")}"
|
221
|
-
|
227
|
+
end
|
222
228
|
end
|
223
229
|
|
224
|
-
def setup(
|
230
|
+
def setup(options = nil)
|
225
231
|
case options
|
226
232
|
when Symbol
|
227
|
-
require_jars_lock!(
|
233
|
+
require_jars_lock!(options)
|
228
234
|
when Hash
|
229
235
|
@_jars_home = options[:jars_home]
|
230
236
|
@_jars_lock = options[:jars_lock]
|
231
|
-
require_jars_lock!(
|
237
|
+
require_jars_lock!(options[:scope] || :runtime)
|
232
238
|
else
|
233
239
|
require_jars_lock!
|
234
240
|
end
|
@@ -242,35 +248,41 @@ module Jars
|
|
242
248
|
end
|
243
249
|
end
|
244
250
|
|
245
|
-
def mark_as_required(
|
246
|
-
require_jar_with_block(
|
251
|
+
def mark_as_required(group_id, artifact_id, *classifier_version)
|
252
|
+
require_jar_with_block(group_id, artifact_id, *classifier_version) do
|
247
253
|
end
|
248
254
|
end
|
249
255
|
|
250
|
-
def require_jar(
|
256
|
+
def require_jar(group_id, artifact_id, *classifier_version, &block)
|
251
257
|
require_jars_lock unless skip_lock?
|
252
|
-
|
253
|
-
|
258
|
+
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
|
263
|
+
end
|
264
|
+
require_jar_with_block(group_id, artifact_id, *classifier_version) do |gid, aid, version, classifier|
|
265
|
+
do_require(gid, aid, version, classifier)
|
254
266
|
end
|
255
267
|
end
|
256
268
|
|
257
|
-
def warn(msg = nil
|
258
|
-
Kernel.warn(msg ||
|
269
|
+
def warn(msg = nil)
|
270
|
+
Kernel.warn(msg || yield) unless quiet? && !verbose?
|
259
271
|
end
|
260
272
|
|
261
|
-
def debug(msg = nil
|
262
|
-
Kernel.warn(msg ||
|
273
|
+
def debug(msg = nil)
|
274
|
+
Kernel.warn(msg || yield) if verbose?
|
263
275
|
end
|
264
276
|
|
265
|
-
def absolute(
|
266
|
-
File.expand_path(
|
277
|
+
def absolute(file)
|
278
|
+
File.expand_path(file) if file
|
267
279
|
end
|
268
280
|
|
269
281
|
def user_home
|
270
|
-
ENV[
|
282
|
+
ENV['HOME'] || begin
|
271
283
|
user_home = Dir.home if Dir.respond_to?(:home)
|
272
284
|
unless user_home
|
273
|
-
user_home = ENV_JAVA[
|
285
|
+
user_home = ENV_JAVA['user.home'] if Object.const_defined?(:ENV_JAVA)
|
274
286
|
end
|
275
287
|
user_home
|
276
288
|
end
|
@@ -278,22 +290,22 @@ module Jars
|
|
278
290
|
|
279
291
|
private
|
280
292
|
|
281
|
-
def require_jar_with_block(
|
282
|
-
version = classifier_version[
|
283
|
-
classifier = classifier_version[
|
293
|
+
def require_jar_with_block(group_id, artifact_id, *classifier_version)
|
294
|
+
version = classifier_version[-1]
|
295
|
+
classifier = classifier_version[-2]
|
284
296
|
|
285
297
|
@@jars ||= {}
|
286
298
|
coordinate = "#{group_id}:#{artifact_id}"
|
287
299
|
coordinate << ":#{classifier}" if classifier
|
288
300
|
if @@jars.key? coordinate
|
289
|
-
if @@jars[
|
301
|
+
if @@jars[coordinate] == version
|
290
302
|
false
|
291
303
|
else
|
292
|
-
@@jars[
|
304
|
+
@@jars[coordinate] # version of already registered jar
|
293
305
|
end
|
294
306
|
else
|
295
307
|
yield group_id, artifact_id, version, classifier
|
296
|
-
@@jars[
|
308
|
+
@@jars[coordinate] = version
|
297
309
|
return true
|
298
310
|
end
|
299
311
|
end
|
@@ -301,60 +313,57 @@ module Jars
|
|
301
313
|
def detect_local_repository(settings)
|
302
314
|
return nil unless settings
|
303
315
|
|
304
|
-
doc = File.read(
|
305
|
-
# TODO filter out xml comments
|
306
|
-
local_repo = doc.sub(
|
316
|
+
doc = File.read(settings)
|
317
|
+
# TODO: filter out xml comments
|
318
|
+
local_repo = doc.sub(/<\/localRepository>.*/m, '').sub(/.*<localRepository>/m, '')
|
307
319
|
# replace maven like system properties embedded into the string
|
308
|
-
local_repo.gsub!(
|
309
|
-
ENV_JAVA[
|
310
|
-
end
|
311
|
-
if local_repo.empty? or not File.exists?( local_repo )
|
312
|
-
local_repo = nil
|
320
|
+
local_repo.gsub!(/\$\{[a-zA-Z.]+\}/) do |a|
|
321
|
+
ENV_JAVA[a[2..-2]] || a
|
313
322
|
end
|
323
|
+
local_repo = nil if local_repo.empty? || !File.exist?(local_repo)
|
314
324
|
local_repo
|
315
325
|
rescue
|
316
326
|
Jars.warn { "error reading or parsing #{settings}" }
|
317
327
|
nil
|
318
328
|
end
|
319
329
|
|
320
|
-
def to_jar(
|
321
|
-
file = String.new("#{group_id.
|
330
|
+
def to_jar(group_id, artifact_id, version, classifier = nil)
|
331
|
+
file = String.new("#{group_id.tr('.', '/')}/#{artifact_id}/#{version}/#{artifact_id}-#{version}")
|
322
332
|
file << "-#{classifier}" if classifier
|
323
333
|
file << '.jar'
|
324
334
|
file
|
325
335
|
end
|
326
336
|
|
327
|
-
def do_require(
|
328
|
-
jar = to_jar(
|
329
|
-
local = File.join(
|
330
|
-
vendor = File.join(
|
331
|
-
file = File.join(
|
337
|
+
def do_require(*args)
|
338
|
+
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)
|
332
342
|
# use jar from local repository if exists
|
333
|
-
if File.
|
343
|
+
if File.exist?(file)
|
334
344
|
require file
|
335
345
|
# use jar from PWD/jars if exists
|
336
|
-
elsif File.
|
346
|
+
elsif File.exist?(local)
|
337
347
|
require local
|
338
348
|
# use jar from PWD/vendor/jars if exists
|
339
|
-
elsif File.
|
349
|
+
elsif File.exist?(vendor)
|
340
350
|
require vendor
|
341
351
|
else
|
342
352
|
# otherwise try to find it on the load path
|
343
353
|
require jar
|
344
354
|
end
|
345
355
|
rescue LoadError => e
|
346
|
-
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 +
|
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)'
|
347
357
|
end
|
348
|
-
|
349
358
|
end # class << self
|
350
|
-
|
351
359
|
end
|
352
360
|
|
353
|
-
def require_jar(
|
361
|
+
def require_jar(*args, &block)
|
354
362
|
return nil unless Jars.require?
|
355
|
-
result = Jars.require_jar(
|
363
|
+
result = Jars.require_jar(*args, &block)
|
356
364
|
if result.is_a? String
|
357
|
-
|
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]}" }
|
358
367
|
Jars.debug { " try to load from #{caller.join("\n\t")}" }
|
359
368
|
return false
|
360
369
|
end
|
data/lib/jars/attach_jars_pom.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# this file is maven DSL
|
2
2
|
|
3
|
-
(
|
4
|
-
coord = ENV_JAVA[
|
3
|
+
(0..10_000).each do |i|
|
4
|
+
coord = ENV_JAVA["jars.#{i}"]
|
5
5
|
break unless coord
|
6
|
-
artifact = Maven::Tools::Artifact.from_coordinate(
|
6
|
+
artifact = Maven::Tools::Artifact.from_coordinate(coord)
|
7
7
|
exclusions = []
|
8
|
-
(
|
9
|
-
exclusion = ENV_JAVA[
|
8
|
+
(0..10_000).each do |j|
|
9
|
+
exclusion = ENV_JAVA["jars.#{i}.exclusions.#{j}"]
|
10
10
|
break unless exclusion
|
11
11
|
exclusions << exclusion
|
12
12
|
end
|
13
|
-
scope = ENV_JAVA[
|
13
|
+
scope = ENV_JAVA["jars.#{i}.scope"]
|
14
14
|
artifact.scope = scope if scope
|
15
|
-
classifier = ENV_JAVA[
|
15
|
+
classifier = ENV_JAVA["jars.#{i}.classifier"]
|
16
16
|
artifact.classifier = classifier if classifier
|
17
17
|
|
18
18
|
# declare the artifact inside the POM
|
19
|
-
dependency_artifact(
|
19
|
+
dependency_artifact(artifact) do
|
20
20
|
exclusions.each do |ex|
|
21
21
|
exclusion ex
|
22
22
|
end
|