lock_jar 0.13.0 → 0.14.0
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/.codeclimate.yml +16 -0
- data/.rubocop.yml +28 -0
- data/.travis.yml +12 -1
- data/Gemfile +6 -3
- data/Guardfile +2 -3
- data/README.md +17 -16
- data/Rakefile +11 -7
- data/lib/lock_jar/buildr.rb +95 -89
- data/lib/lock_jar/bundler.rb +85 -84
- data/lib/lock_jar/class_loader.rb +19 -21
- data/lib/lock_jar/cli.rb +32 -25
- data/lib/lock_jar/domain/artifact.rb +39 -45
- data/lib/lock_jar/domain/dsl.rb +50 -79
- data/lib/lock_jar/domain/dsl_merger.rb +76 -0
- data/lib/lock_jar/domain/gem_dsl.rb +10 -12
- data/lib/lock_jar/domain/jarfile_dsl.rb +6 -18
- data/lib/lock_jar/domain/lockfile.rb +17 -24
- data/lib/lock_jar/logging.rb +4 -3
- data/lib/lock_jar/maven.rb +29 -29
- data/lib/lock_jar/registry.rb +52 -60
- data/lib/lock_jar/resolver.rb +17 -20
- data/lib/lock_jar/runtime/install.rb +28 -0
- data/lib/lock_jar/runtime/list.rb +55 -0
- data/lib/lock_jar/runtime/load.rb +54 -0
- data/lib/lock_jar/runtime/lock.rb +152 -0
- data/lib/lock_jar/runtime.rb +30 -302
- data/lib/lock_jar/version.rb +2 -1
- data/lib/lock_jar.rb +137 -105
- data/lock_jar.gemspec +7 -4
- data/spec/fixtures/jarfile_gem/Gemfile +4 -0
- data/spec/fixtures/jarfile_gem/Jarfile +1 -0
- data/spec/fixtures/jarfile_gem/jarfile_gem.gemspec +23 -0
- data/spec/fixtures/jarfile_gem/lib/jarfile_gem/version.rb +3 -0
- data/spec/fixtures/jarfile_gem/lib/jarfile_gem.rb +5 -0
- data/spec/lock_jar/bundler_spec.rb +27 -0
- data/spec/lock_jar/class_loader_spec.rb +34 -36
- data/spec/lock_jar/cli_spec.rb +39 -46
- data/spec/lock_jar/domain/dsl_merger_spec.rb +49 -0
- data/spec/lock_jar/domain/dsl_spec.rb +35 -37
- data/spec/lock_jar/domain/gem_dsl_spec.rb +18 -0
- data/spec/lock_jar/maven_spec.rb +9 -11
- data/spec/lock_jar/resolver_spec.rb +16 -17
- data/spec/lock_jar/runtime_spec.rb +17 -13
- data/spec/lock_jar_spec.rb +255 -195
- data/spec/spec_helper.rb +13 -8
- data/spec/support/helper.rb +13 -5
- data/spec/support/shared_examples/lockfile.rb +4 -6
- metadata +43 -19
- data/bundler/Gemfile +0 -21
- data/bundler/LICENSE.txt +0 -22
- data/bundler/README.md +0 -29
- data/bundler/Rakefile +0 -2
- data/bundler/lib/lock_jar_bundler/bundler.rb +0 -35
- data/bundler/lib/lock_jar_bundler/piggy_back.rb +0 -98
- data/bundler/lib/lock_jar_bundler/version.rb +0 -5
- data/bundler/lib/lock_jar_bundler.rb +0 -5
- data/bundler/lock_jar_bundler.gemspec +0 -24
- data/bundler/spec/Jarfile +0 -3
- data/bundler/spec/dummy_gem/Jarfile +0 -1
- data/bundler/spec/dummy_gem/dummy_gem.gemspec +0 -19
- data/bundler/spec/lock_jar_bundler_spec.rb +0 -49
- data/bundler/spec/spec_helper.rb +0 -88
- data/lib/lock_jar/domain/dsl_helper.rb +0 -84
- data/spec/lock_jar/domain/dsl_helper_spec.rb +0 -52
data/lib/lock_jar/runtime.rb
CHANGED
@@ -13,7 +13,6 @@
|
|
13
13
|
# License for the specific language governing permissions and limitations under
|
14
14
|
# the License.
|
15
15
|
|
16
|
-
require 'rubygems'
|
17
16
|
require 'yaml'
|
18
17
|
require 'singleton'
|
19
18
|
require 'lock_jar/resolver'
|
@@ -21,11 +20,18 @@ require 'lock_jar/registry'
|
|
21
20
|
require 'lock_jar/domain/dsl'
|
22
21
|
require 'lock_jar/domain/jarfile_dsl'
|
23
22
|
require 'lock_jar/domain/lockfile'
|
23
|
+
require 'lock_jar/runtime/load'
|
24
|
+
require 'lock_jar/runtime/lock'
|
25
|
+
require 'lock_jar/runtime/list'
|
26
|
+
require 'lock_jar/runtime/install'
|
24
27
|
|
25
28
|
module LockJar
|
26
|
-
|
29
|
+
#
|
27
30
|
class Runtime
|
28
31
|
include Singleton
|
32
|
+
include Load
|
33
|
+
include List
|
34
|
+
include Install
|
29
35
|
|
30
36
|
attr_reader :current_resolver
|
31
37
|
|
@@ -33,25 +39,27 @@ module LockJar
|
|
33
39
|
@current_resolver = nil
|
34
40
|
end
|
35
41
|
|
36
|
-
def
|
42
|
+
def lock(jarfile_or_dsl, opts = {}, &blk)
|
43
|
+
Lock.new(self).lock(jarfile_or_dsl, opts, &blk)
|
44
|
+
end
|
45
|
+
|
46
|
+
def opts
|
47
|
+
current_resolver.opts if current_resolver
|
48
|
+
end
|
37
49
|
|
50
|
+
def resolver(opts = {})
|
38
51
|
# XXX: Caches the resolver by the options. Passing in nil opts will replay
|
39
52
|
# from the cache. This need to change.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
53
|
+
if !opts.nil?
|
54
|
+
opts[:local_repo] = File.expand_path(opts[:local_repo]) if opts[:local_repo]
|
55
|
+
elsif @current_resolver
|
56
|
+
opts = @current_resolver.opts
|
45
57
|
else
|
46
|
-
|
47
|
-
opts = @current_resolver.opts
|
48
|
-
else
|
49
|
-
opts = {}
|
50
|
-
end
|
58
|
+
opts = {}
|
51
59
|
end
|
52
60
|
|
53
61
|
if @current_resolver.nil? || opts != @current_resolver.opts
|
54
|
-
@current_resolver = LockJar::Resolver.new(
|
62
|
+
@current_resolver = LockJar::Resolver.new(opts)
|
55
63
|
end
|
56
64
|
|
57
65
|
@current_resolver
|
@@ -61,309 +69,29 @@ module LockJar
|
|
61
69
|
@current_resolver = nil
|
62
70
|
end
|
63
71
|
|
64
|
-
def install( jarfile_lock, groups = ['default'], opts = {}, &blk )
|
65
|
-
deps = list( jarfile_lock, groups, {:with_locals => false}.merge( opts ), &blk )
|
66
|
-
|
67
|
-
lockfile = LockJar::Domain::Lockfile.read( jarfile_lock )
|
68
|
-
if opts[:local_repo].nil? && lockfile.local_repository
|
69
|
-
opts[:local_repo] = lockfile.local_repository
|
70
|
-
end
|
71
|
-
|
72
|
-
# Older Jarfile expected the defaul maven repo, but did not write
|
73
|
-
# it to the lockfile
|
74
|
-
if lockfile.version.to_f >= 0.11
|
75
|
-
resolver(opts).clear_remote_repositories
|
76
|
-
end
|
77
|
-
|
78
|
-
lockfile.remote_repositories.each do |repo|
|
79
|
-
resolver(opts).add_remote_repository( repo )
|
80
|
-
end
|
81
|
-
|
82
|
-
files = resolver(opts).download( deps )
|
83
|
-
|
84
|
-
files
|
85
|
-
end
|
86
|
-
|
87
|
-
def lock( jarfile_or_dsl, opts = {}, &blk )
|
88
|
-
|
89
|
-
opts = {:download => true }.merge( opts )
|
90
|
-
|
91
|
-
jarfile = nil
|
92
|
-
|
93
|
-
if jarfile_or_dsl
|
94
|
-
if jarfile_or_dsl.is_a? LockJar::Domain::Dsl
|
95
|
-
jarfile = jarfile_or_dsl
|
96
|
-
else
|
97
|
-
jarfile = LockJar::Domain::JarfileDsl.create( jarfile_or_dsl )
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
unless blk.nil?
|
102
|
-
dsl = LockJar::Domain::Dsl.create(&blk)
|
103
|
-
if jarfile.nil?
|
104
|
-
jarfile = dsl
|
105
|
-
else
|
106
|
-
jarfile = LockJar::Domain::DslHelper.merge( jarfile, dsl )
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
if jarfile.respond_to?(:bundler_enabled ) && jarfile.bundler_enabled
|
111
|
-
require 'lock_jar_bundler/bundler'
|
112
|
-
|
113
|
-
LockJar::Bundler.bundled_jarfiles(jarfile.bundler_enabled).each do |bundled_jarfile|
|
114
|
-
jarfile = LockJar::Domain::DslHelper.merge( jarfile, LockJar::Domain::JarfileDsl.create(bundled_jarfile) )
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
|
119
|
-
# If not set in opts, and is set in dsl
|
120
|
-
if opts[:local_repo].nil? && jarfile.local_repository
|
121
|
-
opts[:local_repo] = jarfile.local_repository
|
122
|
-
end
|
123
|
-
|
124
|
-
lockfile = LockJar::Domain::Lockfile.new
|
125
|
-
|
126
|
-
if jarfile.clear_repositories
|
127
|
-
resolver(opts).clear_remote_repositories
|
128
|
-
else
|
129
|
-
repos = resolver(opts).remote_repositories
|
130
|
-
lockfile.remote_repositories += repos.to_a if repos
|
131
|
-
end
|
132
|
-
|
133
|
-
jarfile.remote_repositories.each do |repo|
|
134
|
-
resolver(opts).add_remote_repository( repo )
|
135
|
-
lockfile.remote_repositories << repo
|
136
|
-
end
|
137
|
-
|
138
|
-
unless jarfile.local_repository.nil?
|
139
|
-
lockfile.local_repository = jarfile.local_repository
|
140
|
-
end
|
141
|
-
|
142
|
-
if jarfile.maps.size > 0
|
143
|
-
lockfile.maps = jarfile.maps
|
144
|
-
end
|
145
|
-
|
146
|
-
if jarfile.excludes.size > 0
|
147
|
-
lockfile.excludes = jarfile.excludes
|
148
|
-
end
|
149
|
-
|
150
|
-
artifacts = []
|
151
|
-
jarfile.artifacts.each do |group, group_artifacts|
|
152
|
-
group_artifacts.each do |artifact|
|
153
|
-
artifacts += group_artifacts
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
if !jarfile.merged.empty?
|
158
|
-
lockfile.merged = jarfile.merged
|
159
|
-
end
|
160
|
-
|
161
|
-
if !artifacts.empty?
|
162
|
-
resolved_notations = resolver(opts).resolve( artifacts.select{ |artifact| artifact.resolvable? }.map(&:to_dep), opts[:download] == true )
|
163
|
-
|
164
|
-
jarfile.artifacts.each do |group_name, group_artifacts|
|
165
|
-
group = {'locals' => [], 'dependencies' => [], 'artifacts' => []}
|
166
|
-
|
167
|
-
group_artifacts.each do |artifact|
|
168
|
-
|
169
|
-
artifact_data = {}
|
170
|
-
|
171
|
-
if artifact.is_a? LockJar::Domain::Jar
|
172
|
-
group['dependencies'] << artifact.notation
|
173
|
-
g = resolver(opts).dependencies_graph[artifact.notation]
|
174
|
-
artifact_data["transitive"] = g.to_hash if g
|
175
|
-
|
176
|
-
elsif artifact.is_a? LockJar::Domain::Pom
|
177
|
-
artifact_data['scopes'] = artifact.scopes
|
178
|
-
|
179
|
-
# iterate each dependency in Pom to map transitive dependencies
|
180
|
-
transitive = {}
|
181
|
-
artifact.notations.each do |notation|
|
182
|
-
transitive.merge!( notation => resolver(opts).dependencies_graph[notation] )
|
183
|
-
end
|
184
|
-
artifact_data["transitive"] = transitive
|
185
|
-
|
186
|
-
elsif artifact.is_a? LockJar::Domain::Local
|
187
|
-
group['locals'] << artifact.path
|
188
|
-
else
|
189
|
-
# XXX: handle unsupported artifact
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
# flatten the graph of nested hashes
|
194
|
-
dep_merge = lambda do |graph|
|
195
|
-
deps = graph.keys
|
196
|
-
graph.values.each do |next_step|
|
197
|
-
deps += dep_merge.call(next_step)
|
198
|
-
end
|
199
|
-
deps
|
200
|
-
end
|
201
|
-
|
202
|
-
if artifact_data["transitive"]
|
203
|
-
group['dependencies'] += dep_merge.call( artifact_data["transitive"] )
|
204
|
-
|
205
|
-
# xxX: set required_by ?
|
206
|
-
|
207
|
-
group['artifacts'] << { artifact.to_urn => artifact_data }
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
if lockfile.excludes
|
212
|
-
lockfile.excludes.each do |exclude|
|
213
|
-
group['dependencies'].delete_if { |dep| dep =~ /#{exclude}/ }
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
group['dependencies'].sort!
|
218
|
-
if group['locals'].empty?
|
219
|
-
group.delete 'locals'
|
220
|
-
end
|
221
|
-
|
222
|
-
lockfile.groups[group_name] = group
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
lockfile.write( opts[:lockfile] || "Jarfile.lock" )
|
227
|
-
|
228
|
-
lockfile
|
229
|
-
end
|
230
|
-
|
231
|
-
def list( lockfile_or_path, groups = ['default'], opts = {}, &blk )
|
232
|
-
|
233
|
-
lockfile = nil
|
234
|
-
dependencies = []
|
235
|
-
maps = []
|
236
|
-
with_locals = {:with_locals => true }.merge(opts).delete :with_locals
|
237
|
-
|
238
|
-
if lockfile_or_path
|
239
|
-
if lockfile_or_path.is_a? LockJar::Domain::Lockfile
|
240
|
-
lockfile = lockfile_or_path
|
241
|
-
elsif lockfile_or_path
|
242
|
-
lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
|
243
|
-
end
|
244
|
-
|
245
|
-
dependencies = lockfile_dependencies( lockfile, groups, with_locals )
|
246
|
-
maps = lockfile.maps
|
247
|
-
end
|
248
|
-
|
249
|
-
# Support limited DSL from block
|
250
|
-
unless blk.nil?
|
251
|
-
dsl = LockJar::Domain::Dsl.create(&blk)
|
252
|
-
dependencies += dsl_dependencies( dsl, groups, with_locals ).map(&:to_dep)
|
253
|
-
maps = dsl.maps
|
254
|
-
end
|
255
|
-
|
256
|
-
if maps && maps.size > 0
|
257
|
-
mapped_dependencies = []
|
258
|
-
|
259
|
-
maps.each do |notation, replacements|
|
260
|
-
dependencies.each do |dep|
|
261
|
-
if dep =~ /#{notation}/
|
262
|
-
replacements.each do |replacement|
|
263
|
-
mapped_dependencies << replacement
|
264
|
-
end
|
265
|
-
else
|
266
|
-
mapped_dependencies << dep
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
dependencies = mapped_dependencies
|
272
|
-
end
|
273
|
-
|
274
|
-
if opts[:resolve]
|
275
|
-
dependencies = resolver(opts).resolve( dependencies )
|
276
|
-
end
|
277
|
-
|
278
|
-
if opts[:local_paths]
|
279
|
-
opts.delete( :local_paths ) # remove list opts so resolver is not reset
|
280
|
-
resolver(opts).to_local_paths( dependencies )
|
281
|
-
|
282
|
-
else
|
283
|
-
dependencies
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
# Load paths from a lockfile or block. Paths are loaded once per lockfile.
|
288
|
-
#
|
289
|
-
# @param [String] lockfile_path the lockfile
|
290
|
-
# @param [Array] groups to load into classpath
|
291
|
-
# @param [Hash] opts
|
292
|
-
# @param [Block] blk
|
293
|
-
def load( lockfile_or_path, groups = ['default'], opts = {}, &blk )
|
294
|
-
|
295
|
-
lockfile = nil
|
296
|
-
|
297
|
-
# lockfile is only loaded once
|
298
|
-
unless lockfile_or_path.nil?
|
299
|
-
# loaded a Lockfile instance
|
300
|
-
if lockfile_or_path.is_a? LockJar::Domain::Lockfile
|
301
|
-
lockfile = lockfile_or_path
|
302
|
-
|
303
|
-
# check if lockfile path is already loaded
|
304
|
-
elsif LockJar::Registry.instance.lockfile_registered?( lockfile_or_path )
|
305
|
-
return
|
306
|
-
|
307
|
-
# convert lockfile path to a Lockfile instance
|
308
|
-
else
|
309
|
-
lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
|
310
|
-
end
|
311
|
-
|
312
|
-
|
313
|
-
if opts[:local_repo].nil? && lockfile.local_repository
|
314
|
-
opts[:local_repo] = lockfile.local_repository
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
# set local_repo if passed in the block
|
319
|
-
unless blk.nil?
|
320
|
-
dsl = LockJar::Domain::Dsl.create(&blk)
|
321
|
-
|
322
|
-
# set local_repo from block
|
323
|
-
if opts[:local_repo].nil? && dsl.local_repository
|
324
|
-
opts[:local_repo] = dsl.local_repository
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
# registered merged lockfiles for lockfile
|
329
|
-
if lockfile && !lockfile.merged.empty?
|
330
|
-
lockfile.merged.each do |path|
|
331
|
-
LockJar::Registry.instance.register_lockfile( path )
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
dependencies = LockJar::Registry.instance.register_jars( list( lockfile, groups, opts, &blk ) )
|
336
|
-
|
337
|
-
resolver(opts).load_to_classpath( dependencies )
|
338
|
-
end
|
339
|
-
|
340
72
|
private
|
341
73
|
|
342
|
-
def lockfile_dependencies(
|
74
|
+
def lockfile_dependencies(lockfile, groups, with_locals = true)
|
343
75
|
dependencies = []
|
344
76
|
|
345
77
|
groups.each do |group|
|
346
|
-
|
347
|
-
|
78
|
+
next unless lockfile.groups[group.to_s]
|
79
|
+
dependencies += lockfile.groups[group.to_s]['dependencies']
|
348
80
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
end
|
81
|
+
if with_locals
|
82
|
+
locals = lockfile.groups[group.to_s]['locals']
|
83
|
+
dependencies += locals if locals
|
353
84
|
end
|
354
85
|
end
|
355
86
|
|
356
87
|
dependencies
|
357
88
|
end
|
358
89
|
|
359
|
-
def dsl_dependencies(
|
360
|
-
|
90
|
+
def dsl_dependencies(dsl, groups, with_locals = true)
|
361
91
|
dependencies = []
|
362
92
|
|
363
93
|
groups.each do |group|
|
364
|
-
if dsl.artifacts[group.to_s]
|
365
|
-
dependencies += dsl.artifacts[group.to_s]
|
366
|
-
end
|
94
|
+
dependencies += dsl.artifacts[group.to_s] if dsl.artifacts[group.to_s]
|
367
95
|
end
|
368
96
|
|
369
97
|
unless with_locals
|
data/lib/lock_jar/version.rb
CHANGED
data/lib/lock_jar.rb
CHANGED
@@ -13,12 +13,13 @@
|
|
13
13
|
# License for the specific language governing permissions and limitations under
|
14
14
|
# the License.
|
15
15
|
|
16
|
-
require
|
17
|
-
require 'rubygems'
|
16
|
+
require 'yaml'
|
18
17
|
require 'lock_jar/resolver'
|
19
18
|
require 'lock_jar/runtime'
|
20
19
|
require 'lock_jar/version'
|
21
20
|
require 'lock_jar/domain/lockfile'
|
21
|
+
require 'lock_jar/domain/jarfile_dsl'
|
22
|
+
require 'lock_jar/domain/gem_dsl'
|
22
23
|
require 'lock_jar/domain/dsl'
|
23
24
|
|
24
25
|
#
|
@@ -27,128 +28,159 @@ require 'lock_jar/domain/dsl'
|
|
27
28
|
# @author Michael Guymon
|
28
29
|
#
|
29
30
|
module LockJar
|
31
|
+
class << self
|
32
|
+
#
|
33
|
+
# Override LockJar configuration
|
34
|
+
#
|
35
|
+
def config(opts)
|
36
|
+
Runtime.instance.resolver(opts)
|
37
|
+
end
|
30
38
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Runtime.instance.resolver( opts )
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.install( *args, &blk )
|
39
|
-
lockfile, groups, opts = extract_args :lockfile, args, &blk
|
40
|
-
Runtime.instance.install( lockfile, groups, opts, &blk )
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
# Lists all dependencies as notations for groups from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
|
45
|
-
#
|
46
|
-
# * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'. Default lock file is *Jarfile.lock*.
|
47
|
-
# * An arg of an Array will set the groups, e.g. ['development','test']. Defaults group is *default*
|
48
|
-
# * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
|
49
|
-
# * :local_repo [String] sets the local repo path
|
50
|
-
# * :local_paths [Boolean] to true converts the notations to paths to jars in the local repo path
|
51
|
-
# * :resolve [Boolean] to true will make transitive dependences resolve before loading to classpath
|
52
|
-
#
|
53
|
-
# A block can be passed in, overriding values from a Jarfile.lock.
|
54
|
-
#
|
55
|
-
# @return [Array] of jar and mapped path
|
56
|
-
def self.list( *args, &blk )
|
57
|
-
lockfile, groups, opts = extract_args :lockfile, args, &blk
|
58
|
-
Runtime.instance.list( lockfile, groups, opts, &blk )
|
59
|
-
end
|
39
|
+
def install(*args, &blk)
|
40
|
+
lockfile, groups, opts = extract_args :lockfile, args, &blk
|
41
|
+
Runtime.instance.install(lockfile, groups, opts, &blk)
|
42
|
+
end
|
60
43
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
44
|
+
# Lists all dependencies as notations for groups from the Jarfile.lock.
|
45
|
+
# Depending on the type of arg, a different configuration is set.
|
46
|
+
#
|
47
|
+
# * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'.
|
48
|
+
# Default lock file is *Jarfile.lock*.
|
49
|
+
# * An arg of an Array will set the groups, e.g. ['development','test'].
|
50
|
+
# Defaults group is *default*
|
51
|
+
# * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
|
52
|
+
# * :local_repo [String] sets the local repo path
|
53
|
+
# * :local_paths [Boolean] to true converts the notations to paths to jars
|
54
|
+
# in the local repo path
|
55
|
+
# * :resolve [Boolean] to true will make transitive dependences resolve
|
56
|
+
# before loading to classpath
|
57
|
+
#
|
58
|
+
# A block can be passed in, overriding values from a Jarfile.lock.
|
59
|
+
#
|
60
|
+
# @return [Array] of jar and mapped path
|
61
|
+
def list(*args, &blk)
|
62
|
+
lockfile, groups, opts = extract_args :lockfile, args, &blk
|
63
|
+
Runtime.instance.list(lockfile, groups, opts, &blk)
|
64
|
+
end
|
75
65
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
66
|
+
# LockJar.load(*args): Loads all dependencies to the classpath for groups
|
67
|
+
# from the Jarfile.lock. Depending on the type of arg, a different configuration is set.
|
68
|
+
# * An arg of a String will set the Jarfile.lock, e.g. 'Better.lock'.
|
69
|
+
# Default lock file is *Jarfile.lock*.
|
70
|
+
# * An arg of an Array will set the groups, e.g. ['development','test'].
|
71
|
+
# Defaults group is *default*.
|
72
|
+
# * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
|
73
|
+
# * :local_repo [String] sets the local repo path
|
74
|
+
# * :resolve [Boolean] to true will make transitive dependences resolve
|
75
|
+
# before loading to classpath
|
76
|
+
# * :disable [Boolean] to true will disable any additional calls to load and lock
|
77
|
+
#
|
78
|
+
# A block can be passed in, overriding values from a Jarfile.lock.
|
79
|
+
#
|
80
|
+
# @return [Array] of absolute paths of jars and mapped paths loaded into claspath
|
81
|
+
def load(*args, &blk)
|
82
|
+
if Runtime.instance.opts.nil? || !Runtime.instance.opts[:disable]
|
83
|
+
lockfile, groups, opts = extract_args(:lockfile, args, &blk)
|
84
|
+
Runtime.instance.load(lockfile, groups, opts, &blk)
|
85
|
+
else
|
86
|
+
puts 'LockJar#load has been disabled'
|
87
|
+
[]
|
88
|
+
end
|
89
|
+
end
|
93
90
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
91
|
+
# Lock a Jarfile and generate a Jarfile.lock.
|
92
|
+
#
|
93
|
+
# LockJar.lock accepts an Array for parameters. Depending on the type of
|
94
|
+
# arg, a different configuration is set.
|
95
|
+
#
|
96
|
+
# * An arg of a String will set the Jarfile, e.g. 'Jarfile.different'.
|
97
|
+
# Default Jarfile is *Jarfile*.
|
98
|
+
# * An arg of a Hash will set the options, e.g. { :local_repo => 'path' }
|
99
|
+
# * :download_artifacts if true, will download jars to local repo. Defaults to true.
|
100
|
+
# * :local_repo sets the local repo path
|
101
|
+
# * :lockfile sets the Jarfile.lock path. Default lockfile is *Jarfile.lock*.
|
102
|
+
# * :disable [Boolean] to true will disable any additional calls to load and lock
|
103
|
+
|
104
|
+
# A block can be passed in, overriding values from a Jarfile.
|
105
|
+
#
|
106
|
+
# @return [Hash] Lock data
|
107
|
+
def lock(*args, &blk)
|
108
|
+
if Runtime.instance.opts.nil? || !Runtime.instance.opts[:disable]
|
109
|
+
jarfile, _, opts = extract_args(:jarfile, args, &blk)
|
110
|
+
Runtime.instance.lock(jarfile, opts, &blk)
|
111
|
+
else
|
112
|
+
puts 'LockJar#lock has been disabled'
|
113
|
+
[]
|
114
|
+
end
|
115
|
+
end
|
102
116
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
117
|
+
#
|
118
|
+
# Read a Jafile.lock and convert it to a LockJar::Domain::Lockfile
|
119
|
+
#
|
120
|
+
# @param [String] lockfile path to lockfile
|
121
|
+
# @return [Hash] Lock Data
|
122
|
+
def read(lockfile)
|
123
|
+
LockJar::Domain::Lockfile.read(lockfile)
|
124
|
+
end
|
111
125
|
|
112
|
-
|
113
|
-
|
114
|
-
|
126
|
+
# Add a Jarfile to be included when LockJar.lock_registered_jarfiles is called.
|
127
|
+
#
|
128
|
+
# @param [String] jarfile path to register
|
129
|
+
# @param [GemSpec] gem spec if the Jarfile is from a gem
|
130
|
+
# @return [Array] All registered jarfiles
|
131
|
+
def register_jarfile(jarfile, gem_spec = nil)
|
132
|
+
fail "Jarfile not found: #{jarfile}" unless File.exist? jarfile
|
133
|
+
registered_jarfiles[jarfile] = gem_spec
|
134
|
+
end
|
115
135
|
|
116
|
-
|
117
|
-
|
118
|
-
|
136
|
+
# Clear all registered jarfiles
|
137
|
+
def reset_registered_jarfiles
|
138
|
+
@registered_jarfiles = {}
|
139
|
+
end
|
119
140
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
# if a Jarfile is specified, it will be ignored. Use LockJar.register_jarfile
|
124
|
-
# to add dependencies.
|
125
|
-
#
|
126
|
-
# A block can be passed in, overriding values from the Jarfiles.
|
127
|
-
#
|
128
|
-
# @return [Hash] Lock data
|
129
|
-
def self.lock_registered_jarfiles( *args, &blk )
|
130
|
-
jarfiles = registered_jarfiles
|
131
|
-
return if jarfiles.empty?
|
132
|
-
instances = jarfiles.map do |jarfile|
|
133
|
-
LockJar::Domain::JarfileDsl.create jarfile
|
141
|
+
# Hash of registered jarfiles
|
142
|
+
def registered_jarfiles
|
143
|
+
@registered_jarfiles ||= {}
|
134
144
|
end
|
135
|
-
|
136
|
-
|
145
|
+
|
146
|
+
# Lock the registered Jarfiles and generate a Jarfile.lock.
|
147
|
+
#
|
148
|
+
# Options and groups are passed through to the LockJar.lock method, but
|
149
|
+
# if a Jarfile is specified, it will be ignored. Use LockJar.register_jarfile
|
150
|
+
# to add dependencies.
|
151
|
+
#
|
152
|
+
# A block can be passed in, overriding values from the Jarfiles.
|
153
|
+
#
|
154
|
+
# @return [Hash] Lock data
|
155
|
+
def lock_registered_jarfiles(*args, &blk)
|
156
|
+
jarfiles = registered_jarfiles
|
157
|
+
return if jarfiles.empty?
|
158
|
+
instances = jarfiles.map do |jarfile, spec|
|
159
|
+
if spec
|
160
|
+
LockJar::Domain::GemDsl.create spec, jarfile
|
161
|
+
else
|
162
|
+
LockJar::Domain::JarfileDsl.create jarfile
|
163
|
+
end
|
164
|
+
end
|
165
|
+
combined = instances.reduce do |result, inst|
|
166
|
+
LockJar::Domain::DslMerger.new(result, inst).merge
|
167
|
+
end
|
168
|
+
args = args.reject { |arg| arg.is_a? String }
|
169
|
+
lock(combined, *args, &blk)
|
137
170
|
end
|
138
|
-
args = args.reject { |arg| arg.is_a? String }
|
139
|
-
lock combined, *args, &blk
|
140
171
|
end
|
141
172
|
|
142
173
|
private
|
143
174
|
|
144
|
-
|
175
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
176
|
+
def self.extract_args(type, args, &blk)
|
145
177
|
lockfile_or_path = nil
|
146
178
|
opts = {}
|
147
179
|
groups = ['default']
|
148
180
|
args.each do |arg|
|
149
181
|
case arg
|
150
182
|
when Hash
|
151
|
-
opts.merge!(
|
183
|
+
opts.merge!(arg)
|
152
184
|
when String
|
153
185
|
lockfile_or_path = arg
|
154
186
|
when LockJar::Domain::Lockfile
|
@@ -168,5 +200,5 @@ module LockJar
|
|
168
200
|
end
|
169
201
|
[lockfile_or_path, groups, opts]
|
170
202
|
end
|
203
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
171
204
|
end
|
172
|
-
|