Skip to content

Commit cb1a693

Browse files
Excavator: Migrate Groovy nebula test SupportsSpotless622 to the new Java Junit framework
1 parent 88173c1 commit cb1a693

File tree

3 files changed

+2043
-32
lines changed

3 files changed

+2043
-32
lines changed
Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.palantir.javaformat.gradle
16+
package com.palantir.javaformat.gradle;
1717

18-
import nebula.test.IntegrationTestKitSpec
18+
import com.google.common.base.Splitter;
19+
import com.palantir.gradle.testing.execution.GradleInvoker;
20+
import com.palantir.gradle.testing.junit.GradlePluginTests;
21+
import com.palantir.gradle.testing.project.RootProject;
22+
import java.io.File;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.util.List;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
1928

2029
/**
2130
* When we were getting gradle-baseline to support the configuration cache, spotless had some poorly written tasks
@@ -28,20 +37,14 @@
2837
*
2938
* This test forces creation of the spotless steps, which will reveal any eager resolution of configurations.
3039
*/
31-
class SupportsSpotless622 extends IntegrationTestKitSpec {
32-
private static final CLASSPATH_FILE = new File("build/impl.classpath").absolutePath
40+
@GradlePluginTests
41+
class SupportsSpotless622 {
42+
private static final String CLASSPATH_FILE = new File("build/impl.classpath").getAbsolutePath();
3343

34-
private GradlewExecutor executor
35-
36-
def setup() {
37-
definePluginOutsideOfPluginBlock = true
38-
keepFiles = true
39-
executor = new GradlewExecutor(projectDir)
40-
}
41-
42-
def "PalantirJavaFormatPlugin works with spotless 6.22.0"() {
43-
// language=Gradle
44-
buildFile << '''
44+
@BeforeEach
45+
@SuppressWarnings("GradleTestPluginsBlock") // Need to use apply plugin syntax due to buildscript block
46+
void setup(RootProject project) throws Exception {
47+
project.buildGradle().prepend("""
4548
buildscript {
4649
repositories {
4750
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
@@ -52,36 +55,41 @@ def setup() {
5255
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.22.0'
5356
}
5457
}
55-
58+
5659
apply plugin: 'java'
5760
apply plugin: 'com.palantir.java-format'
5861
apply plugin: 'com.palantir.consistent-versions'
5962
apply plugin: 'com.diffplug.spotless'
60-
63+
6164
version = '0.1.0'
62-
'''.stripIndent(true)
65+
""");
6366

67+
project.file("versions.props").createEmpty();
68+
project.file("versions.lock").createEmpty();
69+
}
6470

65-
file("versions.props")
66-
file("versions.lock")
71+
@Test
72+
void palantir_java_format_plugin_works_with_spotless_6_22_0(GradleInvoker gradle, RootProject project)
73+
throws Exception {
74+
// Read the classpath file and add dependencies
75+
String classpathContent = Files.readString(Path.of(CLASSPATH_FILE));
76+
List<String> classpathEntries = Splitter.on(':').splitToList(classpathContent);
6777

68-
runTasks('wrapper')
78+
// Build the files() list for dependencies
79+
String filesArgs = String.join(
80+
", ", classpathEntries.stream().map(entry -> "'" + entry + "'").toList());
6981

70-
buildFile << """
82+
project.buildGradle().append("""
7183
dependencies {
72-
palantirJavaFormat files(file("${CLASSPATH_FILE}").text.split(':'))
84+
palantirJavaFormat files(%s)
7385
}
7486
75-
// This forces the realization of the spotlessJava task, creating the spotless steps.
76-
// If any configurations are eagerly resolved in the spotless steps,
77-
// consistent-versions should catch it and throw here.
87+
// This forces the realization of the spotlessJava task, creating the spotless steps.
88+
// If any configurations are eagerly resolved in the spotless steps,
89+
// consistent-versions should catch it and throw here.
7890
project.getTasks().getByName("spotlessJava")
79-
""".stripIndent(true)
80-
81-
when:
82-
def result = executor.runGradlewTasks('classes', '--info')
91+
""", filesArgs);
8392

84-
then:
85-
assert result.success
93+
gradle.withArgs("classes", "--info").buildsSuccessfully();
8694
}
8795
}

0 commit comments

Comments
 (0)