Skip to content

Commit 11045c4

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

2 files changed

Lines changed: 89 additions & 50 deletions

File tree

lib/jars/installer.rb

Lines changed: 80 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,90 @@ 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+
all_types = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/
29+
coord = line.sub(/:[^:]+:([A-Z]:\\)?[^:]+$/, '')
30+
first, second = coord.split(/:#{type}:/)
5031
group_id, artifact_id = first.split(':')
5132
parts = group_id.split('.')
5233
parts << artifact_id
5334
parts << second.split(':')[-1]
54-
@file = line.slice(@coord.length, line.length).sub(REG, EMPTY).strip
55-
last = @file.reverse.index(%r{\\|/})
35+
file = line.slice(coord.length, line.length).sub(all_types, '').strip
36+
last = file.reverse.index(%r{\\|/})
5637
parts << line[-last..]
57-
@path = File.join(parts).strip
38+
path = File.join(parts).strip
39+
40+
scope = case line
41+
when /:provided:/
42+
:provided
43+
when /:test:/
44+
:test
45+
else
46+
:runtime
47+
end
48+
49+
new(
50+
path: path,
51+
file: file,
52+
gav: coord.sub(all_types, ':'),
53+
scope: scope,
54+
type: type,
55+
coord: coord,
56+
system: !line.index(':system:').nil?
57+
)
58+
end
5859

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

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

6597
def system?
@@ -74,12 +106,21 @@ def self.install_jars(write_require_file: false)
74106
def self.load_from_maven(file)
75107
result = []
76108
File.read(file).each_line do |line|
77-
dep = Dependency.new(line)
109+
dep = Dependency.parse(line)
78110
result << dep if dep && dep.scope == :runtime
79111
end
80112
result
81113
end
82114

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

@@ -211,14 +252,8 @@ def do_install(vendor_dir, write_require_file)
211252
end
212253

213254
def install_dependencies
214-
deps = File.join(@mvn.basedir, 'deps.lst')
215-
216255
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
256+
self.class.load_from_resolved(@mvn.resolve_dependencies)
222257
end
223258
end
224259
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)