Skip to content

Commit bb50f60

Browse files
committed
Split up patch DSL test
1 parent e171d8f commit bb50f60

File tree

8 files changed

+535
-509
lines changed

8 files changed

+535
-509
lines changed

src/test/groovy/org/gradlex/jvm/dependency/conflict/test/CustomRulesTest.groovy

Lines changed: 0 additions & 509 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.gradlex.jvm.dependency.conflict.test.patch
2+
3+
import org.gradlex.jvm.dependency.conflict.test.fixture.GradleBuild
4+
import spock.lang.Specification
5+
6+
abstract class AbstractPatchTest extends Specification {
7+
8+
@Delegate
9+
GradleBuild build = new GradleBuild()
10+
11+
def setup() {
12+
file('src/main/java/Dummy.java') << 'class Dummy {}'
13+
buildFile << """
14+
plugins {
15+
id("org.gradlex.jvm-dependency-conflict-resolution")
16+
id("java-library")
17+
}
18+
repositories.mavenCentral()
19+
"""
20+
}
21+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package org.gradlex.jvm.dependency.conflict.test.patch
2+
3+
class AddAlignmentTest extends AbstractPatchTest {
4+
5+
def "can add alignment"() {
6+
given:
7+
buildFile << """
8+
jvmDependencyConflicts {
9+
patch {
10+
align(
11+
"org.apache.poi:poi",
12+
"org.apache.poi:poi-excelant",
13+
"org.apache.poi:poi-ooxml",
14+
"org.apache.poi:poi-scratchpad"
15+
)
16+
}
17+
}
18+
dependencies {
19+
implementation("org.apache.poi:poi:5.2.5")
20+
implementation("org.apache.poi:poi-excelant")
21+
implementation("org.apache.poi:poi-ooxml")
22+
implementation("org.apache.poi:poi-scratchpad")
23+
}
24+
"""
25+
26+
expect:
27+
dependenciesCompile().output.contains '''
28+
compileClasspath - Compile classpath for source set 'main'.
29+
+--- org.apache.poi:poi:5.2.5
30+
| +--- commons-codec:commons-codec:1.16.0
31+
| +--- org.apache.commons:commons-collections4:4.4
32+
| +--- org.apache.commons:commons-math3:3.6.1
33+
| +--- commons-io:commons-io:2.15.0
34+
| +--- com.zaxxer:SparseBitSet:1.3
35+
| +--- org.apache.logging.log4j:log4j-api:2.21.1
36+
| | \\--- org.apache.logging.log4j:log4j-bom:2.21.1
37+
| | \\--- org.apache.logging.log4j:log4j-api:2.21.1 (c)
38+
| +--- org.apache.poi:poi:5.2.5 (c)
39+
| +--- org.apache.poi:poi-excelant:5.2.5 (c)
40+
| +--- org.apache.poi:poi-ooxml:5.2.5 (c)
41+
| \\--- org.apache.poi:poi-scratchpad:5.2.5 (c)
42+
+--- org.apache.poi:poi-excelant -> 5.2.5
43+
| +--- org.apache.ant:ant:1.10.14
44+
| | \\--- org.apache.ant:ant-launcher:1.10.14
45+
| +--- org.apache.poi:poi-ooxml:5.2.5
46+
| | +--- org.apache.poi:poi:5.2.5 (*)
47+
| | +--- org.apache.poi:poi-ooxml-lite:5.2.5
48+
| | | \\--- org.apache.xmlbeans:xmlbeans:5.2.0
49+
| | | \\--- org.apache.logging.log4j:log4j-api:2.21.1 (*)
50+
| | +--- org.apache.xmlbeans:xmlbeans:5.2.0 (*)
51+
| | +--- org.apache.commons:commons-compress:1.25.0
52+
| | +--- commons-io:commons-io:2.15.0
53+
| | +--- com.github.virtuald:curvesapi:1.08
54+
| | +--- org.apache.logging.log4j:log4j-api:2.21.1 (*)
55+
| | +--- org.apache.commons:commons-collections4:4.4
56+
| | +--- org.apache.poi:poi:5.2.5 (c)
57+
| | +--- org.apache.poi:poi-excelant:5.2.5 (c)
58+
| | +--- org.apache.poi:poi-ooxml:5.2.5 (c)
59+
| | \\--- org.apache.poi:poi-scratchpad:5.2.5 (c)
60+
| +--- org.apache.poi:poi:5.2.5 (c)
61+
| +--- org.apache.poi:poi-excelant:5.2.5 (c)
62+
| +--- org.apache.poi:poi-ooxml:5.2.5 (c)
63+
| \\--- org.apache.poi:poi-scratchpad:5.2.5 (c)
64+
+--- org.apache.poi:poi-ooxml -> 5.2.5 (*)
65+
\\--- org.apache.poi:poi-scratchpad -> 5.2.5
66+
+--- org.apache.poi:poi:5.2.5 (*)
67+
+--- org.apache.logging.log4j:log4j-api:2.21.1 (*)
68+
+--- org.apache.commons:commons-math3:3.6.1
69+
+--- commons-codec:commons-codec:1.16.0
70+
+--- org.apache.poi:poi:5.2.5 (c)
71+
+--- org.apache.poi:poi-excelant:5.2.5 (c)
72+
+--- org.apache.poi:poi-ooxml:5.2.5 (c)
73+
\\--- org.apache.poi:poi-scratchpad:5.2.5 (c)
74+
'''
75+
}
76+
77+
def "can add alignment via BOM"() {
78+
given:
79+
buildFile << """
80+
jvmDependencyConflicts {
81+
patch {
82+
alignWithBom("org.ow2.asm:asm-bom",
83+
"org.ow2.asm:asm",
84+
"org.ow2.asm:asm-tree",
85+
"org.ow2.asm:asm-analysis",
86+
"org.ow2.asm:asm-util",
87+
"org.ow2.asm:asm-commons"
88+
)
89+
}
90+
}
91+
dependencies {
92+
implementation("org.ow2.asm:asm")
93+
implementation("org.ow2.asm:asm-tree:9.6")
94+
implementation("org.ow2.asm:asm-analysis")
95+
implementation("org.ow2.asm:asm-util")
96+
implementation("org.ow2.asm:asm-commons")
97+
}
98+
"""
99+
100+
expect:
101+
dependenciesCompile().output.contains '''
102+
compileClasspath - Compile classpath for source set 'main'.
103+
+--- org.ow2.asm:asm -> 9.6
104+
| \\--- org.ow2.asm:asm-bom:9.6
105+
| +--- org.ow2.asm:asm:9.6 (c)
106+
| +--- org.ow2.asm:asm-tree:9.6 (c)
107+
| +--- org.ow2.asm:asm-analysis:9.6 (c)
108+
| +--- org.ow2.asm:asm-util:9.6 (c)
109+
| \\--- org.ow2.asm:asm-commons:9.6 (c)
110+
+--- org.ow2.asm:asm-tree:9.6
111+
| +--- org.ow2.asm:asm:9.6 (*)
112+
| \\--- org.ow2.asm:asm-bom:9.6 (*)
113+
+--- org.ow2.asm:asm-analysis -> 9.6
114+
| +--- org.ow2.asm:asm-tree:9.6 (*)
115+
| \\--- org.ow2.asm:asm-bom:9.6 (*)
116+
+--- org.ow2.asm:asm-util -> 9.6
117+
| +--- org.ow2.asm:asm:9.6 (*)
118+
| +--- org.ow2.asm:asm-tree:9.6 (*)
119+
| +--- org.ow2.asm:asm-analysis:9.6 (*)
120+
| \\--- org.ow2.asm:asm-bom:9.6 (*)
121+
\\--- org.ow2.asm:asm-commons -> 9.6
122+
+--- org.ow2.asm:asm:9.6 (*)
123+
+--- org.ow2.asm:asm-tree:9.6 (*)
124+
\\--- org.ow2.asm:asm-bom:9.6 (*)
125+
'''
126+
}
127+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.gradlex.jvm.dependency.conflict.test.patch
2+
3+
class AddFeatureTest extends AbstractPatchTest {
4+
5+
def "can add feature"() {
6+
given:
7+
buildFile << """
8+
jvmDependencyConflicts {
9+
patch {
10+
module("io.netty:netty-transport-native-epoll") {
11+
addFeature("linux-x86_64")
12+
addFeature("linux-aarch_64")
13+
}
14+
}
15+
}
16+
dependencies {
17+
implementation("io.netty:netty-transport-native-epoll:4.1.106.Final")
18+
implementation("io.netty:netty-transport-native-epoll:4.1.106.Final") {
19+
capabilities { requireCapabilities("io.netty:netty-transport-native-epoll-linux-x86_64") }
20+
}
21+
implementation("io.netty:netty-transport-native-epoll:4.1.106.Final") {
22+
capabilities { requireCapabilities("io.netty:netty-transport-native-epoll-linux-aarch_64") }
23+
}
24+
}
25+
"""
26+
27+
expect:
28+
def output = dependencyInsight('io.netty:netty-transport-native-epoll').output
29+
output.contains 'linux-x86_64Compile'
30+
output.contains 'linux-aarch_64Compile'
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.gradlex.jvm.dependency.conflict.test.patch
2+
3+
class AddTargetPlatformVariantTest extends AbstractPatchTest {
4+
def "can add target variant"() {
5+
given:
6+
buildFile << """
7+
jvmDependencyConflicts {
8+
patch {
9+
module("org.openjfx:javafx-base") {
10+
addTargetPlatformVariant("", "none", "none")
11+
addTargetPlatformVariant("mac", "macos", "x86-64")
12+
addTargetPlatformVariant("mac-aarch64", "macos", "aarch64")
13+
addTargetPlatformVariant("win", "windows", "x86-64")
14+
addTargetPlatformVariant("linux-aarch64", "linux", "x86-64")
15+
}
16+
}
17+
}
18+
configurations.compileClasspath {
19+
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named("windows"))
20+
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named("x86-64"))
21+
}
22+
dependencies {
23+
implementation("org.openjfx:javafx-base:17.0.10")
24+
}
25+
"""
26+
27+
expect:
28+
String output = dependencyInsight("org.openjfx:javafx-base").output
29+
output.contains 'windows'
30+
output.contains 'x86-64'
31+
}
32+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.gradlex.jvm.dependency.conflict.test.patch
2+
3+
import org.gradlex.jvm.dependency.conflict.test.fixture.GradleBuild
4+
5+
class ModifyCapabilitiesTest extends AbstractPatchTest {
6+
7+
def "can add capability by enum"() {
8+
given:
9+
buildFile.text = 'import org.gradlex.jvm.dependency.conflict.detection.rules.CapabilityDefinition.STAX_API\n' + buildFile.text
10+
buildFile << """
11+
jvmDependencyConflicts {
12+
patch {
13+
module("org.eclipse.birt.runtime:javax.xml.stream") {
14+
addCapability(STAX_API)
15+
}
16+
}
17+
}
18+
dependencies {
19+
implementation("stax:stax-api:1.0.1")
20+
implementation("org.eclipse.birt.runtime:javax.xml.stream:1.0.1.v201004272200")
21+
}
22+
"""
23+
24+
expect:
25+
dependenciesCompile().output.contains '''
26+
compileClasspath - Compile classpath for source set 'main'.
27+
+--- stax:stax-api:1.0.1
28+
\\--- org.eclipse.birt.runtime:javax.xml.stream:1.0.1.v201004272200 -> stax:stax-api:1.0.1
29+
30+
'''
31+
}
32+
33+
def "can add capability by string"() {
34+
given:
35+
buildFile << """
36+
jvmDependencyConflicts {
37+
patch {
38+
module("org.apache.commons:commons-lang3") {
39+
addCapability("commons-lang:commons-lang") // artificial case for testing!
40+
}
41+
}
42+
}
43+
dependencies {
44+
implementation("commons-lang:commons-lang:2.6")
45+
implementation("org.apache.commons:commons-lang3:3.11")
46+
}
47+
"""
48+
49+
expect:
50+
fail().output.contains "Cannot select module with conflict on capability 'commons-lang:commons-lang:2.6' also provided by [org.apache.commons:commons-lang3:3.11(compile)]"
51+
}
52+
53+
def "can remove capability by enum"() {
54+
given:
55+
buildFile.text = 'import org.gradlex.jvm.dependency.conflict.detection.rules.CapabilityDefinition.STAX_API\n' + buildFile.text
56+
buildFile << """
57+
jvmDependencyConflicts {
58+
patch {
59+
module("javax.xml.stream:stax-api") {
60+
removeCapability(STAX_API)
61+
}
62+
}
63+
}
64+
dependencies {
65+
implementation("stax:stax-api:1.0.1")
66+
implementation("javax.xml.stream:stax-api:1.0-2")
67+
}
68+
"""
69+
70+
expect:
71+
dependenciesCompile().output.contains '''
72+
compileClasspath - Compile classpath for source set 'main'.
73+
+--- stax:stax-api:1.0.1
74+
\\--- javax.xml.stream:stax-api:1.0-2
75+
76+
'''
77+
}
78+
79+
def "can remove capability by string"() {
80+
given:
81+
if (GradleBuild.GRADLE6_TEST) {
82+
buildFile << """
83+
configurations.runtimeClasspath {
84+
attributes.attribute(Attribute.of("org.gradle.jvm.environment", String::class.java), "standard-jvm")
85+
}
86+
"""
87+
}
88+
89+
buildFile << """
90+
jvmDependencyConflicts {
91+
patch {
92+
module("com.google.guava:guava") {
93+
removeCapability("com.google.collections:google-collections")
94+
}
95+
}
96+
}
97+
dependencies {
98+
implementation("com.google.guava:guava:33.1.0-jre")
99+
implementation("com.google.collections:google-collections:1.0")
100+
}
101+
"""
102+
103+
expect:
104+
dependenciesRuntime().output.contains '''
105+
runtimeClasspath - Runtime classpath of source set 'main'.
106+
+--- com.google.guava:guava:33.1.0-jre
107+
| +--- com.google.guava:failureaccess:1.0.2
108+
| +--- com.google.code.findbugs:jsr305:3.0.2
109+
| +--- org.checkerframework:checker-qual:3.42.0
110+
| \\--- com.google.errorprone:error_prone_annotations:2.26.1
111+
\\--- com.google.collections:google-collections:1.0
112+
113+
'''
114+
}
115+
}

0 commit comments

Comments
 (0)