lock_jar 0.10.5 → 0.12.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.
@@ -19,17 +19,15 @@ require 'lock_jar/version'
19
19
  module LockJar
20
20
  module Domain
21
21
  class Lockfile
22
-
23
- attr_accessor :local_repository, :maps, :excludes, :remote_repositories,
22
+
23
+ attr_accessor :local_repository, :maps, :excludes, :remote_repositories,
24
24
  :version, :groups, :gems, :merged
25
- attr_reader :force_utf8
26
-
27
-
25
+
28
26
  def self.read( path )
29
27
  lockfile = Lockfile.new
30
-
28
+
31
29
  lock_data = YAML.load_file( path )
32
-
30
+
33
31
  lockfile.version = lock_data['version'] || LockJar::VERSION
34
32
  lockfile.merged = lock_data['merged']
35
33
  lockfile.local_repository = lock_data['local_repository']
@@ -41,69 +39,55 @@ module LockJar
41
39
  lockfile.gems = lock_data['gems'] || []
42
40
  lockfile
43
41
  end
44
-
42
+
45
43
  def initialize
46
- @force_utf8 ||= RUBY_VERSION =~ /^1.9/
47
44
  @groups = { 'default' => {} }
48
45
  @maps = []
49
46
  @excludes = []
50
47
  @remote_repositories = []
51
48
  @gems = []
52
49
  @merged = []
53
-
50
+
54
51
  @version = LockJar::VERSION # default version
55
52
  end
56
-
53
+
57
54
  def to_hash
58
55
  lock_data = { 'version' => @version }
59
-
56
+
60
57
  unless local_repository.nil?
61
58
  lock_data['local_repository'] = local_repository
62
-
63
- if @force_utf8
64
- lock_data['local_repository'] = lock_data['local_repository'].force_encoding("UTF-8")
65
- end
66
59
  end
67
-
60
+
68
61
  unless merged.empty?
69
62
  lock_data['merged'] = merged
70
63
  end
71
-
64
+
72
65
  if maps.size > 0
73
66
  lock_data['maps'] = maps
74
67
  end
75
-
76
- if excludes.size > 0
68
+
69
+ if excludes.size > 0
77
70
  lock_data['excludes'] = excludes
78
-
79
- if @force_utf8
80
- lock_data['excludes'].map! { |exclude| exclude.force_encoding("UTF-8") }
81
- end
82
71
  end
83
-
72
+
84
73
  unless gems.empty?
85
74
  lock_data['gems'] = gems
86
75
  end
87
-
76
+
88
77
  lock_data['groups'] = groups
89
-
90
- #if @force_utf8
91
- # lock_data['groups'].each do |group, group_notations|
92
- # group_notations.map! { |notation| notation.force_encoding("UTF-8") }
93
- # end
94
- #end
95
-
78
+
96
79
  if remote_repositories.size > 0
97
80
  lock_data['remote_repositories'] = remote_repositories
98
81
  end
99
-
82
+
100
83
  lock_data
101
84
  end
102
-
85
+ alias_method :to_h, :to_hash
86
+
103
87
  def to_yaml
104
88
  to_hash.to_yaml
105
89
  end
106
-
90
+
107
91
  def write( path )
108
92
  File.open( path, "w") do |f|
109
93
  f.write( to_yaml )
@@ -111,4 +95,4 @@ module LockJar
111
95
  end
112
96
  end
113
97
  end
114
- end
98
+ end
@@ -20,50 +20,54 @@ require 'fileutils'
20
20
 
21
21
  module LockJar
22
22
  class Resolver
23
-
23
+
24
24
  attr_reader :opts
25
25
  attr_reader :naether
26
-
26
+
27
27
  def initialize( opts = {} )
28
28
 
29
29
  @opts = opts
30
30
  local_repo = opts[:local_repo] || Naether::Bootstrap.default_local_repo
31
-
31
+
32
32
  # Bootstrap Naether
33
33
  Naether::Bootstrap.bootstrap_local_repo( local_repo, opts )
34
-
35
- # Bootstrapping naether will create an instance from downloaded jars.
34
+
35
+ # Bootstrapping naether will create an instance from downloaded jars.
36
36
  # If jars exist locally already, create manually
37
37
  @naether = Naether.create
38
38
  @naether.local_repo_path = local_repo if local_repo
39
39
  @naether.clear_remote_repositories if opts[:offline]
40
40
  end
41
-
41
+
42
42
  def remote_repositories
43
43
  @naether.remote_repository_urls
44
44
  end
45
-
45
+
46
+ def clear_remote_repositories
47
+ @naether.clear_remote_repositories
48
+ end
49
+
46
50
  def add_remote_repository( repo )
47
51
  @naether.add_remote_repository( repo )
48
52
  end
49
-
50
-
53
+
54
+
51
55
  def resolve( dependencies, download_artifacts = true )
52
56
  @naether.dependencies = dependencies
53
57
  @naether.resolve_dependencies( download_artifacts )
54
58
  @naether.dependencies_notation
55
59
  end
56
-
60
+
57
61
  def dependencies_graph
58
62
  @naether.dependencies_graph
59
63
  end
60
-
64
+
61
65
  def download( dependencies )
62
66
  @naether.download_artifacts( dependencies )
63
67
  end
64
-
68
+
65
69
  def to_local_paths( notations )
66
- paths = []
70
+ paths = []
67
71
  notations.each do |notation|
68
72
  if File.exists?(notation)
69
73
  paths << notation
@@ -71,12 +75,12 @@ module LockJar
71
75
  paths = paths + @naether.to_local_paths( [notation] )
72
76
  end
73
77
  end
74
-
78
+
75
79
  paths
76
80
  end
77
-
81
+
78
82
  def load_to_classpath( artifacts )
79
- paths = []
83
+ paths = []
80
84
  notations = []
81
85
 
82
86
  artifacts.each do |art|
@@ -86,11 +90,11 @@ module LockJar
86
90
  notations << art
87
91
  end
88
92
  end
89
-
93
+
90
94
  paths += @naether.to_local_paths( notations )
91
95
  Naether::Java.load_paths( paths )
92
-
96
+
93
97
  paths
94
98
  end
95
99
  end
96
- end
100
+ end
@@ -23,21 +23,21 @@ require 'lock_jar/domain/jarfile_dsl'
23
23
  require 'lock_jar/domain/lockfile'
24
24
 
25
25
  module LockJar
26
-
26
+
27
27
  class Runtime
28
28
  include Singleton
29
-
29
+
30
30
  attr_reader :current_resolver
31
-
31
+
32
32
  def initialize
33
33
  @current_resolver = nil
34
34
  end
35
-
35
+
36
36
  def resolver( opts = {} )
37
-
37
+
38
38
  # XXX: Caches the resolver by the options. Passing in nil opts will replay
39
39
  # from the cache. This need to change.
40
-
40
+
41
41
  unless opts.nil?
42
42
  if opts[:local_repo]
43
43
  opts[:local_repo] = File.expand_path(opts[:local_repo])
@@ -49,35 +49,45 @@ module LockJar
49
49
  opts = {}
50
50
  end
51
51
  end
52
-
52
+
53
53
  if @current_resolver.nil? || opts != @current_resolver.opts
54
54
  @current_resolver = LockJar::Resolver.new( opts )
55
55
  end
56
-
56
+
57
57
  @current_resolver
58
58
  end
59
-
59
+
60
+ def reset!
61
+ @current_resolver = nil
62
+ end
63
+
60
64
  def install( jarfile_lock, groups = ['default'], opts = {}, &blk )
61
65
  deps = list( jarfile_lock, groups, {:with_locals => false}.merge( opts ), &blk )
62
-
66
+
63
67
  lockfile = LockJar::Domain::Lockfile.read( jarfile_lock )
64
68
  if opts[:local_repo].nil? && lockfile.local_repository
65
69
  opts[:local_repo] = lockfile.local_repository
66
70
  end
67
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
+
68
78
  lockfile.remote_repositories.each do |repo|
69
79
  resolver(opts).add_remote_repository( repo )
70
80
  end
71
-
81
+
72
82
  files = resolver(opts).download( deps )
73
-
83
+
74
84
  files
75
85
  end
76
-
86
+
77
87
  def lock( jarfile_or_dsl, opts = {}, &blk )
78
-
88
+
79
89
  opts = {:download => true }.merge( opts )
80
-
90
+
81
91
  jarfile = nil
82
92
 
83
93
  if jarfile_or_dsl
@@ -87,7 +97,7 @@ module LockJar
87
97
  jarfile = LockJar::Domain::JarfileDsl.create( jarfile_or_dsl )
88
98
  end
89
99
  end
90
-
100
+
91
101
  unless blk.nil?
92
102
  dsl = LockJar::Domain::Dsl.create(&blk)
93
103
  if jarfile.nil?
@@ -105,14 +115,20 @@ module LockJar
105
115
  end
106
116
  end
107
117
 
108
-
118
+
109
119
  # If not set in opts, and is set in dsl
110
120
  if opts[:local_repo].nil? && jarfile.local_repository
111
- opts[:local_repo] = jarfile.local_repository
121
+ opts[:local_repo] = jarfile.local_repository
112
122
  end
113
-
123
+
114
124
  lockfile = LockJar::Domain::Lockfile.new
115
-
125
+
126
+ if jarfile.clear_repositories
127
+ resolver(opts).clear_remote_repositories
128
+ else
129
+ lockfile.remote_repositories += resolver(opts).remote_repositories.to_a
130
+ end
131
+
116
132
  jarfile.remote_repositories.each do |repo|
