lock_jar 0.10.5 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,369 +4,398 @@ require 'lib/lock_jar'
4
4
  require 'lib/lock_jar/domain/dsl'
5
5
  require 'naether'
6
6
 
7
- describe LockJar, "#lock" do
8
- it "should create a lock file" do
7
+ describe LockJar do
8
+
9
+ before do
10
+ LockJar::Runtime.instance.reset!
11
+
9
12
  if File.exists?( TEMP_DIR )
10
13
  File.delete( "#{TEMP_DIR}/Jarfile.lock" ) if File.exists?( "#{TEMP_DIR}/Jarfile.lock" )
11
14
  else
12
15
  Dir.mkdir( TEMP_DIR )
13
16
  end
17
+ end
14
18
 
15
- LockJar.lock( "spec/fixtures/Jarfile", :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
16
- File.exists?( "#{TEMP_DIR}/Jarfile.lock" ).should be_true
17
-
18
- lockfile = LockJar.read("#{TEMP_DIR}/Jarfile.lock")
19
- lockfile.to_hash.should eql({
20
- "version"=> LockJar::VERSION,
21
- "local_repository"=>"~/.m2/repository",
22
- "groups"=>{
23
- "default"=>{
24
- "locals"=>["spec/fixtures/naether-0.13.0.jar"],
25
- "dependencies"=>["ch.qos.logback:logback-classic:jar:0.9.24",
26
- "ch.qos.logback:logback-core:jar:0.9.24", "com.metapossum:metapossum-scanner:jar:1.0",
27
- "com.slackworks:modelcitizen:jar:0.2.2",
28
- "commons-beanutils:commons-beanutils:jar:1.8.3", "commons-io:commons-io:jar:1.4",
29
- "commons-lang:commons-lang:jar:2.6", "commons-logging:commons-logging:jar:1.1.1",
30
- "org.apache.mina:mina-core:jar:2.0.4",
31
- "org.slf4j:slf4j-api:jar:1.6.1"],
32
- "artifacts"=>[{
33
- "jar:org.apache.mina:mina-core:jar:2.0.4"=>{
34
- "transitive"=>{"org.slf4j:slf4j-api:jar:1.6.1"=>{}}
35
- }
36
- }, {
37
- "pom:spec/pom.xml"=>{
38
- "scopes"=>["runtime", "compile"],
39
- "transitive"=>{
40
- "com.slackworks:modelcitizen:jar:0.2.2" => {
41
- "com.metapossum:metapossum-scanner:jar:1.0"=>{
42
- "commons-io:commons-io:jar:1.4"=>{}
43
- },
44
- "commons-beanutils:commons-beanutils:jar:1.8.3"=>{
45
- "commons-logging:commons-logging:jar:1.1.1"=>{}
46
- },
47
- "ch.qos.logback:logback-classic:jar:0.9.24"=>{
48
- "ch.qos.logback:logback-core:jar:0.9.24"=>{}
49
- },
50
- "commons-lang:commons-lang:jar:2.6"=>{}
19
+ describe "#lock" do
20
+ context "creates a lockfile" do
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
24
+ LockJar.read("#{TEMP_DIR}/Jarfile.lock")
25
+ end
26
+
27
+ context "from Jarfile" do
28
+ let(:lockjar_source) { "spec/fixtures/Jarfile" }
29
+
30
+ let(:expected_version) { LockJar::VERSION }
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/] }
34
+ let(:expected_groups) do
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"=>{}}
51
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"=>{}
64
+ }
65
+ }
66
+ }
67
+ }]
68
+ },
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
+ },
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
+ }]
81
+ }
82
+ }
83
+ end
84
+ end
85
+
86
+ context "from a dsl" do
87
+
88
+ describe '#map' do
89
+ let(:lockjar_source) do
90
+ LockJar::Domain::Dsl.create do
91
+ map 'junit:junit:4.10', "#{TEMP_DIR}"
92
+ jar 'junit:junit:4.10'
93
+ end
94
+ end
95
+
96
+ let(:expected_version) { LockJar::VERSION }
97
+ let(:expected_maps) { {"junit:junit:4.10"=>["#{TEMP_DIR}"] } }
98
+ let(:expected_remote_repositories) do
99
+ %w[
100
+ http://repo1.maven.org/maven2/
101
+ ]
102
+ end
103
+ let(:expected_groups) do
104
+ {
105
+ "default"=>{
106
+ "dependencies"=>["junit:junit:jar:4.10", "org.hamcrest:hamcrest-core:jar:1.1"],
107
+ "artifacts"=>[{
108
+ "jar:junit:junit:jar:4.10"=>{
109
+ "transitive"=>{"org.hamcrest:hamcrest-core:jar:1.1"=>{}}}
110
+ }]
52
111
  }
53
112
  }
