Skip to content

Commit be13bc8

Browse files
Excavator: Migrate Groovy nebula test CircleCiArtifactsTest to the new Java Junit framework
1 parent 4065278 commit be13bc8

File tree

7 files changed

+3500
-137
lines changed

7 files changed

+3500
-137
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildscript {
99
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0'
1010
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.69.0'
1111
classpath 'com.palantir.gradle.jdkslatest:gradle-jdks-latest:0.24.0'
12+
classpath 'com.palantir.gradle.plugintesting:gradle-plugin-testing:0.43.0'
1213
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.27.0'
1314
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.83.0'
1415
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.26.0'

circleci-artifacts/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dependencies {
1414
testImplementation 'org.assertj:assertj-core'
1515
testImplementation 'org.junit.jupiter:junit-jupiter'
1616
testImplementation 'com.netflix.nebula:nebula-test'
17+
testImplementation 'com.palantir.gradle.plugintesting:gradle-plugin-testing-junit'
1718
}

circleci-artifacts/src/test/groovy/com/palantir/gradle/utils/circleciartifacts/CircleCiArtifactsTest.groovy

Lines changed: 0 additions & 133 deletions
This file was deleted.
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.palantir.gradle.utils.circleciartifacts;
18+
19+
import static com.palantir.gradle.testing.assertion.GradlePluginTestAssertions.assertThat;
20+
21+
import com.palantir.gradle.testing.execution.GradleInvoker;
22+
import com.palantir.gradle.testing.execution.InvocationResult;
23+
import com.palantir.gradle.testing.files.Directory;
24+
import com.palantir.gradle.testing.files.gradle.GradleFile;
25+
import com.palantir.gradle.testing.junit.DisabledConfigurationCache;
26+
import com.palantir.gradle.testing.junit.GradlePluginTests;
27+
import com.palantir.gradle.testing.project.RootProject;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
30+
31+
@GradlePluginTests
32+
@DisabledConfigurationCache
33+
class CircleCiArtifactsTest {
34+
35+
@BeforeEach
36+
void setup(RootProject project) {
37+
standardBuildFile(project);
38+
}
39+
40+
private GradleFile standardBuildFile(RootProject project) {
41+
return project.buildGradle().overwrite("""
42+
import com.palantir.gradle.utils.circleciartifacts.CircleCiArtifacts
43+
44+
public abstract class CircleCiArtifactsTask extends DefaultTask {
45+
@Nested
46+
abstract CircleCiArtifacts getCircleCiArtifacts();
47+
}
48+
49+
tasks.register("printCircleCiLocation", CircleCiArtifactsTask) {
50+
doLast { task ->
51+
def artifactLocation = task.circleCiArtifacts.resolveArtifactLocation('location/in/artifacts')
52+
if (artifactLocation.isPresent()) {
53+
println "Physical path: ${artifactLocation.get().physicalPath()}"
54+
println "External location: ${artifactLocation.get().externalLocation()}"
55+
println "Circle link: ${artifactLocation.get().circleLink()}"
56+
} else {
57+
println "Not in Circle, empty artifact location"
58+
}
59+
}
60+
}
61+
""");
62+
}
63+
64+
@Test
65+
void can_use_circleci_artifacts_when_the_right_environment_variables_are_set(
66+
GradleInvoker gradle, RootProject project) {
67+
Directory fakeCircleArtifacts =
68+
project.directory("build/circle-artifacts").createDirectories();
69+
project.gradlePropertiesFile()
70+
.appendProperty("__TESTING", "true")
71+
.appendProperty("__TESTING_CI", "true")
72+
.appendProperty(
73+
"__TESTING_CIRCLE_ARTIFACTS",
74+
project.path().relativize(fakeCircleArtifacts.path()).toString())
75+
.appendProperty("__TESTING_CIRCLE_PROJECT_USERNAME", "palantir")
76+
.appendProperty("__TESTING_CIRCLE_PROJECT_REPONAME", "gradle-utils")
77+
.appendProperty("__TESTING_CIRCLE_BUILD_NUM", "1234")
78+
.appendProperty("__TESTING_CIRCLE_NODE_INDEX", "2345")
79+
.appendProperty("__TESTING_CIRCLE_BUILD_URL", "https://circleci.com/gh/palantir/gradle-utils/1234")
80+
.appendProperty("__TESTING_CIRCLE_WORKFLOW_JOB_ID", "abc-123-def-456");
81+
82+
InvocationResult result = gradle.withArgs("printCircleCiLocation").buildsSuccessfully();
83+
84+
assertThat(result)
85+
.output()
86+
.containsPattern("Physical path: .*/build/circle-artifacts/location/in/artifacts")
87+
.containsPattern(
88+
"External location: palantir/gradle-utils/1234/artifacts/2345/.*/location/in/artifacts")
89+
.containsPattern("Circle link:"
90+
+ " https://circleci.com/output/job/abc-123-def-456/artifacts/2345/.*/location/in/artifacts");
91+
}
92+
93+
@Test
94+
void empty_property_if_were_not_in_circle(GradleInvoker gradle, RootProject project) {
95+
project.gradlePropertiesFile().appendProperty("__TESTING", "true");
96+
97+
InvocationResult result = gradle.withArgs("printCircleCiLocation").buildsSuccessfully();
98+
99+
assertThat(result).output().contains("Not in Circle, empty artifact location");
100+
}
101+
102+
@Test
103+
void handles_missing_circleci_url_gracefully(GradleInvoker gradle, RootProject project) {
104+
Directory fakeCircleArtifacts =
105+
project.directory("build/circle-artifacts").createDirectories();
106+
project.gradlePropertiesFile()
107+
.appendProperty("__TESTING", "true")
108+
.appendProperty("__TESTING_CI", "true")
109+
.appendProperty(
110+
"__TESTING_CIRCLE_ARTIFACTS",
111+
project.path().relativize(fakeCircleArtifacts.path()).toString())
112+
.appendProperty("__TESTING_CIRCLE_PROJECT_USERNAME", "palantir")
113+
.appendProperty("__TESTING_CIRCLE_PROJECT_REPONAME", "gradle-utils")
114+
.appendProperty("__TESTING_CIRCLE_BUILD_NUM", "1234")
115+
.appendProperty("__TESTING_CIRCLE_NODE_INDEX", "2345")
116+
.appendProperty("__TESTING_CIRCLE_WORKFLOW_JOB_ID", "abc-123-def-456");
117+
118+
InvocationResult result = gradle.withArgs("printCircleCiLocation").buildsSuccessfully();
119+
120+
assertThat(result)
121+
.output()
122+
.containsPattern("Physical path: .*/build/circle-artifacts/location/in/artifacts")
123+
.containsPattern(
124+
"External location: palantir/gradle-utils/1234/artifacts/2345/.*/location/in/artifacts")
125+
.containsPattern("Circle link:"
126+
+ " https://<circle_url>/output/job/abc-123-def-456/artifacts/2345/.*/location/in/artifacts");
127+
}
128+
129+
@Test
130+
void handles_custom_circle_home_directory_environment_variable(GradleInvoker gradle, RootProject project) {
131+
String customHome = "/custom/home/path/";
132+
project.gradlePropertiesFile()
133+
.appendProperty("__TESTING", "true")
134+
.appendProperty("__TESTING_CI", "true")
135+
.appendProperty("__TESTING_CIRCLE_ARTIFACTS", customHome + "circle-artifacts")
136+
.appendProperty("__TESTING_CIRCLE_PROJECT_USERNAME", "palantir")
137+
.appendProperty("__TESTING_CIRCLE_PROJECT_REPONAME", "gradle-utils")
138+
.appendProperty("__TESTING_CIRCLE_BUILD_NUM", "1234")
139+
.appendProperty("__TESTING_CIRCLE_NODE_INDEX", "2345")
140+
.appendProperty("__TESTING_CIRCLE_BUILD_URL", "https://circleci.com/gh/palantir/gradle-utils/1234")
141+
.appendProperty("__TESTING_CIRCLE_WORKFLOW_JOB_ID", "abc-123-def-456")
142+
.appendProperty("__TESTING_CIRCLE_HOME_DIRECTORY", customHome);
143+
144+
InvocationResult result = gradle.withArgs("printCircleCiLocation").buildsSuccessfully();
145+
146+
assertThat(result)
147+
.output()
148+
.contains("Physical path: " + customHome + "circle-artifacts/location/in/artifacts")
149+
.contains("External location:"
150+
+ " palantir/gradle-utils/1234/artifacts/2345/~/circle-artifacts/location/in/artifacts")
151+
.contains(
152+
"Circle link:"
153+
+ " https://circleci.com/output/job/abc-123-def-456/artifacts/2345/~/circle-artifacts/location/in/artifacts");
154+
}
155+
}

test-migration-notes/CircleCiArtifactsTest.html

Lines changed: 3322 additions & 0 deletions
Large diffs are not rendered by default.

versions.lock

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,43 @@ org.immutables:value:2.11.7 (1 constraints: 3d05393b)
1414

1515
cglib:cglib-nodep:3.2.2 (1 constraints: 490ded24)
1616

17+
com.google.errorprone:error_prone_annotations:2.41.0 (2 constraints: 7e0f1fa1)
18+
19+
com.google.guava:failureaccess:1.0.3 (1 constraints: 160ae3b4)
20+
21+
com.google.guava:guava:33.5.0-jre (1 constraints: 481bc549)
22+
23+
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
24+
25+
com.google.j2objc:j2objc-annotations:3.1 (1 constraints: b809f1a0)
26+
1727
com.netflix.nebula:nebula-test:10.6.2 (1 constraints: 3b053b3b)
1828

29+
com.palantir.gradle.plugintesting:gradle-plugin-testing-junit:0.43.0 (1 constraints: 3905383b)
30+
31+
commons-io:commons-io:2.19.0 (1 constraints: db190cdf)
32+
1933
junit:junit:4.13.2 (1 constraints: 1b0e1d4c)
2034

2135
net.bytebuddy:byte-buddy:1.17.7 (1 constraints: 560b56df)
2236

2337
org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 5366ce6e)
2438

