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