Skip to content

Commit 0363e9c

Browse files
committed
Remove JvmLocalCache now that everything is round-trippable on its own.
1 parent e90f0a3 commit 0363e9c

File tree

5 files changed

+20
-132
lines changed

5 files changed

+20
-132
lines changed

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/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+
this.steps.clear();
162+
PluginGradlePreconditions.requireElementsNonNull(steps);
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/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;

0 commit comments

Comments
 (0)