Skip to content

Commit 0ce3cbf

Browse files
committed
Remove the Spotless step for the native image
SpotlessInterop picked NativePalantirJavaFormatStep when the native formatter was switched on and Gradle ran on a JVM older than 21. The plugin is compiled for 21 and does not load on an older JVM, so the branch never ran: Spotless formats on the Gradle JVM, as the docs say, whatever openjavaformat.native.formatter is. The step, the version check and the native configuration lookup go. So does PalantirJavaFormatStep.create(Configuration, Supplier), deprecated when the step stopped using the supplier; nothing calls it.
1 parent 7160468 commit 0ce3cbf

4 files changed

Lines changed: 6 additions & 108 deletions

File tree

‎gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/SpotlessInterop.java‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,19 @@
1717

1818
import com.diffplug.gradle.spotless.JavaExtension;
1919
import com.diffplug.spotless.FormatterStep;
20-
import com.palantir.javaformat.gradle.spotless.NativePalantirJavaFormatStep;
2120
import com.palantir.javaformat.gradle.spotless.PalantirJavaFormatStep;
2221
import java.io.File;
2322
import java.util.List;
2423
import java.util.concurrent.Callable;
2524
import java.util.regex.Pattern;
2625
import javax.inject.Inject;
2726
import org.gradle.api.Action;
28-
import org.gradle.api.JavaVersion;
2927
import org.gradle.api.artifacts.ConfigurationContainer;
3028
import org.gradle.api.file.FileCollection;
3129
import org.gradle.api.logging.Logger;
3230
import org.gradle.api.logging.Logging;
3331
import org.gradle.api.model.ObjectFactory;
3432
import org.gradle.api.specs.Spec;
35-
import org.gradle.api.tasks.Nested;
3633
import org.gradle.api.tasks.SourceSetContainer;
3734

3835
/**
@@ -56,9 +53,6 @@ public abstract class SpotlessInterop implements Action<JavaExtension> {
5653
private final File projectDir;
5754
private final SourceSetContainer sourceSets;
5855

59-
@Nested
60-
protected abstract NativeImageSupport getNativeImageSupport();
61-
6256
@Inject
6357
protected abstract ConfigurationContainer getConfigurations();
6458

@@ -90,14 +84,12 @@ private FileCollection generatedSources() {
9084
.toList());
9185
}
9286

87+
/**
88+
* The Java-based formatter, on the Gradle JVM, whether or not {@code openjavaformat.native.formatter} is set: the
89+
* property is about formatDiff, and Spotless has no native step.
90+
*/
9391
private FormatterStep spotlessJavaFormatStep() {
94-
if (getNativeImageSupport().isNativeImageConfigured()
95-
&& JavaVersion.current().compareTo(JavaVersion.VERSION_21) < 0) {
96-
logger.info("Using the native-image formatter");
97-
return NativePalantirJavaFormatStep.create(
98-
getConfigurations().getByName(NativeImageFormatProviderPlugin.NATIVE_CONFIGURATION_NAME));
99-
}
100-
logger.info("Using the Java-based formatter {}", JavaVersion.current());
92+
logger.info("Using the Java-based formatter");
10193
return PalantirJavaFormatStep.create(
10294
getConfigurations().getByName(PalantirJavaFormatProviderPlugin.CONFIGURATION_NAME));
10395
}

‎gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/NativePalantirJavaFormatStep.java‎

Lines changed: 0 additions & 75 deletions
This file was deleted.

‎gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
import com.diffplug.spotless.FileSignature;
1919
import com.diffplug.spotless.FormatterFunc;
2020
import com.diffplug.spotless.FormatterStep;
21-
import com.google.errorprone.annotations.InlineMe;
2221
import com.palantir.javaformat.gradle.FormatterServiceLoader;
2322
import com.palantir.javaformat.java.FormatterService;
24-
import java.util.function.Supplier;
2523
import org.gradle.api.artifacts.Configuration;
2624

2725
public final class PalantirJavaFormatStep {
@@ -47,19 +45,6 @@ public static FormatterStep create(Configuration palantirJavaFormat) {
4745
PalantirJavaFormatStep::createFormat);
4846
}
4947

50-
/**
51-
* Creates the same step as {@link #create(Configuration)}.
52-
*
53-
* @deprecated the step loads the formatter from the configuration's jars, and ignores {@code memoizedService}.
54-
*/
55-
@Deprecated
56-
@InlineMe(
57-
replacement = "PalantirJavaFormatStep.create(palantirJavaFormat)",
58-
imports = "com.palantir.javaformat.gradle.spotless.PalantirJavaFormatStep")
59-
public static FormatterStep create(Configuration palantirJavaFormat, Supplier<FormatterService> memoizedService) {
60-
return create(palantirJavaFormat);
61-
}
62-
6348
private static FormatterFunc createFormat(FileSignature jars) {
6449
FormatterService formatter = FormatterServiceLoader.load(jars.files());
6550
return formatter::formatSourceReflowStringsAndFixImports;

‎gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/PalantirJavaFormatSpotlessPluginTest.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ final class PalantirJavaFormatSpotlessPluginTest {
5151
@TempDir
5252
private Path projectDir;
5353

54-
// There used to be a third case — native.formatter=true on Java 17, expecting the native-image
55-
// formatter. SpotlessInterop only picks the native image when JavaVersion.current() < 21, and the
56-
// generated build's daemon used to be forced onto 17 by palantir/gradle-jdks. Without that plugin
57-
// TestKit runs the generated build on the same JVM as the test, so the case could only ever assert
58-
// the Java-based path. Restoring it means pointing org.gradle.java.home at a JDK below 21.
54+
// native.formatter=true too formats on the Gradle JVM: Spotless has no native step.
5955
@ParameterizedTest
6056
@CsvSource(
6157
delimiter = '|',

0 commit comments

Comments
 (0)