Skip to content

Commit b4a9a7c

Browse files
Excavator: Migrate Groovy nebula test SupportsSpotless622 to the new Java Junit framework (#1481)
1 parent cbdaaa5 commit b4a9a7c

6 files changed

Lines changed: 1903 additions & 95 deletions

File tree

gradle-palantir-java-format/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ dependencies {
3232

3333
pluginClasspath 'com.diffplug.spotless:spotless-plugin-gradle'
3434

35+
gradlePluginForTesting 'com.palantir.gradle.consistentversions:gradle-consistent-versions'
36+
gradlePluginForTesting 'com.diffplug.spotless:spotless-plugin-gradle'
3537
gradlePluginForTesting 'com.palantir.gradle.jdks:gradle-jdks-settings'
3638
gradlePluginForTesting 'com.palantir.baseline:gradle-baseline-java'
3739
gradlePluginForTesting 'com.palantir.gradle.jdkslatest:gradle-jdks-latest'

gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/SupportsSpotless622.groovy

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* (c) Copyright 2019 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+
package com.palantir.javaformat.gradle;
17+
18+
import com.palantir.gradle.testing.execution.GradleInvoker;
19+
import com.palantir.gradle.testing.junit.DisabledConfigurationCache;
20+
import com.palantir.gradle.testing.junit.GradlePluginTests;
21+
import com.palantir.gradle.testing.project.RootProject;
22+
import java.io.File;
23+
import org.junit.jupiter.api.Test;
24+
25+
/**
26+
* When we were getting gradle-baseline to support the configuration cache, spotless had some poorly written tasks
27+
* which caused issues with the configuration cache.
28+
* <p>
29+
* Bumping spotless to 6.22.0 or newer fixed this, but revealed a new error — the {@code palantirJavaFormat} configuration was
30+
* being <a href="https://github.com/palantir/palantir-java-format/blob/b7b5995df3be690780939c0d0cb2ec49b99c68c8/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/NativePalantirJavaFormatStep.java#L45"> resolved eagerly</a>.
31+
* <p>
32+
* gradle-consistent-versions enforces against resolving configurations at configuration time, and throws an error.
33+
* <p>
34+
* This test forces creation of the spotless steps, which will reveal any eager resolution of configurations.
35+
*/
36+
@GradlePluginTests
37+
@DisabledConfigurationCache
38+
class SupportsCurrentSpotlessTest {
39+
private static final String CLASSPATH_FILE = new File("build/impl.classpath").getAbsolutePath();
40+
41+
@Test
42+
void palantirjavaformatplugin_works_with_current_spotless(GradleInvoker gradle, RootProject rootProject) {
43+
rootProject
44+
.buildGradle()
45+
.plugins()
46+
.add("java")
47+
.add("com.palantir.java-format")
48+
.add("com.palantir.consistent-versions")
49+
.add("com.diffplug.spotless");
50+
51+
rootProject.file("versions.props").createEmpty();
52+
rootProject.file("versions.lock").createEmpty();
53+
54+
gradle.withArgs("wrapper").buildsSuccessfully();
55+
56+
rootProject.buildGradle().append("""
57+
dependencies {
58+
palantirJavaFormat files(file("%s").text.split(':'))
59+
}
60+
61+
// This forces the realization of the spotlessJava task, creating the spotless steps.
62+
// If any configurations are eagerly resolved in the spotless steps,
63+
// consistent-versions should catch it and throw here.
64+
project.getTasks().getByName("spotlessJava")
65+
""", CLASSPATH_FILE);
66+
67+
gradle.withArgs("classes", "--info").buildsSuccessfully();
68+
}
69+
}

0 commit comments

Comments
 (0)