Skip to content

Commit 7aec7a2

Browse files
committed
resolve deps directly (don't create deps.lst)
1 parent 52b1dbd commit 7aec7a2

2 files changed

Lines changed: 88 additions & 50 deletions

File tree

lib/jars/installer.rb

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,89 @@ class Installer
88
class Dependency
99
attr_reader :path, :file, :gav, :scope, :type, :coord
1010

11-
def self.new(line)
12-
super if /:jar:|:pom:/.match?(line)
13-
end
11+
# @param line [String] Maven dependency:list output line
12+
# @return [Dependency, nil]
13+
def self.parse(line)
14+
return unless /:jar:|:pom:/.match?(line)
1415

15-
def setup_type(line)
16-
if line.index(':pom:')
17-
@type = :pom
18-
elsif line.index(':jar:')
19-
@type = :jar
20-
end
21-
end
22-
private :setup_type
23-
24-
def setup_scope(line)
25-
@scope =
26-
case line
27-
when /:provided:/
28-
:provided
29-
when /:test:/
30-
:test
31-
else
32-
:runtime
33-
end
34-
end
35-
private :setup_scope
36-
37-
REG = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/.freeze
38-
EMPTY = ''
39-
def initialize(line)
4016
# remove ANSI escape sequences and module section (https://issues.apache.org/jira/browse/MDEP-974)
4117
line = line.gsub(/\e\[\d*m/, '')
4218
line = line.gsub(/ -- module.*/, '')
4319

44-
setup_type(line)
20+
type = if line.index(':pom:')
21+
:pom
22+
elsif line.index(':jar:')
23+
:jar
24+
end
4525

4626
line.strip!
4727

48-
@coord = line.sub(/:[^:]+:([A-Z]:\\)?[^:]+$/, EMPTY)
49-
first, second = @coord.split(/:#{type}:/)
28+
coord = line.sub(/:[^:]+:([A-Z]:\\)?[^:]+$/, '')
29+
first, second = coord.split(/:#{type}:/)
5030
group_id, artifact_id = first.split(':')
5131
parts = group_id.split('.')
5232
parts << artifact_id
5333
parts << second.split(':')[-1]
54-
@file = line.slice(@coord.length, line.length).sub(REG, EMPTY).strip
55-
last = @file.reverse.index(%r{\\|/})
34+
file = line.slice(coord.length, line.length).sub(REG, '').strip
35+
last = file.reverse.index(%r{\\|/})
5636
parts << line[-last..]
57-
@path = File.join(parts).strip
37+
path = File.join(parts).strip
38+
39+
scope = case line
40+
when /:provided:/
41+
:provided
42+
when /:test:/
43+
:test
44+
else
45+
:runtime
46+
end
47+
48+
new(
49+
path: path,
50+
file: file,
51+
gav: coord.sub(REG, ':'),
52+
scope: scope,
53+
type: type,
54+
coord: coord,
55+
system: !line.index(':system:').nil?
56+
)
57+
end
5858

59-
setup_scope(line)
59+
# @param dep [Jars::Mima::ResolvedDependency]
60+
# @return [Dependency]
61+
def self.from_resolved(dep)
62+
coord = "#{dep.group_id}:#{dep.artifact_id}:#{dep.type}:"
63+
coord << "#{dep.classifier}:" if dep.classifier
64+
coord << "#{dep.version}:#{dep.scope}"
65+
66+
scope = case dep.scope
67+
when 'test'
68+
:test
69+
when 'provided'
70+
:provided
71+
else
72+
:runtime
73+
end
74+
75+
new(
76+
path: dep.path,
77+
file: dep.file,
78+
gav: dep.gav,
79+
scope: scope,
80+
type: dep.type.to_sym,
81+
coord: coord,
82+
system: dep.system?
83+
)
84+
end
6085

61-
@system = !line.index(':system:').nil?
62-
@gav = @coord.sub(REG, ':')
86+
def initialize(path:, file:, gav:, scope:, type:, coord:, system: false)
87+
@path = path
88+
@file = file
89+
@gav = gav
90+
@scope = scope
91+
@type = type
92+
@coord = coord
93+
@system = system
6394
end
6495

6596
def system?
@@ -74,12 +105,21 @@ def self.install_jars(write_require_file: false)
74105
def self.load_from_maven(file)
75106
result = []
76107
File.read(file).each_line do |line|
77-
dep = Dependency.new(line)
108+
dep = Dependency.parse(line)
78109
result << dep if dep && dep.scope == :runtime
79110
end
80111
result
81112
end
82113

114+
def self.load_from_resolved(resolved)
115+
resolved.each_with_object([]) do |mima_dep, result|
116+
next unless MavenExec::RESOLVED_TYPES.include?(mima_dep.type)
117+
118+
dep = Dependency.from_resolved(mima_dep)
119+
result << dep if dep.scope == :runtime
120+
end
121+
end
122+
83123
def self.vendor_file(dir, dep)
84124
return unless !dep.system? && dep.type == :jar && dep.scope == :runtime
85125

@@ -211,14 +251,8 @@ def do_install(vendor_dir, write_require_file)
211251
end
212252

213253
def install_dependencies
214-
deps = File.join(@mvn.basedir, 'deps.lst')
215-
216254
puts " jar dependencies for #{spec.spec_name} . . ." unless Jars.quiet?
217-
@mvn.resolve_dependencies_list(deps)
218-
219-
self.class.load_from_maven(deps)
220-
ensure
221-
FileUtils.rm_f(deps) if deps
255+
self.class.load_from_resolved(@mvn.resolve_dependencies)
222256
end
223257
end
224258
end

lib/jars/maven_exec.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,25 @@ def setup(spec = nil, allow_no_file: false)
5656
@spec = spec
5757
end
5858

59-
def resolve_dependencies_list(file)
59+
def resolve_dependencies
6060
require 'jars/mima'
6161

6262
artifacts = GemspecArtifacts.new(@spec)
6363
is_local_file = File.expand_path(File.dirname(@specfile)) == File.expand_path(Dir.pwd)
6464

65-
resolved = Jars::Mima.resolve_artifacts(artifacts.artifacts, all_dependencies: is_local_file)
65+
Jars::Mima.resolve_artifacts(artifacts.artifacts, all_dependencies: is_local_file)
66+
end
67+
68+
RESOLVED_TYPES = %w[jar pom].freeze
69+
70+
def resolve_dependencies_list(file)
71+
resolved = resolve_dependencies
6672

6773
# Write output in Maven dependency:list format for Installer::Dependency compatibility
68-
allowed_types = %w[jar pom].freeze
6974
File.open(file, 'w') do |f|
70-
f.puts
7175
f.puts 'The following files have been resolved:'
7276
resolved.each do |dep|
73-
next unless allowed_types.include?(dep.type)
77+
next unless RESOLVED_TYPES.include?(dep.type)
7478

7579
line = +" #{dep.group_id}:#{dep.artifact_id}:#{dep.type}:"
7680
line << "#{dep.classifier}:" if dep.classifier

0 commit comments

Comments
 (0)