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/lib/jars/classpath.rb
CHANGED
@@ -3,42 +3,40 @@ require 'jars/lock'
|
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
5
|
module Jars
|
6
|
-
|
7
6
|
class Classpath
|
8
|
-
|
9
7
|
# convenient method
|
10
|
-
def self.require(
|
11
|
-
new.require(
|
8
|
+
def self.require(scope = nil)
|
9
|
+
new.require(scope)
|
12
10
|
end
|
13
11
|
|
14
12
|
# convenient method
|
15
|
-
def self.classpath(
|
16
|
-
new.classpath(
|
13
|
+
def self.classpath(scope = nil)
|
14
|
+
new.classpath(scope)
|
17
15
|
end
|
18
16
|
|
19
17
|
# convenient method
|
20
|
-
def self.classpath_string(
|
21
|
-
new.classpath_string(
|
18
|
+
def self.classpath_string(scope = nil)
|
19
|
+
new.classpath_string(scope)
|
22
20
|
end
|
23
21
|
|
24
|
-
def initialize(
|
22
|
+
def initialize(spec = nil, deps = nil)
|
25
23
|
@spec = spec
|
26
24
|
@deps = deps
|
27
25
|
end
|
28
26
|
|
29
27
|
def mvn
|
30
|
-
@mvn ||= MavenExec.new(
|
28
|
+
@mvn ||= MavenExec.new(@spec)
|
31
29
|
end
|
32
30
|
|
33
|
-
def workdir(
|
34
|
-
dir = File.join(
|
35
|
-
dir if File.directory?(
|
31
|
+
def workdir(dirname)
|
32
|
+
dir = File.join(mvn.basedir, dirname)
|
33
|
+
dir if File.directory?(dir)
|
36
34
|
end
|
37
35
|
|
38
36
|
def dependencies_list
|
39
37
|
if @deps.nil?
|
40
|
-
deps = Jars.lock_path(
|
41
|
-
@deps = deps if deps && File.exist?(
|
38
|
+
deps = Jars.lock_path(mvn.basedir)
|
39
|
+
@deps = deps if deps && File.exist?(deps)
|
42
40
|
end
|
43
41
|
if @deps
|
44
42
|
@deps
|
@@ -47,50 +45,50 @@ module Jars
|
|
47
45
|
end
|
48
46
|
end
|
49
47
|
private :dependencies_list
|
50
|
-
|
51
|
-
DEPENDENCY_LIST = 'dependencies.list'
|
48
|
+
|
49
|
+
DEPENDENCY_LIST = 'dependencies.list'.freeze
|
52
50
|
def resolve_dependencies
|
53
|
-
basedir = workdir(
|
54
|
-
deps = File.join(
|
55
|
-
mvn.resolve_dependencies_list(
|
51
|
+
basedir = workdir('pkg') || workdir('target') || workdir('')
|
52
|
+
deps = File.join(basedir, DEPENDENCY_LIST)
|
53
|
+
mvn.resolve_dependencies_list(deps)
|
56
54
|
deps
|
57
55
|
end
|
58
56
|
private :resolve_dependencies
|
59
57
|
|
60
|
-
def require(
|
61
|
-
process(
|
58
|
+
def require(scope = nil)
|
59
|
+
process(scope) do |jar|
|
62
60
|
if jar.scope == :system
|
63
61
|
Kernel.require jar.path
|
64
62
|
else
|
65
|
-
require_jar(
|
63
|
+
require_jar(*jar.gacv)
|
66
64
|
end
|
67
65
|
end
|
68
|
-
if scope
|
69
|
-
process(
|
70
|
-
Jars.mark_as_required(
|
66
|
+
if scope.nil? || scope == :runtime
|
67
|
+
process(:provided) do |jar|
|
68
|
+
Jars.mark_as_required(*jar.gacv)
|
71
69
|
end
|
72
70
|
end
|
73
71
|
end
|
74
72
|
|
75
|
-
def classpath(
|
73
|
+
def classpath(scope = nil)
|
76
74
|
classpath = []
|
77
|
-
process(
|
75
|
+
process(scope) do |jar|
|
78
76
|
classpath << jar.file
|
79
77
|
end
|
80
78
|
classpath
|
81
79
|
end
|
82
80
|
|
83
|
-
def process(
|
81
|
+
def process(scope, &block)
|
84
82
|
deps = dependencies_list
|
85
|
-
Lock.new(
|
83
|
+
Lock.new(deps).process(scope, &block)
|
86
84
|
ensure
|
87
85
|
# just delete the temporary file if it exists
|
88
|
-
FileUtils.rm_f(
|
86
|
+
FileUtils.rm_f(DEPENDENCY_LIST)
|
89
87
|
end
|
90
88
|
private :process
|
91
89
|
|
92
|
-
def classpath_string(
|
93
|
-
classpath(
|
90
|
+
def classpath_string(scope = nil)
|
91
|
+
classpath(scope).join(File::PATH_SEPARATOR)
|
94
92
|
end
|
95
93
|
end
|
96
94
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Jars
|
2
|
-
|
3
2
|
class MavenVersion < String
|
4
3
|
def self.new(*args)
|
5
|
-
if args.
|
4
|
+
if args.empty? || (args.size == 1 && args[0].nil?)
|
6
5
|
nil
|
7
6
|
else
|
8
7
|
low, high = convert(args[0])
|
@@ -20,7 +19,7 @@ module Jars
|
|
20
19
|
def self.convert(arg, low = nil, high = nil)
|
21
20
|
if arg =~ /~>/
|
22
21
|
val = arg.sub(/~>\s*/, '')
|
23
|
-
last = val
|
22
|
+
last = val =~ /\./ ? val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999') : '99999'
|
24
23
|
["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"]
|
25
24
|
elsif arg =~ />=/
|
26
25
|
val = arg.sub(/>=\s*/, '')
|
@@ -29,7 +28,7 @@ module Jars
|
|
29
28
|
val = arg.sub(/<=\s*/, '')
|
30
29
|
[(nil || low), "#{snapshot_version(val)}]"]
|
31
30
|
# treat '!' the same way as '>' since maven can not describe such range
|
32
|
-
elsif arg =~ /[!>]/
|
31
|
+
elsif arg =~ /[!>]/
|
33
32
|
val = arg.sub(/[!>]\s*/, '')
|
34
33
|
["(#{snapshot_version(val)}", (nil || high)]
|
35
34
|
elsif arg =~ /</
|
@@ -38,8 +37,8 @@ module Jars
|
|
38
37
|
elsif arg =~ /\=/
|
39
38
|
val = arg.sub(/=\s*/, '')
|
40
39
|
# for prereleased version pick the maven version (no version range)
|
41
|
-
if val
|
42
|
-
[
|
40
|
+
if val =~ /[a-z]|[A-Z]/
|
41
|
+
[val, val]
|
43
42
|
else
|
44
43
|
["[#{val}", "#{val}.0.0.0.0.1)"]
|
45
44
|
end
|
@@ -49,7 +48,7 @@ module Jars
|
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
def self.snapshot_version(
|
51
|
+
def self.snapshot_version(val)
|
53
52
|
if val.match(/[a-z]|[A-Z]/) && !val.match(/-SNAPSHOT|[${}]/)
|
54
53
|
val + '-SNAPSHOT'
|
55
54
|
else
|
@@ -59,12 +58,11 @@ module Jars
|
|
59
58
|
end
|
60
59
|
|
61
60
|
class GemspecArtifacts
|
62
|
-
|
63
61
|
class Exclusion
|
64
62
|
attr_reader :group_id, :artifact_id
|
65
63
|
|
66
64
|
def initialize(line)
|
67
|
-
@group_id, @artifact_id = line.gsub(/['"]/, '').strip.split(
|
65
|
+
@group_id, @artifact_id = line.gsub(/['"]/, '').strip.split(':')
|
68
66
|
@artifact_id.strip!
|
69
67
|
end
|
70
68
|
|
@@ -72,68 +70,62 @@ module Jars
|
|
72
70
|
"#{@group_id}:#{@artifact_id}"
|
73
71
|
end
|
74
72
|
end
|
75
|
-
|
76
|
-
class Exclusions < Array
|
77
73
|
|
74
|
+
class Exclusions < Array
|
78
75
|
def to_s
|
79
76
|
"[#{join(', ')}]"
|
80
77
|
end
|
81
78
|
|
82
|
-
def initialize(
|
79
|
+
def initialize(line)
|
83
80
|
super()
|
84
|
-
line.gsub(/'"|^\s*\[|\]\s*$/, '').split(
|
85
|
-
self.<< Exclusion.new(
|
81
|
+
line.gsub(/'"|^\s*\[|\]\s*$/, '').split(/,\s*/).each do |exclusion|
|
82
|
+
self.<< Exclusion.new(exclusion)
|
86
83
|
end
|
87
84
|
freeze
|
88
85
|
end
|
89
86
|
end
|
90
87
|
|
91
88
|
class Artifact
|
92
|
-
|
93
89
|
attr_reader :type, :group_id, :artifact_id, :classifier, :version, :scope, :exclusions
|
94
90
|
|
95
|
-
ALLOWED_TYPES = [
|
96
|
-
|
97
|
-
def initialize(
|
91
|
+
ALLOWED_TYPES = %w[jar pom].freeze
|
92
|
+
|
93
|
+
def initialize(options, *args)
|
98
94
|
@type, @group_id, @artifact_id, @classifier, @version, @exclusions = *args
|
99
|
-
options.each do |k,v|
|
100
|
-
instance_variable_set(
|
95
|
+
options.each do |k, v|
|
96
|
+
instance_variable_set("@#{k}", v)
|
101
97
|
end
|
102
98
|
end
|
103
99
|
|
104
|
-
def self.new(
|
100
|
+
def self.new(line)
|
105
101
|
line = line.strip
|
106
|
-
index = line.index(
|
107
|
-
if index.nil?
|
108
|
-
return nil
|
109
|
-
end
|
102
|
+
index = line.index(/\s/)
|
103
|
+
return nil if index.nil?
|
110
104
|
type = line[0..index].strip
|
111
|
-
unless ALLOWED_TYPES.member?(
|
112
|
-
return nil
|
113
|
-
end
|
105
|
+
return nil unless ALLOWED_TYPES.member?(type)
|
114
106
|
line = line[index..-1]
|
115
107
|
line.gsub!(/['"]/, '')
|
116
108
|
line.strip!
|
117
109
|
|
118
110
|
options = {}
|
119
111
|
line.sub!(/,\s*:exclusions\s*(:|=>)\s*(\[[^\]]+\])/) do
|
120
|
-
options[
|
112
|
+
options[:exclusions] = Exclusions.new(Regexp.last_match(2).strip)
|
121
113
|
''
|
122
114
|
end
|
123
115
|
line.sub!(/,\s*:([a-z]+)\s*(:|=>)\s*(:?[a-zA-Z0-9_]+)/) do
|
124
|
-
options[
|
116
|
+
options[Regexp.last_match(1).to_sym] = Regexp.last_match(3).sub(/^:/, '')
|
125
117
|
''
|
126
118
|
end
|
127
119
|
exclusions = nil
|
128
120
|
line.sub!(/[,:]\s*\[(.+:.+,?\s*)+\]$/) do |a|
|
129
|
-
exclusions = Exclusions.new(
|
121
|
+
exclusions = Exclusions.new(a[1..-1].strip)
|
130
122
|
''
|
131
123
|
end
|
132
124
|
|
133
125
|
line.strip!
|
134
126
|
line.gsub!(/,\s*/, ':')
|
135
127
|
|
136
|
-
if line
|
128
|
+
if line =~ /[\[\(\)\]]/
|
137
129
|
index = line.index(/[\[\(].+$/)
|
138
130
|
version = line[index..-1].sub(/:/, ', ')
|
139
131
|
line = line[0..index - 1].strip.sub(/:$/, '')
|
@@ -153,7 +145,7 @@ module Jars
|
|
153
145
|
warn line
|
154
146
|
return nil
|
155
147
|
end
|
156
|
-
super(
|
148
|
+
super(options, type, group_id, artifact_id, classifier, version, exclusions)
|
157
149
|
end
|
158
150
|
|
159
151
|
def to_s
|
@@ -174,7 +166,7 @@ module Jars
|
|
174
166
|
def to_coord_no_classifier
|
175
167
|
args = [@group_id, @artifact_id]
|
176
168
|
args << @type
|
177
|
-
args << MavenVersion.new(
|
169
|
+
args << MavenVersion.new(@version)
|
178
170
|
args.join(':')
|
179
171
|
end
|
180
172
|
|
@@ -182,7 +174,7 @@ module Jars
|
|
182
174
|
args = [@group_id, @artifact_id]
|
183
175
|
args << @classifier if @classifier
|
184
176
|
args << @type
|
185
|
-
args << MavenVersion.new(
|
177
|
+
args << MavenVersion.new(@version)
|
186
178
|
args.join(':')
|
187
179
|
end
|
188
180
|
|
@@ -195,11 +187,11 @@ module Jars
|
|
195
187
|
|
196
188
|
attr_reader :artifacts
|
197
189
|
|
198
|
-
def initialize(
|
190
|
+
def initialize(spec)
|
199
191
|
@artifacts = []
|
200
192
|
spec.requirements.each do |req|
|
201
|
-
req.split(
|
202
|
-
if (
|
193
|
+
req.split(/\n/).each do |line|
|
194
|
+
if (a = Artifact.new(line))
|
203
195
|
@artifacts << a
|
204
196
|
end
|
205
197
|
end
|
data/lib/jars/gemspec_pom.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# this file is maven DSL and used by maven via jars/maven_exec.rb
|
2
2
|
|
3
|
-
eval(
|
3
|
+
eval(File.read(File.join(File.dirname(__FILE__), 'attach_jars_pom.rb')))
|
4
4
|
|
5
|
-
eval(
|
5
|
+
eval(File.read(File.join(File.dirname(__FILE__), 'output_jars_pom.rb')))
|
data/lib/jars/installer.rb
CHANGED
@@ -3,18 +3,14 @@ require 'jars/maven_exec'
|
|
3
3
|
|
4
4
|
module Jars
|
5
5
|
class Installer
|
6
|
-
|
7
6
|
class Dependency
|
8
|
-
|
9
7
|
attr_reader :path, :file, :gav, :scope, :type, :coord
|
10
8
|
|
11
|
-
def self.new(
|
12
|
-
if line
|
13
|
-
super
|
14
|
-
end
|
9
|
+
def self.new(line)
|
10
|
+
super if line =~ /:jar:|:pom:/
|
15
11
|
end
|
16
12
|
|
17
|
-
def setup_type(
|
13
|
+
def setup_type(line)
|
18
14
|
if line.index(':pom:')
|
19
15
|
@type = :pom
|
20
16
|
elsif line.index(':jar:')
|
@@ -23,7 +19,7 @@ module Jars
|
|
23
19
|
end
|
24
20
|
private :setup_type
|
25
21
|
|
26
|
-
def setup_scope(
|
22
|
+
def setup_scope(line)
|
27
23
|
@scope =
|
28
24
|
case line
|
29
25
|
when /:provided:/
|
@@ -37,25 +33,25 @@ module Jars
|
|
37
33
|
private :setup_scope
|
38
34
|
|
39
35
|
REG = /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:|:system:/
|
40
|
-
EMPTY = ''
|
41
|
-
def initialize(
|
42
|
-
setup_type(
|
36
|
+
EMPTY = ''.freeze
|
37
|
+
def initialize(line)
|
38
|
+
setup_type(line)
|
43
39
|
|
44
40
|
line.strip!
|
45
|
-
@coord = line.sub(
|
46
|
-
first, second = @coord.split(
|
47
|
-
group_id, artifact_id = first.split(
|
48
|
-
parts = group_id.split(
|
41
|
+
@coord = line.sub(/:[^:]+:([A-Z]:\\)?[^:]+$/, EMPTY)
|
42
|
+
first, second = @coord.split(/:#{type}:/)
|
43
|
+
group_id, artifact_id = first.split(/:/)
|
44
|
+
parts = group_id.split('.')
|
49
45
|
parts << artifact_id
|
50
|
-
parts << second.split(
|
46
|
+
parts << second.split(':')[-1]
|
51
47
|
@file = line.slice(@coord.length, line.length).sub(REG, EMPTY).strip
|
52
|
-
last = @file.reverse.index
|
48
|
+
last = @file.reverse.index(/\\|\//)
|
53
49
|
parts << line[-last..-1]
|
54
|
-
@path = File.join(
|
50
|
+
@path = File.join(parts).strip
|
55
51
|
|
56
|
-
setup_scope(
|
52
|
+
setup_scope(line)
|
57
53
|
|
58
|
-
@system = line.index(':system:')
|
54
|
+
@system = !line.index(':system:').nil?
|
59
55
|
@gav = @coord.sub(REG, ':')
|
60
56
|
end
|
61
57
|
|
@@ -64,24 +60,24 @@ module Jars
|
|
64
60
|
end
|
65
61
|
end
|
66
62
|
|
67
|
-
def self.install_jars(
|
68
|
-
new.install_jars(
|
63
|
+
def self.install_jars(write_require_file = false)
|
64
|
+
new.install_jars(write_require_file)
|
69
65
|
end
|
70
|
-
|
71
|
-
def self.load_from_maven(
|
66
|
+
|
67
|
+
def self.load_from_maven(file)
|
72
68
|
result = []
|
73
|
-
File.read(
|
74
|
-
dep = Dependency.new(
|
69
|
+
File.read(file).each_line do |line|
|
70
|
+
dep = Dependency.new(line)
|
75
71
|
result << dep if dep && dep.scope == :runtime
|
76
72
|
end
|
77
73
|
result
|
78
74
|
end
|
79
75
|
|
80
|
-
def self.write_require_file(
|
81
|
-
warn
|
76
|
+
def self.write_require_file(require_filename)
|
77
|
+
warn 'deprecated'
|
82
78
|
if needs_to_write?(require_filename)
|
83
|
-
FileUtils.mkdir_p(
|
84
|
-
f = File.open(
|
79
|
+
FileUtils.mkdir_p(File.dirname(require_filename))
|
80
|
+
f = File.open(require_filename, 'w')
|
85
81
|
f.puts COMMENT
|
86
82
|
f.puts "require 'jar_dependencies'"
|
87
83
|
f.puts
|
@@ -89,113 +85,115 @@ module Jars
|
|
89
85
|
end
|
90
86
|
end
|
91
87
|
|
92
|
-
def self.vendor_file(
|
88
|
+
def self.vendor_file(dir, dep)
|
93
89
|
if !dep.system? && dep.type == :jar && dep.scope == :runtime
|
94
|
-
vendored = File.join(
|
95
|
-
FileUtils.mkdir_p(
|
96
|
-
FileUtils.cp(
|
90
|
+
vendored = File.join(dir, dep.path)
|
91
|
+
FileUtils.mkdir_p(File.dirname(vendored))
|
92
|
+
FileUtils.cp(dep.file, vendored)
|
97
93
|
end
|
98
94
|
end
|
99
95
|
|
100
|
-
def self.write_dep(
|
101
|
-
warn
|
102
|
-
print_require_jar(
|
96
|
+
def self.write_dep(file, _dir, dep, _vendor)
|
97
|
+
warn 'deprecated'
|
98
|
+
print_require_jar(file, dep)
|
103
99
|
end
|
104
100
|
|
105
|
-
def self.print_require_jar(
|
101
|
+
def self.print_require_jar(file, dep, fallback = false)
|
106
102
|
return if dep.type != :jar || dep.scope != :runtime
|
107
103
|
if dep.system?
|
108
|
-
file.puts(
|
104
|
+
file.puts("require '#{dep.file}'") if file
|
109
105
|
elsif dep.scope == :runtime
|
110
106
|
if fallback
|
111
|
-
file.puts(
|
107
|
+
file.puts(" require '#{dep.path}'") if file
|
112
108
|
else
|
113
|
-
file.puts(
|
109
|
+
file.puts(" require_jar '#{dep.gav.gsub(':', "', '")}'") if file
|
114
110
|
end
|
115
111
|
end
|
116
112
|
end
|
117
113
|
|
118
|
-
COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment'
|
114
|
+
COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment'.freeze
|
119
115
|
def self.needs_to_write?(require_filename)
|
120
|
-
require_filename
|
116
|
+
require_filename && (!File.exist?(require_filename) || File.read(require_filename).match(COMMENT))
|
121
117
|
end
|
122
118
|
|
123
|
-
def self.install_deps(
|
124
|
-
warn
|
125
|
-
write_require_jars(
|
126
|
-
vendor_jars(
|
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
|
127
123
|
end
|
128
124
|
|
129
|
-
def self.write_require_jars(
|
125
|
+
def self.write_require_jars(deps, require_filename)
|
130
126
|
if needs_to_write?(require_filename)
|
131
|
-
FileUtils.mkdir_p(
|
132
|
-
File.open(
|
127
|
+
FileUtils.mkdir_p(File.dirname(require_filename))
|
128
|
+
File.open(require_filename, 'w') do |f|
|
133
129
|
f.puts COMMENT
|
134
|
-
f.puts
|
130
|
+
f.puts 'begin'
|
135
131
|
f.puts " require 'jar_dependencies'"
|
136
|
-
f.puts
|
132
|
+
f.puts 'rescue LoadError'
|
137
133
|
deps.each do |dep|
|
138
|
-
|
139
|
-
print_require_jar(
|
134
|
+
# do not use require_jar method
|
135
|
+
print_require_jar(f, dep, true)
|
140
136
|
end
|
141
|
-
f.puts
|
137
|
+
f.puts 'end'
|
142
138
|
f.puts
|
143
|
-
f.puts
|
139
|
+
f.puts 'if defined? Jars'
|
144
140
|
deps.each do |dep|
|
145
|
-
print_require_jar(
|
141
|
+
print_require_jar(f, dep)
|
146
142
|
end
|
147
|
-
f.puts
|
143
|
+
f.puts 'end'
|
148
144
|
yield f if block_given?
|
149
145
|
end
|
150
146
|
end
|
151
147
|
end
|
152
148
|
|
153
|
-
def self.vendor_jars(
|
149
|
+
def self.vendor_jars(deps, dir)
|
154
150
|
deps.each do |dep|
|
155
|
-
vendor_file(
|
151
|
+
vendor_file(dir, dep)
|
156
152
|
end
|
157
153
|
end
|
158
154
|
|
159
|
-
def initialize(
|
160
|
-
@mvn = MavenExec.new(
|
155
|
+
def initialize(spec = nil)
|
156
|
+
@mvn = MavenExec.new(spec)
|
161
157
|
end
|
162
158
|
|
163
|
-
def spec
|
159
|
+
def spec
|
160
|
+
@mvn.spec
|
161
|
+
end
|
164
162
|
|
165
|
-
def vendor_jars(
|
163
|
+
def vendor_jars(write_require_file = true, vendor_dir = nil)
|
166
164
|
return unless has_jars?
|
167
|
-
if Jars.to_prop(
|
165
|
+
if Jars.to_prop(Jars::VENDOR) == 'false'
|
168
166
|
vendor_dir = nil
|
169
167
|
else
|
170
168
|
vendor_dir ||= spec.require_path
|
171
169
|
end
|
172
|
-
do_install(
|
170
|
+
do_install(vendor_dir, write_require_file)
|
173
171
|
end
|
174
172
|
|
175
173
|
def self.vendor_jars!(vendor_dir = nil)
|
176
174
|
new.vendor_jars!(true, vendor_dir)
|
177
175
|
end
|
178
176
|
|
179
|
-
def vendor_jars!(
|
177
|
+
def vendor_jars!(write_require_file = true, vendor_dir = nil)
|
180
178
|
vendor_dir ||= spec.require_path
|
181
|
-
do_install(
|
179
|
+
do_install(vendor_dir, write_require_file)
|
182
180
|
end
|
183
181
|
|
184
|
-
def install_jars(
|
182
|
+
def install_jars(write_require_file = true)
|
185
183
|
return unless has_jars?
|
186
|
-
do_install(
|
184
|
+
do_install(nil, write_require_file)
|
187
185
|
end
|
188
186
|
|
189
|
-
def ruby_maven_install_options=(
|
190
|
-
@mvn.ruby_maven_install_options=
|
187
|
+
def ruby_maven_install_options=(options)
|
188
|
+
@mvn.ruby_maven_install_options = options
|
191
189
|
end
|
192
190
|
|
193
191
|
def has_jars?
|
194
192
|
# first look if there are any requirements in the spec
|
195
193
|
# and then if gem depends on jar-dependencies for runtime.
|
196
194
|
# only then install the jars declared in the requirements
|
197
|
-
result = (
|
198
|
-
|
195
|
+
result = (spec = self.spec) && !spec.requirements.empty? &&
|
196
|
+
spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime } != nil
|
199
197
|
if result && spec.platform.to_s != 'java'
|
200
198
|
Jars.warn "\njar dependencies found on non-java platform gem - do not install jars\n"
|
201
199
|
false
|
@@ -203,42 +201,40 @@ module Jars
|
|
203
201
|
result
|
204
202
|
end
|
205
203
|
end
|
206
|
-
|
204
|
+
alias jars? has_jars?
|
207
205
|
|
208
206
|
private
|
209
207
|
|
210
|
-
def do_install(
|
211
|
-
if !spec.require_paths.include?(vendor_dir)
|
208
|
+
def do_install(vendor_dir, write_require_file)
|
209
|
+
if !spec.require_paths.include?(vendor_dir) && vendor_dir
|
212
210
|
raise "vendor dir #{vendor_dir} not in require_paths of gemspec #{spec.require_paths}"
|
213
211
|
end
|
214
|
-
target_dir = File.join(
|
215
|
-
jars_file = File.join(
|
212
|
+
target_dir = File.join(@mvn.basedir, vendor_dir || spec.require_path)
|
213
|
+
jars_file = File.join(target_dir, "#{spec.name}_jars.rb")
|
216
214
|
|
217
215
|
# write out new jars_file it write_require_file is true or
|
218
216
|
# check timestamps:
|
219
217
|
# do not generate file if specfile is older then the generated file
|
220
|
-
if !
|
221
|
-
|
222
|
-
|
218
|
+
if !write_require_file &&
|
219
|
+
File.exist?(jars_file) &&
|
220
|
+
File.mtime(@mvn.specfile) < File.mtime(jars_file)
|
223
221
|
# leave jars_file as is
|
224
222
|
jars_file = nil
|
225
223
|
end
|
226
|
-
deps = install_dependencies
|
227
|
-
self.class.write_require_jars(
|
228
|
-
if vendor_dir
|
229
|
-
self.class.vendor_jars( deps, target_dir )
|
230
|
-
end
|
224
|
+
deps = install_dependencies
|
225
|
+
self.class.write_require_jars(deps, jars_file)
|
226
|
+
self.class.vendor_jars(deps, target_dir) if vendor_dir
|
231
227
|
end
|
232
228
|
|
233
229
|
def install_dependencies
|
234
|
-
deps = File.join(
|
230
|
+
deps = File.join(@mvn.basedir, 'deps.lst')
|
235
231
|
|
236
232
|
puts " jar dependencies for #{spec.spec_name} . . ." unless Jars.quiet?
|
237
|
-
@mvn.resolve_dependencies_list(
|
233
|
+
@mvn.resolve_dependencies_list(deps)
|
238
234
|
|
239
|
-
self.class.load_from_maven(
|
235
|
+
self.class.load_from_maven(deps)
|
240
236
|
ensure
|
241
|
-
FileUtils.rm_f(
|
237
|
+
FileUtils.rm_f(deps) if deps
|
242
238
|
end
|
243
239
|
end
|
244
240
|
# to stay backward compatible
|