lock_jar 0.15.11-java

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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +59 -0
  4. data/.rubocop.yml +31 -0
  5. data/.travis.yml +21 -0
  6. data/CHANGELOG.md +80 -0
  7. data/Gemfile +13 -0
  8. data/Guardfile +8 -0
  9. data/LICENSE +176 -0
  10. data/README.md +392 -0
  11. data/Rakefile +28 -0
  12. data/bin/lockjar +6 -0
  13. data/lib/lock_jar/buildr.rb +151 -0
  14. data/lib/lock_jar/bundler.rb +68 -0
  15. data/lib/lock_jar/class_loader.rb +67 -0
  16. data/lib/lock_jar/cli.rb +92 -0
  17. data/lib/lock_jar/config.rb +41 -0
  18. data/lib/lock_jar/domain/artifact.rb +114 -0
  19. data/lib/lock_jar/domain/dsl.rb +165 -0
  20. data/lib/lock_jar/domain/dsl_merger.rb +76 -0
  21. data/lib/lock_jar/domain/gem_dsl.rb +43 -0
  22. data/lib/lock_jar/domain/jarfile_dsl.rb +35 -0
  23. data/lib/lock_jar/domain/lockfile.rb +113 -0
  24. data/lib/lock_jar/logging.rb +14 -0
  25. data/lib/lock_jar/maven.rb +112 -0
  26. data/lib/lock_jar/registry.rb +85 -0
  27. data/lib/lock_jar/resolver.rb +100 -0
  28. data/lib/lock_jar/runtime/install.rb +28 -0
  29. data/lib/lock_jar/runtime/list.rb +77 -0
  30. data/lib/lock_jar/runtime/load.rb +53 -0
  31. data/lib/lock_jar/runtime/lock.rb +152 -0
  32. data/lib/lock_jar/runtime.rb +106 -0
  33. data/lib/lock_jar/version.rb +5 -0
  34. data/lib/lock_jar.rb +203 -0
  35. data/lock_jar.gemspec +36 -0
  36. data/spec/fixtures/Jarfile +14 -0
  37. data/spec/fixtures/Jarfile2 +1 -0
  38. data/spec/fixtures/jarfile_gem/Gemfile +4 -0
  39. data/spec/fixtures/jarfile_gem/Jarfile +1 -0
  40. data/spec/fixtures/jarfile_gem/jarfile_gem.gemspec +23 -0
  41. data/spec/fixtures/jarfile_gem/lib/jarfile_gem/version.rb +3 -0
  42. data/spec/fixtures/jarfile_gem/lib/jarfile_gem.rb +5 -0
  43. data/spec/fixtures/lock_jar_config.yml +4 -0
  44. data/spec/fixtures/naether-0.13.0.jar +0 -0
  45. data/spec/lock_jar/bundler_spec.rb +34 -0
  46. data/spec/lock_jar/class_loader_spec.rb +55 -0
  47. data/spec/lock_jar/cli_spec.rb +93 -0
  48. data/spec/lock_jar/config_spec.rb +51 -0
  49. data/spec/lock_jar/domain/dsl_merger_spec.rb +51 -0
  50. data/spec/lock_jar/domain/dsl_spec.rb +55 -0
  51. data/spec/lock_jar/domain/gem_dsl_spec.rb +18 -0
  52. data/spec/lock_jar/maven_spec.rb +21 -0
  53. data/spec/lock_jar/resolver_spec.rb +69 -0
  54. data/spec/lock_jar/runtime_spec.rb +30 -0
  55. data/spec/lock_jar_spec.rb +472 -0
  56. data/spec/pom.xml +28 -0
  57. data/spec/spec_helper.rb +45 -0
  58. data/spec/support/Jarfile +1 -0
  59. data/spec/support/helper.rb +52 -0
  60. data/spec/support/shared_examples/lockfile.rb +45 -0
  61. metadata +203 -0
