jar-dependencies 0.4.1 → 0.5.0
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 -22
- data/lib/jar-dependencies.rb +2 -0
- data/lib/jar_dependencies.rb +91 -84
- 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 +50 -71
- 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 +11 -8
- 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 +21 -34
- data/lib/jar_installer.rb +0 -1
@@ -1,58 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Jars
|
2
4
|
class MavenVersion < String
|
3
|
-
|
4
|
-
|
5
|
-
nil
|
6
|
-
|
7
|
-
low, high = convert(args[0])
|
8
|
-
low, high = convert(args[1], low, high) if args[1] =~ /[=~><]/
|
9
|
-
if low == high
|
10
|
-
low
|
5
|
+
class << self
|
6
|
+
def new(*args)
|
7
|
+
if args.empty? || (args.size == 1 && args[0].nil?)
|
8
|
+
nil
|
11
9
|
else
|
12
|
-
|
10
|
+
low, high = convert(args[0])
|
11
|
+
low, high = convert(args[1], low, high) if /[=~><]/.match?(args[1])
|
12
|
+
if low == high
|
13
|
+
low
|
14
|
+
else
|
15
|
+
super "#{low || '[0'},#{high || ')'}"
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
20
|
+
private
|
21
|
+
|
22
|
+
def convert(arg, low = nil, high = nil)
|
23
|
+
if arg.include?('~>')
|
24
|
+
val = arg.sub(/~>\s*/, '')
|
25
|
+
last = val.include?('.') ? val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999') : '99999'
|
26
|
+
["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"]
|
27
|
+
elsif arg.include?('>=')
|
28
|
+
val = arg.sub(/>=\s*/, '')
|
29
|
+
["[#{snapshot_version(val)}", (nil || high)]
|
30
|
+
elsif arg.include?('<=')
|
31
|
+
val = arg.sub(/<=\s*/, '')
|
32
|
+
[(nil || low), "#{snapshot_version(val)}]"]
|
33
|
+
# treat '!' the same way as '>' since maven can not describe such range
|
34
|
+
elsif /[!>]/.match?(arg)
|
35
|
+
val = arg.sub(/[!>]\s*/, '')
|
36
|
+
["(#{snapshot_version(val)}", (nil || high)]
|
37
|
+
elsif arg.include?('<')
|
38
|
+
val = arg.sub(/<\s*/, '')
|
39
|
+
[(nil || low), "#{snapshot_version(val)})"]
|
40
|
+
elsif arg.include?('=')
|
41
|
+
val = arg.sub(/=\s*/, '')
|
42
|
+
# for prereleased version pick the maven version (no version range)
|
43
|
+
if /[a-z]|[A-Z]/.match?(val)
|
44
|
+
[val, val]
|
45
|
+
else
|
46
|
+
["[#{val}", "#{val}.0.0.0.0.1)"]
|
47
|
+
end
|
42
48
|
else
|
43
|
-
|
49
|
+
# no conversion here, i.e. assume maven version
|
50
|
+
[arg, arg]
|
44
51
|
end
|
45
|
-
else
|
46
|
-
# no conversion here, i.e. assume maven version
|
47
|
-
[arg, arg]
|
48
52
|
end
|
49
|
-
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
def snapshot_version(val)
|
55
|
+
if val.match(/[a-z]|[A-Z]/) && !val.match(/-SNAPSHOT|[${}]/)
|
56
|
+
"#{val}-SNAPSHOT"
|
57
|
+
else
|
58
|
+
val
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
@@ -79,7 +83,7 @@ module Jars
|
|
79
83
|
def initialize(line)
|
80
84
|
super()
|
81
85
|
line.gsub(/'"|^\s*\[|\]\s*$/, '').split(/,\s*/).each do |exclusion|
|
82
|
-
self
|
86
|
+
self << Exclusion.new(exclusion)
|
83
87
|
end
|
84
88
|
freeze
|
85
89
|
end
|
@@ -93,7 +97,7 @@ module Jars
|
|
93
97
|
def initialize(options, *args)
|
94
98
|
@type, @group_id, @artifact_id, @classifier, @version, @exclusions = *args
|
95
99
|
options.each do |k, v|
|
96
|
-
instance_variable_set("@#{k}", v)
|
100
|
+
instance_variable_set(:"@#{k}", v)
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
@@ -101,9 +105,11 @@ module Jars
|
|
101
105
|
line = line.strip
|
102
106
|
index = line.index(/\s/)
|
103
107
|
return nil if index.nil?
|
108
|
+
|
104
109
|
type = line[0..index].strip
|
105
110
|
return nil unless ALLOWED_TYPES.member?(type)
|
106
|
-
|
111
|
+
|
112
|
+
line = line[index..]
|
107
113
|
line.gsub!(/['"]/, '')
|
108
114
|
line.strip!
|
109
115
|
|
@@ -118,20 +124,20 @@ module Jars
|
|
118
124
|
end
|
119
125
|
exclusions = nil
|
120
126
|
line.sub!(/[,:]\s*\[(.+:.+,?\s*)+\]$/) do |a|
|
121
|
-
exclusions = Exclusions.new(a[1
|
127
|
+
exclusions = Exclusions.new(a[1..].strip)
|
122
128
|
''
|
123
129
|
end
|
124
130
|
|
125
131
|
line.strip!
|
126
132
|
line.gsub!(/,\s*/, ':')
|
127
133
|
|
128
|
-
if
|
129
|
-
index = line.index(/[\[
|
130
|
-
version = line[index
|
134
|
+
if /[\[()\]]/.match?(line)
|
135
|
+
index = line.index(/[\[(].+$/)
|
136
|
+
version = line[index..].sub(/:/, ', ')
|
131
137
|
line = line[0..index - 1].strip.sub(/:$/, '')
|
132
138
|
else
|
133
|
-
index = line.index(
|
134
|
-
version = line[index + 1
|
139
|
+
index = line.index(/:[^:]+$/)
|
140
|
+
version = line[index + 1..]
|
135
141
|
line = line[0..index - 1].strip
|
136
142
|
end
|
137
143
|
|
@@ -153,7 +159,7 @@ module Jars
|
|
153
159
|
args << @classifier if @classifier
|
154
160
|
args << @version
|
155
161
|
args << @exclusions.to_s if @exclusions
|
156
|
-
"#{@type} #{group_id}:#{args[1
|
162
|
+
"#{@type} #{group_id}:#{args[1..].join(', ')}"
|
157
163
|
end
|
158
164
|
|
159
165
|
def to_gacv
|
@@ -190,7 +196,7 @@ module Jars
|
|
190
196
|
def initialize(spec)
|
191
197
|
@artifacts = []
|
192
198
|
spec.requirements.each do |req|
|
193
|
-
req.split(
|
199
|
+
req.split("\n").each do |line|
|
194
200
|
if (a = Artifact.new(line))
|
195
201
|
@artifacts << a
|
196
202
|
end
|
data/lib/jars/gemspec_pom.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# this file is maven DSL and used by maven via jars/maven_exec.rb
|
2
4
|
|
3
|
-
|
5
|
+
def eval_file(file)
|
6
|
+
file = File.join(__dir__, file)
|
7
|
+
eval(File.read(file), nil, file) # rubocop:disable Security/Eval
|
8
|
+
end
|
4
9
|
|
5
|
-
|
10
|
+
eval_file('attach_jars_pom.rb')
|
11
|
+
eval_file('output_jars_pom.rb')
|
data/lib/jars/installer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'jar_dependencies'
|
2
4
|
require 'jars/maven_exec'
|
3
5
|
|
@@ -7,7 +9,7 @@ module Jars
|
|
7
9
|
attr_reader :path, :file, :gav, :scope, :type, :coord
|
8
10
|
|
9
11
|
def self.new(line)
|
10
|
-
super if
|
12
|
+
super if /:jar:|:pom:/.match?(line)
|
11
13
|
end
|
12
14
|
|
13
15
|
def setup_type(line)
|
@@ -32,21 +34,21 @@ module Jars
|
|
32
34
|
end
|
33
35
|
private :setup_scope
|
34
36
|
|
35
|
-
REG = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system
|
36
|
-
EMPTY = ''
|
37
|
+
REG = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/.freeze
|
38
|
+
EMPTY = ''
|
37
39
|
def initialize(line)
|
38
40
|
setup_type(line)
|
39
41
|
|
40
42
|
line.strip!
|
41
43
|
@coord = line.sub(/:[^:]+:([A-Z]:\\)?[^:]+$/, EMPTY)
|
42
44
|
first, second = @coord.split(/:#{type}:/)
|
43
|
-
group_id, artifact_id = first.split(
|
45
|
+
group_id, artifact_id = first.split(':')
|
44
46
|
parts = group_id.split('.')
|
45
47
|
parts << artifact_id
|
46
48
|
parts << second.split(':')[-1]
|
47
49
|
@file = line.slice(@coord.length, line.length).sub(REG, EMPTY).strip
|
48
|
-
last = @file.reverse.index(
|
49
|
-
parts << line[-last
|
50
|
+
last = @file.reverse.index(%r{\\|/})
|
51
|
+
parts << line[-last..]
|
50
52
|
@path = File.join(parts).strip
|
51
53
|
|
52
54
|
setup_scope(line)
|
@@ -60,8 +62,8 @@ module Jars
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
def self.install_jars(write_require_file
|
64
|
-
new.install_jars(write_require_file)
|
65
|
+
def self.install_jars(write_require_file: false)
|
66
|
+
new.install_jars(write_require_file: write_require_file)
|
65
67
|
end
|
66
68
|
|
67
69
|
def self.load_from_maven(file)
|
@@ -73,76 +75,53 @@ module Jars
|
|
73
75
|
result
|
74
76
|
end
|
75
77
|
|
76
|
-
def self.write_require_file(require_filename)
|
77
|
-
warn 'deprecated'
|
78
|
-
if needs_to_write?(require_filename)
|
79
|
-
FileUtils.mkdir_p(File.dirname(require_filename))
|
80
|
-
f = File.open(require_filename, 'w')
|
81
|
-
f.puts COMMENT
|
82
|
-
f.puts "require 'jar_dependencies'"
|
83
|
-
f.puts
|
84
|
-
f
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
78
|
def self.vendor_file(dir, dep)
|
89
|
-
|
90
|
-
vendored = File.join(dir, dep.path)
|
91
|
-
FileUtils.mkdir_p(File.dirname(vendored))
|
92
|
-
FileUtils.cp(dep.file, vendored)
|
93
|
-
end
|
94
|
-
end
|
79
|
+
return unless !dep.system? && dep.type == :jar && dep.scope == :runtime
|
95
80
|
|
96
|
-
|
97
|
-
|
98
|
-
|
81
|
+
vendored = File.join(dir, dep.path)
|
82
|
+
FileUtils.mkdir_p(File.dirname(vendored))
|
83
|
+
FileUtils.cp(dep.file, vendored)
|
99
84
|
end
|
100
85
|
|
101
|
-
def self.print_require_jar(file, dep, fallback
|
86
|
+
def self.print_require_jar(file, dep, fallback: false)
|
102
87
|
return if dep.type != :jar || dep.scope != :runtime
|
88
|
+
|
103
89
|
if dep.system?
|
104
|
-
file
|
90
|
+
file&.puts("require '#{dep.file}'")
|
105
91
|
elsif dep.scope == :runtime
|
106
92
|
if fallback
|
107
|
-
file
|
93
|
+
file&.puts(" require '#{dep.path}'")
|
108
94
|
else
|
109
|
-
file
|
95
|
+
file&.puts(" require_jar '#{dep.gav.gsub(':', "', '")}'")
|
110
96
|
end
|
111
97
|
end
|
112
98
|
end
|
113
99
|
|
114
|
-
COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment'
|
100
|
+
COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment'
|
115
101
|
def self.needs_to_write?(require_filename)
|
116
102
|
require_filename && (!File.exist?(require_filename) || File.read(require_filename).match(COMMENT))
|
117
103
|
end
|
118
104
|
|
119
|
-
def self.install_deps(deps, dir, require_filename, vendor)
|
120
|
-
warn 'deprecated'
|
121
|
-
write_require_jars(deps, require_filename)
|
122
|
-
vendor_jars(deps, dir) if dir && vendor
|
123
|
-
end
|
124
|
-
|
125
105
|
def self.write_require_jars(deps, require_filename)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
f.puts 'end'
|
138
|
-
f.puts
|
139
|
-
f.puts 'if defined? Jars'
|
140
|
-
deps.each do |dep|
|
141
|
-
print_require_jar(f, dep)
|
142
|
-
end
|
143
|
-
f.puts 'end'
|
144
|
-
yield f if block_given?
|
106
|
+
return unless needs_to_write?(require_filename)
|
107
|
+
|
108
|
+
FileUtils.mkdir_p(File.dirname(require_filename))
|
109
|
+
File.open(require_filename, 'w') do |f|
|
110
|
+
f.puts COMMENT
|
111
|
+
f.puts 'begin'
|
112
|
+
f.puts " require 'jar_dependencies'"
|
113
|
+
f.puts 'rescue LoadError'
|
114
|
+
deps.each do |dep|
|
115
|
+
# do not use require_jar method
|
116
|
+
print_require_jar(f, dep, fallback: true)
|
145
117
|
end
|
118
|
+
f.puts 'end'
|
119
|
+
f.puts
|
120
|
+
f.puts 'if defined? Jars'
|
121
|
+
deps.each do |dep|
|
122
|
+
print_require_jar(f, dep)
|
123
|
+
end
|
124
|
+
f.puts 'end'
|
146
125
|
end
|
147
126
|
end
|
148
127
|
|
@@ -160,8 +139,9 @@ module Jars
|
|
160
139
|
@mvn.spec
|
161
140
|
end
|
162
141
|
|
163
|
-
def vendor_jars(
|
164
|
-
return unless
|
142
|
+
def vendor_jars(vendor_dir = nil, write_require_file: true)
|
143
|
+
return unless jars?
|
144
|
+
|
165
145
|
if Jars.to_prop(Jars::VENDOR) == 'false'
|
166
146
|
vendor_dir = nil
|
167
147
|
else
|
@@ -171,16 +151,17 @@ module Jars
|
|
171
151
|
end
|
172
152
|
|
173
153
|
def self.vendor_jars!(vendor_dir = nil)
|
174
|
-
new.vendor_jars!(
|
154
|
+
new.vendor_jars!(vendor_dir)
|
175
155
|
end
|
176
156
|
|
177
|
-
def vendor_jars!(
|
157
|
+
def vendor_jars!(vendor_dir = nil, write_require_file: true)
|
178
158
|
vendor_dir ||= spec.require_path
|
179
159
|
do_install(vendor_dir, write_require_file)
|
180
160
|
end
|
181
161
|
|
182
|
-
def install_jars(write_require_file
|
183
|
-
return unless
|
162
|
+
def install_jars(write_require_file: true)
|
163
|
+
return unless jars?
|
164
|
+
|
184
165
|
do_install(nil, write_require_file)
|
185
166
|
end
|
186
167
|
|
@@ -188,12 +169,12 @@ module Jars
|
|
188
169
|
@mvn.ruby_maven_install_options = options
|
189
170
|
end
|
190
171
|
|
191
|
-
def
|
172
|
+
def jars?
|
192
173
|
# first look if there are any requirements in the spec
|
193
174
|
# and then if gem depends on jar-dependencies for runtime.
|
194
175
|
# only then install the jars declared in the requirements
|
195
176
|
result = (spec = self.spec) && !spec.requirements.empty? &&
|
196
|
-
spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime }
|
177
|
+
spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime }
|
197
178
|
if result && spec.platform.to_s != 'java'
|
198
179
|
Jars.warn "\njar dependencies found on non-java platform gem - do not install jars\n"
|
199
180
|
false
|
@@ -201,7 +182,6 @@ module Jars
|
|
201
182
|
result
|
202
183
|
end
|
203
184
|
end
|
204
|
-
alias jars? has_jars?
|
205
185
|
|
206
186
|
private
|
207
187
|
|
@@ -209,6 +189,7 @@ module Jars
|
|
209
189
|
if !spec.require_paths.include?(vendor_dir) && vendor_dir
|
210
190
|
raise "vendor dir #{vendor_dir} not in require_paths of gemspec #{spec.require_paths}"
|
211
191
|
end
|
192
|
+
|
212
193
|
target_dir = File.join(@mvn.basedir, vendor_dir || spec.require_path)
|
213
194
|
jars_file = File.join(target_dir, "#{spec.name}_jars.rb")
|
214
195
|
|
@@ -223,7 +204,7 @@ module Jars
|
|
223
204
|
end
|
224
205
|
deps = install_dependencies
|
225
206
|
self.class.write_require_jars(deps, jars_file)
|
226
|
-
self.class.vendor_jars(
|
207
|
+
self.class.vendor_jars(target_dir, write_require_file: deps) if vendor_dir
|
227
208
|
end
|
228
209
|
|
229
210
|
def install_dependencies
|
@@ -237,6 +218,4 @@ module Jars
|
|
237
218
|
FileUtils.rm_f(deps) if deps
|
238
219
|
end
|
239
220
|
end
|
240
|
-
# to stay backward compatible
|
241
|
-
JarInstaller = Installer unless defined? JarInstaller
|
242
221
|
end
|
data/lib/jars/lock.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'jars/maven_exec'
|
2
4
|
|
3
5
|
module Jars
|
@@ -24,7 +26,9 @@ module Jars
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def classifier
|
27
|
-
size == 5
|
29
|
+
return nil if size == 5
|
30
|
+
|
31
|
+
self[2]
|
28
32
|
end
|
29
33
|
|
30
34
|
def gacv
|
@@ -38,7 +42,7 @@ module Jars
|
|
38
42
|
ENV_JAVA[a[2..-2]] || a
|
39
43
|
end
|
40
44
|
else
|
41
|
-
File.join(Jars.home, group_id.gsub(/[.]/, '/'), artifact_id, version, gacv[1
|
45
|
+
File.join(Jars.home, group_id.gsub(/[.]/, '/'), artifact_id, version, "#{gacv[1..].join('-')}.jar")
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -51,10 +55,11 @@ module Jars
|
|
51
55
|
def process(scope)
|
52
56
|
scope ||= :runtime
|
53
57
|
File.read(@file).each_line do |line|
|
54
|
-
next
|
55
|
-
|
58
|
+
next unless /:.+:/.match?(line)
|
59
|
+
|
60
|
+
jar = JarDetails.new(line.strip.sub(/:jar:/, ':').sub(/:$/, ': ').split(':'))
|
56
61
|
case scope
|
57
|
-
when :all
|
62
|
+
when :all, :test
|
58
63
|
yield jar
|
59
64
|
when :compile
|
60
65
|
# jar.scope is maven scope
|
@@ -65,8 +70,6 @@ module Jars
|
|
65
70
|
when :runtime
|
66
71
|
# jar.scope is maven scope
|
67
72
|
yield jar if (jar.scope != :test) && (jar.scope != :provided)
|
68
|
-
when :test
|
69
|
-
yield jar
|
70
73
|
end
|
71
74
|
end
|
72
75
|
end
|
data/lib/jars/lock_down.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fileutils'
|
2
4
|
require 'jar_dependencies'
|
3
5
|
require 'jars/version'
|
@@ -15,7 +17,7 @@ module Jars
|
|
15
17
|
|
16
18
|
def maven_new
|
17
19
|
factory = MavenFactory.new({}, @debug, @verbose)
|
18
|
-
pom = File.expand_path('
|
20
|
+
pom = File.expand_path('lock_down_pom.rb', __dir__)
|
19
21
|
m = factory.maven_new(pom)
|
20
22
|
m['jruby.plugins.version'] = Jars::JRUBY_PLUGINS_VERSION
|
21
23
|
m['dependency.plugin.version'] = Jars::DEPENDENCY_PLUGIN_VERSION
|
@@ -41,50 +43,40 @@ module Jars
|
|
41
43
|
# TODO: make this group a commandline option
|
42
44
|
Bundler.setup('default')
|
43
45
|
maven.property('jars.bundler', true)
|
44
|
-
done = []
|
45
|
-
index = 0
|
46
46
|
cwd = File.expand_path('.')
|
47
47
|
Gem.loaded_specs.each do |_name, spec|
|
48
48
|
# if gemspec is local then include all dependencies
|
49
|
-
maven.attach_jars(spec, cwd == spec.full_gem_path)
|
49
|
+
maven.attach_jars(spec, all_dependencies: cwd == spec.full_gem_path)
|
50
50
|
end
|
51
|
-
rescue
|
52
|
-
|
53
|
-
|
54
|
-
if
|
55
|
-
warn e.message
|
56
|
-
warn 'no bundler found - ignore Gemfile if exists'
|
57
|
-
end
|
58
|
-
when 'Bundler::GemfileNotFound'
|
59
|
-
# do nothing then as we have bundler but no Gemfile
|
60
|
-
when 'Bundler::GemNotFound'
|
61
|
-
warn "can not setup bundler with #{Bundler.default_lockfile}"
|
62
|
-
raise e
|
63
|
-
else
|
64
|
-
# reraise exception so user sees it
|
65
|
-
raise e
|
51
|
+
rescue LoadError => e
|
52
|
+
if Jars.verbose?
|
53
|
+
warn e.message
|
54
|
+
warn 'no bundler found - ignore Gemfile if exists'
|
66
55
|
end
|
56
|
+
rescue Bundler::GemfileNotFound
|
57
|
+
# do nothing then as we have bundler but no Gemfile
|
58
|
+
rescue Bundler::GemNotFound
|
59
|
+
warn "can not setup bundler with #{Bundler.default_lockfile}"
|
60
|
+
raise
|
67
61
|
ensure
|
68
62
|
$LOAD_PATH.replace(load_path)
|
69
63
|
end
|
70
64
|
|
71
|
-
def lock_down(
|
72
|
-
vendor_dir = File.expand_path(options[:vendor_dir]) if options[:vendor_dir]
|
65
|
+
def lock_down(vendor_dir = nil, force: false, update: false, tree: nil)
|
73
66
|
out = File.expand_path('.jars.output')
|
74
|
-
|
67
|
+
tree_provided = tree
|
68
|
+
tree ||= File.expand_path('.jars.tree')
|
75
69
|
maven.property('jars.outputFile', out)
|
76
70
|
maven.property('maven.repo.local', Jars.local_maven_repo)
|
77
|
-
maven.property('jars.home', vendor_dir) if vendor_dir
|
71
|
+
maven.property('jars.home', File.expand_path(vendor_dir)) if vendor_dir
|
78
72
|
maven.property('jars.lock', File.expand_path(Jars.lock))
|
79
|
-
maven.property('jars.force',
|
80
|
-
maven.property('jars.update',
|
73
|
+
maven.property('jars.force', force)
|
74
|
+
maven.property('jars.update', update) if update
|
81
75
|
# tell not to use Jars.lock as part of POM when running mvn
|
82
76
|
maven.property('jars.skip.lock', true)
|
83
77
|
|
84
78
|
args = ['gem:jars-lock']
|
85
|
-
|
86
|
-
args += ['dependency:tree', '-P -gemfile.lock', '-DoutputFile=' + tree]
|
87
|
-
end
|
79
|
+
args += ['dependency:tree', '-P -gemfile.lock', "-DoutputFile=#{tree}"] if tree_provided
|
88
80
|
|
89
81
|
puts
|
90
82
|
puts '-- jar root dependencies --'
|
@@ -99,7 +91,7 @@ module Jars
|
|
99
91
|
puts
|
100
92
|
end
|
101
93
|
puts
|
102
|
-
puts File.read(out).gsub(
|
94
|
+
puts File.read(out).gsub("#{File.dirname(out)}/", '')
|
103
95
|
puts
|
104
96
|
ensure
|
105
97
|
FileUtils.rm_f out
|
data/lib/jars/lock_down_pom.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# this file is maven DSL and used by maven via jars/lock_down.rb
|
2
4
|
|
3
5
|
basedir(ENV_JAVA['jars.basedir'])
|
4
6
|
|
5
|
-
|
7
|
+
def eval_file(file)
|
8
|
+
file = File.join(__dir__, file)
|
9
|
+
eval(File.read(file), nil, file) # rubocop:disable Security/Eval
|
10
|
+
end
|
11
|
+
|
12
|
+
eval_file('attach_jars_pom.rb')
|
6
13
|
|
7
14
|
jfile = ENV_JAVA['jars.jarfile']
|
8
15
|
jarfile(jfile) if jfile
|
@@ -14,17 +21,15 @@ jruby_plugin :gem, ENV_JAVA['jruby.plugins.version']
|
|
14
21
|
# from each gemspec file. otherwise we need to resolve
|
15
22
|
# the gemspec artifact in the maven way
|
16
23
|
unless ENV_JAVA['jars.bundler']
|
17
|
-
|
18
24
|
begin
|
19
25
|
gemspec
|
20
26
|
rescue
|
21
27
|
nil
|
22
28
|
end
|
23
|
-
|
24
29
|
end
|
25
30
|
|
26
31
|
properties('project.build.sourceEncoding' => 'utf-8')
|
27
32
|
|
28
33
|
plugin :dependency, ENV_JAVA['dependency.plugin.version']
|
29
34
|
|
30
|
-
|
35
|
+
eval_file('output_jars_pom.rb')
|
data/lib/jars/maven_exec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'jar_dependencies'
|
2
4
|
require 'jars/maven_factory'
|
3
5
|
|
@@ -23,11 +25,11 @@ module Jars
|
|
23
25
|
setup(spec)
|
24
26
|
rescue StandardError, LoadError => e
|
25
27
|
# If spec load fails, skip looking for jar-dependencies
|
26
|
-
warn
|
28
|
+
warn "jar-dependencies: #{e}"
|
27
29
|
warn e.backtrace.join("\n") if Jars.verbose?
|
28
30
|
end
|
29
31
|
|
30
|
-
def setup(spec = nil, allow_no_file
|
32
|
+
def setup(spec = nil, allow_no_file: false)
|
31
33
|
spec ||= find_spec(allow_no_file)
|
32
34
|
|
33
35
|
case spec
|
@@ -35,7 +37,7 @@ module Jars
|
|
35
37
|
@specfile = File.expand_path(spec)
|
36
38
|
@basedir = File.dirname(@specfile)
|
37
39
|
Dir.chdir(@basedir) do
|
38
|
-
spec = eval(File.read(@specfile), TOPLEVEL_BINDING, @specfile)
|
40
|
+
spec = eval(File.read(@specfile), TOPLEVEL_BINDING, @specfile) # rubocop:disable Security/Eval
|
39
41
|
end
|
40
42
|
when Gem::Specification
|
41
43
|
if File.exist?(spec.loaded_from)
|
@@ -46,12 +48,13 @@ module Jars
|
|
46
48
|
# there the spec_file is "not installed" but inside
|
47
49
|
# the gem_dir directory
|
48
50
|
Dir.chdir(spec.gem_dir) do
|
49
|
-
setup(nil, true)
|
51
|
+
setup(nil, allow_no_file: true)
|
50
52
|
end
|
51
53
|
end
|
52
|
-
when
|
54
|
+
when nil
|
55
|
+
# ignore
|
53
56
|
else
|
54
|
-
Jars.debug('spec must be either String or Gem::Specification. '
|
57
|
+
Jars.debug('spec must be either String or Gem::Specification. ' \
|
55
58
|
'File an issue on github if you need it.')
|
56
59
|
end
|
57
60
|
@spec = spec
|
@@ -63,10 +66,10 @@ module Jars
|
|
63
66
|
|
64
67
|
def resolve_dependencies_list(file)
|
65
68
|
factory = MavenFactory.new(@options)
|
66
|
-
maven = factory.maven_new(File.expand_path('
|
69
|
+
maven = factory.maven_new(File.expand_path('gemspec_pom.rb', __dir__))
|
67
70
|
|
68
71
|
is_local_file = File.expand_path(File.dirname(@specfile)) == File.expand_path(Dir.pwd)
|
69
|
-
maven.attach_jars(@spec, is_local_file)
|
72
|
+
maven.attach_jars(@spec, all_dependencies: is_local_file)
|
70
73
|
|
71
74
|
maven['jars.specfile'] = @specfile.to_s
|
72
75
|
maven['outputAbsoluteArtifactFilename'] = 'true'
|