117
133
  resolver(opts).add_remote_repository( repo )
118
134
  end
@@ -120,57 +136,55 @@ module LockJar
120
136
  unless jarfile.local_repository.nil?
121
137
  lockfile.local_repository = jarfile.local_repository
122
138
  end
123
-
139
+
124
140
  if jarfile.maps.size > 0
125
141
  lockfile.maps = jarfile.maps
126
142
  end
127
-
128
- if jarfile.excludes.size > 0
143
+
144
+ if jarfile.excludes.size > 0
129
145
  lockfile.excludes = jarfile.excludes
130
146
  end
131
-
147
+
132
148
  artifacts = []
133
149
  jarfile.artifacts.each do |group, group_artifacts|
134
150
  group_artifacts.each do |artifact|
135
151
  artifacts += group_artifacts
136
152
  end
137
153
  end
138
-
154
+
139
155
  if !jarfile.merged.empty?
140
156
  lockfile.merged = jarfile.merged
141
157
  end
142
-
143
- if !artifacts.empty?
158
+
159
+ if !artifacts.empty?
144
160
  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
-
161
+
148
162
  jarfile.artifacts.each do |group_name, group_artifacts|
149
163
  group = {'locals' => [], 'dependencies' => [], 'artifacts' => []}
150
-
164
+
151
165
  group_artifacts.each do |artifact|
152
-
166
+
153
167
  artifact_data = {}
154
-
168
+
155
169
  if artifact.is_a? LockJar::Domain::Jar
156
170
  group['dependencies'] << artifact.notation
157
171
  artifact_data["transitive"] = resolver(opts).dependencies_graph[artifact.notation].to_hash
158
172
 
159
173
  elsif artifact.is_a? LockJar::Domain::Pom
160
174
  artifact_data['scopes'] = artifact.scopes
161
-
175
+
162
176
  # iterate each dependency in Pom to map transitive dependencies
163
177
  transitive = {}
164
- artifact.notations.each do |notation|
178
+ artifact.notations.each do |notation|
165
179
  transitive.merge!( notation => resolver(opts).dependencies_graph[notation] )
166
180
  end
167
181
  artifact_data["transitive"] = transitive
168
-
182
+
169
183
  elsif artifact.is_a? LockJar::Domain::Local
170
184
  group['locals'] << artifact.path
171
185
  else
172
186
  # XXX: handle unsupported artifact
173
-
187
+
174
188
  end
175
189
 
176
190
  # flatten the graph of nested hashes
@@ -181,64 +195,64 @@ module LockJar
181
195
  end
182
196
  deps
183
197
  end
184
-
198
+
185
199
  if artifact_data["transitive"]
186
200
  group['dependencies'] += dep_merge.call( artifact_data["transitive"] )
187
-
201
+
188
202
  # xxX: set required_by ?
189
-
203
+
190
204
  group['artifacts'] << { artifact.to_urn => artifact_data }
191
205
  end
192
206
  end
193
-
207
+
194
208
  if lockfile.excludes
195
209
  lockfile.excludes.each do |exclude|