@@ -0,0 +1,472 @@
1
+ require 'spec_helper'
2
+ require 'lib/lock_jar'
3
+ require 'lib/lock_jar/domain/dsl'
4
+ require 'naether'
5
+
6
+ describe LockJar do
7
+ include Spec::Helpers
8
+
9
+ let(:local_repo) { "#{TEMP_DIR}/test-repo" }
10
+
11
+ before do
12
+ LockJar::Runtime.instance.reset!
13
+
14
+ if File.exist?(TEMP_DIR)
15
+ remove_file("#{TEMP_DIR}/Jarfile.lock")
16
+ else
17
+ Dir.mkdir(TEMP_DIR)
18
+ end
19
+ end
20
+
21
+ describe '#lock' do
22
+ context 'creates a lockfile' do
23
+ let(:lockfile) do
24
+ LockJar.lock(lockjar_source, local_repo: local_repo, lockfile: "#{TEMP_DIR}/Jarfile.lock")
25
+ expect(File).to exist("#{TEMP_DIR}/Jarfile.lock")
26
+ LockJar.read("#{TEMP_DIR}/Jarfile.lock")
27
+ end
28
+ let(:test_dependencies) { %w(com.beust:jcommander:jar:1.48 org.beanshell:bsh:jar:2.0b4 org.testng:testng:jar:6.9.10) }
29
+ let(:test_artifacts) do
30
+ [
31
+ {
32
+ 'jar:org.testng:testng:jar:6.9.10' => {
33
+ 'transitive' => {
34
+ 'com.beust:jcommander:jar:1.48' => {},
35
+ 'org.beanshell:bsh:jar:2.0b4' => {}
36
+ }
37
+ }
38
+ }
39
+ ]
40
+ end
41
+
42
+ context 'from Jarfile' do
43
+ let(:lockjar_source) { 'spec/fixtures/Jarfile' }
44
+ let(:expected_version) { LockJar::VERSION }
45
+ let(:expected_local_repository) { '~/.m2/repository' }
46
+ let(:expected_excludes) { %w(commons-logging logkit) }
47
+ let(:expected_remote_repositories) { %w(https://repo1.maven.org/maven2/) }
48
+ let(:expected_groups) do
49
+ {
50
+ 'default' => {
51
+ 'locals' => ['spec/fixtures/naether-0.13.0.jar'],
52
+ 'dependencies' => %w(
53
+ ch.qos.logback:logback-classic:jar:0.9.24
54
+ ch.qos.logback:logback-core:jar:0.9.24 com.metapossum:metapossum-scanner:jar:1.0
55
+ com.tobedevoured.modelcitizen:core:jar:0.8.1
56
+ commons-beanutils:commons-beanutils:jar:1.8.3 commons-io:commons-io:jar:1.4
57
+ commons-lang:commons-lang:jar:2.6 commons-logging:commons-logging:jar:1.1.1
58
+ org.apache.mina:mina-core:jar:2.0.4
59
+ org.slf4j:slf4j-api:jar:1.6.1
60
+ ),
61
+ 'artifacts' => [
62
+ {
63
+ 'jar:org.apache.mina:mina-core:jar:2.0.4' => {
64
+ 'transitive' => { 'org.slf4j:slf4j-api:jar:1.6.1' => {} }
65
+ }
66
+ },
67
+ {
68
+ 'pom:spec/pom.xml' => {
69
+ 'scopes' => %w(runtime compile),
70
+ 'transitive' => {
71
+ 'com.tobedevoured.modelcitizen:core:jar:0.8.1' => {
72
+ 'com.metapossum:metapossum-scanner:jar:1.0' => {
73
+ 'commons-io:commons-io:jar:1.4' => {}
74
+ },
75
+ 'commons-beanutils:commons-beanutils:jar:1.8.3' => {
76
+ 'commons-logging:commons-logging:jar:1.1.1' => {}
77
+ },
78
+ 'ch.qos.logback:logback-classic:jar:0.9.24' => {
79
+ 'ch.qos.logback:logback-core:jar:0.9.24' => {}
80
+ },
81
+ 'commons-lang:commons-lang:jar:2.6' => {}
82
+ }
83
+ }
84
+ }
85
+ }
86
+ ]
87
+ },
88
+ 'development' => {
89
+ 'dependencies' => ['com.typesafe:config:jar:0.5.0'],
90
+ 'artifacts' => [
91
+ { 'jar:com.typesafe:config:jar:0.5.0' => { 'transitive' => {} } }
92
+ ]
93
+ },
94
+ 'test' => {
95
+ 'dependencies' => test_dependencies,
96
+ 'artifacts' => test_artifacts
97
+ }
98
+ }
99
+ end
100
+ end
101
+
102
+ context 'from a dsl' do
103
+ describe '#without_default_maven_repo' do
104
+ let(:lockjar_source) do
105
+ LockJar::Domain::Dsl.create do
106
+ without_default_maven_repo
107
+ remote_repo 'https://repository.jboss.org/nexus/content/groups/public'
108
+ jar 'org.jboss.logging:jboss-logging:3.1.0.GA'
109
+ end
110
+ end
111
+
112
+ let(:expected_version) { LockJar::VERSION }
113
+ let(:expected_remote_repositories) { ['https://repository.jboss.org/nexus/content/groups/public'] }
114
+ let(:expected_groups) do
115
+ {
116
+ 'default' => {
117
+ 'dependencies' => ['org.jboss.logging:jboss-logging:jar:3.1.0.GA'],
118
+ 'artifacts' => [
119
+ { 'jar:org.jboss.logging:jboss-logging:jar:3.1.0.GA' => { 'transitive' => {} } }
120
+ ]
121
+ }
122
+ }
123
+ end
124
+
125
+ it_behaves_like 'a lockfile'
126
+ end
127
+
128
+ describe '#map' do
129
+ let(:lockjar_source) do
130
+ LockJar::Domain::Dsl.create do
131
+ map 'org.testng:testng:jar:6.9.10', 'path/to/jar'
132
+ jar 'org.testng:testng:jar:6.9.10'
133
+ end
134
+ end
135
+
136
+ let(:expected_version) { LockJar::VERSION }
137
+ let(:expected_maps) { { 'org.testng:testng:jar:6.9.10' => ['path/to/jar'] } }
138
+ let(:expected_remote_repositories) { ['https://repo1.maven.org/maven2/'] }
139
+ let(:expected_groups) do
140
+ {
141
+ 'default' => {
142
+ 'dependencies' => test_dependencies,
143
+ 'artifacts' => test_artifacts
144
+ }
145
+ }
146
+ end
147
+
148
+ it_behaves_like 'a lockfile'
149
+ end
150
+
151
+ describe '#exclude' do
152
+ let(:lockjar_source) do
153
+ LockJar::Domain::Dsl.create do
154
+ remote_repo 'https://repository.jboss.org/nexus/content/groups/public'
155
+ exclude 'commons-logging', 'logkit'
156
+ jar 'opensymphony:oscache:jar:2.4.1'
157
+ end
158
+ end
159
+
160
+ let(:expected_version) { LockJar::VERSION }
161
+ let(:expected_excludes) { %w(commons-logging logkit) }
162
+ let(:expected_remote_repositories) { %w(https://repo1.maven.org/maven2/ https://repository.jboss.org/nexus/content/groups/public) }
163
+ let(:expected_groups) do
164
+ {
165
+ 'default' => {
166
+ 'dependencies' => %w(
167
+ avalon-framework:avalon-framework:jar:4.1.3 javax.jms:jms:jar:1.1
168
+ javax.servlet:servlet-api:jar:2.3 log4j:log4j:jar:1.2.12
169
+ opensymphony:oscache:jar:2.4.1
170
+ ),
171
+ 'artifacts' => [
172
+ {
173
+ 'jar:opensymphony:oscache:jar:2.4.1' => {
174
+ 'transitive' => {
175
+ 'commons-logging:commons-logging:jar:1.1' => {
176
+ 'logkit:logkit:jar:1.0.1' => {},
177
+ 'log4j:log4j:jar:1.2.12' => {},
178
+ 'avalon-framework:avalon-framework:jar:4.1.3' => {}
179
+ },
180
+ 'javax.jms:jms:jar:1.1' => {},
181
+ 'javax.servlet:servlet-api:jar:2.3' => {}
182
+ }
183
+ }
184
+ }
185
+ ]
186
+ }
187
+ }
188
+ end
189
+
190
+ it_behaves_like 'a lockfile'
191
+ end
192
+ end
193
+
194
+ context 'from a block' do
195
+ let(:lockfile) do
196
+ LockJar.lock(local_repo: local_repo, lockfile: "#{TEMP_DIR}/NoRepoJarfile.lock") do
197
+ jar 'org.eclipse.jetty:jetty-servlet:8.1.3.v20120416'
198
+ end
199
+
200
+ File.exist?("#{TEMP_DIR}/NoRepoJarfile.lock").should be_truthy
201
+
202
+ LockJar.read("#{TEMP_DIR}/NoRepoJarfile.lock")
203
+ end
204
+
205
+ let(:expected_version) { LockJar::VERSION }
206
+ let(:expected_remote_repositories) { %w(https://repo1.maven.org/maven2/) }
207
+ let(:expected_groups) do
208
+ {
209
+ 'default' => {
210
+ 'dependencies' => %w(
211
+ org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016
212
+ org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416
213
+ org.eclipse.jetty:jetty-http:jar:8.1.3.v20120416
214
+ org.eclipse.jetty:jetty-io:jar:8.1.3.v20120416
215
+ org.eclipse.jetty:jetty-security:jar:8.1.3.v20120416
216
+ org.eclipse.jetty:jetty-server:jar:8.1.3.v20120416
217
+ org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416
218
+ org.eclipse.jetty:jetty-util:jar:8.1.3.v20120416),
219
+ 'artifacts' => [
220
+ {
221
+ 'jar:org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416' => {
222
+ 'transitive' => {
223
+ 'org.eclipse.jetty:jetty-security:jar:8.1.3.v20120416' => {
224
+ 'org.eclipse.jetty:jetty-server:jar:8.1.3.v20120416' => {
225
+ 'org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016' => {},
226
+ 'org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416' => {},
227
+ 'org.eclipse.jetty:jetty-http:jar:8.1.3.v20120416' => {
228
+ 'org.eclipse.jetty:jetty-io:jar:8.1.3.v20120416' => {
229
+ 'org.eclipse.jetty:jetty-util:jar:8.1.3.v20120416' => {}
230
+ }
231
+ }
232
+ }
233
+ }
234
+ }
235
+ }
236
+ }
237
+ ]
238
+ }
239
+ }
240
+ end
241
+
242
+ it_behaves_like 'a lockfile'
243
+ end
244
+ end
245
+ end
246
+
247
+ describe '#install' do
248
+ let(:repo_path) { "#{TEMP_DIR}/test-repo-install" }
249
+
250
+ it 'should install jars' do
251
+ LockJar.lock('spec/fixtures/Jarfile', download_artifacts: false, local_repo: "#{TEMP_DIR}/test-repo-install", lockfile: "#{TEMP_DIR}/Jarfile.lock")
252
+
253
+ jars = LockJar.install("#{TEMP_DIR}/Jarfile.lock", ['default'], local_repo: "#{TEMP_DIR}/test-repo-install")
254
+ expect(jars).to eql(
255
+ [
256
+ File.expand_path("#{repo_path}/com/google/guava/guava/14.0.1/guava-14.0.1.jar"),
257
+ File.expand_path("#{repo_path}/org/apache/mina/mina-core/2.0.4/mina-core-2.0.4.jar"),
258
+ File.expand_path("#{repo_path}/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar")
259
+ ]
260
+ )
261
+ end
262
+ end
263
+
264
+ describe '#register_jarfile' do
265
+ after do
266
+ LockJar.reset_registered_jarfiles
267
+ end
268
+
269
+ it 'should add an existing jarfiles in order' do
270
+ LockJar.register_jarfile 'spec/fixtures/Jarfile'
271
+ LockJar.register_jarfile 'spec/fixtures/Jarfile2'
272
+ LockJar.registered_jarfiles.keys.should ==
273
+ ['spec/fixtures/Jarfile', 'spec/fixtures/Jarfile2']
274
+ end
275
+
276
+ it 'should not add a missing jarfile' do
277
+ expect { LockJar.register_jarfile 'spec/fixtures/NotAJarfile' }.to(
278
+ raise_error(RuntimeError, 'Jarfile not found: spec/fixtures/NotAJarfile')
279
+ )
280
+ end
281
+ end
282
+
283
+ describe '#lock_registered_jarfiles' do
284
+ let(:lockfile) { "#{TEMP_DIR}/Jarfile.lock" }
285
+ let(:lock_registered_jarfiles) { LockJar.lock_registered_jarfiles lockfile: lockfile }
286
+
287
+ after do
288
+ LockJar.reset_registered_jarfiles
289
+ end
290
+
291
+ context 'with LRJJarfile1.lock' do
292
+ before do
293
+ File.unlink lockfile if File.exist? lockfile
294
+ end
295
+
296
+ it 'should work with no jarfiles' do
297
+ expect(lock_registered_jarfiles).to be_nil
298
+ expect(File).to_not exist(lockfile)
299
+ end
300
+ end
301
+
302
+ context 'with multiple lockfiles' do
303
+ before do
304
+ LockJar.register_jarfile 'spec/fixtures/Jarfile'
305
+ LockJar.register_jarfile 'spec/fixtures/Jarfile2'
306
+ File.unlink lockfile if File.exist? lockfile
307
+ end
308
+
309
+ it 'should dependencies from all jarfiles' do
310
+ artifacts = lock_registered_jarfiles.to_hash['groups']['default']['artifacts'].flat_map(&:keys)
311
+ artifacts.should eq %w(
312
+ jar:org.apache.mina:mina-core:jar:2.0.4
313
+ pom:spec/pom.xml
314
+ jar:org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416
315
+ )
316
+ expect(File).to exist(lockfile)
317
+ end
318
+ end
319
+
320
+ context 'with gem lockfiles' do
321
+ let(:gem_spec) { Gem::Specification.find_by_name('jarfile_gem') }
322
+ let(:lock_registered_jarfiles) { LockJar.lock_registered_jarfiles lockfile: lockfile }
323
+
324
+ before do
325
+ LockJar.register_jarfile 'spec/fixtures/jarfile_gem/Jarfile', gem_spec
326
+ File.unlink lockfile if File.exist? lockfile
327
+ end
328
+
329
+ it 'should have gem dependencies' do
330
+ artifacts = lock_registered_jarfiles.to_hash['groups']['default']['artifacts'].flat_map(&:keys)
331
+ artifacts.should eq %w(
332
+ jar:commons-lang:commons-lang:jar:2.4
333
+ )
334
+ expect(File).to exist(lockfile)
335
+ end
336
+ end
337
+ end
338
+
339
+ describe '#list' do
340
+ let(:lockfile) { "#{TEMP_DIR}/Jarfile.lock" }
341
+ let(:lock) do
342
+ LockJar.lock('spec/fixtures/Jarfile', local_repo: local_repo, lockfile: lockfile)
343
+ end
344
+ let(:jars) do
345
+ lock
346
+ LockJar.list(lockfile, ['default', 'development', 'bad scope'], local_repo: local_repo)
347
+ end
348
+
349
+ it 'should list jars' do
350
+ jars.should eql(
351
+ %w(
352
+ com.google.guava:guava:jar:14.0.1 org.apache.mina:mina-core:jar:2.0.4
353
+ org.slf4j:slf4j-api:jar:1.6.1 spec/fixtures/naether-0.13.0.jar
354
+ com.typesafe:config:jar:0.5.0
355
+ )
356
+ )
357
+ end
358
+
359
+ context 'with a dsl' do
360
+ let(:local_path) { "#{TEMP_DIR}/guava.jar" }
361
+ let(:lockfile) { "#{TEMP_DIR}/ListJarfile.lock" }
362
+ let(:dsl) do
363
+ LockJar::Domain::Dsl.create do
364
+ map 'com.google.guava:guava', "#{TEMP_DIR}/guava.jar"
365
+ jar 'com.google.guava:guava:14.0.1'
366
+ end
367
+ end
368
+ let(:paths) { LockJar.list(lockfile, local_repo: local_repo) }
369
+
370
+ before { LockJar.lock(dsl, local_repo: local_repo, lockfile: lockfile) }
371
+
372
+ it 'should replace dependencies with maps' do
373
+ paths.should eql([local_path])
374
+ end
375
+ end
376
+
377
+ context 'with resolve: false' do
378
+ let(:jars) do
379
+ lock
380
+ LockJar.list(lockfile, local_repo: local_repo, resolve: false)
381
+ end
382
+
383
+ it 'should only list root dependencies' do
384
+ jars.should eql(
385
+ %w(
386
+ org.apache.mina:mina-core:jar:2.0.4 spec/pom.xml spec/fixtures/naether-0.13.0.jar
387
+ )
388
+ )
389
+ end
390
+ end
391
+ end
392
+
393
+ describe '#load' do
394
+ def expect_java_class_not_loaded(java_class)
395
+ if Naether.platform == 'java'
396
+ lambda { java_import java_class }.should raise_error
397
+ else
398
+ lambda { Rjb.import(java_class) }.should raise_error
399
+ end
400
+ end
401
+
402
+ def expect_java_class_loaded(java_class)
403
+ if Naether.platform == 'java'
404
+ lambda { java_import java_class }.should_not raise_error
405
+ else
406
+ lambda { Rjb.import(java_class) }.should_not raise_error
407
+ end
408
+ end
409
+
410
+ let(:repo_path) { "#{TEMP_DIR}/test-repo" }
411
+
412
+ it 'by Jarfile.lock' do
413
+ expect_java_class_not_loaded('org.apache.mina.core.IoUtil')
414
+
415
+ LockJar.lock('spec/fixtures/Jarfile', local_repo: local_repo, lockfile: "#{TEMP_DIR}/Jarfile.lock")
416
+ LockJar.load("#{TEMP_DIR}/Jarfile.lock", ['default'], local_repo: local_repo)
417
+ expect(LockJar::Registry.instance.lockfile_registered?("#{TEMP_DIR}/Jarfile.lock")).to_not be
418
+ expect_java_class_loaded('org.apache.mina.core.IoUtil')
419
+ end
420
+
421
+ it 'by block with resolve option' do
422
+ expect_java_class_not_loaded('org.modeshape.common.math.Duration')
423
+
424
+ LockJar.load(local_repo: TEST_REPO, resolve: true) do
425
+ jar 'org.modeshape:modeshape-common:3.4.0.Final'
426
+ end
427
+
428
+ expect_java_class_loaded('org.modeshape.common.math.Duration')
429
+ end
430
+
431
+ context 'with disable option' do
432
+ it 'consective calls to load should return nil' do
433
+ LockJar.load(local_repo: TEST_REPO, resolve: true, disable: true) do
434
+ jar 'org.modeshape:modeshape-common:3.4.0.Final'
435
+ end
436
+
437
+ jars = LockJar.load(local_repo: TEST_REPO, resolve: true) do
438
+ jar 'another:jar:1.2.3'
439
+ end
440
+ expect(jars).to be_empty
441
+ end
442
+ end
443
+ end
444
+
445
+ describe '#extract_args' do
446
+ # Certain argument combinations can't really be tested
447
+
448
+ it 'should have the right defaults for :lockfile' do
449
+ LockJar.send(:extract_args, :lockfile, []).should eq ['Jarfile.lock', ['default'], {}]
450
+ end
451
+
452
+ it 'should have the right defaults for :jarfile' do
453
+ LockJar.send(:extract_args, :jarfile, []).should eq ['Jarfile', ['default'], {}]
454
+ end
455
+
456
+ it 'should not have a default filename if a block is given' do
457
+ blk = proc {}
458
+ LockJar.send(:extract_args, :jarfile, [], &blk).should eq [nil, ['default'], {}]
459
+ LockJar.send(:extract_args, :lockfile, [], &blk).should eq [nil, ['default'], {}]
460
+ end
461
+
462
+ it 'should use the :lockfile opt when lockfile is requested' do
463
+ LockJar.send(:extract_args, :lockfile, [{ lockfile: 'LF' }]).should eq ['LF', ['default'], { lockfile: 'LF' }]
464
+ end
465
+ it 'should not use the :lockfile opt when jarfile is requested' do
466
+ LockJar.send(:extract_args, :jarfile, [{ lockfile: 'LF' }]).should eq ['Jarfile', ['default'], { lockfile: 'LF' }]
467
+ end
468
+ it 'should not use the :lockfile opt when a lockfile provided' do
469
+ LockJar.send(:extract_args, :lockfile, ['MyLF', { lockfile: 'LF' }]).should eq ['MyLF', ['default'], { lockfile: 'LF' }]
470
+ end
471
+ end
472
+ end
data/spec/pom.xml ADDED
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/
3
+ 2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 h
4
+ ttp://maven.apache.org/maven-v4_0_0.xsd ">
5
+ <modelVersion>4.0.0</modelVersion>
6
+ <groupId>lockjar</groupId>
7
+ <artifactId>test</artifactId>
8
+ <version>3</version>
9
+ <packaging>jar</packaging>
10
+ <repositories>
11
+ <repository>
12
+ <url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
13
+ </repository>
14
+ </repositories>
15
+ <dependencies>
16
+ <dependency>
17
+ <groupId>com.google.guava</groupId>
18
+ <artifactId>guava</artifactId>
19
+ <version>14.0.1</version>
20
+ </dependency>
21
+ <dependency>
22
+ <groupId>org.jboss.unit</groupId>
23
+ <artifactId>jboss-unit</artifactId>
24
+ <version>1.2.4</version>
25
+ <scope>test</scope>
26
+ </dependency>
27
+ </dependencies>
28
+ </project>
@@ -0,0 +1,45 @@
1
+ $LOAD_PATH.unshift File.expand_path('.')
2
+ $LOAD_PATH.unshift File.expand_path(File.join('..', File.dirname(__FILE__)))
3
+ $LOAD_PATH.unshift File.expand_path(File.join('..', File.dirname(__FILE__), 'lib'))
4
+
5
+ require 'rspec'
6
+ require 'lock_jar'
7
+ require 'lock_jar/cli'
8
+ require 'stringio'
9
+ require 'fileutils'
10
+ require 'lock_jar/logging'
11
+ require 'pry'
12
+
13
+ # Requires supporting ruby files with custom matchers and macros, etc,
14
+ # in spec/support/ and its subdirectories.
15
+ Dir[File.expand_path('.') + '/spec/support/**/*.rb'].each { |f| require f }
16
+
17
+ LockJar::Logging.verbose!
18
+
19
+ # rubocop:disable Style/GlobalVars
20
+ def mock_terminal
21
+ @input = StringIO.new
22
+ @output = StringIO.new
23
+ $terminal = HighLine.new @input, @output
24
+ end
25
+ # rubocop:enable Style/GlobalVars
26
+
27
+ TEMP_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
28
+ TEST_REPO = File.expand_path(File.join(TEMP_DIR, 'test-repo-install'))
29
+ PARAM_CONFIG = File.expand_path(File.join(TEMP_DIR, 'param_config'))
30
+ DSL_CONFIG = File.expand_path(File.join(TEMP_DIR, 'dsl_config'))
31
+
32
+ RSpec.configure do |config|
33
+ config.treat_symbols_as_metadata_keys_with_true_values = true
34
+ config.run_all_when_everything_filtered = true
35
+ config.filter_run :focus
36
+
37
+ config.before(:suite) do
38
+ FileUtils.mkdir_p(DSL_CONFIG)
39
+ end
40
+
41
+ config.after(:suite) do
42
+ FileUtils.rm_rf(PARAM_CONFIG)
43
+ FileUtils.rm_rf(DSL_CONFIG)
44
+ end
45
+ end
@@ -0,0 +1 @@
1
+ jar "com.google.guava:guava:14.0.1"
@@ -0,0 +1,52 @@
1
+ require 'open3'
2
+ require 'pathname'
3
+
4
+ module Spec
5
+ module Helpers
6
+ def remove_file(path)
7
+ FileUtils.rm(path) if File.exist? path
8
+ end
9
+
10
+ def lockjar(cmd, _options = {})
11
+ lockjar_bin = File.expand_path('../../../bin/lockjar', __FILE__)
12
+ cmd = "ruby -I#{lib} #{lockjar_bin} #{cmd}"
13
+
14
+ sys_exec(cmd)
15
+ end
16
+
17
+ def lib
18
+ File.expand_path('../../../lib', __FILE__)
19
+ end
20
+
21
+ # rubocop:disable Style/GlobalVars
22
+ def sys_exec(cmd, expect_err = false)
23
+ Open3.popen3(cmd.to_s) do |stdin, stdout, stderr|
24
+ @in_p = stdin
25
+ @out_p = stdout
26
+ @err_p = stderr
27
+
28
+ yield @in_p if block_given?
29
+ @in_p.close
30
+
31
+ @out = @out_p.read.strip
32
+ @err = @err_p.read.strip
33
+ end
34
+
35
+ puts @err unless expect_err || @err.empty? || !$show_err
36
+ @out
37
+ end
38
+ # rubocop:enable Style/GlobalVars
39
+
40
+ def install_jarfile(*args)
41
+ root_path ||= Pathname.new(File.expand_path('../../..', __FILE__))
42
+ jarfile_path = root_path.join('Jarfile')
43
+ File.open(jarfile_path.to_s, 'w') do |f|
44
+ f.puts args.last
45
+ end
46
+ end
47
+
48
+ def is_jruby?
49
+ defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'jruby')
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'a lockfile' do
4
+ let(:lockfile_hash) { lockfile.to_h }
5
+
6
+ it 'should have a version' do
7
+ lockfile_hash['version'].should eql LockJar::VERSION
8
+ end
9
+
10
+ it 'should have a excludes' do
11
+ if respond_to? :expected_excludes
12
+ lockfile_hash['excludes'].should eql expected_excludes
13
+ end
14
+ end
15
+
16
+ it 'should have a local repository' do
17
+ if respond_to? :expected_local_repository
18
+ expect(lockfile_hash['local_repository']).to(eql(expected_local_repository))
19
+ end
20
+ end
21
+
22
+ it 'should have a maps' do
23
+ expect(lockfile_hash['maps']).to(eql(expected_map)) if respond_to? :expected_map
24
+ end
25
+
26
+ it 'should have remote repositories' do
27
+ lockfile_hash['remote_repositories'].should eql expected_remote_repositories
28
+ end
29
+
30
+ context 'for groups' do
31
+ let(:groups) { lockfile_hash['groups'] }
32
+
33
+ it 'should have default' do
34
+ groups['default'].should eql expected_groups['default']
35
+ end
36
+
37
+ it 'should match development' do
38
+ groups['development'].should eql expected_groups['development']
39
+ end
40
+
41
+ it 'should match test' do
42
+ groups['test'].should eql expected_groups['test']
43
+ end
44
+ end
45
+ end