-
Notifications
You must be signed in to change notification settings - Fork 951
/
AetherDependencyManagerSpec.groovy
600 lines (522 loc) · 23.3 KB
/
AetherDependencyManagerSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.grails.resolve.maven
import org.grails.dependency.resolution.Dependency
import org.grails.dependency.resolution.DependencyReport
import org.grails.dependency.resolution.maven.aether.AetherDependencyManager
import org.grails.dependency.resolution.maven.aether.config.GrailsAetherCoreDependencies
import org.eclipse.aether.RepositorySystem
import org.eclipse.aether.repository.Authentication
import org.eclipse.aether.repository.RemoteRepository
import org.eclipse.aether.resolution.DependencyRequest
import org.eclipse.aether.resolution.DependencyResult
import spock.lang.Ignore
import spock.lang.Issue
import spock.lang.Specification
import spock.lang.Unroll
/**
* @author Graeme Rocher
* @since 2.3
*/
class AetherDependencyManagerSpec extends Specification {
void "Test that dependency management can be applied to dependencies"() {
given:"A dependency manager that applies management to transitive dependencies"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
}
management {
dependency "commons-logging:commons-logging:1.1.3"
}
dependencies {
compile 'org.springframework:spring-core:3.2.0.RELEASE'
}
}
when:"The dependencies are resolved"
def report = dependencyManager.resolve("compile")
then:"The correct versions of transitives are resolved"
report.jarFiles.any { File f -> f.name.contains('commons-logging-1.1.3')}
}
@Issue('GRAILS-11055')
void "Test that a transitive dependency excluded with the map syntax is actually excluded"() {
given:"A dependency with an exclusion"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
grailsCentral()
}
plugins {
compile(":jasper:1.7.0") {
excludes([group: 'org.apache.poi', name: 'poi'])
}
}
}
when:"The dependency is resolved"
def report = dependencyManager.resolve('compile')
then:"The transitive dependency is excluded"
report.pluginZips.any { File f -> f.name.contains('jasper')}
!report.jarFiles.any { File f -> f.name.contains('poi')}
}
@Issue('GRAILS-10638')
void "Test that a dependency included in both compile and test scopes ends up in both scopes"() {
given:"A dependency manager with a dependency that contains the dependency in both scopes"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
}
dependencies {
compile 'mysql:mysql-connector-java:5.1.24'
test 'mysql:mysql-connector-java:5.1.24'
}
}
when:"The compile and test scopes are obtained"
def compileFiles = dependencyManager.resolve('compile').allArtifacts
def testFiles = dependencyManager.resolve('test').allArtifacts
then:"The dependency is present in both scopes"
compileFiles.size() == 1
testFiles.size() == 1
}
@Issue('GRAILS-10638')
void "Test that a transitive dependency included in both compile and test scopes ends up in both scopes 2"() {
given:"A dependency manager with a dependency that contains exclusions"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
}
dependencies {
test 'org.grails:grails-test:2.3.2'
test 'org.grails:grails-plugin-testing:2.3.2'
compile 'org.grails:grails-test:2.3.2'
}
}
when:"The compile and test scopes are obtained"
def compileFiles = dependencyManager.resolve('compile').allArtifacts
def testFiles = dependencyManager.resolve('test').allArtifacts
then:"The grails-test jar is in both scopes"
compileFiles.find { File f -> f.name.contains('grails-test')}
testFiles.find { File f -> f.name.contains('grails-test')}
}
@Issue('GRAILS-10513')
void "Test that plugin scopes are correct"() {
given:"A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
when:"Plugins are parsed in unique scopes"
dependencyManager.parseDependencies {
plugins {
build ":tomcat:7.0.42"
test ':cache:1.1.1'
// plugins needed at runtime but not for compilation
runtime ":hibernate:3.6.10.1" // or ":hibernate4:4.1.11.1"
provided ":database-migration:1.3.5"
optional ":jquery:1.10.2"
}
}
then:"The scopes are correct"
dependencyManager.getPluginDependencies('build').size() == 1
dependencyManager.getPluginDependencies('build')[0].name == 'tomcat'
dependencyManager.getPluginDependencies('test')[0].name == 'cache'
dependencyManager.getPluginDependencies('test').size() == 1
dependencyManager.getPluginDependencies('runtime')[0].name == 'hibernate'
dependencyManager.getPluginDependencies('runtime').size() == 1
dependencyManager.getPluginDependencies('provided')[0].name == 'database-migration'
dependencyManager.getPluginDependencies('provided').size() == 1
dependencyManager.getPluginDependencies('optional')[0].name == 'jquery'
dependencyManager.getPluginDependencies('optional').size() == 1
}
@Issue('GRAILS-10414')
void "Test Aether with map based dependency syntax"() {
given:"A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
}
dependencies {
runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.24'
}
}
when:"Plugin info is downloaded and no version specified"
def result = dependencyManager.resolve()
then:"The result is correct"
!result.hasError()
}
void "Test download plugin info"() {
given:"A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
grailsCentral()
}
}
when:"Plugin info is downloaded and no version specified"
def result = dependencyManager.downloadPluginInfo("feeds", null)
then:"The result is correct"
result != null
result.@name.text() == 'feeds'
}
void "Test resolve agent"() {
given:"A dependency manager specifies a custom agent"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenRepo("http://repo.grails.org/grails/core")
}
dependencies {
agent "org.springsource.springloaded:springloaded-core:1.1.1"
}
}
when:"When the agent is resolved"
def report = dependencyManager.resolveAgent()
then:"The result is correct"
report != null
report.jarFiles.find { File f -> f.name.contains('springloaded')}
}
void "Test customize repository policy"() {
given:"A dependency manager with a custom repository policy"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral {
updatePolicy "interval:1"
proxy "foo", 8080, auth(username:"bob", password:"builder")
}
}
}
when:"The repository is obtained"
def repo = dependencyManager.repositories.find { RemoteRepository rr -> rr.id == 'mavenCentral'}
then:"It is configured correctly"
repo.getPolicy(true).updatePolicy == 'interval:1'
repo.proxy.host == 'foo'
repo.proxy.port == 8080
repo.proxy.authentication != null
}
void "Test grails dependency transitive setting"() {
given:"A dependency manager with a dependency that has transitive resolves disabled"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
dependencies {
compile("org.apache.maven:maven-ant-tasks:2.1.3") {
transitive = false
}
}
}
when:"The grails dependencies are obtained"
Dependency dependency = dependencyManager.applicationDependencies.find { Dependency d -> d.name == "maven-ant-tasks" }
then:"The exclusions are present"
dependency != null
dependency.transitive == false
}
void "Test grails dependency exclusions"() {
given:"A dependency manager with a dependency that contains exclusions"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
dependencies {
compile("org.apache.maven:maven-ant-tasks:2.1.3") {
excludes "commons-logging", "xml-apis", "groovy"
}
}
}
when:"The grails dependencies are obtained"
Dependency dependency = dependencyManager.applicationDependencies.find { Dependency d -> d.name == "maven-ant-tasks" }
then:"The exclusions are present"
dependency != null
dependency.excludes.size() == 3
}
void "Test grails dependency exclusions with plugins"() {
given:"A dependency manager with a dependency that contains exclusions"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
dependencies {
build("org.grails.plugins:tomcat:7.0.40") {
excludes "tomcat-embed-logging-juli"
}
}
}
when:"The grails dependencies are obtained"
def files = dependencyManager.resolve("build").allArtifacts
then:"The exclusions are present"
!files.any { it.name.contains("tomcat-embed-logging-juli")}
}
@Ignore
void "Test grails dependency with transitive disabled with plugins"() {
given:"A dependency manager with a dependency that contains exclusions"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
plugins {
compile("org.grails.plugins:tomcat:7.0.40") {
transitive = false
}
}
}
when:"The grails dependencies are obtained"
def files = dependencyManager.resolve().allArtifacts
then:"The exclusions are present"
files.size() == 1
}
@Unroll
void "Test resolve with source and javadocs"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
grailsCentral()
}
dependencies {
compile "org.grails:grails-bootstrap:2.2.0"
}
}
when: "A dependency is resolved"
dependencyManager.includeJavadoc = includeJavadoc
dependencyManager.includeSource = includeSource
def report = dependencyManager.resolve("compile")
then: "The dependencies are resolved"
dependencyResolved == report.files.any { it.name.contains('grails-bootstrap-2.2.0')}
sourceResolved == report.files.any { it.name.contains('grails-bootstrap-2.2.0-sources')}
javadocResolved == report.files.any { it.name.contains('grails-bootstrap-2.2.0-javadoc')}
dependencyResolved == report.files.any { it.name.contains('jline-1.0')}
sourceResolved == report.files.any { it.name.contains('jline-1.0-sources')}
javadocResolved == report.files.any { it.name.contains('jline-1.0-javadoc')}
where:
includeJavadoc | includeSource | dependencyResolved | javadocResolved | sourceResolved
false | false | true | false | false
true | false | true | true | false
false | true | true | false | true
true | true | true | true | true
}
void "Test simple dependency resolve"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
grailsCentral()
}
dependencies {
compile "org.grails:grails-bootstrap:2.2.0"
}
}
when: "A dependency is resolved"
def report = dependencyManager.resolve()
then: "The dependencies are resolved"
report.files.find { it.name.contains('grails-bootstrap')}
}
void "Test simple dependency with exclusions resolve correctly"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
grailsCentral()
}
dependencies {
compile "org.grails:grails-core:2.2.0"
}
}
when: "A dependency is resolved"
def report = dependencyManager.resolve()
then: "The transitive dependencies are resolved"
report.files.find { it.name.contains('spring-core')}
when: "When the dependency is resolved with an exclude rule"
dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
grailsCentral()
}
dependencies {
compile "org.grails:grails-core:2.2.0", {
exclude 'spring-core'
}
}
}
report = dependencyManager.resolve()
then: "The transitive dependencies are excluded"
!report.files.find { it.name.contains('spring-core')}
}
void "Test plugin dependency resolve"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.parseDependencies {
repositories {
mavenCentral()
grailsCentral()
}
dependencies {
compile "org.grails:grails-bootstrap:2.2.0"
}
plugins {
compile ":feeds:1.5"
}
}
when: "A dependency is resolved"
def report = dependencyManager.resolve()
then: "The dependencies are resolved"
report.files.find { it.name.contains('feeds')}
}
@Issue('GRAILS-10671')
void "Test exclude build dependency inherited from framework"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.inheritedDependencies.global = new GrailsAetherCoreDependencies("2.2.0").createDeclaration()
dependencyManager.parseDependencies {
inherits("global") {
excludes 'grails-docs'
}
repositories {
mavenRepo "http://repo.grails.org/grails/core"
}
}
when:"The dependencies are resolved"
def dependencies = dependencyManager.getApplicationDependencies('build')
then:"The resolve is successful"
!dependencies.find { it.name == 'grails-docs' }
}
void "Test dependencies inherited from framework"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.inheritedDependencies.global = new GrailsAetherCoreDependencies("2.2.0").createDeclaration()
dependencyManager.parseDependencies {
inherits("global")
repositories {
mavenRepo "http://repo.grails.org/grails/core"
}
}
when:"The dependencies are resolved"
def report = dependencyManager.resolve()
then:"The resolve is successful"
report != null
report.files.find { it.name.contains 'spring-tx' }
}
void "Test dependencies inherited from framework can be excluded"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.inheritedDependencies.global = new GrailsAetherCoreDependencies("2.2.0").createDeclaration()
dependencyManager.parseDependencies {
inherits("global") {
excludes 'grails-plugin-servlets'
}
repositories {
mavenRepo "http://repo.grails.org/grails/core"
}
}
when:"The dependencies are resolved"
def report = dependencyManager.resolve()
then:"The resolve is successful"
report != null
!dependencyManager.allDependencies.find { Dependency d -> d.name == 'grails-plugin-servlets'}
!report.files.find { it.name.contains 'grails-plugin-servlets' }
}
void "Test dependencies inherited vs dependencies not inherited"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.inheritedDependencies.global = new GrailsAetherCoreDependencies("2.2.0").createDeclaration()
dependencyManager.parseDependencies {
inherits("global") {
excludes 'ehcache-core'
}
repositories {
mavenRepo "http://repo.grails.org/grails/core"
}
dependencies {
runtime 'mysql:mysql-connector-java:5.1.20'
}
}
when:"The dependencies are resolved"
def applicationDependencies = dependencyManager.applicationDependencies
def allDependenices = dependencyManager.allDependencies
then:"The resolve is successful"
applicationDependencies.size() == 1
allDependenices.size() > 1
}
void "Test configure authentication" () {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.inheritedDependencies.global = new GrailsAetherCoreDependencies("2.2.0").createDeclaration()
when:"Credentials are specified"
Authentication authentication
RemoteRepository repository
dependencyManager.parseDependencies {
authentication = credentials {
username = "foo"
password = "bar"
id = "grailsCentral"
}
repositories {
repository = mavenRepo( id:'grailsCentral', url:"http://repo.grails.org/grails/core" )
}
}
then:"The credentials are correctly populated"
authentication != null
repository.id == 'grailsCentral'
repository.url == "http://repo.grails.org/grails/core"
repository.authentication == authentication
dependencyManager.session.authenticationSelector.getAuthentication(repository) != null
}
void "Test configure authentication for a repo with no id" () {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.inheritedDependencies.global = new GrailsAetherCoreDependencies("2.2.0").createDeclaration()
when:"Credentials are specified"
Authentication authentication
RemoteRepository repository
dependencyManager.parseDependencies {
authentication = credentials {
username = "foo"
password = "bar"
id = "repo_grails_org_grails_core"
}
repositories {
repository = mavenRepo("http://repo.grails.org/grails/core" )
}
}
then:"The credentials are correctly populated"
authentication != null
repository.id == 'repo_grails_org_grails_core'
repository.url == "http://repo.grails.org/grails/core"
repository.authentication == authentication
dependencyManager.session.authenticationSelector.getAuthentication(repository) != null
}
void "Test jcenter repository"() {
given:
def dependencyManager = new AetherDependencyManager()
dependencyManager.inheritedDependencies.global = new GrailsAetherCoreDependencies("2.2.0").createDeclaration()
when:
dependencyManager.parseDependencies {
repositories {
jcenter()
}
}
then:
dependencyManager.repositories.size() == 1
}
void "Test the resolution of a single dependency"() {
given: "A dependency manager instance"
def dependencyManager = new AetherDependencyManager()
dependencyManager.repositorySystem = Mock(RepositorySystem) {
resolveDependencies(_,_) >> { new DependencyResult(new DependencyRequest()) }
}
when: "A dependency is provided"
Dependency dependency = new Dependency('org.slf4j', 'slf4j-api', '1.7.2')
DependencyReport report = dependencyManager.resolveDependency(dependency)
then: "The dependency is resolved"
report != null
!report.hasError()
}
}