/
ArtifactTransformWithDependenciesIntegrationTest.groovy
1436 lines (1211 loc) · 52.1 KB
/
ArtifactTransformWithDependenciesIntegrationTest.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
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2018 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.transform
import com.google.common.collect.Comparators
import com.google.common.collect.ImmutableSortedMultiset
import com.google.common.collect.Iterables
import com.google.common.collect.Multiset
import groovy.transform.Canonical
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.CompileClasspath
import org.gradle.integtests.fixtures.AbstractHttpDependencyResolutionTest
import org.gradle.integtests.fixtures.ToBeFixedForConfigurationCache
import org.gradle.integtests.fixtures.executer.GradleContextualExecuter
import org.hamcrest.CoreMatchers
import spock.lang.IgnoreIf
import spock.lang.Issue
import spock.lang.Unroll
import javax.annotation.Nonnull
import java.util.regex.Pattern
// This is failing on release6x and we don't want to spent time on it
@IgnoreIf({ GradleContextualExecuter.parallel || GradleContextualExecuter.isForceRealize() })
class ArtifactTransformWithDependenciesIntegrationTest extends AbstractHttpDependencyResolutionTest implements ArtifactTransformTestFixture {
def setup() {
settingsFile << """
rootProject.name = 'transform-deps'
include 'common', 'lib', 'app'
"""
withColorVariants(mavenHttpRepo.module("org.slf4j", "slf4j-api", "1.7.24")).publish().allowAll()
withColorVariants(mavenHttpRepo.module("org.slf4j", "slf4j-api", "1.7.25")).publish().allowAll()
withColorVariants(mavenHttpRepo.module("junit", "junit", "4.11"))
.dependsOn("hamcrest", "hamcrest-core", "1.3")
.publish()
.allowAll()
withColorVariants(mavenHttpRepo.module("hamcrest", "hamcrest-core", "1.3")).publish().allowAll()
}
void setupBuildWithNoSteps(@DelegatesTo(Builder) Closure cl = {}) {
setupBuildWithColorAttributes(buildFile, cl)
setupTransformerTypes()
buildFile << """
allprojects {
repositories {
maven {
url = '${mavenHttpRepo.uri}'
metadataSources { gradleMetadata() }
}
}
dependencies {
artifactTypes {
jar {
attributes.attribute(color, 'blue')
}
}
}
task resolveGreen(type: Copy) {
def artifacts = configurations.implementation.incoming.artifactView {
attributes { it.attribute(color, 'green') }
}.artifacts
from artifacts.artifactFiles
into "\${buildDir}/green"
}
}
project(':common') {
}
project(':lib') {
dependencies {
implementation providers.gradleProperty('useOldDependencyVersion').forUseAtConfigurationTime().map { 'org.slf4j:slf4j-api:1.7.24' }.orElse('org.slf4j:slf4j-api:1.7.25')
implementation project(':common')
}
}
project(':app') {
dependencies {
implementation 'junit:junit:4.11'
implementation project(':lib')
}
}
"""
}
void setupTransformerTypes() {
buildFile << """
abstract class TestTransform implements TransformAction<Parameters> {
interface Parameters extends TransformParameters {
@Input
String getTransformName()
void setTransformName(String name)
}
@InputArtifactDependencies
abstract FileCollection getInputArtifactDependencies()
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
void transform(TransformOutputs outputs) {
def input = inputArtifact.get().asFile
println "\${parameters.transformName} received dependencies files \${inputArtifactDependencies*.name} for processing \${input.name}"
assert inputArtifactDependencies.every { it.exists() }
def output = outputs.file(input.name + ".txt")
def workspace = output.parentFile
assert workspace.directory && workspace.list().length == 0
println "Transforming \${input.name} to \${output.name}"
output.text = String.valueOf(input.length())
}
}
abstract class SimpleTransform implements TransformAction<TransformParameters.None> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
void transform(TransformOutputs outputs) {
def input = inputArtifact.get().asFile
def output = outputs.file(input.name + ".txt")
def workspace = output.parentFile
assert workspace.directory && workspace.list().length == 0
println "Transforming without dependencies \${input.name} to \${output.name}"
if (input.name == System.getProperty("failTransformOf")) {
throw new RuntimeException("Cannot transform")
}
output.text = String.valueOf(input.length())
}
}
"""
}
void setupBuildWithSingleStep() {
setupBuildWithNoSteps()
buildFile << """
allprojects {
dependencies {
registerTransform(TestTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'green')
parameters {
transformName = 'Single step transform'
}
}
}
}
"""
}
void setupBuildWithMultipleGraphsPerProject() {
setupBuildWithColorAttributes()
setupTransformerTypes()
buildFile << """
allprojects {
repositories {
maven {
url = '${mavenHttpRepo.uri}'
metadataSources { gradleMetadata() }
}
}
configurations {
testImplementation {
extendsFrom implementation
canBeResolved = true
canBeConsumed = false
attributes.attribute(color, 'blue')
}
}
task resolveTest(type: ShowFileCollection) {
def view = configurations.testImplementation.incoming.artifactView {
attributes.attribute(color, 'green')
}.files
files.from(view)
}
}
"""
}
void setupSingleStepTransform() {
buildFile << """
allprojects {
dependencies {
registerTransform(TestTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'green')
parameters {
transformName = 'Single step transform'
}
}
}
}
"""
}
void setupTransformWithNoDependencies() {
buildFile << """
allprojects {
dependencies {
registerTransform(SimpleTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'green')
}
}
}
"""
}
void setupBuildWithFirstStepThatDoesNotUseDependencies() {
setupBuildWithNoSteps()
buildFile << """
allprojects {
dependencies {
//Multi step transform, without dependencies at step 1
registerTransform(SimpleTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'yellow')
}
registerTransform(TestTransform) {
from.attribute(color, 'yellow')
to.attribute(color, 'green')
parameters {
transformName = 'Transform step 2'
}
}
}
}
"""
}
void setupBuildWithTwoSteps() {
setupBuildWithNoSteps()
buildFile << """
allprojects {
dependencies {
// Multi step transform
registerTransform(TestTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'yellow')
parameters {
transformName = 'Transform step 1'
}
}
registerTransform(TestTransform) {
from.attribute(color, 'yellow')
to.attribute(color, 'green')
parameters {
transformName = 'Transform step 2'
}
}
}
}
"""
}
def "transform can access artifact dependencies as a set of files when using ArtifactView"() {
given:
setupBuildWithSingleStep()
when:
executer.withArgument("--parallel")
run ":app:resolveGreen"
then:
output.count('Transforming') == 5
output.contains('Single step transform received dependencies files [slf4j-api-1.7.25.jar, common.jar] for processing lib.jar')
output.contains('Single step transform received dependencies files [hamcrest-core-1.3.jar] for processing junit-4.11.jar')
}
def "transform can access file dependencies as a set of files when using ArtifactView"() {
given:
setupBuildWithSingleStep()
buildFile << """
project(':common') {
dependencies {
implementation files("otherLib.jar")
}
}
"""
when:
executer.withArgument("--parallel")
run "common:resolveGreen"
then:
output.count('Transforming') == 1
output.contains('Single step transform received dependencies files [] for processing otherLib.jar')
}
def "transform can access artifact dependencies as a set of files when using ArtifactView, even if first step did not use dependencies"() {
given:
setupBuildWithFirstStepThatDoesNotUseDependencies()
when:
executer.withArgument("--parallel")
run "app:resolveGreen"
then:
assertTransformationsExecuted(
simpleTransform('common.jar'),
simpleTransform('hamcrest-core-1.3.jar'),
simpleTransform('lib.jar'),
simpleTransform('junit-4.11.jar'),
simpleTransform('slf4j-api-1.7.25.jar'),
transformStep2('common.jar'),
transformStep2('hamcrest-core-1.3.jar'),
transformStep2('lib.jar', 'slf4j-api-1.7.25.jar', 'common.jar'),
transformStep2('junit-4.11.jar', 'hamcrest-core-1.3.jar'),
transformStep2('slf4j-api-1.7.25.jar')
)
}
def "transform can access artifact dependencies, in previous transform step, as set of files when using ArtifactView"() {
given:
setupBuildWithTwoSteps()
when:
executer.withArgument("--parallel")
run "app:resolveGreen"
then:
assertTransformationsExecuted(
transformStep1('common.jar'),
transformStep1('hamcrest-core-1.3.jar'),
transformStep1('lib.jar', 'slf4j-api-1.7.25.jar', 'common.jar'),
transformStep1('junit-4.11.jar', 'hamcrest-core-1.3.jar'),
transformStep1('slf4j-api-1.7.25.jar'),
transformStep2('common.jar'),
transformStep2('hamcrest-core-1.3.jar'),
transformStep2('lib.jar', 'slf4j-api-1.7.25.jar', 'common.jar'),
transformStep2('junit-4.11.jar', 'hamcrest-core-1.3.jar'),
transformStep2('slf4j-api-1.7.25.jar')
)
}
def "transform of project artifact can consume different transform of external artifact as dependency"() {
given:
mavenHttpRepo.module("test", "test", "1.2")
.adhocVariants()
.variant('runtime', [color: 'blue'])
.variant('test', [color: 'orange'])
.withModuleMetadata()
.publish()
.allowAll()
settingsFile << "include 'a', 'b'"
setupBuildWithColorAttributes()
buildFile << """
allprojects {
repositories {
maven { url = '${mavenHttpRepo.uri}' }
}
configurations.implementation.outgoing.variants {
additional {
attributes {
attribute(color, 'purple')
artifact(producer.output)
}
}
}
dependencies {
registerTransform(ExternalTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'purple')
parameters {
transformName = 'external'
}
}
registerTransform(LocalTransform) {
from.attribute(color, 'purple')
to.attribute(color, 'green')
parameters {
transformName = 'local'
}
}
}
}
project('a') {
dependencies {
implementation "test:test:1.2"
}
}
dependencies {
implementation project('a')
}
interface Params extends TransformParameters {
@Input
Property<String> getTransformName()
}
abstract class ExternalTransform implements TransformAction<Params> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
void transform(TransformOutputs outputs) {
println("transform external " + inputArtifact.get().asFile.name)
def input = inputArtifact.get().asFile
def output = outputs.file(input.name + ".external")
output.text = "content"
}
}
abstract class LocalTransform implements TransformAction<Params> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
@InputArtifactDependencies
abstract FileCollection getInputArtifactDependencies()
void transform(TransformOutputs outputs) {
println("transform local " + inputArtifact.get().asFile.name + " using " + inputArtifactDependencies.files.name)
def input = inputArtifact.get().asFile
def output = outputs.file(input.name + ".local")
output.text = "content"
}
}
"""
when:
run(":resolve")
then:
outputContains("transform external test-1.2.jar")
outputContains("transform local a.jar using [test-1.2.jar.external]")
outputContains("transform local test-1.2.jar.external using []")
outputContains("result = [a.jar.local, test-1.2.jar.external.local]")
when:
run(":resolve")
then:
outputDoesNotContain("transform")
outputContains("result = [a.jar.local, test-1.2.jar.external.local]")
}
def setupBuildWithTransformOfExternalDependencyThatUsesDifferentTransformForUpstreamDependencies() {
def m1 = mavenHttpRepo.module("test", "test", "1.2")
.adhocVariants()
.variant('runtime', [color: 'blue'])
.variant('test', [color: 'orange'])
.withModuleMetadata()
.publish()
.allowAll()
mavenHttpRepo.module("test", "test2", "1.5")
.hasType("thing")
.dependsOn(m1)
.publish()
.allowAll()
mavenHttpRepo.module("test", "test3", "1.5")
.hasType("thing")
.dependsOn(m1)
.publish()
.allowAll()
setupBuildWithColorAttributes()
buildFile << """
allprojects {
repositories {
maven { url = '${mavenHttpRepo.uri}' }
}
dependencies {
artifactTypes {
thing {
attributes.attribute(color, 'purple')
}
}
registerTransform(ExternalTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'purple')
parameters {
transformName = 'external'
}
}
registerTransform(LocalTransform) {
from.attribute(color, 'purple')
to.attribute(color, 'green')
parameters {
transformName = 'local'
}
}
}
}
interface Params extends TransformParameters {
@Input
Property<String> getTransformName()
}
abstract class ExternalTransform implements TransformAction<Params> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
void transform(TransformOutputs outputs) {
println("transform external " + inputArtifact.get().asFile.name)
def input = inputArtifact.get().asFile
def output = outputs.file(input.name + ".external")
output.text = "content"
}
}
interface LocalParams extends Params {}
abstract class LocalTransform implements TransformAction<LocalParams> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
@InputArtifactDependencies
abstract FileCollection getInputArtifactDependencies()
void transform(TransformOutputs outputs) {
println("transform local " + inputArtifact.get().asFile.name + " using " + inputArtifactDependencies.files.name)
def input = inputArtifact.get().asFile
def output = outputs.file(input.name + ".local")
output.text = "content"
}
}
dependencies {
implementation 'test:test2:1.5'
implementation 'test:test3:1.5'
}
def view = configurations.implementation.incoming.artifactView {
attributes.attribute(color, 'green')
// NOTE: filter out the dependency to trigger the problem, so that the main thread, which holds the project lock, does not see and isolate the second transform while
// queuing the transforms for execution
// The problem can potentially also be triggered by including many direct dependencies so that the queued transforms start to execute before the main thread sees the second transform
componentFilter { it instanceof ModuleComponentIdentifier && it.module != 'test' }
}.artifacts
"""
}
def "file collection queried can contain the transform of external artifact can consume different transform of external artifact as dependency"() {
given:
setupBuildWithTransformOfExternalDependencyThatUsesDifferentTransformForUpstreamDependencies()
buildFile << """
resolveArtifacts.collection = view
"""
when:
run(":resolveArtifacts")
then:
output.count("transform") == 3
outputContains("transform external test-1.2.jar")
outputContains("transform local test2-1.5.thing using [test-1.2.jar.external]")
outputContains("transform local test3-1.5.thing using [test-1.2.jar.external]")
outputContains("artifacts = [test2-1.5.thing.local (test:test2:1.5), test3-1.5.thing.local (test:test3:1.5)]")
when:
run(":resolveArtifacts")
then:
outputDoesNotContain("transform")
outputContains("artifacts = [test2-1.5.thing.local (test:test2:1.5), test3-1.5.thing.local (test:test3:1.5)]")
}
def "file collection queried during task graph calculation can contain the transform of external artifact can consume different transform of external artifact as dependency"() {
given:
setupBuildWithTransformOfExternalDependencyThatUsesDifferentTransformForUpstreamDependencies()
buildFile << """
resolveArtifacts.collection = view
resolveArtifacts.dependsOn {
view.forEach { println("artifact = " + it) }
[]
}
"""
when:
run(":resolveArtifacts")
then:
output.count("transform") == 3
output.count("transform external test-1.2.jar") == 1
output.count("transform local test2-1.5.thing using [test-1.2.jar.external]") == 1
output.count("transform local test3-1.5.thing using [test-1.2.jar.external]") == 1
output.count("artifacts = [test2-1.5.thing.local (test:test2:1.5), test3-1.5.thing.local (test:test3:1.5)]") == 1
when:
run(":resolveArtifacts")
then:
outputDoesNotContain("transform")
outputContains("artifacts = [test2-1.5.thing.local (test:test2:1.5), test3-1.5.thing.local (test:test3:1.5)]")
}
@Issue("https://github.com/gradle/gradle/issues/14529")
def "transform of project artifact can consume transform of external artifact whose upstream dependency has been substituted with local project"() {
given:
def m1 = mavenRepo.module("test", "lib", "1.2").publish()
mavenRepo.module("test", "lib2", "1.2").dependsOn(m1).publish()
settingsFile << "include 'app', 'lib'"
setupBuildWithChainedColorTransformThatTakesUpstreamArtifacts()
buildFile << """
allprojects {
repositories {
maven { url = '${mavenRepo.uri}' }
}
}
project(':lib') {
// To trigger the substitution: use coordinates that conflict with the published library but which are newer
group = 'test'
version = '2.0'
}
project(':app') {
dependencies {
// To trigger the subsitution: include paths to the other project via both a project dependency and external dependency
implementation "test:lib2:1.2"
implementation project(':lib')
artifactTypes {
jar {
attributes.attribute(color, 'red')
}
}
}
configurations.implementation.resolutionStrategy.dependencySubstitution.all {
// To trigger the substitution: include dependency substitution rule to include external dependencies in the execution graph calculation
}
tasks.resolveArtifacts.collection = configurations.implementation.incoming.artifactView {
attributes.attribute(color, 'green')
// To trigger the problem: exclude the local library from the result, so that only the execution node edges that are reachable via the external dependency are included in the graph
componentFilter { it instanceof ModuleComponentIdentifier }
}.artifacts
}
"""
when:
run(":app:resolveArtifacts")
then:
outputContains("processing [lib.jar]")
outputContains("processing lib2-1.2.jar using [lib.jar.red]")
outputContains("files = [lib2-1.2.jar.green]")
when:
run(":app:resolveArtifacts")
then:
outputDoesNotContain("processing")
outputContains("files = [lib2-1.2.jar.green]")
}
def "transform of project artifact can consume upstream dependencies when accessed via ArtifactView even when artifacts of original configuration cannot be resolved"() {
given:
setupBuildWithColorAttributes()
setupTransformerTypes()
taskTypeLogsInputFileCollectionContent()
buildFile << """
def flavor = Attribute.of('flavor', String)
allprojects {
configurations {
implementation.outgoing.variants {
one {
attributes.attribute(flavor, 'bland')
artifact(producer.output)
}
two {
attributes.attribute(flavor, 'cloying')
}
}
}
dependencies {
registerTransform(TestTransform) {
from.attribute(color, 'blue')
from.attribute(flavor, 'bland')
to.attribute(color, 'green')
to.attribute(flavor, 'tasty')
parameters {
transformName = 'Single step transform'
}
}
}
def view = configurations.implementation.incoming.artifactView {
attributes {
it.attribute(color, 'green')
it.attribute(flavor, 'tasty')
}
}.files
task resolveView(type: ShowFilesTask) {
inFiles.from(view)
}
task broken(type: ShowFilesTask) {
inFiles.from(configurations.implementation)
}
}
project(':app') {
dependencies {
implementation project(':lib')
// Needs to also include a file dependency to trigger the issue
implementation files('app.txt')
}
}
project(':lib') {
dependencies {
implementation project(':common')
}
}
"""
when:
fails("app:broken")
then:
failure.assertHasCause("The consumer was configured to find attribute 'color' with value 'blue'. However we cannot choose between the following variants of project :lib:")
when:
run("app:resolveView")
then:
assertTransformationsExecuted(
singleStep("common.jar"),
singleStep("lib.jar", "common.jar")
)
outputContains("result = [app.txt, lib.jar.txt, common.jar.txt]")
when:
run("app:resolveView")
then:
assertTransformationsExecuted()
outputContains("result = [app.txt, lib.jar.txt, common.jar.txt]")
}
def "transform with changed set of dependencies are re-executed"() {
given:
setupBuildWithSingleStep()
when:
run ":app:resolveGreen"
then:
assertTransformationsExecuted(
singleStep('slf4j-api-1.7.25.jar'),
singleStep('hamcrest-core-1.3.jar'),
singleStep('junit-4.11.jar', 'hamcrest-core-1.3.jar'),
singleStep('common.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.25.jar', 'common.jar'),
)
when:
run ":app:resolveGreen", "-PuseOldDependencyVersion"
then: // new version, should run
assertTransformationsExecuted(
singleStep('slf4j-api-1.7.24.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.24.jar', 'common.jar'),
)
when:
run ":app:resolveGreen", "-PuseOldDependencyVersion"
then: // no changes, should be up-to-date
assertTransformationsExecuted()
when:
run ":app:resolveGreen"
then: // have seen these inputs before
assertTransformationsExecuted()
}
def "transform with changed project file dependencies content or path are re-executed"() {
given:
setupBuildWithSingleStep()
when:
run ":app:resolveGreen"
then:
assertTransformationsExecuted(
singleStep('slf4j-api-1.7.25.jar'),
singleStep('hamcrest-core-1.3.jar'),
singleStep('junit-4.11.jar', 'hamcrest-core-1.3.jar'),
singleStep('common.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.25.jar', 'common.jar'),
)
when:
run ":app:resolveGreen"
then: // no changes, should be up-to-date
result.assertTasksNotSkipped()
assertTransformationsExecuted()
when:
run ":app:resolveGreen", "-PcommonOutputDir=out"
then: // new path, should re-run
result.assertTasksNotSkipped(":common:producer")
assertTransformationsExecuted(
singleStep('common.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.25.jar', 'common.jar'),
)
when:
run ":app:resolveGreen", "-PcommonOutputDir=out"
then: // no changes, should be up-to-date
result.assertTasksNotSkipped()
assertTransformationsExecuted()
when:
run ":app:resolveGreen", "-PcommonOutputDir=out", "-PcommonFileName=common-blue.jar"
then: // new name, should re-run
result.assertTasksNotSkipped(":common:producer", ":app:resolveGreen")
assertTransformationsExecuted(
singleStep('common-blue.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.25.jar', 'common-blue.jar'),
)
when:
run ":app:resolveGreen", "-PcommonOutputDir=out", "-PcommonFileName=common-blue.jar"
then: // no changes, should be up-to-date
result.assertTasksNotSkipped()
assertTransformationsExecuted()
when:
run ":app:resolveGreen", "-PcommonOutputDir=out", "-PcommonFileName=common-blue.jar", "-PcommonContent=new"
then: // new content, should re-run
result.assertTasksNotSkipped(":common:producer", ":app:resolveGreen")
assertTransformationsExecuted(
singleStep('common-blue.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.25.jar', 'common-blue.jar'),
)
when:
run ":app:resolveGreen"
then: // have seen these inputs before
result.assertTasksNotSkipped(":common:producer", ":app:resolveGreen")
assertTransformationsExecuted()
}
def "can attach @PathSensitive(NONE) to dependencies property"() {
given:
setupBuildWithNoSteps()
buildFile << """
allprojects {
dependencies {
registerTransform(NoneTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'green')
}
}
}
abstract class NoneTransform implements TransformAction<TransformParameters.None> {
@InputArtifactDependencies @PathSensitive(PathSensitivity.NONE)
abstract FileCollection getInputArtifactDependencies()
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
void transform(TransformOutputs outputs) {
def input = inputArtifact.get().asFile
println "Single step transform received dependencies files \${inputArtifactDependencies*.name} for processing \${input.name}"
def output = outputs.file(input.name + ".txt")
println "Transforming \${input.name} to \${output.name}"
output.text = String.valueOf(input.length())
}
}
"""
when:
run ":app:resolveGreen"
then:
assertTransformationsExecuted(
singleStep('slf4j-api-1.7.25.jar'),
singleStep('hamcrest-core-1.3.jar'),
singleStep('junit-4.11.jar', 'hamcrest-core-1.3.jar'),
singleStep('common.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.25.jar', 'common.jar'),
)
when:
run ":app:resolveGreen"
then: // no changes, should be up-to-date
result.assertTasksNotSkipped()
assertTransformationsExecuted()
when:
run ":app:resolveGreen", "-PcommonOutputDir=out"
then: // new path, should skip consumer
result.assertTasksNotSkipped(":common:producer")
assertTransformationsExecuted(
singleStep('common.jar'),
)
when:
run ":app:resolveGreen", "-PcommonOutputDir=out", "-PcommonFileName=common-blue.jar"
then: // new name, should skip consumer
result.assertTasksNotSkipped(":common:producer", ":app:resolveGreen")
assertTransformationsExecuted(
singleStep('common-blue.jar'),
)
when:
run ":app:resolveGreen", "-PcommonOutputDir=out", "-PcommonFileName=common-blue.jar"
then: // no changes, should be up-to-date
result.assertTasksNotSkipped()
assertTransformationsExecuted()
when:
run ":app:resolveGreen", "-PcommonOutputDir=out", "-PcommonFileName=common-blue.jar", "-PcommonContent=new"
then: // new content, should re-run
result.assertTasksNotSkipped(":common:producer", ":app:resolveGreen")
assertTransformationsExecuted(
singleStep('common-blue.jar'),
singleStep('lib.jar', 'slf4j-api-1.7.25.jar', 'common-blue.jar'),
)
when:
run ":app:resolveGreen"
then: // have seen these inputs before
result.assertTasksNotSkipped(":common:producer", ":app:resolveGreen")
assertTransformationsExecuted()
}
@Unroll
def "can attach @#classpathAnnotation.simpleName to dependencies property"() {
given:
setupBuildWithNoSteps {
produceJars()
}
buildFile << """
allprojects {
dependencies {
registerTransform(ClasspathTransform) {
from.attribute(color, 'blue')
to.attribute(color, 'green')
}
}
}
abstract class ClasspathTransform implements TransformAction<TransformParameters.None> {
@InputArtifactDependencies @${classpathAnnotation.simpleName}
abstract FileCollection getInputArtifactDependencies()
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
void transform(TransformOutputs outputs) {
def input = inputArtifact.get().asFile
println "Single step transform received dependencies files \${inputArtifactDependencies*.name} for processing \${input.name}"
def output = outputs.file(input.name + ".txt")
println "Transforming \${input.name} to \${output.name}"
output.text = String.valueOf(input.length())
}
}
"""
when: