lock_jar 0.10.0 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +59 -59
  3. data/.travis.yml +8 -8
  4. data/CHANGELOG.md +30 -21
  5. data/Gemfile +13 -13
  6. data/Guardfile +9 -9
  7. data/README.md +375 -375
  8. data/Rakefile +24 -24
  9. data/bundler/Gemfile +21 -21
  10. data/bundler/LICENSE.txt +22 -22
  11. data/bundler/README.md +29 -29
  12. data/bundler/Rakefile +2 -2
  13. data/bundler/lib/lock_jar_bundler/bundler.rb +35 -35
  14. data/bundler/lib/lock_jar_bundler/piggy_back.rb +97 -97
  15. data/bundler/lib/lock_jar_bundler/version.rb +5 -5
  16. data/bundler/lib/lock_jar_bundler.rb +4 -4
  17. data/bundler/lock_jar_bundler.gemspec +24 -24
  18. data/bundler/spec/Jarfile +2 -2
  19. data/bundler/spec/dummy_gem/dummy_gem.gemspec +19 -19
  20. data/bundler/spec/lock_jar_bundler_spec.rb +48 -48
  21. data/bundler/spec/spec_helper.rb +88 -88
  22. data/lib/lock_jar/buildr.rb +144 -144
  23. data/lib/lock_jar/bundler.rb +154 -154
  24. data/lib/lock_jar/cli.rb +64 -64
  25. data/lib/lock_jar/domain/artifact.rb +123 -123
  26. data/lib/lock_jar/domain/dsl.rb +187 -187
  27. data/lib/lock_jar/domain/dsl_helper.rb +83 -83
  28. data/lib/lock_jar/domain/gem_dsl.rb +44 -44
  29. data/lib/lock_jar/domain/jarfile_dsl.rb +46 -46
  30. data/lib/lock_jar/domain/lockfile.rb +113 -113
  31. data/lib/lock_jar/maven.rb +111 -111
  32. data/lib/lock_jar/registry.rb +92 -92
  33. data/lib/lock_jar/resolver.rb +95 -95
  34. data/lib/lock_jar/runtime.rb +359 -355
  35. data/lib/lock_jar/version.rb +3 -3
  36. data/lib/lock_jar.rb +172 -177
  37. data/lock_jar.gemspec +27 -27
  38. data/spec/fixtures/Jarfile +13 -13
  39. data/spec/fixtures/Jarfile2 +1 -0
  40. data/spec/lock_jar/class_loader_spec.rb +57 -57
  41. data/spec/lock_jar/cli_spec.rb +100 -100
  42. data/spec/lock_jar/domain/dsl_helper_spec.rb +52 -52
  43. data/spec/lock_jar/domain/dsl_spec.rb +57 -57
  44. data/spec/lock_jar/maven_spec.rb +23 -23
  45. data/spec/lock_jar/resolver_spec.rb +26 -26
  46. data/spec/lock_jar/runtime_spec.rb +26 -26
  47. data/spec/lock_jar_spec.rb +372 -295
  48. data/spec/pom.xml +34 -34
  49. data/spec/spec_helper.rb +38 -38
  50. data/spec/support/helper.rb +44 -44
  51. metadata +3 -1