54
- }]
55
- },
56
- "development"=>{
57
- "dependencies"=>["com.typesafe:config:jar:0.5.0"],
58
- "artifacts"=>[{
59
- "jar:com.typesafe:config:jar:0.5.0"=>{"transitive"=>{}}
60
- }]
61
- },
62
- "test"=>{
63
- "dependencies"=>["junit:junit:jar:4.10", "org.hamcrest:hamcrest-core:jar:1.1"],
64
- "artifacts"=>[{
65
- "jar:junit:junit:jar:4.10"=>{
66
- "transitive"=>{"org.hamcrest:hamcrest-core:jar:1.1"=>{}}}
67
- }]
68
- }
69
- },
70
- "remote_repositories" => ["http://mirrors.ibiblio.org/pub/mirrors/maven2", "http://repository.jboss.org/nexus/content/groups/public-jboss"]
71
- })
72
- end
73
-
74
- it "should replace dependencies with map" do
75
- dsl = LockJar::Domain::Dsl.create do
76
- map 'junit:junit:4.10', "#{TEMP_DIR}"
77
- jar 'junit:junit:4.10'
78
- end
79
-
80
- LockJar.lock( dsl, :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
81
- lockfile = LockJar.read("#{TEMP_DIR}/Jarfile.lock")
82
- lockfile.to_hash.should eql({
83
- "version"=> LockJar::VERSION,
84
- "maps"=>{"junit:junit:4.10"=>["#{TEMP_DIR}"]},
85
- "groups"=>{
86
- "default"=>{
87
- "dependencies"=>["junit:junit:jar:4.10", "org.hamcrest:hamcrest-core:jar:1.1"],
88
- "artifacts"=>[{
89
- "jar:junit:junit:jar:4.10"=>{
90
- "transitive"=>{"org.hamcrest:hamcrest-core:jar:1.1"=>{}}}
91
- }]
92
- }
93
- },
94
- "remote_repositories" => ["http://mirrors.ibiblio.org/pub/mirrors/maven2", "http://repository.jboss.org/nexus/content/groups/public-jboss"]
95
- })
96
- end
97
-
98
- it "should exclude excludes from dependencies" do
99
- dsl = LockJar::Domain::Dsl.create do
100
- exclude 'commons-logging', 'logkit'
101
- jar 'opensymphony:oscache:jar:2.4.1'
102
- end
103
-
104
- LockJar.lock( dsl, :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
105
- File.exists?( "#{TEMP_DIR}/Jarfile.lock" ).should be_true
106
- lockfile = LockJar.read("#{TEMP_DIR}/Jarfile.lock")
107
- lockfile.to_hash.should eql({
108
- "version"=> LockJar::VERSION,
109
- "excludes"=>["commons-logging", "logkit"],
110
- "groups"=>{
111
- "default"=>{
112
- "dependencies"=>[
113
- "avalon-framework:avalon-framework:jar:4.1.3", "javax.jms:jms:jar:1.1",
114
- "javax.servlet:servlet-api:jar:2.3", "log4j:log4j:jar:1.2.12",
115
- "opensymphony:oscache:jar:2.4.1"],
116
- "artifacts"=>[{
117
- "jar:opensymphony:oscache:jar:2.4.1"=>{
118
- "transitive"=>{
119
- "commons-logging:commons-logging:jar:1.1"=>{
120
- "logkit:logkit:jar:1.0.1"=>{},
121
- "log4j:log4j:jar:1.2.12"=>{},
122
- "avalon-framework:avalon-framework:jar:4.1.3"=>{}
123
- },
124
- "javax.jms:jms:jar:1.1"=>{},
125
- "javax.servlet:servlet-api:jar:2.3"=>{}
113
+ end
114
+
115
+ it_behaves_like 'a lockfile'
116
+ end
117
+
118
+ describe '#exclude' do
119
+ let(:lockjar_source) do
120
+ LockJar::Domain::Dsl.create do
121
+ remote_repo 'https://repository.jboss.org/nexus/content/groups/public'
122
+ exclude 'commons-logging', 'logkit'
123
+ jar 'opensymphony:oscache:jar:2.4.1'
124
+ end
125
+ end
126
+
127
+ let(:expected_version) { LockJar::VERSION }
128
+ let(:expected_excludes) { %w[commons-logging logkit] }
129
+ let(:expected_remote_repositories) { %w[http://repo1.maven.org/maven2/] }
130
+ let(:expected_groups) do
131
+ { "default" =>
132
+ {
133
+ "dependencies"=>[
134
+ "avalon-framework:avalon-framework:jar:4.1.3", "javax.jms:jms:jar:1.1",
135
+ "javax.servlet:servlet-api:jar:2.3", "log4j:log4j:jar:1.2.12",
136
+ "opensymphony:oscache:jar:2.4.1"],
137
+ "artifacts"=>[{
138
+ "jar:opensymphony:oscache:jar:2.4.1"=>{
139
+ "transitive"=>{
140
+ "commons-logging:commons-logging:jar:1.1"=>{
141
+ "logkit:logkit:jar:1.0.1"=>{},
142
+ "log4j:log4j:jar:1.2.12"=>{},
143
+ "avalon-framework:avalon-framework:jar:4.1.3"=>{}
144
+ },
145
+ "javax.jms:jms:jar:1.1"=>{},
146
+ "javax.servlet:servlet-api:jar:2.3"=>{}
147
+ }
148
+ }
149
+ }]
126
150
  }
127
151
  }
128
- }]
129
- }
130
- },
131
- "remote_repositories" => ["http://mirrors.ibiblio.org/pub/mirrors/maven2", "http://repository.jboss.org/nexus/content/groups/public-jboss"]
132
- })
133
-
134
- end
135
-
136
-
137
- it "should lock using a block" do
138
- LockJar.lock( :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/NoRepoJarfile.lock" ) do
139
- jar "org.eclipse.jetty:jetty-servlet:8.1.3.v20120416"
140
- end
141
-
142
- File.exists?( "#{TEMP_DIR}/NoRepoJarfile.lock" ).should be_true
143
-
144
- lockfile = LockJar.read("#{TEMP_DIR}/NoRepoJarfile.lock")
145
- lockfile.to_hash.should eql({
146
- "version"=> LockJar::VERSION,
147
- "groups"=>{
148
- "default"=>{
149
- "dependencies"=>["org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016",
150
- "org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416",
151
- "org.eclipse.jetty:jetty-http:jar:8.1.3.v20120416",
152
- "org.eclipse.jetty:jetty-io:jar:8.1.3.v20120416",
153
- "org.eclipse.jetty:jetty-security:jar:8.1.3.v20120416",
154
- "org.eclipse.jetty:jetty-server:jar:8.1.3.v20120416",
155
- "org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416",
156
- "org.eclipse.jetty:jetty-util:jar:8.1.3.v20120416"],
157
- "artifacts"=>[{
158
- "jar:org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416"=>{
159
- "transitive"=>{
160
- "org.eclipse.jetty:jetty-security:jar:8.1.3.v20120416"=>{
161
- "org.eclipse.jetty:jetty-server:jar:8.1.3.v20120416"=>{
162
- "org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016"=>{},
163
- "org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416"=>{},
164
- "org.eclipse.jetty:jetty-http:jar:8.1.3.v20120416"=>{
165
- "org.eclipse.jetty:jetty-io:jar:8.1.3.v20120416"=>{
166
- "org.eclipse.jetty:jetty-util:jar:8.1.3.v20120416"=>{}
152
+ end
153
+
154
+ it_behaves_like 'a lockfile'
155
+ end
156
+ end
157
+
158
+ context 'from a block' do
159
+ let(:lockfile) do
160
+ LockJar.lock( :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/NoRepoJarfile.lock" ) do
161
+ jar "org.eclipse.jetty:jetty-servlet:8.1.3.v20120416"
162
+ end
163
+
164
+ File.exists?( "#{TEMP_DIR}/NoRepoJarfile.lock" ).should be_true
165
+
166
+ LockJar.read("#{TEMP_DIR}/NoRepoJarfile.lock")
167
+ end
168
+
169
+ let(:expected_version) { LockJar::VERSION }
170
+ let(:expected_remote_repositories) { %w[http://repo1.maven.org/maven2/] }
171
+ let(:expected_groups) do
172
+ {
173
+ "default"=>{
174
+ "dependencies"=>["org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016",
175
+ "org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416",
176
+ "org.eclipse.jetty:jetty-http:jar:8.1.3.v20120416",
177
+ "org.eclipse.jetty:jetty-io:jar:8.1.3.v20120416",
178
+ "org.eclipse.jetty:jetty-security:jar:8.1.3.v20120416",
179
+ "org.eclipse.jetty:jetty-server:jar:8.1.3.v20120416",
180
+ "org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416",
181
+ "org.eclipse.jetty:jetty-util:jar:8.1.3.v20120416"],
182
+ "artifacts"=>[{
183
+ "jar:org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416"=>{
184
+ "transitive"=>{
185
+ "org.eclipse.jetty:jetty-security:jar:8.1.3.v20120416"=>{
186
+ "org.eclipse.jetty:jetty-server:jar:8.1.3.v20120416"=>{
187
+ "org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016"=>{},
188
+ "org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416"=>{},
189
+ "org.eclipse.jetty:jetty-http:jar:8.1.3.v20120416"=>{
190
+ "org.eclipse.jetty:jetty-io:jar:8.1.3.v20120416"=>{
191
+ "org.eclipse.jetty:jetty-util:jar:8.1.3.v20120416"=>{}
192
+ }
193
+ }
167
194
  }
168
195
  }
169
196
  }
170
197
  }
171
- }
198
+ }]
172
199
  }
173
- }]
174
- }
175
- }
176
- })
177
- end
178
- end
179
-
180
- describe LockJar, "#install" do
181
- it "should install jars" do
182
-
183
- LockJar.lock( "spec/fixtures/Jarfile", :download_artifacts => false, :local_repo => "#{TEMP_DIR}/test-repo-install", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
184
-
185
- jars = LockJar.install( "#{TEMP_DIR}/Jarfile.lock", ['default'], :local_repo => "#{TEMP_DIR}/test-repo-install" )
186
- jars.should eql([
187
- File.expand_path("#{TEMP_DIR}/test-repo-install/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar"),
188
- File.expand_path("#{TEMP_DIR}/test-repo-install/ch/qos/logback/logback-core/0.9.24/logback-core-0.9.24.jar"),
189
- File.expand_path("#{TEMP_DIR}/test-repo-install/com/metapossum/metapossum-scanner/1.0/metapossum-scanner-1.0.jar"),
190
- File.expand_path("#{TEMP_DIR}/test-repo-install/com/slackworks/modelcitizen/0.2.2/modelcitizen-0.2.2.jar"),
191
- File.expand_path("#{TEMP_DIR}/test-repo-install/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar"),
192
- File.expand_path("#{TEMP_DIR}/test-repo-install/commons-io/commons-io/1.4/commons-io-1.4.jar"),
193
- File.expand_path("#{TEMP_DIR}/test-repo-install/commons-lang/commons-lang/2.6/commons-lang-2.6.jar"),
194
- File.expand_path("#{TEMP_DIR}/test-repo-install/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"),
195
- File.expand_path("#{TEMP_DIR}/test-repo-install/org/apache/mina/mina-core/2.0.4/mina-core-2.0.4.jar"),
196
- File.expand_path("#{TEMP_DIR}/test-repo-install/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar")
197
- ])
198
- end
199
-
200
- end
200
+ }
201
+ end
201
202
 
202
- describe LockJar, "#register_jarfile" do
203
- after do
204
- LockJar.reset_registered_jarfiles
203
+ it_behaves_like 'a lockfile'
204
+ end
205
+ end
205
206
  end
206
207
 
207
- it 'should add an existing jarfiles in order' do
208
- LockJar.register_jarfile "spec/fixtures/Jarfile"
209
- LockJar.register_jarfile "spec/fixtures/Jarfile2"
210
- LockJar.registered_jarfiles.should ==
211
- ["spec/fixtures/Jarfile", "spec/fixtures/Jarfile2"]
212
- end
208
+ describe "#install" do
209
+ it "should install jars" do
210
+
211
+ LockJar.lock( "spec/fixtures/Jarfile", :download_artifacts => false, :local_repo => "#{TEMP_DIR}/test-repo-install", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
212
+
213
+ jars = LockJar.install( "#{TEMP_DIR}/Jarfile.lock", ['default'], :local_repo => "#{TEMP_DIR}/test-repo-install" )
214
+ jars.should eql([
215
+ File.expand_path("#{TEMP_DIR}/test-repo-install/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar"),
216
+ File.expand_path("#{TEMP_DIR}/test-repo-install/ch/qos/logback/logback-core/0.9.24/logback-core-0.9.24.jar"),
217
+ File.expand_path("#{TEMP_DIR}/test-repo-install/com/metapossum/metapossum-scanner/1.0/metapossum-scanner-1.0.jar"),
218
+ File.expand_path("#{TEMP_DIR}/test-repo-install/com/slackworks/modelcitizen/0.2.2/modelcitizen-0.2.2.jar"),
219
+ File.expand_path("#{TEMP_DIR}/test-repo-install/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar"),
220
+ File.expand_path("#{TEMP_DIR}/test-repo-install/commons-io/commons-io/1.4/commons-io-1.4.jar"),
221
+ File.expand_path("#{TEMP_DIR}/test-repo-install/commons-lang/commons-lang/2.6/commons-lang-2.6.jar"),
222
+ File.expand_path("#{TEMP_DIR}/test-repo-install/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"),
223
+ File.expand_path("#{TEMP_DIR}/test-repo-install/org/apache/mina/mina-core/2.0.4/mina-core-2.0.4.jar"),
224
+ File.expand_path("#{TEMP_DIR}/test-repo-install/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar")
225
+ ])
226
+ end
213
227
 
214
- it 'should not add a missing jarfile' do
215
- proc {
216
- LockJar.register_jarfile "spec/fixtures/NotAJarfile"
217
- }.should raise_exception(RuntimeError,
218
- "Jarfile not found: spec/fixtures/NotAJarfile")
219
228
  end
220
- end
221
229
 
222
- describe LockJar, "#lock_registered_jarfiles" do
223
- after do
224
- LockJar.reset_registered_jarfiles
225
- end
230
+ describe "#register_jarfile" do
231
+ after do
232
+ LockJar.reset_registered_jarfiles
233
+ end
226
234
 
227
- it 'should work with no jarfiles' do
228
- lockfile = "#{TEMP_DIR}/LRJJarfile1.lock"
229
- File.unlink lockfile if File.exists? lockfile
230
- result = LockJar.lock_registered_jarfiles lockfile: lockfile
231
- result.should be_nil
232
- File.exists?(lockfile).should be_false
233
- end
235
+ it 'should add an existing jarfiles in order' do
236
+ LockJar.register_jarfile "spec/fixtures/Jarfile"
237
+ LockJar.register_jarfile "spec/fixtures/Jarfile2"
238
+ LockJar.registered_jarfiles.should ==
239
+ ["spec/fixtures/Jarfile", "spec/fixtures/Jarfile2"]
240
+ end
234
241
 
235
- it 'should merge all jarfiles' do
236
- LockJar.register_jarfile "spec/fixtures/Jarfile"
237
- LockJar.register_jarfile "spec/fixtures/Jarfile2"
238
- lockfile = "#{TEMP_DIR}/LRJJarfile2.lock"
239
- File.unlink lockfile if File.exists? lockfile
240
- result = LockJar.lock_registered_jarfiles lockfile: lockfile
241
- artifacts = result.to_hash['groups']['default']['artifacts'].flat_map { |a| a.keys }
242
- artifacts.should == [
243
- "jar:org.apache.mina:mina-core:jar:2.0.4",
244
- "pom:spec/pom.xml",
245
- "jar:org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416"
246
- ]
247
- File.exists?(lockfile).should be_true
242
+ it 'should not add a missing jarfile' do
243
+ proc {
244
+ LockJar.register_jarfile "spec/fixtures/NotAJarfile"
245
+ }.should raise_exception(RuntimeError,
246
+ "Jarfile not found: spec/fixtures/NotAJarfile")
247
+ end
248
248
  end
249
- end
250
249
 
251
- describe LockJar, "#list" do
252
- it "should list jars" do
250
+ describe "#lock_registered_jarfiles" do
251
+ after do
252
+ LockJar.reset_registered_jarfiles
253
+ end
253
254
 
254
- LockJar.lock( "spec/fixtures/Jarfile", :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
255
+ it 'should work with no jarfiles' do
256
+ lockfile = "#{TEMP_DIR}/LRJJarfile1.lock"
257
+ File.unlink lockfile if File.exists? lockfile
258
+ result = LockJar.lock_registered_jarfiles lockfile: lockfile
259
+ result.should be_nil
260
+ File.exists?(lockfile).should be_false
261
+ end
255
262
 
256
- jars = LockJar.list( "#{TEMP_DIR}/Jarfile.lock", ['default', 'development', 'bad scope'], :local_repo => "#{TEMP_DIR}/test-repo" )
257
- jars.should eql([
258
- "ch.qos.logback:logback-classic:jar:0.9.24", "ch.qos.logback:logback-core:jar:0.9.24",
259
- "com.metapossum:metapossum-scanner:jar:1.0", "com.slackworks:modelcitizen:jar:0.2.2",
260
- "commons-beanutils:commons-beanutils:jar:1.8.3", "commons-io:commons-io:jar:1.4",
261
- "commons-lang:commons-lang:jar:2.6", "commons-logging:commons-logging:jar:1.1.1",
262
- "org.apache.mina:mina-core:jar:2.0.4",
263
- "org.slf4j:slf4j-api:jar:1.6.1", "spec/fixtures/naether-0.13.0.jar", "com.typesafe:config:jar:0.5.0" ])
263
+ it 'should merge all jarfiles' do
264
+ LockJar.register_jarfile "spec/fixtures/Jarfile"
265
+ LockJar.register_jarfile "spec/fixtures/Jarfile2"
266
+ lockfile = "#{TEMP_DIR}/LRJJarfile2.lock"
267
+ File.unlink lockfile if File.exists? lockfile
268
+ result = LockJar.lock_registered_jarfiles lockfile: lockfile
269
+ artifacts = result.to_hash['groups']['default']['artifacts'].flat_map { |a| a.keys }
270
+ artifacts.should == [
271
+ "jar:org.apache.mina:mina-core:jar:2.0.4",
272
+ "pom:spec/pom.xml",
273
+ "jar:org.eclipse.jetty:jetty-servlet:jar:8.1.3.v20120416"
274
+ ]
275
+ File.exists?(lockfile).should be_true
276
+ end
264
277
  end
265
278
 
266
- it "should replace dependencies with maps" do
267
- dsl = LockJar::Domain::Dsl.create do
268
- map 'junit:junit', "#{TEMP_DIR}"
269
- jar 'junit:junit:4.10'
270
- end
279
+ describe "#list" do
280
+ it "should list jars" do
271
281
 
272
- LockJar.lock( dsl, :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/ListJarfile.lock")
273
- paths = LockJar.list( "#{TEMP_DIR}/ListJarfile.lock", :local_repo => "#{TEMP_DIR}/test-repo" )
274
- paths.should eql( [ "#{TEMP_DIR}", "org.hamcrest:hamcrest-core:jar:1.1"] )
275
- end
282
+ LockJar.lock( "spec/fixtures/Jarfile", :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
276
283
 
277
- it "should replace dependencies with maps and get local paths" do
278
- dsl = LockJar::Domain::Dsl.create do
279
- map 'junit:junit', "#{TEMP_DIR}"
280
- jar 'junit:junit:4.10'
284
+ jars = LockJar.list( "#{TEMP_DIR}/Jarfile.lock", ['default', 'development', 'bad scope'], :local_repo => "#{TEMP_DIR}/test-repo" )
285
+ jars.should eql([
286
+ "ch.qos.logback:logback-classic:jar:0.9.24", "ch.qos.logback:logback-core:jar:0.9.24",
287
+ "com.metapossum:metapossum-scanner:jar:1.0", "com.slackworks:modelcitizen:jar:0.2.2",
288
+ "commons-beanutils:commons-beanutils:jar:1.8.3", "commons-io:commons-io:jar:1.4",
289
+ "commons-lang:commons-lang:jar:2.6", "commons-logging:commons-logging:jar:1.1.1",
290
+ "org.apache.mina:mina-core:jar:2.0.4",
291
+ "org.slf4j:slf4j-api:jar:1.6.1", "spec/fixtures/naether-0.13.0.jar", "com.typesafe:config:jar:0.5.0" ])
281
292
  end
282
293
 
283
- LockJar.lock( dsl, :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/ListJarfile.lock" )
284
- paths = LockJar.list( "#{TEMP_DIR}/ListJarfile.lock", :local_repo => "#{TEMP_DIR}/test-repo" )
285
- paths.should eql( [ "#{TEMP_DIR}", "org.hamcrest:hamcrest-core:jar:1.1"] )
286
- end
287
- end
294
+ it "should replace dependencies with maps" do
295
+ dsl = LockJar::Domain::Dsl.create do
296
+ map 'junit:junit', "#{TEMP_DIR}"
297
+ jar 'junit:junit:4.10'
298
+ end
288
299
 
289
- describe LockJar, "#load" do
290
- it "by Jarfile.lock" do
291
- if Naether.platform == 'java'
292
- lambda { java_import 'org.apache.mina.core.IoUtil' }.should raise_error
293
- else
294
- lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should raise_error
300
+ LockJar.lock( dsl, :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/ListJarfile.lock")
301
+ paths = LockJar.list( "#{TEMP_DIR}/ListJarfile.lock", :local_repo => "#{TEMP_DIR}/test-repo" )
302
+ paths.should eql( [ "#{TEMP_DIR}", "org.hamcrest:hamcrest-core:jar:1.1"] )
295
303
  end
296
304
 
305
+ it "should replace dependencies with maps and get local paths" do
306
+ dsl = LockJar::Domain::Dsl.create do
307
+ map 'junit:junit', "#{TEMP_DIR}"
308
+ jar 'junit:junit:4.10'
309
+ end
297
310
 
298
- LockJar.lock( "spec/fixtures/Jarfile", :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
299
-
300
- jars = LockJar.load( "#{TEMP_DIR}/Jarfile.lock", ['default'], :local_repo => "#{TEMP_DIR}/test-repo" )
301
- LockJar::Registry.instance.lockfile_registered?( "#{TEMP_DIR}/Jarfile.lock" ).should be_false
302
-
303
- jars.should eql([
304
- "spec/fixtures/naether-0.13.0.jar",
305
- File.expand_path("#{TEMP_DIR}/test-repo/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar"),
306
- File.expand_path("#{TEMP_DIR}/test-repo/ch/qos/logback/logback-core/0.9.24/logback-core-0.9.24.jar"),
307
- File.expand_path("#{TEMP_DIR}/test-repo/com/metapossum/metapossum-scanner/1.0/metapossum-scanner-1.0.jar"),
308
- File.expand_path("#{TEMP_DIR}/test-repo/com/slackworks/modelcitizen/0.2.2/modelcitizen-0.2.2.jar"),
309
- File.expand_path("#{TEMP_DIR}/test-repo/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar"),
310
- File.expand_path("#{TEMP_DIR}/test-repo/commons-io/commons-io/1.4/commons-io-1.4.jar"),
311
- File.expand_path("#{TEMP_DIR}/test-repo/commons-lang/commons-lang/2.6/commons-lang-2.6.jar"),
312
- File.expand_path("#{TEMP_DIR}/test-repo/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"),
313
- File.expand_path("#{TEMP_DIR}/test-repo/org/apache/mina/mina-core/2.0.4/mina-core-2.0.4.jar"),
314
- File.expand_path("#{TEMP_DIR}/test-repo/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"),
315
- ])
316
- if Naether.platform == 'java'
317
- lambda { java_import 'org.apache.mina.core.IoUtil' }.should_not raise_error
318
- else
319
- lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should_not raise_error
311
+ LockJar.lock( dsl, :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/ListJarfile.lock" )
312
+ paths = LockJar.list( "#{TEMP_DIR}/ListJarfile.lock", :local_repo => "#{TEMP_DIR}/test-repo" )
313
+ paths.should eql( [ "#{TEMP_DIR}", "org.hamcrest:hamcrest-core:jar:1.1"] )
320
314
  end
315
+ end
321
316
 
317
+ describe "#load" do
318
+ it "by Jarfile.lock" do
319
+ if Naether.platform == 'java'
320
+ lambda { java_import 'org.apache.mina.core.IoUtil' }.should raise_error
321
+ else
322
+ lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should raise_error
323
+ end
324
+
325
+
326
+ LockJar.lock( "spec/fixtures/Jarfile", :local_repo => "#{TEMP_DIR}/test-repo", :lockfile => "#{TEMP_DIR}/Jarfile.lock" )
327
+
328
+ jars = LockJar.load( "#{TEMP_DIR}/Jarfile.lock", ['default'], :local_repo => "#{TEMP_DIR}/test-repo" )
329
+ LockJar::Registry.instance.lockfile_registered?( "#{TEMP_DIR}/Jarfile.lock" ).should be_false
330
+
331
+ jars.should eql([
332
+ "spec/fixtures/naether-0.13.0.jar",
333
+ File.expand_path("#{TEMP_DIR}/test-repo/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar"),
334
+ File.expand_path("#{TEMP_DIR}/test-repo/ch/qos/logback/logback-core/0.9.24/logback-core-0.9.24.jar"),
335
+ File.expand_path("#{TEMP_DIR}/test-repo/com/metapossum/metapossum-scanner/1.0/metapossum-scanner-1.0.jar"),
336
+ File.expand_path("#{TEMP_DIR}/test-repo/com/slackworks/modelcitizen/0.2.2/modelcitizen-0.2.2.jar"),
337
+ File.expand_path("#{TEMP_DIR}/test-repo/commons-beanutils/commons-beanutils/1.8.3/commons-beanutils-1.8.3.jar"),
338
+ File.expand_path("#{TEMP_DIR}/test-repo/commons-io/commons-io/1.4/commons-io-1.4.jar"),
339
+ File.expand_path("#{TEMP_DIR}/test-repo/commons-lang/commons-lang/2.6/commons-lang-2.6.jar"),
340
+ File.expand_path("#{TEMP_DIR}/test-repo/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"),
341
+ File.expand_path("#{TEMP_DIR}/test-repo/org/apache/mina/mina-core/2.0.4/mina-core-2.0.4.jar"),
342
+ File.expand_path("#{TEMP_DIR}/test-repo/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar"),
343
+ ])
344
+ if Naether.platform == 'java'
345
+ lambda { java_import 'org.apache.mina.core.IoUtil' }.should_not raise_error
346
+ else
347
+ lambda { Rjb::import('org.apache.mina.core.IoUtil') }.should_not raise_error
348
+ end
322
349
 
323
- end
324
350
 
325
- it "by block with resolve option" do
326
- if Naether.platform == 'java'
327
- lambda { java_import 'org.modeshape.common.math.Duration' }.should raise_error
328
- else
329
- lambda { Rjb::import('org.modeshape.common.math.Duration') }.should raise_error
330
351
  end
331
352
 
332
- jars = LockJar.load(:local_repo => TEST_REPO, :resolve => true) do
333
- jar 'org.modeshape:modeshape-common:3.4.0.Final'
334
- end
353
+ it "by block with resolve option" do
354
+ if Naether.platform == 'java'
355
+ lambda { java_import 'org.modeshape.common.math.Duration' }.should raise_error
356
+ else
357
+ lambda { Rjb::import('org.modeshape.common.math.Duration') }.should raise_error
358
+ end
335
359
 
336
- jars.should eql( [File.expand_path(TEST_REPO + "/org/modeshape/modeshape-common/3.4.0.Final/modeshape-common-3.4.0.Final.jar")] )
360
+ jars = LockJar.load(:local_repo => TEST_REPO, :resolve => true) do
361
+ jar 'org.modeshape:modeshape-common:3.4.0.Final'
362
+ end
337
363
 
338
- if Naether.platform == 'java'
339
- lambda { java_import 'org.modeshape.common.math.Duration' }.should_not raise_error
340
- else
341
- lambda { Rjb::import('org.modeshape.common.math.Duration') }.should_not raise_error
364
+ jars.should eql( [File.expand_path(TEST_REPO + "/org/modeshape/modeshape-common/3.4.0.Final/modeshape-common-3.4.0.Final.jar")] )
365
+
366
+ if Naether.platform == 'java'
367
+ lambda { java_import 'org.modeshape.common.math.Duration' }.should_not raise_error
368
+ else
369
+ lambda { Rjb::import('org.modeshape.common.math.Duration') }.should_not raise_error
370
+ end
342
371
  end
343
372
  end
344
- end
345
373
 
346
- describe LockJar, "#extract_args" do
347
- # Certain argument combinations can't really be tested
374
+ describe "#extract_args" do
375
+ # Certain argument combinations can't really be tested
348
376
 
349
- it 'should have the right defaults for :lockfile' do
350
- LockJar.send(:extract_args, :lockfile, []).should == ['Jarfile.lock', ['default'], {}]
351
- end
377
+ it 'should have the right defaults for :lockfile' do
378
+ LockJar.send(:extract_args, :lockfile, []).should == ['Jarfile.lock', ['default'], {}]
379
+ end
352
380
 
353
- it 'should have the right defaults for :jarfile' do
354
- LockJar.send(:extract_args, :jarfile, []).should == ['Jarfile', ['default'], {}]
355
- end
381
+ it 'should have the right defaults for :jarfile' do
382
+ LockJar.send(:extract_args, :jarfile, []).should == ['Jarfile', ['default'], {}]
383
+ end
356
384
 
357
- it 'should not have a default filename if a block is given' do
358
- blk = proc {}
359
- LockJar.send(:extract_args, :jarfile, [], &blk).should == [nil, ['default'], {}]
360
- LockJar.send(:extract_args, :lockfile, [], &blk).should == [nil, ['default'], {}]
361
- end
385
+ it 'should not have a default filename if a block is given' do
386
+ blk = proc {}
387
+ LockJar.send(:extract_args, :jarfile, [], &blk).should == [nil, ['default'], {}]
388
+ LockJar.send(:extract_args, :lockfile, [], &blk).should == [nil, ['default'], {}]
389
+ end
362
390
 
363
- it 'should use the :lockfile opt when lockfile is requested' do
364
- LockJar.send(:extract_args, :lockfile, [{lockfile: "LF"}]).should == ["LF", ['default'], {lockfile: "LF"}]
365
- end
366
- it 'should not use the :lockfile opt when jarfile is requested' do
367
- LockJar.send(:extract_args, :jarfile, [{lockfile: "LF"}]).should == ["Jarfile", ['default'], {lockfile: "LF"}]
368
- end
369
- it 'should not use the :lockfile opt when a lockfile provided' do
370
- LockJar.send(:extract_args, :lockfile, ["MyLF", {lockfile: "LF"}]).should == ["MyLF", ['default'], {lockfile: "LF"}]
391
+ it 'should use the :lockfile opt when lockfile is requested' do
392
+ LockJar.send(:extract_args, :lockfile, [{lockfile: "LF"}]).should == ["LF", ['default'], {lockfile: "LF"}]
393
+ end
394
+ it 'should not use the :lockfile opt when jarfile is requested' do
395
+ LockJar.send(:extract_args, :jarfile, [{lockfile: "LF"}]).should == ["Jarfile", ['default'], {lockfile: "LF"}]
396
+ end
397
+ it 'should not use the :lockfile opt when a lockfile provided' do
398
+ LockJar.send(:extract_args, :lockfile, ["MyLF", {lockfile: "LF"}]).should == ["MyLF", ['default'], {lockfile: "LF"}]
399
+ end
371
400
  end
372
401
  end