Skip to content

Commit 7262511

Browse files
authored
Remove JvmLocalCache now that everything is round-trippable on its own (#2088)
2 parents f7346d5 + 53d0399 commit 7262511

File tree

10 files changed

+29
-150
lines changed

10 files changed

+29
-150
lines changed

plugin-gradle/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Fixed
7+
* Full no-asterisk support for configuration cache ([#2088](https://github.com/diffplug/spotless/pull/2088) closes [#1274](https://github.com/diffplug/spotless/issues/1274) and [#987](https://github.com/diffplug/spotless/issues/987)).
78
* Ignore system git config when running tests ([#1990](https://github.com/diffplug/spotless/issues/1990))
89
* Correctly provide EditorConfig property types for Ktlint ([#2052](https://github.com/diffplug/spotless/issues/2052))
910
* Fixed memory leak introduced in 6.21.0 ([#2067](https://github.com/diffplug/spotless/issues/2067))

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLocalCache.java

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

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public LineEnding getLineEndings() {
6464
}
6565

6666
public void setLineEndings(LineEnding lineEndings) {
67+
if (lineEndings == LineEnding.GIT_ATTRIBUTES) {
68+
throw new IllegalArgumentException("GIT_ATTRIBUTES not supported in Gradle, use GIT_ATTRIBUTES_FAST_ALLSAME instead. See https://github.com/diffplug/spotless/issues/1274 for more details.");
69+
}
6770
this.lineEndings = requireNonNull(lineEndings);
6871
}
6972

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 DiffPlug
2+
* Copyright 2020-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,6 @@
3737
import org.gradle.api.tasks.PathSensitivity;
3838
import org.gradle.work.Incremental;
3939

40-
import com.diffplug.gradle.spotless.JvmLocalCache.LiveCache;
4140
import com.diffplug.spotless.FormatExceptionPolicy;
4241
import com.diffplug.spotless.FormatExceptionPolicyStrict;
4342
import com.diffplug.spotless.Formatter;
@@ -49,10 +48,6 @@ public abstract class SpotlessTask extends DefaultTask {
4948
@Internal
5049
abstract Property<SpotlessTaskService> getTaskService();
5150

52-
protected <T> LiveCache<T> createLive(String keyName) {
53-
return JvmLocalCache.createLive(this, keyName);
54-
}
55-
5651
// set by SpotlessExtension, but possibly overridden by FormatExtension
5752
protected String encoding = "UTF-8";
5853

@@ -65,15 +60,15 @@ public void setEncoding(String encoding) {
6560
this.encoding = Objects.requireNonNull(encoding);
6661
}
6762

68-
protected final LiveCache<Provider<LineEnding.Policy>> lineEndingsPolicy = createLive("lineEndingsPolicy");
63+
protected Provider<LineEnding.Policy> lineEndingsPolicy = null;
6964

7065
@Input
7166
public Provider<LineEnding.Policy> getLineEndingsPolicy() {
72-
return lineEndingsPolicy.get();
67+
return lineEndingsPolicy;
7368
}
7469

7570
public void setLineEndingsPolicy(Provider<LineEnding.Policy> lineEndingsPolicy) {
76-
this.lineEndingsPolicy.set(lineEndingsPolicy);
71+
this.lineEndingsPolicy = lineEndingsPolicy;
7772
}
7873

7974
/** The sha of the tree at repository root, used for determining if an individual *file* is clean according to git. */
@@ -155,22 +150,17 @@ public File getOutputDirectory() {
155150
return outputDirectory;
156151
}
157152

158-
protected final LiveCache<List<FormatterStep>> steps = createLive("steps");
159-
{
160-
steps.set(new ArrayList<FormatterStep>());
161-
}
153+
protected final List<FormatterStep> steps = new ArrayList<>();
162154

163155
@Input
164156
public List<FormatterStep> getSteps() {
165-
return Collections.unmodifiableList(steps.get());
157+
return Collections.unmodifiableList(steps);
166158
}
167159

168160
public void setSteps(List<FormatterStep> steps) {
169-
this.steps.set(PluginGradlePreconditions.requireElementsNonNull(steps));
170-
}
171-
172-
public boolean addStep(FormatterStep step) {
173-
return this.steps.get().add(Objects.requireNonNull(step));
161+
PluginGradlePreconditions.requireElementsNonNull(steps);
162+
this.steps.clear();
163+
this.steps.addAll(steps);
174164
}
175165

176166
/** Returns the name of this format. */
@@ -186,10 +176,10 @@ String formatName() {
186176
Formatter buildFormatter() {
187177
return Formatter.builder()
188178
.name(formatName())
189-
.lineEndingsPolicy(lineEndingsPolicy.get().get())
179+
.lineEndingsPolicy(getLineEndingsPolicy().get())
190180
.encoding(Charset.forName(encoding))
191181
.rootDir(getProjectDir().get().getAsFile().toPath())
192-
.steps(steps.get())
182+
.steps(steps)
193183
.exceptionPolicy(exceptionPolicy)
194184
.build();
195185
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void failureWhenExeNotFound() throws Exception {
310310
var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail();
311311
assertThat(spotlessApply.getOutput()).contains("Build failed with an exception");
312312
assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js");
313-
assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMybiomeApply'");
313+
assertThat(spotlessApply.getOutput()).contains("Execution failed for task ':spotlessMybiome'");
314314
assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist");
315315
}
316316

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 DiffPlug
2+
* Copyright 2020-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,11 +17,8 @@
1717

1818
import java.io.IOException;
1919

20-
import org.gradle.testkit.runner.BuildResult;
2120
import org.gradle.testkit.runner.GradleRunner;
2221
import org.junit.jupiter.api.Test;
23-
import org.junit.jupiter.api.condition.EnabledForJreRange;
24-
import org.junit.jupiter.api.condition.JRE;
2522

2623
public class ConfigurationCacheTest extends GradleIntegrationHarness {
2724
@Override
@@ -65,8 +62,7 @@ public void helpConfiguresIfTasksAreCreated() throws IOException {
6562
}
6663

6764
@Test
68-
@EnabledForJreRange(max = JRE.JAVA_20)
69-
public void jvmLocalCache() throws IOException {
65+
public void multipleRuns() throws IOException {
7066
setFile("build.gradle").toLines(
7167
"plugins {",
7268
" id 'com.diffplug.spotless'",
@@ -93,14 +89,5 @@ public void jvmLocalCache() throws IOException {
9389
gradleRunner().withArguments("spotlessCheck").buildAndFail();
9490
gradleRunner().withArguments("spotlessApply").build();
9591
assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test");
96-
97-
// the withDebug forces it to start a new deamon, but only in Gradle 8.3 and older
98-
// starting with Gradle 8.5 this doesn't work anymore
99-
// and we need Gradle 8.5 for Java 21
100-
// so we can't test this on Java 21 for now
101-
BuildResult failure = gradleRunner().withDebug(true).withArguments("spotlessApply", "--stacktrace").buildAndFail();
102-
failure.getOutput().contains("Spotless daemon-local cache is stale. Regenerate the cache with\n" +
103-
" rm -rf .gradle/configuration-cache\n" +
104-
"For more information see #123\n");
10592
}
10693
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -151,10 +151,10 @@ void customRunToFixMessage() throws Exception {
151151
@Test
152152
void whitespaceProblem() throws Exception {
153153
Bundle spotless = create(setFile("testFile").toContent("A \nB\t\nC \n"));
154-
spotless.task.addStep(FormatterStep.createNeverUpToDate("trimTrailing", input -> {
154+
spotless.task.setSteps(List.of(FormatterStep.createNeverUpToDate("trimTrailing", input -> {
155155
Pattern pattern = Pattern.compile("[ \t]+$", Pattern.UNIX_LINES | Pattern.MULTILINE);
156156
return pattern.matcher(input).replaceAll("");
157-
}));
157+
})));
158158
assertCheckFailure(spotless,
159159
" testFile",
160160
" @@ -1,3 +1,3 @@",

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import java.io.File;
1919
import java.util.Collections;
20+
import java.util.List;
2021

2122
import org.gradle.api.Project;
2223
import org.gradle.api.services.BuildServiceParameters;
@@ -61,7 +62,7 @@ void testStep() throws Exception {
6162
File outputFile = new File(spotlessTask.getOutputDirectory(), "testFile");
6263
spotlessTask.setTarget(Collections.singleton(testFile));
6364

64-
spotlessTask.addStep(FormatterStep.createNeverUpToDate("double-p", content -> content.replace("pp", "p")));
65+
spotlessTask.setSteps(List.of(FormatterStep.createNeverUpToDate("double-p", content -> content.replace("pp", "p"))));
6566
Tasks.execute(spotlessTask);
6667

6768
assertFile(outputFile).hasContent("aple");

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.util.Arrays;
2323
import java.util.Collections;
24+
import java.util.List;
2425

2526
import org.gradle.api.Project;
2627
import org.gradle.api.provider.Provider;
@@ -65,7 +66,7 @@ public BuildServiceParameters.None getParameters() {
6566
private SpotlessTaskImpl createFormatTask(String name, FormatterStep step) {
6667
SpotlessTaskImpl task = project.getTasks().create("spotless" + SpotlessPlugin.capitalize(name), SpotlessTaskImpl.class);
6768
task.init(taskService);
68-
task.addStep(step);
69+
task.setSteps(List.of(step));
6970
task.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
7071
task.setTarget(Collections.singletonList(file));
7172
return task;

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 DiffPlug
2+
* Copyright 2023-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -310,7 +310,7 @@ void failureWhenExeNotFound() throws Exception {
310310
var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail();
311311
assertThat(spotlessApply.getOutput()).contains("Build failed with an exception");
312312
assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js");
313-
assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMyromeApply'");
313+
assertThat(spotlessApply.getOutput()).contains("Execution failed for task ':spotlessMyrome'");
314314
assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist");
315315
}
316316

0 commit comments

Comments
 (0)