196
210
  group['dependencies'].delete_if { |dep| dep =~ /#{exclude}/ }
197
211
  end
198
212
  end
199
-
213
+
200
214
  group['dependencies'].sort!
201
215
  if group['locals'].empty?
202
216
  group.delete 'locals'
203
217
  end
204
-
205
- lockfile.groups[group_name] = group
206
- end
218
+
219
+ lockfile.groups[group_name] = group
220
+ end
207
221
  end
208
-
222
+
209
223
  lockfile.write( opts[:lockfile] || "Jarfile.lock" )
210
-
224
+
211
225
  lockfile
212
226
  end
213
-
227
+
214
228
  def list( lockfile_or_path, groups = ['default'], opts = {}, &blk )
215
-
229
+
216
230
  lockfile = nil
217
231
  dependencies = []
218
232
  maps = []
219
233
  with_locals = {:with_locals => true }.merge(opts).delete :with_locals
220
-
234
+
221
235
  if lockfile_or_path
222
236
  if lockfile_or_path.is_a? LockJar::Domain::Lockfile
223
237
  lockfile = lockfile_or_path
224
238
  elsif lockfile_or_path
225
239
  lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
226
240
  end
227
-
241
+
228
242
  dependencies = lockfile_dependencies( lockfile, groups, with_locals )
229
243
  maps = lockfile.maps
230
244
  end
231
-
245
+
232
246
  # Support limited DSL from block
233
247
  unless blk.nil?
234
248
  dsl = LockJar::Domain::Dsl.create(&blk)
235
249
  dependencies += dsl_dependencies( dsl, groups, with_locals ).map(&:to_dep)
236
250
  maps = dsl.maps
237
251
  end
238
-
239
- if maps && maps.size > 0
252
+
253
+ if maps && maps.size > 0
240
254
  mapped_dependencies = []
241
-
255
+
242
256
  maps.each do |notation, replacements|
243
257
  dependencies.each do |dep|
244
258
  if dep =~ /#{notation}/
@@ -250,84 +264,84 @@ module LockJar
250
264
  end
251
265
  end
252
266
  end
253
-
267
+
254
268
  dependencies = mapped_dependencies
255
269
  end
256
-
270
+
257
271
  if opts[:resolve]
258
272
  dependencies = resolver(opts).resolve( dependencies )
259
273
  end
260
-
274
+
261
275
  if opts[:local_paths]
262
276
  opts.delete( :local_paths ) # remove list opts so resolver is not reset
263
277
  resolver(opts).to_local_paths( dependencies )
264
-
278
+
265
279
  else
266
280
  dependencies
267
281
  end
268
282
  end
269
-
283
+
270
284
  # Load paths from a lockfile or block. Paths are loaded once per lockfile.
271
- #
285
+ #
272
286
  # @param [String] lockfile_path the lockfile
273
287
  # @param [Array] groups to load into classpath
274
288
  # @param [Hash] opts
275
289
  # @param [Block] blk
276
290
  def load( lockfile_or_path, groups = ['default'], opts = {}, &blk )
277
-
291
+
278
292
  lockfile = nil
279
-
293
+
280
294
  # lockfile is only loaded once
281
- unless lockfile_or_path.nil?
295
+ unless lockfile_or_path.nil?
282
296
  # loaded a Lockfile instance
283
297
  if lockfile_or_path.is_a? LockJar::Domain::Lockfile
284
298
  lockfile = lockfile_or_path
285
-
299
+
286
300
  # check if lockfile path is already loaded
287
301
  elsif LockJar::Registry.instance.lockfile_registered?( lockfile_or_path )
288
- return
289
-
302
+ return
303
+
290
304
  # convert lockfile path to a Lockfile instance
291
305
  else
292
306
  lockfile = LockJar::Domain::Lockfile.read( lockfile_or_path )
293
307
  end
294
-
295
-
308
+
309
+
296
310
  if opts[:local_repo].nil? && lockfile.local_repository
297
311
  opts[:local_repo] = lockfile.local_repository
298
312
  end
299
313
  end
300
-
314
+
301
315
  # set local_repo if passed in the block
302
316
  unless blk.nil?
303
317
  dsl = LockJar::Domain::Dsl.create(&blk)
304
-
318
+
305
319
  # set local_repo from block
306
320
  if opts[:local_repo].nil? && dsl.local_repository
307
321
  opts[:local_repo] = dsl.local_repository
308
322
  end
309
323
  end
310
-
324
+
311
325
  # registered merged lockfiles for lockfile
312
326
  if lockfile && !lockfile.merged.empty?
313
327
  lockfile.merged.each do |path|
314
328
  LockJar::Registry.instance.register_lockfile( path )
315
329
  end
316
330
  end
317
-
331
+
318
332
  dependencies = LockJar::Registry.instance.register_jars( list( lockfile, groups, opts, &blk ) )
319
-
333
+
320
334
  resolver(opts).load_to_classpath( dependencies )
321
335
  end
322
-
336
+
323
337
  private
324
-
338
+
325
339
  def lockfile_dependencies( lockfile, groups, with_locals = true)
326
340
  dependencies = []
327
-
341
+
328
342
  groups.each do |group|
329
343
  if lockfile.groups[group.to_s]
330
- dependencies += lockfile.groups[group.to_s]['dependencies']
344
+ dependencies += lockfile.groups[group.to_s]['dependencies']
331
345
 
332
346
  if with_locals
333
347
  locals = lockfile.groups[group.to_s]['locals']
@@ -335,14 +349,14 @@ module LockJar
335
349
  end
336
350
  end
337
351
  end
338
-
352
+
339
353
  dependencies
340
354
  end
341
-
355
+
342
356
  def dsl_dependencies( dsl, groups, with_locals = true)
343
-
357
+
344
358
  dependencies = []
345
-
359
+
346
360
  groups.each do |group|
347
361
  if dsl.artifacts[group.to_s]
348
362
  dependencies += dsl.artifacts[group.to_s]
@@ -352,7 +366,7 @@ module LockJar
352
366
  unless with_locals
353
367
  dependencies.select! { |dep| !dep.is_a? LockJar::Domain::Local }
354
368
  end
355
-
369
+
356
370
  dependencies
357
371
  end
358
372
  end
@@ -1,3 +1,3 @@
1
1
  module LockJar
2
- VERSION = '0.10.5'
2
+ VERSION = '0.12.0'
3
3
  end