-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathMavenSnapshotResolveIntegrationTest.groovy
More file actions
629 lines (504 loc) · 20.8 KB
/
MavenSnapshotResolveIntegrationTest.groovy
File metadata and controls
629 lines (504 loc) · 20.8 KB
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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/*
* Copyright 2012 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.gradle.integtests.resolve.maven
import org.gradle.integtests.fixtures.AbstractDependencyResolutionTest
import org.gradle.test.fixtures.maven.MavenHttpModule
import spock.lang.Ignore
import spock.lang.Issue
class MavenSnapshotResolveIntegrationTest extends AbstractDependencyResolutionTest {
def "can find and cache snapshots in multiple Maven HTTP repositories"() {
server.start()
def repo1 = mavenHttpRepo("repo1")
def repo2 = mavenHttpRepo("repo2")
given:
buildFile << """
repositories {
maven { url "${repo1.uri}" }
maven { url "${repo2.uri}" }
}
configurations { compile }
dependencies {
compile "org.gradle.integtests.resolve:projectA:1.0-SNAPSHOT"
compile "org.gradle.integtests.resolve:projectB:1.0-SNAPSHOT"
compile "org.gradle.integtests.resolve:nonunique:1.0-SNAPSHOT"
}
task retrieve(type: Sync) {
into 'libs'
from configurations.compile
}
"""
and: "snapshot modules are published"
def repo1ProjectA = repo1.module("org.gradle.integtests.resolve", "projectA", "1.0-SNAPSHOT").publish()
def repo1ProjectB = repo1.module("org.gradle.integtests.resolve", "projectB", "1.0-SNAPSHOT")
def repo2ProjectB = repo2.module("org.gradle.integtests.resolve", "projectB", "1.0-SNAPSHOT").publish()
def repo1NonUnique = repo1.module("org.gradle.integtests.resolve", "nonunique", "1.0-SNAPSHOT").withNonUniqueSnapshots()
def repo2NonUnique = repo2.module("org.gradle.integtests.resolve", "nonunique", "1.0-SNAPSHOT").withNonUniqueSnapshots().publish()
when: "Server provides projectA from repo1"
expectModuleServed(repo1ProjectA)
and: "Server provides projectB from repo2"
expectModuleMissing(repo1ProjectB)
expectModuleServed(repo2ProjectB)
and: "Server provides nonunique snapshot from repo2"
expectModuleMissing(repo1NonUnique)
expectModuleServed(repo2NonUnique)
and: "We resolve dependencies"
run 'retrieve'
then: "Snapshots are downloaded"
file('libs').assertHasDescendants('projectA-1.0-SNAPSHOT.jar', 'projectB-1.0-SNAPSHOT.jar', 'nonunique-1.0-SNAPSHOT.jar')
def snapshotA = file('libs/projectA-1.0-SNAPSHOT.jar').snapshot()
def snapshotNonUnique = file('libs/nonunique-1.0-SNAPSHOT.jar').snapshot()
when: "We resolve with snapshots cached: no server requests"
server.resetExpectations()
def result = run('retrieve')
then: "Everything is up to date"
result.assertTaskSkipped(':retrieve')
file('libs/projectA-1.0-SNAPSHOT.jar').assertHasNotChangedSince(snapshotA);
file('libs/nonunique-1.0-SNAPSHOT.jar').assertHasNotChangedSince(snapshotNonUnique);
}
def "can find and cache snapshots in Maven HTTP repository with additional artifact urls"() {
server.start()
def repo1 = mavenHttpRepo("repo1")
def repo2 = mavenHttpRepo("repo2")
given:
buildFile << """
repositories {
maven {
url "${repo1.uri}"
artifactUrls "${repo2.uri}"
}
}
configurations { compile }
dependencies {
compile "org.gradle.integtests.resolve:projectA:1.0-SNAPSHOT"
compile "org.gradle.integtests.resolve:projectB:1.0-SNAPSHOT"
}
task retrieve(type: Sync) {
into 'libs'
from configurations.compile
}
"""
and: "snapshot modules are published"
def projectA = repo1.module("org.gradle.integtests.resolve", "projectA", "1.0-SNAPSHOT").publish()
def repo1ProjectB = repo1.module("org.gradle.integtests.resolve", "projectB", "1.0-SNAPSHOT").publish()
def repo2ProjectB = repo2.module("org.gradle.integtests.resolve", "projectB", "1.0-SNAPSHOT").publish()
when: "Server provides projectA from repo1"
expectModuleServed(projectA)
and: "Server provides projectB with artifact in repo2"
repo1ProjectB.metaData.expectGet()
repo1ProjectB.pom.expectGet()
repo1ProjectB.artifact.expectGetMissing()
repo2ProjectB.artifact.expectGet()
and: "We resolve dependencies"
run 'retrieve'
then: "Snapshots are downloaded"
file('libs').assertHasDescendants('projectA-1.0-SNAPSHOT.jar', 'projectB-1.0-SNAPSHOT.jar')
def snapshotA = file('libs/projectA-1.0-SNAPSHOT.jar').snapshot()
def snapshotB = file('libs/projectB-1.0-SNAPSHOT.jar').snapshot()
when: "We resolve with snapshots cached: no server requests"
server.resetExpectations()
def result = run('retrieve')
then: "Everything is up to date"
result.assertTaskSkipped(':retrieve')
file('libs/projectA-1.0-SNAPSHOT.jar').assertHasNotChangedSince(snapshotA);
file('libs/projectB-1.0-SNAPSHOT.jar').assertHasNotChangedSince(snapshotB);
}
def "will detect changed snapshot artifacts when pom has not changed"() {
server.start()
buildFile << """
repositories {
maven { url "${mavenHttpRepo.uri}" }
}
configurations { compile }
configurations.compile.resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
dependencies {
compile "org.gradle.integtests.resolve:unique:1.0-SNAPSHOT"
compile "org.gradle.integtests.resolve:nonunique:1.0-SNAPSHOT"
}
task retrieve(type: Sync) {
into 'libs'
from configurations.compile
}
"""
when: "snapshot modules are published"
def uniqueVersionModule = mavenHttpRepo.module("org.gradle.integtests.resolve", "unique", "1.0-SNAPSHOT").publish()
def nonUniqueVersionModule = mavenHttpRepo.module("org.gradle.integtests.resolve", "nonunique", "1.0-SNAPSHOT").withNonUniqueSnapshots().publish()
and: "Server handles requests"
expectModuleServed(uniqueVersionModule)
expectModuleServed(nonUniqueVersionModule)
and: "We resolve dependencies"
run 'retrieve'
then: "Snapshots are downloaded"
file('libs').assertHasDescendants('unique-1.0-SNAPSHOT.jar', 'nonunique-1.0-SNAPSHOT.jar')
def uniqueJarSnapshot = file('libs/unique-1.0-SNAPSHOT.jar').assertIsCopyOf(uniqueVersionModule.artifactFile).snapshot()
def nonUniqueJarSnapshot = file('libs/nonunique-1.0-SNAPSHOT.jar').assertIsCopyOf(nonUniqueVersionModule.artifactFile).snapshot()
server.resetExpectations()
when: "Change the snapshot artifacts directly: do not change the pom"
uniqueVersionModule.artifactFile << 'more content'
uniqueVersionModule.backingModule.sha1File(uniqueVersionModule.artifactFile)
nonUniqueVersionModule.artifactFile << 'more content'
nonUniqueVersionModule.backingModule.sha1File(nonUniqueVersionModule.artifactFile)
and: "No server requests"
expectChangedArtifactServed(uniqueVersionModule)
expectChangedArtifactServed(nonUniqueVersionModule)
and: "Resolve dependencies again"
run 'retrieve'
then:
file('libs/unique-1.0-SNAPSHOT.jar').assertIsCopyOf(uniqueVersionModule.artifactFile).assertHasChangedSince(uniqueJarSnapshot)
file('libs/nonunique-1.0-SNAPSHOT.jar').assertIsCopyOf(nonUniqueVersionModule.artifactFile).assertHasChangedSince(nonUniqueJarSnapshot)
}
def "uses cached snapshots from a Maven HTTP repository until the snapshot timeout is reached"() {
server.start()
given:
buildFile << """
repositories {
maven { url "${mavenHttpRepo.uri}" }
}
configurations { compile }
if (project.hasProperty('noTimeout')) {
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
compile "org.gradle.integtests.resolve:unique:1.0-SNAPSHOT"
compile "org.gradle.integtests.resolve:nonunique:1.0-SNAPSHOT"
}
task retrieve(type: Sync) {
into 'libs'
from configurations.compile
}
"""
when: "snapshot modules are published"
def uniqueVersionModule = mavenHttpRepo.module("org.gradle.integtests.resolve", "unique", "1.0-SNAPSHOT").publish()
def nonUniqueVersionModule = mavenHttpRepo.module("org.gradle.integtests.resolve", "nonunique", "1.0-SNAPSHOT").withNonUniqueSnapshots().publish()
and: "Server handles requests"
expectModuleServed(uniqueVersionModule)
expectModuleServed(nonUniqueVersionModule)
and: "We resolve dependencies"
run 'retrieve'
then: "Snapshots are downloaded"
file('libs').assertHasDescendants('unique-1.0-SNAPSHOT.jar', 'nonunique-1.0-SNAPSHOT.jar')
def uniqueJarSnapshot = file('libs/unique-1.0-SNAPSHOT.jar').assertIsCopyOf(uniqueVersionModule.artifactFile).snapshot()
def nonUniqueJarSnapshot = file('libs/nonunique-1.0-SNAPSHOT.jar').assertIsCopyOf(nonUniqueVersionModule.artifactFile).snapshot()
when: "Republish the snapshots"
uniqueVersionModule.publishWithChangedContent()
nonUniqueVersionModule.publishWithChangedContent()
and: "No server requests"
server.resetExpectations()
and: "Resolve dependencies again, with cached versions"
run 'retrieve'
then:
file('libs/unique-1.0-SNAPSHOT.jar').assertHasNotChangedSince(uniqueJarSnapshot)
file('libs/nonunique-1.0-SNAPSHOT.jar').assertHasNotChangedSince(nonUniqueJarSnapshot)
when: "Server handles requests"
expectChangedModuleServed(uniqueVersionModule)
expectChangedModuleServed(nonUniqueVersionModule)
and: "Resolve dependencies with cache expired"
executer.withArguments("-PnoTimeout")
run 'retrieve'
then:
file('libs').assertHasDescendants('unique-1.0-SNAPSHOT.jar', 'nonunique-1.0-SNAPSHOT.jar')
file('libs/unique-1.0-SNAPSHOT.jar').assertIsCopyOf(uniqueVersionModule.artifactFile).assertHasChangedSince(uniqueJarSnapshot)
file('libs/nonunique-1.0-SNAPSHOT.jar').assertIsCopyOf(nonUniqueVersionModule.artifactFile).assertHasChangedSince(nonUniqueJarSnapshot);
}
def "does not download snapshot artifacts after expiry when snapshot has not changed"() {
server.start()
buildFile << """
repositories {
maven { url "${mavenHttpRepo.uri}" }
}
configurations { compile }
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compile "org.gradle.integtests.resolve:testproject:1.0-SNAPSHOT"
}
task retrieve(type: Sync) {
into 'build'
from configurations.compile
}
"""
when: "Publish the first snapshot"
def module = mavenHttpRepo.module("org.gradle.integtests.resolve", "testproject", "1.0-SNAPSHOT").publish()
and: "Server handles requests"
expectModuleServed(module)
and:
run 'retrieve'
then:
file('build').assertHasDescendants('testproject-1.0-SNAPSHOT.jar')
def snapshot = file('build/testproject-1.0-SNAPSHOT.jar').assertIsCopyOf(module.artifactFile).snapshot()
when: "Server handles requests"
server.resetExpectations()
expectChangedProbe(module)
// Retrieve again with zero timeout should check for updated snapshot
and:
def result = run 'retrieve'
then:
result.assertTaskSkipped(':retrieve')
file('build/testproject-1.0-SNAPSHOT.jar').assertHasNotChangedSince(snapshot);
}
def "does not download snapshot artifacts more than once per build"() {
server.start()
given:
def module = mavenHttpRepo.module("org.gradle.integtests.resolve", "testproject", "1.0-SNAPSHOT").publish()
and:
settingsFile << "include 'a', 'b'"
buildFile << """
allprojects {
repositories {
maven { url "${mavenHttpRepo.uri}" }
}
configurations { compile }
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compile "org.gradle.integtests.resolve:testproject:1.0-SNAPSHOT"
}
task retrieve(type: Sync) {
into 'build'
from configurations.compile
}
}
//imposing an artificial order so that the parallel build retrieves sequentially, GRADLE-2788
retrieve.dependsOn ":a:retrieve"
tasks.getByPath(":a:retrieve").dependsOn ":b:retrieve"
"""
when: "Module is requested once"
expectModuleServed(module)
then:
run 'retrieve'
and:
file('build').assertHasDescendants('testproject-1.0-SNAPSHOT.jar')
file('a/build').assertHasDescendants('testproject-1.0-SNAPSHOT.jar')
file('b/build').assertHasDescendants('testproject-1.0-SNAPSHOT.jar')
}
@Ignore //TODO SF need to rework this test. First step might be turning off in-memory metadata caching for this test.
def "can update snapshot artifact during build even if it is locked earlier in build"() {
server.start()
given:
def module = mavenHttpRepo("/repo", maven("repo1")).module("org.gradle.integtests.resolve", "testproject", "1.0-SNAPSHOT").withNonUniqueSnapshots().publish()
def module2 = mavenHttpRepo("/repo", maven("repo2")).module("org.gradle.integtests.resolve", "testproject", "1.0-SNAPSHOT").withNonUniqueSnapshots().publish()
module2.pomFile << ' ' // ensure it's a different length to the first one
module2.backingModule.sha1File(module2.pomFile)
module2.artifactFile << module2.artifactFile.bytes // ensure it's a different length to the first one
module2.backingModule.sha1File(module2.artifactFile)
and:
settingsFile << "include 'first', 'second'"
buildFile << """
def fileLocks = [:]
subprojects {
repositories {
maven { url "http://localhost:${server.port}/repo" }
}
configurations { compile }
configurations.all {
resolutionStrategy.resolutionRules.eachArtifact({ artifact ->
artifact.refresh()
} as Action)
}
dependencies {
compile "org.gradle.integtests.resolve:testproject:1.0-SNAPSHOT"
}
task lock << {
configurations.compile.each { file ->
println "locking " + file
def lockFile = new RandomAccessFile(file.canonicalPath, 'r')
fileLocks[file] = lockFile
}
}
task retrieve(type: Sync) {
into 'build'
from configurations.compile
}
retrieve.dependsOn 'lock'
}
project('second') {
lock.dependsOn ':first:lock'
retrieve.dependsOn ':first:retrieve'
task cleanup << {
fileLocks.each { key, value ->
println "unlocking " + key
value.close()
}
}
cleanup.dependsOn 'retrieve'
}
"""
when: "Module is requested once"
module.metaData.expectGet()
module.pom.expectGet()
module.artifact.expectGet()
module2.artifact.expectHead()
module2.artifact.sha1.expectGet()
module2.artifact.expectGet()
then:
run 'cleanup'
and:
file('first/build/testproject-1.0-SNAPSHOT.jar').assertIsCopyOf(module.artifactFile)
file('second/build/testproject-1.0-SNAPSHOT.jar').assertIsCopyOf(module2.artifactFile)
}
def "avoid redownload unchanged artifact when no checksum available"() {
server.start()
given:
buildFile << """
repositories {
maven { url "${mavenHttpRepo.uri}" }
}
configurations { compile }
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compile group: "group", name: "projectA", version: "1.1-SNAPSHOT"
}
task retrieve(type: Copy) {
into 'build'
from configurations.compile
}
"""
and:
def module = mavenHttpRepo.module("group", "projectA", "1.1-SNAPSHOT").withNonUniqueSnapshots().publish()
// Set the last modified to something that's not going to be anything “else”.
// There are lots of dates floating around in a resolution and we want to make
// sure we use this.
module.artifactFile.setLastModified(2000)
module.pom.file.setLastModified(6000)
def artifact = module.artifact
when:
expectModuleServed(module)
run "retrieve"
then:
def downloadedJarFile = file("build/projectA-1.1-SNAPSHOT.jar")
downloadedJarFile.assertIsCopyOf(module.artifactFile)
def initialDownloadJarFileSnapshot = downloadedJarFile.snapshot()
when:
server.resetExpectations()
expectChangedProbe(module)
run "retrieve"
then:
downloadedJarFile.assertHasNotChangedSince(initialDownloadJarFileSnapshot)
when:
module.publishWithChangedContent()
server.resetExpectations()
module.metaData.expectGet()
module.pom.expectHead()
module.pom.sha1.expectGetMissing()
module.pom.expectGet()
artifact.expectHead()
artifact.sha1.expectGetMissing()
artifact.expectGet()
run "retrieve"
then:
downloadedJarFile.assertHasChangedSince(initialDownloadJarFileSnapshot)
downloadedJarFile.assertIsCopyOf(module.artifactFile)
}
@Issue("GRADLE-3017")
def "resolves changed metadata in snapshot dependency"() {
given:
server.start()
def projectB1 = mavenHttpRepo.module('group', 'projectB', '1.0').publish()
def projectB2 = mavenHttpRepo.module('group', 'projectB', '2.0').publish()
def projectA = mavenHttpRepo.module('group', 'projectA', "1.0-SNAPSHOT").dependsOn('group', 'projectB', '1.0').publish()
buildFile << """
repositories {
maven { url '${mavenHttpRepo.uri}' }
}
configurations {
compile {
if (project.hasProperty('bypassCache')) {
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
}
}
}
dependencies {
compile 'group:projectA:1.0-SNAPSHOT'
}
task retrieve(type: Sync) {
into 'libs'
from configurations.compile
}
"""
when:
projectA.pom.expectGet()
projectA.metaData.expectGet()
projectA.artifact.expectGet()
projectB1.pom.expectGet()
projectB1.artifact.expectGet()
and:
run 'retrieve'
then:
file('libs').assertHasDescendants('projectA-1.0-SNAPSHOT.jar', 'projectB-1.0.jar')
when: "Project A is published with changed dependencies"
server.resetExpectations()
projectA = projectA.dependsOn('group', 'projectB', '2.0').publish()
and: "Resolve with caching"
run 'retrieve'
then: "Gets original ProjectA metadata from cache"
file('libs').assertHasDescendants('projectA-1.0-SNAPSHOT.jar', 'projectB-1.0.jar')
when: "Resolve without cache"
projectA.metaData.expectGet()
projectA.pom.expectHead()
projectA.pom.sha1.expectGet()
projectA.pom.expectGet()
projectA.artifact.expectHead()
projectB2.pom.expectGet()
projectB2.artifact.expectGet()
and:
executer.withArguments("-PbypassCache")
run 'retrieve'
then: "Gets updated metadata"
file('libs').assertHasDescendants('projectA-1.0-SNAPSHOT.jar', 'projectB-2.0.jar')
when: "Resolve with caching"
server.resetExpectations()
run 'retrieve'
then: "Gets updated metadata from cache"
file('libs').assertHasDescendants('projectA-1.0-SNAPSHOT.jar', 'projectB-2.0.jar')
}
private expectModuleServed(MavenHttpModule module) {
module.metaData.expectGet()
module.pom.expectGet()
module.artifact.expectGet()
}
private expectChangedModuleServed(MavenHttpModule module) {
module.metaData.expectGet()
module.pom.expectHead()
module.pom.sha1.expectGet()
module.pom.expectGet()
module.artifact.expectHead()
module.artifact.sha1.expectGet()
module.artifact.expectGet()
}
private expectChangedArtifactServed(MavenHttpModule module) {
module.metaData.expectGet()
module.pom.expectHead()
def artifact = module.artifact
artifact.expectHead()
artifact.sha1.expectGet()
artifact.expectGet()
}
private expectChangedProbe(MavenHttpModule module) {
module.metaData.expectGet()
module.pom.expectHead()
module.artifact.expectHead()
}
private expectModuleMissing(MavenHttpModule module) {
module.metaData.expectGetMissing()
module.pom.expectGetMissing()
module.artifact.expectHeadMissing()
}
}