Skip to content

Commit 312b25e

Browse files
committed
An easier way to detect that we are running with configuration-cache is to check to see if transient fields are null.
1 parent 4dfc4c8 commit 312b25e

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void setEncoding(String encoding) {
5656
this.encoding = Objects.requireNonNull(encoding);
5757
}
5858

59-
protected LineEnding.Policy lineEndingsPolicy;
59+
protected transient LineEnding.Policy lineEndingsPolicy;
6060

6161
@Input
6262
public LineEnding.Policy getLineEndingsPolicy() {
@@ -69,15 +69,15 @@ public void setLineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) {
6969

7070
/*** API which performs git up-to-date tasks. */
7171
@Nullable
72-
private GitRatchetGradle ratchet;
72+
private transient GitRatchetGradle ratchet;
7373
/** The sha of the tree at repository root, used for determining if an individual *file* is clean according to git. */
74-
private ObjectId rootTreeSha;
74+
private transient ObjectId rootTreeSha;
7575
/**
7676
* The sha of the tree at the root of *this project*, used to determine if the git baseline has changed within this folder.
7777
* Using a more fine-grained tree (rather than the project root) allows Gradle to mark more subprojects as up-to-date
7878
* compared to using the project root.
7979
*/
80-
private ObjectId subtreeSha = ObjectId.zeroId();
80+
private transient ObjectId subtreeSha = ObjectId.zeroId();
8181

8282
public void setupRatchet(GitRatchetGradle gitRatchet, String ratchetFrom) {
8383
ratchet = gitRatchet;
@@ -139,7 +139,7 @@ public File getOutputDirectory() {
139139
return outputDirectory;
140140
}
141141

142-
protected List<FormatterStep> steps = new ArrayList<>();
142+
protected transient List<FormatterStep> steps = new ArrayList<>();
143143

144144
@Input
145145
public List<FormatterStep> getSteps() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public abstract class SpotlessTaskImpl extends SpotlessTask {
5050
void init(Provider<SpotlessTaskService> service) {
5151
getTaskService().set(service);
5252
getProjectDir().set(getProject().getProjectDir());
53-
service.get().registerSourceCreated(this);
5453
}
5554

5655
@Inject
@@ -69,7 +68,7 @@ public void performAction(InputChanges inputs) throws Exception {
6968
Files.createDirectories(outputDirectory.toPath());
7069
}
7170

72-
if (getTaskService().get().sourceWasCreatedThisBuild(this)) {
71+
if (lineEndingsPolicy != null) {
7372
try (Formatter formatter = buildFormatter()) {
7473
for (FileChange fileChange : inputs.getFileChanges(target)) {
7574
File input = fileChange.getFile();

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
* apply already did).
4343
*/
4444
public abstract class SpotlessTaskService implements BuildService<BuildServiceParameters.None> {
45-
private final Map<String, SpotlessTask> sourceCreated = Collections.synchronizedMap(new HashMap<>());
4645
private final Map<String, SpotlessApply> apply = Collections.synchronizedMap(new HashMap<>());
4746
private final Map<String, SpotlessTask> source = Collections.synchronizedMap(new HashMap<>());
4847
private final Map<String, Provisioner> provisioner = Collections.synchronizedMap(new HashMap<>());
@@ -53,14 +52,6 @@ Provisioner provisionerFor(Project project) {
5352
});
5453
}
5554

56-
void registerSourceCreated(SpotlessTask spotlessTask) {
57-
sourceCreated.put(spotlessTask.getPath(), spotlessTask);
58-
}
59-
60-
boolean sourceWasCreatedThisBuild(SpotlessTask spotlessTask) {
61-
return sourceCreated.containsKey(spotlessTask.getPath());
62-
}
63-
6455
void registerSourceAlreadyRan(SpotlessTask task) {
6556
source.put(task.getPath(), task);
6657
}

0 commit comments

Comments
 (0)