@@ -1,355 +1,359 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with this
3
- # work for additional information regarding copyright ownership. The ASF
4
- # licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations under
14
- # the License.
15
-
16
- require 'rubygems'
17
- require 'yaml'
18
- require 'singleton'
19
- require 'lock_jar/resolver'
20
- require 'lock_jar/registry'
21
- require 'lock_jar/domain/dsl'
22
- require 'lock_jar/domain/jarfile_dsl'
23
- require 'lock_jar/domain/lockfile'
24
-
25
- module LockJar
26
-
27
- class Runtime
28
- include Singleton
29
-
30
- attr_reader :current_resolver
31
-
32
- def initialize
33
- @current_resolver = nil
34
- end
35
-
36
- def resolver( opts = {} )
37
-
38
- # XXX: Caches the resolver by the options. Passing in nil opts will replay
39
- # from the cache. This need to change.
40
-
41
- unless opts.nil?
42
- if opts[:local_repo]
43
- opts[:local_repo] = File.expand_path(opts[:local_repo])
44
- end
45
- else
46
- if @current_resolver
47
- opts = @current_resolver.opts
48
- else
49
- opts = {}
50
- end
51
- end
52
-
53
- if @current_resolver.nil? || opts != @current_resolver.opts
54
- @current_resolver = LockJar::Resolver.new( opts )
55
- end
56
-
57
- @current_resolver
58
- end
59
-
60
- def install( jarfile_lock, groups = ['default'], opts = {}, &blk )
61
- deps = list( jarfile_lock, groups, {:with_locals => false}.merge( opts ), &blk )
62
-
63
- lockfile = LockJar::Domain::Lockfile.read( jarfile_lock )
64
- lockfile.remote_repositories.each do |repo|
65
- resolver(opts).add_remote_repository( repo )
66
- end
67
-
68
- files = resolver(opts).download( deps )
69
-
70
- files
71
- end
72
-
73
- def lock( jarfile_or_dsl, opts = {}, &blk )
74
-
75
- opts = {:download => true }.merge( opts )
76
-
77
- jarfile = nil
78
-
79
- if jarfile_or_dsl
80
- if jarfile_or_dsl.is_a? LockJar::Domain::Dsl
81
- jarfile = jarfile_or_dsl
82
- else
83
- jarfile = LockJar::Domain::JarfileDsl.create( jarfile_or_dsl )
84
- end
85
- end
86
-
87
- unless blk.nil?
88
- dsl = LockJar::Domain::Dsl.create(&blk)
89
- if jarfile.nil?
90
- jarfile = dsl
91
- else
92
- jarfile = LockJar::Domain::DslHelper.merge( jarfile, dsl )
93
- end
94
- end
95
-
96
- if jarfile.respond_to?(:bundler_enabled ) && jarfile.bundler_enabled
97
- require 'lock_jar_bundler/bundler'
98
-
99
- LockJar::Bundler.bundled_jarfiles(jarfile.bundler_enabled).each do |bundled_jarfile|
100
- jarfile = LockJar::Domain::DslHelper.merge( jarfile, LockJar::Domain::JarfileDsl.create(bundled_jarfile) )
101
- end
102
- end
103
-
104
-
105
- # If not set in opts, and is set in dsl
106
- if opts[:local_repo].nil? && jarfile.local_repository
107
- opts[:local_repo] = jarfile.local_repository
108
- end
109
-
110
- lockfile = LockJar::Domain::Lockfile.new
111
-
112
- jarfile.remote_repositories.each do |repo|
113
- resolver(opts).add_remote_repository( repo )
114
- end
115
-
116
- unless jarfile.local_repository.nil?
117
- lockfile.local_repository = jarfile.local_repository
118
- end
119
-
120
- if jarfile.maps.size > 0
121
- lockfile.maps = jarfile.maps
122
- end
123
-
124
- if jarfile.excludes.size > 0
125
- lockfile.excludes = jarfile.excludes
126
- end
127
-
128
- artifacts = []
129
- jarfile.artifacts.each do |group, group_artifacts|
130
- group_artifacts.each do |artifact|
131
- artifacts += group_artifacts
132
- end
133
- end
134
-
135
- if !jarfile.merged.empty?
136
- lockfile.merged = jarfile.merged
137
- end
138
-
139
- if !artifacts.empty?
140
- resolved_notations = resolver(opts).resolve( artifacts.select{ |artifact| artifact.resolvable? }.map(&:to_dep), opts[:download] == true )
141
-
142
- lockfile.remote_repositories = resolver(opts).remote_repositories - ['http://repo1.maven.org/maven2/']
143
-
144
- jarfile.artifacts.each do |group_name, group_artifacts|
145
- group = {'locals' => [], 'dependencies' => [], 'artifacts' => []}
146
-
147
- group_artifacts.each do |artifact|
148
-
149
- artifact_data = {}
150
-
151
- if artifact.is_a? LockJar::Domain::Jar
152
- group['dependencies'] << artifact.notation
153
- artifact_data["transitive"] = resolver(opts).dependencies_graph[artifact.notation].to_hash
154
-
155
- elsif artifact.is_a? LockJar::Domain::Pom
156
- artifact_data['scopes'] = artifact.scopes
157
-
158
- # iterate each dependency in Pom to map transitive dependencies
159
- transitive = {}
160
- artifact.notations.each do |notation|
161
- transitive.merge!( notation => resolver(opts).dependencies_graph[notation] )
162
- end
163
- artifact_data["transitive"] = transitive
164
-
165
- elsif artifact.is_a? LockJar::Domain::Local
166
- group['locals'] << artifact.path
167
- else
168
- # XXX: handle unsupported artifact
169
-
170
- end
171
-
172
- # flatten the graph of nested hashes
173
- dep_merge = lambda do |graph|
174
- deps = graph.keys
175
- graph.values.each do |next_step|
176
- deps += dep_merge.call(next_step)
177
- end
178
- deps
179
- end
180
-
181
- if artifact_data["transitive"]
182
- group['dependencies'] += dep_merge.call( artifact_data["transitive"] )
183
-
184
- # xxX: set required_by ?
185
-
186
- group['artifacts'] << { artifact.to_urn => artifact_data }
187
- end
188
- end
189
-
190
- if lockfile.excludes
191
- lockfile.excludes.each do |exclude|
192
- group['dependencies'].delete_if { |dep| dep =~ /#{exclude}/ }
193
- end
194
- end
195
-
196
- group['dependencies'].sort!
197
- if group['locals'].empty?
198
- group.delete 'locals'
199
- end
200
-
201
- lockfile.groups[group_name] = group
202
- end
203
- end
204
-
205
- lockfile.write( opts[:lockfile] || "Jarfile.lock" )
206
-
207
- lockfile
208
- end
209
-
210
- def list( lockfile_or_path, groups = ['default'], opts = {}, &blk )
211
-
212
- lockfile = nil
213
- dependencies = []
214
- maps = []
215
- with_locals = {:with_locals => true }.merge(opts).delete :with_locals
216
-
217
- if lockfile_or_path
218
- if lockfile_or_path.is_a? LockJar::Domain::Lockfile
219
- lockfile = lockfile_or_path
220
- elsif lockfile_or_path
221
- lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
222
- end
223
-
224
- dependencies = lockfile_dependencies( lockfile, groups, with_locals )
225
- maps = lockfile.maps
226
- end
227
-
228
- # Support limited DSL from block
229
- unless blk.nil?
230
- dsl = LockJar::Domain::Dsl.create(&blk)
231
- dependencies += dsl_dependencies( dsl, groups, with_locals ).map(&:to_dep)
232
- maps = dsl.maps
233
- end
234
-
235
- if maps && maps.size > 0
236
- mapped_dependencies = []
237
-
238
- maps.each do |notation, replacements|
239
- dependencies.each do |dep|
240
- if dep =~ /#{notation}/
241
- replacements.each do |replacement|
242
- mapped_dependencies << replacement
243
- end
244
- else
245
- mapped_dependencies << dep
246
- end
247
- end
248
- end
249
-
250
- dependencies = mapped_dependencies
251
- end
252
-
253
- if opts[:resolve]
254
- dependencies = resolver(opts).resolve( dependencies )
255
- end
256
-
257
- if opts[:local_paths]
258
- opts.delete( :local_paths ) # remove list opts so resolver is not reset
259
- resolver(opts).to_local_paths( dependencies )
260
-
261
- else
262
- dependencies
263
- end
264
- end
265
-
266
- # Load paths from a lockfile or block. Paths are loaded once per lockfile.
267
- #
268
- # @param [String] lockfile_path the lockfile
269
- # @param [Array] groups to load into classpath
270
- # @param [Hash] opts
271
- # @param [Block] blk
272
- def load( lockfile_or_path, groups = ['default'], opts = {}, &blk )
273
-
274
- lockfile = nil
275
-
276
- # lockfile is only loaded once
277
- unless lockfile_or_path.nil?
278
- # loaded a Lockfile instance
279
- if lockfile_or_path.is_a? LockJar::Domain::Lockfile
280
- lockfile = lockfile_or_path
281
-
282
- # check if lockfile path is already loaded
283
- elsif LockJar::Registry.instance.lockfile_registered?( lockfile_or_path )
284
- return
285
-
286
- # convert lockfile path to a Lockfile instance
287
- else
288
- lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
289
- end
290
-
291
-
292
- if opts[:local_repo].nil? && lockfile.local_repository
293
- opts[:local_repo] = lockfile.local_repository
294
- end
295
- end
296
-
297
- # set local_repo if passed in the block
298
- unless blk.nil?
299
- dsl = LockJar::Domain::Dsl.create(&blk)
300
-
301
- # set local_repo from block
302
- if opts[:local_repo].nil? && dsl.local_repository
303
- opts[:local_repo] = dsl.local_repository
304
- end
305
- end
306
-
307
- # registered merged lockfiles for lockfile
308
- if lockfile && !lockfile.merged.empty?
309
- lockfile.merged.each do |path|
310
- LockJar::Registry.instance.register_lockfile( path )
311
- end
312
- end
313
-
314
- dependencies = LockJar::Registry.instance.register_jars( list( lockfile, groups, opts, &blk ) )
315
-
316
- resolver(opts).load_to_classpath( dependencies )
317
- end
318
-
319
- private
320
-
321
- def lockfile_dependencies( lockfile, groups, with_locals = true)
322
- dependencies = []
323
-
324
- groups.each do |group|
325
- if lockfile.groups[group.to_s]
326
- dependencies += lockfile.groups[group.to_s]['dependencies']
327
-
328
- if with_locals
329
- locals = lockfile.groups[group.to_s]['locals']
330
- dependencies += locals if locals
331
- end
332
- end
333
- end
334
-
335
- dependencies
336
- end
337
-
338
- def dsl_dependencies( dsl, groups, with_locals = true)
339
-
340
- dependencies = []
341
-
342
- groups.each do |group|
343
- if dsl.artifacts[group.to_s]
344
- dependencies += dsl.artifacts[group.to_s]
345
- end
346
- end
347
-
348
- unless with_locals
349
- dependencies.select! { |dep| !dep.is_a? LockJar::Domain::Local }
350
- end
351
-
352
- dependencies
353
- end
354
- end
355
- end
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'rubygems'
17
+ require 'yaml'
18
+ require 'singleton'
19
+ require 'lock_jar/resolver'
20
+ require 'lock_jar/registry'
21
+ require 'lock_jar/domain/dsl'
22
+ require 'lock_jar/domain/jarfile_dsl'
23
+ require 'lock_jar/domain/lockfile'
24
+
25
+ module LockJar
26
+
27
+ class Runtime
28
+ include Singleton
29
+
30
+ attr_reader :current_resolver
31
+
32
+ def initialize
33
+ @current_resolver = nil
34
+ end
35
+
36
+ def resolver( opts = {} )
37
+
38
+ # XXX: Caches the resolver by the options. Passing in nil opts will replay
39
+ # from the cache. This need to change.
40
+
41
+ unless opts.nil?
42
+ if opts[:local_repo]
43
+ opts[:local_repo] = File.expand_path(opts[:local_repo])
44
+ end
45
+ else
46
+ if @current_resolver
47
+ opts = @current_resolver.opts
48
+ else
49
+ opts = {}
50
+ end
51
+ end
52
+
53
+ if @current_resolver.nil? || opts != @current_resolver.opts
54
+ @current_resolver = LockJar::Resolver.new( opts )
55
+ end
56
+
57
+ @current_resolver
58
+ end
59
+
60
+ def install( jarfile_lock, groups = ['default'], opts = {}, &blk )
61
+ deps = list( jarfile_lock, groups, {:with_locals => false}.merge( opts ), &blk )
62
+
63
+ lockfile = LockJar::Domain::Lockfile.read( jarfile_lock )
64
+ if opts[:local_repo].nil? && lockfile.local_repository
65
+ opts[:local_repo] = lockfile.local_repository
66
+ end
67
+
68
+ lockfile.remote_repositories.each do |repo|
69
+ resolver(opts).add_remote_repository( repo )
70
+ end
71
+
72
+ files = resolver(opts).download( deps )
73
+
74
+ files
75
+ end
76
+
77
+ def lock( jarfile_or_dsl, opts = {}, &blk )
78
+
79
+ opts = {:download => true }.merge( opts )
80
+
81
+ jarfile = nil
82
+
83
+ if jarfile_or_dsl
84
+ if jarfile_or_dsl.is_a? LockJar::Domain::Dsl
85
+ jarfile = jarfile_or_dsl
86
+ else
87
+ jarfile = LockJar::Domain::JarfileDsl.create( jarfile_or_dsl )
88
+ end
89
+ end
90
+
91
+ unless blk.nil?
92
+ dsl = LockJar::Domain::Dsl.create(&blk)
93
+ if jarfile.nil?
94
+ jarfile = dsl
95
+ else
96
+ jarfile = LockJar::Domain::DslHelper.merge( jarfile, dsl )
97
+ end
98
+ end
99
+
100
+ if jarfile.respond_to?(:bundler_enabled ) && jarfile.bundler_enabled
101
+ require 'lock_jar_bundler/bundler'
102
+
103
+ LockJar::Bundler.bundled_jarfiles(jarfile.bundler_enabled).each do |bundled_jarfile|
104
+ jarfile = LockJar::Domain::DslHelper.merge( jarfile, LockJar::Domain::JarfileDsl.create(bundled_jarfile) )
105
+ end
106
+ end
107
+
108
+
109
+ # If not set in opts, and is set in dsl
110
+ if opts[:local_repo].nil? && jarfile.local_repository
111
+ opts[:local_repo] = jarfile.local_repository
112
+ end
113
+
114
+ lockfile = LockJar::Domain::Lockfile.new
115
+
116
+ jarfile.remote_repositories.each do |repo|
117
+ resolver(opts).add_remote_repository( repo )
118
+ end
119
+
120
+ unless jarfile.local_repository.nil?
121
+ lockfile.local_repository = jarfile.local_repository
122
+ end
123
+
124
+ if jarfile.maps.size > 0
125
+ lockfile.maps = jarfile.maps
126
+ end
127
+
128
+ if jarfile.excludes.size > 0
129
+ lockfile.excludes = jarfile.excludes
130
+ end
131
+
132
+ artifacts = []
133
+ jarfile.artifacts.each do |group, group_artifacts|
134
+ group_artifacts.each do |artifact|
135
+ artifacts += group_artifacts
136
+ end
137
+ end
138
+
139
+ if !jarfile.merged.empty?
140
+ lockfile.merged = jarfile.merged
141
+ end
142
+
143
+ if !artifacts.empty?
144
+ resolved_notations = resolver(opts).resolve( artifacts.select{ |artifact| artifact.resolvable? }.map(&:to_dep), opts[:download] == true )
145
+
146
+ lockfile.remote_repositories = resolver(opts).remote_repositories - ['http://repo1.maven.org/maven2/']
147
+
148
+ jarfile.artifacts.each do |group_name, group_artifacts|
149
+ group = {'locals' => [], 'dependencies' => [], 'artifacts' => []}
150
+
151
+ group_artifacts.each do |artifact|
152
+
153
+ artifact_data = {}
154
+
155
+ if artifact.is_a? LockJar::Domain::Jar
156
+ group['dependencies'] << artifact.notation
157
+ artifact_data["transitive"] = resolver(opts).dependencies_graph[artifact.notation].to_hash
158
+
159
+ elsif artifact.is_a? LockJar::Domain::Pom
160
+ artifact_data['scopes'] = artifact.scopes
161
+
162
+ # iterate each dependency in Pom to map transitive dependencies
163
+ transitive = {}
164
+ artifact.notations.each do |notation|
165
+ transitive.merge!( notation => resolver(opts).dependencies_graph[notation] )
166
+ end
167
+ artifact_data["transitive"] = transitive
168
+
169
+ elsif artifact.is_a? LockJar::Domain::Local
170
+ group['locals'] << artifact.path
171
+ else
172
+ # XXX: handle unsupported artifact
173
+
174
+ end
175
+
176
+ # flatten the graph of nested hashes
177
+ dep_merge = lambda do |graph|
178
+ deps = graph.keys
179
+ graph.values.each do |next_step|
180
+ deps += dep_merge.call(next_step)
181
+ end
182
+ deps
183
+ end
184
+
185
+ if artifact_data["transitive"]
186
+ group['dependencies'] += dep_merge.call( artifact_data["transitive"] )
187
+
188
+ # xxX: set required_by ?
189
+
190
+ group['artifacts'] << { artifact.to_urn => artifact_data }
191
+ end
192
+ end
193
+
194
+ if lockfile.excludes
195
+ lockfile.excludes.each do |exclude|
196
+ group['dependencies'].delete_if { |dep| dep =~ /#{exclude}/ }
197
+ end
198
+ end
199
+
200
+ group['dependencies'].sort!
201
+ if group['locals'].empty?
202
+ group.delete 'locals'
203
+ end
204
+
205
+ lockfile.groups[group_name] = group
206
+ end
207
+ end
208
+
209
+ lockfile.write( opts[:lockfile] || "Jarfile.lock" )
210
+
211
+ lockfile
212
+ end
213
+
214
+ def list( lockfile_or_path, groups = ['default'], opts = {}, &blk )
215
+
216
+ lockfile = nil
217
+ dependencies = []
218
+ maps = []
219
+ with_locals = {:with_locals => true }.merge(opts).delete :with_locals
220
+
221
+ if lockfile_or_path
222
+ if lockfile_or_path.is_a? LockJar::Domain::Lockfile
223
+ lockfile = lockfile_or_path
224
+ elsif lockfile_or_path
225
+ lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
226
+ end
227
+
228
+ dependencies = lockfile_dependencies( lockfile, groups, with_locals )
229
+ maps = lockfile.maps
230
+ end
231
+
232
+ # Support limited DSL from block
233
+ unless blk.nil?
234
+ dsl = LockJar::Domain::Dsl.create(&blk)
235
+ dependencies += dsl_dependencies( dsl, groups, with_locals ).map(&:to_dep)
236
+ maps = dsl.maps
237
+ end
238
+
239
+ if maps && maps.size > 0
240
+ mapped_dependencies = []
241
+
242
+ maps.each do |notation, replacements|
243
+ dependencies.each do |dep|
244
+ if dep =~ /#{notation}/
245
+ replacements.each do |replacement|
246
+ mapped_dependencies << replacement
247
+ end
248
+ else
249
+ mapped_dependencies << dep
250
+ end
251
+ end
252
+ end
253
+
254
+ dependencies = mapped_dependencies
255
+ end
256
+
257
+ if opts[:resolve]
258
+ dependencies = resolver(opts).resolve( dependencies )
259
+ end
260
+
261
+ if opts[:local_paths]
262
+ opts.delete( :local_paths ) # remove list opts so resolver is not reset
263
+ resolver(opts).to_local_paths( dependencies )
264
+
265
+ else
266
+ dependencies
267
+ end
268
+ end
269
+
270
+ # Load paths from a lockfile or block. Paths are loaded once per lockfile.
271
+ #
272
+ # @param [String] lockfile_path the lockfile
273
+ # @param [Array] groups to load into classpath
274
+ # @param [Hash] opts
275
+ # @param [Block] blk
276
+ def load( lockfile_or_path, groups = ['default'], opts = {}, &blk )
277
+
278
+ lockfile = nil
279
+
280
+ # lockfile is only loaded once
281
+ unless lockfile_or_path.nil?
282
+ # loaded a Lockfile instance
283
+ if lockfile_or_path.is_a? LockJar::Domain::Lockfile
284
+ lockfile = lockfile_or_path
285
+
286
+ # check if lockfile path is already loaded
287
+ elsif LockJar::Registry.instance.lockfile_registered?( lockfile_or_path )
288
+ return
289
+
290
+ # convert lockfile path to a Lockfile instance
291
+ else
292
+ lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
293
+ end
294
+
295
+
296
+ if opts[:local_repo].nil? && lockfile.local_repository
297
+ opts[:local_repo] = lockfile.local_repository
298
+ end
299
+ end
300
+
301
+ # set local_repo if passed in the block
302
+ unless blk.nil?
303
+ dsl = LockJar::Domain::Dsl.create(&blk)
304
+
305
+ # set local_repo from block
306
+ if opts[:local_repo].nil? && dsl.local_repository
307
+ opts[:local_repo] = dsl.local_repository
308
+ end
309
+ end
310
+
311
+ # registered merged lockfiles for lockfile
312
+ if lockfile && !lockfile.merged.empty?
313
+ lockfile.merged.each do |path|
314
+ LockJar::Registry.instance.register_lockfile( path )
315
+ end
316
+ end
317
+
318
+ dependencies = LockJar::Registry.instance.register_jars( list( lockfile, groups, opts, &blk ) )
319
+
320
+ resolver(opts).load_to_classpath( dependencies )
321
+ end
322
+
323
+ private
324
+
325
+ def lockfile_dependencies( lockfile, groups, with_locals = true)
326
+ dependencies = []
327
+
328
+ groups.each do |group|
329
+ if lockfile.groups[group.to_s]
330
+ dependencies += lockfile.groups[group.to_s]['dependencies']
331
+
332
+ if with_locals
333
+ locals = lockfile.groups[group.to_s]['locals']
334
+ dependencies += locals if locals
335
+ end
336
+ end
337
+ end
338
+
339
+ dependencies
340
+ end
341
+
342
+ def dsl_dependencies( dsl, groups, with_locals = true)
343
+
344
+ dependencies = []
345
+
346
+ groups.each do |group|
347
+ if dsl.artifacts[group.to_s]
348
+ dependencies += dsl.artifacts[group.to_s]
349
+ end
350
+ end
351
+
352
+ unless with_locals
353
+ dependencies.select! { |dep| !dep.is_a? LockJar::Domain::Local }
354
+ end
355
+
356
+ dependencies
357
+ end
358
+ end
359
+ end