jar-dependencies 0.5.7 → 0.6.0.pre2
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 +16 -27
- data/Rakefile +51 -2
- data/Readme.md +6 -11
- data/jar-dependencies.gemspec +4 -13
- data/lib/jar_dependencies.rb +56 -49
- data/lib/jars/gemspec_artifacts.rb +10 -10
- data/lib/jars/installer.rb +11 -13
- data/lib/jars/lock.rb +1 -1
- data/lib/jars/lock_down.rb +90 -59
- data/lib/jars/maven_exec.rb +23 -25
- data/lib/jars/maven_settings.rb +2 -70
- data/lib/jars/mima/context-2.4.42.jar +0 -0
- data/lib/jars/mima/jcl-over-slf4j-2.0.17.jar +0 -0
- data/lib/jars/mima/slf4j-api-2.0.17.jar +0 -0
- data/lib/jars/mima/slf4j-simple-2.0.17.jar +0 -0
- data/lib/jars/mima/standalone-static-uber-2.4.42.jar +0 -0
- data/lib/jars/mima/version.rb +42 -0
- data/lib/jars/mima.rb +262 -0
- data/lib/jars/post_install_hook.rb +0 -1
- data/lib/jars/version.rb +1 -3
- metadata +16 -36
- data/lib/jars/attach_jars_pom.rb +0 -28
- data/lib/jars/gemspec_pom.rb +0 -11
- data/lib/jars/lock_down_pom.rb +0 -35
- data/lib/jars/maven_factory.rb +0 -132
- data/lib/jars/output_jars_pom.rb +0 -16
- data/lib/jars/settings.xml +0 -20
data/lib/jars/lock_down.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
33
|
-
@maven ||= maven_new
|
|
34
|
-
end
|
|
17
|
+
attach_jar_coordinates_from_bundler_dependencies(artifacts, done)
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
|
|
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(
|
|
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.
|
|
48
|
-
# if gemspec is local then include all dependencies
|
|
49
|
-
|
|
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
|
-
|
|
56
|
+
# bundler is available, but there is no Gemfile to inspect
|
|
58
57
|
rescue Bundler::GemNotFound
|
|
59
|
-
warn "
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
data/lib/jars/maven_exec.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'jar_dependencies'
|
|
4
|
-
require 'jars/
|
|
4
|
+
require 'jars/gemspec_artifacts'
|
|
5
5
|
|
|
6
6
|
module Jars
|
|
7
7
|
class MavenExec
|
|
@@ -13,7 +13,7 @@ module Jars
|
|
|
13
13
|
when 1
|
|
14
14
|
specs.first
|
|
15
15
|
else
|
|
16
|
-
raise 'more
|
|
16
|
+
raise 'more than one gemspec found; please specify a specfile' unless allow_no_file
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
private :find_spec
|
|
@@ -21,12 +21,10 @@ module Jars
|
|
|
21
21
|
attr_reader :basedir, :spec, :specfile
|
|
22
22
|
|
|
23
23
|
def initialize(spec = nil)
|
|
24
|
-
@options = {}
|
|
25
24
|
setup(spec)
|
|
26
25
|
rescue StandardError, LoadError => e
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
warn e.backtrace.join("\n") if Jars.verbose?
|
|
26
|
+
Jars.warn "unable to load gemspec (#{e.message}); skipping jar dependency discovery"
|
|
27
|
+
Jars.debug(e)
|
|
30
28
|
end
|
|
31
29
|
|
|
32
30
|
def setup(spec = nil, allow_no_file: false)
|
|
@@ -45,8 +43,7 @@ module Jars
|
|
|
45
43
|
@specfile = spec.loaded_from
|
|
46
44
|
else
|
|
47
45
|
# this happens with bundle and local gems
|
|
48
|
-
# there
|
|
49
|
-
# the gem_dir directory
|
|
46
|
+
# there spec_file is "not installed" but is inside the gem_dir directory
|
|
50
47
|
Dir.chdir(spec.gem_dir) do
|
|
51
48
|
setup(nil, allow_no_file: true)
|
|
52
49
|
end
|
|
@@ -54,32 +51,33 @@ module Jars
|
|
|
54
51
|
when nil
|
|
55
52
|
# ignore
|
|
56
53
|
else
|
|
57
|
-
Jars.debug
|
|
58
|
-
'File an issue on github if you need it.')
|
|
54
|
+
Jars.debug "unsupported spec argument #{spec.class}; expected String or Gem::Specification"
|
|
59
55
|
end
|
|
60
56
|
@spec = spec
|
|
61
57
|
end
|
|
62
58
|
|
|
63
|
-
def ruby_maven_install_options=(options)
|
|
64
|
-
@options = options
|
|
65
|
-
end
|
|
66
|
-
|
|
67
59
|
def resolve_dependencies_list(file)
|
|
68
|
-
|
|
69
|
-
maven = factory.maven_new(File.expand_path('gemspec_pom.rb', __dir__))
|
|
60
|
+
require 'jars/mima'
|
|
70
61
|
|
|
62
|
+
artifacts = GemspecArtifacts.new(@spec)
|
|
71
63
|
is_local_file = File.expand_path(File.dirname(@specfile)) == File.expand_path(Dir.pwd)
|
|
72
|
-
maven.attach_jars(@spec, all_dependencies: is_local_file)
|
|
73
64
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
resolved = Jars::Mima.resolve_artifacts(artifacts.artifacts, all_dependencies: is_local_file)
|
|
66
|
+
|
|
67
|
+
# Write output in Maven dependency:list format for Installer::Dependency compatibility
|
|
68
|
+
allowed_types = %w[jar pom].freeze
|
|
69
|
+
File.open(file, 'w') do |f|
|
|
70
|
+
f.puts
|
|
71
|
+
f.puts 'The following files have been resolved:'
|
|
72
|
+
resolved.each do |dep|
|
|
73
|
+
next unless allowed_types.include?(dep.type)
|
|
81
74
|
|
|
82
|
-
|
|
75
|
+
line = +" #{dep.group_id}:#{dep.artifact_id}:#{dep.type}:"
|
|
76
|
+
line << "#{dep.classifier}:" if dep.classifier
|
|
77
|
+
line << "#{dep.version}:#{dep.scope}:#{dep.file}"
|
|
78
|
+
f.puts line
|
|
79
|
+
end
|
|
80
|
+
end
|
|
83
81
|
end
|
|
84
82
|
end
|
|
85
83
|
end
|
data/lib/jars/maven_settings.rb
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
module Jars
|
|
4
4
|
class MavenSettings
|
|
5
|
-
LINE_SEPARATOR = ENV_JAVA['line.separator']
|
|
6
|
-
|
|
7
5
|
class << self
|
|
8
6
|
def local_settings
|
|
9
7
|
@_jars_maven_local_settings_ = nil unless instance_variable_defined?(:@_jars_maven_local_settings_)
|
|
@@ -36,36 +34,6 @@ module Jars
|
|
|
36
34
|
@_jars_maven_user_settings_ || nil
|
|
37
35
|
end
|
|
38
36
|
|
|
39
|
-
def effective_settings
|
|
40
|
-
@_jars_effective_maven_settings_ = nil unless instance_variable_defined?(:@_jars_effective_maven_settings_)
|
|
41
|
-
if @_jars_effective_maven_settings_.nil?
|
|
42
|
-
begin
|
|
43
|
-
require 'rubygems/request'
|
|
44
|
-
|
|
45
|
-
http = Gem::Request.proxy_uri(Gem.configuration[:http_proxy] || Gem::Request.get_proxy_from_env('http'))
|
|
46
|
-
https = Gem::Request.proxy_uri(Gem.configuration[:https_proxy] || Gem::Request.get_proxy_from_env('https'))
|
|
47
|
-
rescue
|
|
48
|
-
Jars.debug('ignore rubygems proxy configuration as rubygems is too old')
|
|
49
|
-
end
|
|
50
|
-
@_jars_effective_maven_settings_ = if http.nil? && https.nil?
|
|
51
|
-
settings
|
|
52
|
-
else
|
|
53
|
-
setup_interpolated_settings(http, https) || settings
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
@_jars_effective_maven_settings_
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def cleanup
|
|
60
|
-
File.unlink(effective_settings) if effective_settings != settings
|
|
61
|
-
ensure
|
|
62
|
-
reset
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def reset
|
|
66
|
-
instance_variables.each { |var| instance_variable_set(var, nil) }
|
|
67
|
-
end
|
|
68
|
-
|
|
69
37
|
def settings
|
|
70
38
|
@_jars_maven_settings_ = nil unless instance_variable_defined?(:@_jars_maven_settings_)
|
|
71
39
|
local_settings || user_settings if @_jars_maven_settings_.nil?
|
|
@@ -85,44 +53,8 @@ module Jars
|
|
|
85
53
|
@_jars_maven_global_settings_ || nil
|
|
86
54
|
end
|
|
87
55
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def setup_interpolated_settings(http, https)
|
|
91
|
-
proxy = raw_proxy_settings_xml(http, https).gsub("\n", LINE_SEPARATOR)
|
|
92
|
-
if settings.nil?
|
|
93
|
-
raw = "<settings>#{LINE_SEPARATOR}#{proxy}</settings>"
|
|
94
|
-
else
|
|
95
|
-
raw = File.read(settings)
|
|
96
|
-
if raw.include?('<proxy>')
|
|
97
|
-
Jars.warn("can not interpolated proxy info for #{settings}")
|
|
98
|
-
return
|
|
99
|
-
else
|
|
100
|
-
raw.sub!('<settings>', "<settings>#{LINE_SEPARATOR}#{proxy}")
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
tempfile = java.io.File.create_temp_file('settings', '.xml')
|
|
104
|
-
tempfile.delete_on_exit
|
|
105
|
-
File.write(tempfile.path, raw)
|
|
106
|
-
tempfile.path
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def raw_proxy_settings_xml(http, https)
|
|
110
|
-
raw = File.read(File.join(File.dirname(__FILE__), 'settings.xml'))
|
|
111
|
-
if http
|
|
112
|
-
raw.sub!('__HTTP_ACTIVE__', 'true')
|
|
113
|
-
raw.sub!('__HTTP_SERVER__', http.host)
|
|
114
|
-
raw.sub!('__HTTP_PORT__', http.port.to_s)
|
|
115
|
-
else
|
|
116
|
-
raw.sub!('__HTTP_ACTIVE__', 'false')
|
|
117
|
-
end
|
|
118
|
-
if https
|
|
119
|
-
raw.sub!('__HTTPS_ACTIVE__', 'true')
|
|
120
|
-
raw.sub!('__HTTPS_SERVER__', https.host)
|
|
121
|
-
raw.sub!('__HTTPS_PORT__', https.port.to_s)
|
|
122
|
-
else
|
|
123
|
-
raw.sub!('__HTTPS_ACTIVE__', 'false')
|
|
124
|
-
end
|
|
125
|
-
raw
|
|
56
|
+
def reset
|
|
57
|
+
instance_variables.each { |var| instance_variable_set(var, nil) }
|
|
126
58
|
end
|
|
127
59
|
end
|
|
128
60
|
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jars
|
|
4
|
+
module Mima
|
|
5
|
+
MIMA_VERSION = '2.4.42'
|
|
6
|
+
SLF4J_VERSION = '2.0.17'
|
|
7
|
+
|
|
8
|
+
MAVEN_CENTRAL = 'https://repo.maven.apache.org/maven2'
|
|
9
|
+
MIMA_DIR = 'lib/jars/mima'
|
|
10
|
+
|
|
11
|
+
# GAV and SHA-1 checksum (as published on Maven Central) for each jar
|
|
12
|
+
jars = %w[
|
|
13
|
+
org.slf4j:slf4j-api:2.0.17
|
|
14
|
+
d9e58ac9c7779ba3bf8142aff6c830617a7fe60f
|
|
15
|
+
|
|
16
|
+
org.slf4j:slf4j-simple:2.0.17
|
|
17
|
+
9872a3fd794ffe7b18d17747926a64d61526ca96
|
|
18
|
+
|
|
19
|
+
org.slf4j:jcl-over-slf4j:2.0.17
|
|
20
|
+
76ea503eb688f06556a9ba69995d7eab63e34531
|
|
21
|
+
|
|
22
|
+
eu.maveniverse.maven.mima:context:2.4.42
|
|
23
|
+
72aa4d9ccef7a329f473e43752ec863c5194c72c
|
|
24
|
+
|
|
25
|
+
eu.maveniverse.maven.mima.runtime:standalone-static-uber:2.4.42
|
|
26
|
+
43666099e6eb31610f9d3b146811479dd3e4aef1
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
JARS = jars.each_slice(2).to_h do |gav, sha1|
|
|
30
|
+
group, artifact, version = gav.split(':')
|
|
31
|
+
group = group.tr('.', '/')
|
|
32
|
+
jar_file = "#{artifact}-#{version}.jar"
|
|
33
|
+
[
|
|
34
|
+
jar_file,
|
|
35
|
+
{
|
|
36
|
+
url: "#{MAVEN_CENTRAL}/#{group}/#{artifact}/#{version}/#{jar_file}",
|
|
37
|
+
sha1: sha1
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|