25-
org.assertj:assertj-core:3.27.6 (1 constraints: 4405543b)
39+
org.assertj:assertj-core:3.27.6 (2 constraints: 211f1a90)
2640

2741
org.codehaus.groovy:groovy:3.0.12 (2 constraints: 781b1f9d)
2842

2943
org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04)
3044

3145
org.hamcrest:hamcrest-core:1.3 (1 constraints: cc05fe3f)
3246

33-
org.jspecify:jspecify:1.0.0 (6 constraints: 4166fe65)
47+
org.jetbrains:annotations:26.0.2 (1 constraints: d9190fdf)
48+
49+
org.jspecify:jspecify:1.0.0 (7 constraints: 5370d26f)
3450

3551
org.junit.jupiter:junit-jupiter:6.0.1 (1 constraints: 48070970)
3652

37-
org.junit.jupiter:junit-jupiter-api:6.0.1 (3 constraints: 5e2fd3d8)
53+
org.junit.jupiter:junit-jupiter-api:6.0.1 (4 constraints: 39496641)
3854

3955
org.junit.jupiter:junit-jupiter-engine:6.0.1 (1 constraints: 040ecb3b)
4056

versions.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
com.fasterxml.jackson.*:* = 2.20.0
22
com.fasterxml.jackson.core:jackson-annotations = 2.20
3+
com.palantir.gradle.plugintesting:gradle-plugin-testing-junit = 0.43.0
34
org.apache.commons:commons-lang3 = 3.20.0
45

56
org.junit.jupiter:* = 6.0.1
@@ -12,4 +13,4 @@ com.google.code.findbugs:jsr305 = 3.0.2
1213
com.google.errorprone:error_prone_annotations = 2.11.0
1314
org.checkerframework:checker-qual = 3.52.1
1415
com.gradle:develocity-gradle-plugin-adapters = 1.2.1
15-
org.junit.platform:* = 6.0.1
16+
org.junit.platform:* = 6.0.1

0 commit comments

Comments
 (0)