From 70cc4916c881b3da9229b09070c651da3c6ab393 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 8 Dec 2024 10:28:29 -0800 Subject: [PATCH 1/4] Run the NativeCmd integration test with and without the configuration cache to reproduce #2347. --- .../spotless/NativeCmdIntegrationTest.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java index a4f8d6205c..fa08d3b5f0 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,26 +20,40 @@ import java.io.File; import java.io.IOException; +import org.gradle.testkit.runner.GradleRunner; import org.junit.jupiter.api.Test; -class NativeCmdIntegrationTest extends GradleIntegrationHarness { +interface NativeCmdIntegrationTest { @Test - void nativeCmd() throws IOException { + default void nativeCmd() throws IOException { // This will only work if /usr/bin/sed is available assumeThat(new File("/usr/bin/sed")).exists(); - setFile("build.gradle").toLines( + GradleIntegrationHarness harness = (GradleIntegrationHarness) this; + harness.setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", "}", "spotless {", + " lineEndings 'UNIX'", " format 'test', {", - " target '**/*.txt'", + " target '*.txt'", " nativeCmd('sed', '/usr/bin/sed', ['s/placeholder/replaced/g'])", " }", "}"); - setFile("test.txt").toResource("native_cmd/dirty.txt"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("test.txt").sameAsResource("native_cmd/clean.txt"); + harness.setFile("test.txt").toResource("native_cmd/dirty.txt"); + harness.gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); + harness.assertFile("test.txt").sameAsResource("native_cmd/clean.txt"); + } + + class NativeCmdWithoutConfigCacheTest extends GradleIntegrationHarness implements NativeCmdIntegrationTest {} + + class NativeCmdWithConfigCacheTest extends GradleIntegrationHarness implements NativeCmdIntegrationTest { + @Override + public GradleRunner gradleRunner() throws IOException { + setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true"); + setFile("settings.gradle").toContent("enableFeaturePreview(\"STABLE_CONFIGURATION_CACHE\")"); + return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version); + } } } From b0837a2b7c15997d5367187d6c0306507617e7df Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 8 Dec 2024 10:16:43 -0800 Subject: [PATCH 2/4] It seems that Gradle's custom serialization doesn't support the `List.of()` stuff introduced in recent JDKs.... --- lib/src/main/java/com/diffplug/spotless/FileSignature.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FileSignature.java b/lib/src/main/java/com/diffplug/spotless/FileSignature.java index 3d37ec2983..0d26d86ff8 100644 --- a/lib/src/main/java/com/diffplug/spotless/FileSignature.java +++ b/lib/src/main/java/com/diffplug/spotless/FileSignature.java @@ -126,7 +126,7 @@ public static Promised promise(Iterable files) { } public static Promised promise(File file) { - return new Promised(List.of(file), null); + return new Promised(MoreIterables.toNullHostileList(List.of(file)), null); } /** Returns all of the files in this signature, throwing an exception if there are more or less than 1 file. */ From bcfe83fccbca9e03b635357fe10b3d56d57074a8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 9 Dec 2024 08:09:15 -0800 Subject: [PATCH 3/4] Stop using `STABLE_CONFIGURATION_CACHE` because it causes error in some versions of Gradle. --- .../com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java index fa08d3b5f0..418bded954 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NativeCmdIntegrationTest.java @@ -52,7 +52,7 @@ class NativeCmdWithConfigCacheTest extends GradleIntegrationHarness implements N @Override public GradleRunner gradleRunner() throws IOException { setFile("gradle.properties").toContent("org.gradle.unsafe.configuration-cache=true"); - setFile("settings.gradle").toContent("enableFeaturePreview(\"STABLE_CONFIGURATION_CACHE\")"); + setFile("gradle.properties").toContent("org.gradle.configuration-cache=true"); return super.gradleRunner().withGradleVersion(GradleVersionSupport.CONFIGURATION_CACHE.version); } } From 4938c84e34a6f45a2c4e08ce70236e8972562ee3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 9 Dec 2024 10:55:44 -0800 Subject: [PATCH 4/4] Undisable the npm test now that status.npmjs is happy again. --- .../gradle/spotless/NpmTestsWithoutNpmInstallationTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 50ea620778..22fe466dbe 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -17,12 +17,10 @@ import org.assertj.core.api.Assertions; import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.common.base.Predicates; -@Disabled("https://status.npmjs.org/ shows npm services down on 12/8/2024, should undisable this later") class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { @Test