16
16
package com .diffplug .gradle .spotless ;
17
17
18
18
import java .io .File ;
19
- import java .io .IOException ;
20
- import java .io .Serializable ;
21
19
import java .util .Collections ;
22
20
import java .util .HashMap ;
23
- import java .util .List ;
24
21
import java .util .Map ;
25
22
26
23
import org .gradle .api .DefaultTask ;
31
28
32
29
import com .diffplug .common .base .Preconditions ;
33
30
import com .diffplug .common .base .Unhandled ;
34
- import com .diffplug .common .collect .Maps ;
35
- import com .diffplug .spotless .FileSignature ;
36
- import com .diffplug .spotless .Formatter ;
37
- import com .diffplug .spotless .extra .integration .DiffMessageFormatter ;
38
31
39
32
/**
40
33
* Allows the check and apply tasks to coordinate
@@ -47,8 +40,6 @@ public abstract class SpotlessTaskService implements BuildService<BuildServicePa
47
40
private final Map <String , SpotlessTask > source = Collections .synchronizedMap (new HashMap <>());
48
41
49
42
public void registerSourceAlreadyRan (SpotlessTask task ) {
50
- // if there's a registered source, we can wipe the cache
51
- cachePut (task .getOutputDirectory (), null , null );
52
43
source .put (task .getPath (), task );
53
44
}
54
45
@@ -97,50 +88,5 @@ protected boolean sourceDidWork() {
97
88
protected boolean applyHasRun () {
98
89
return service ().apply .containsKey (sourceTaskPath ());
99
90
}
100
-
101
- protected String errorMsgForCheck (List <File > problemFiles , String runToFix ) throws IOException {
102
- SpotlessTask task = service ().source .get (sourceTaskPath ());
103
- ((SpotlessCheck ) this ).getSpotlessOutDirectory ();
104
- if (task != null ) {
105
- try (Formatter formatter = task .buildFormatter ()) {
106
- String msg = DiffMessageFormatter .builder ()
107
- .runToFix (runToFix )
108
- .formatter (formatter )
109
- .problemFiles (problemFiles )
110
- .getMessage ();
111
- cachePut (FileSignature .signAsList (problemFiles ), msg );
112
- return msg ;
113
- }
114
- } else {
115
- return cacheGet (FileSignature .signAsList (problemFiles ));
116
- }
117
- }
118
-
119
- private void cachePut (FileSignature key , String msg ) {
120
- SpotlessTaskService .cachePut (getSpotlessOutDirectory ().get (), key , msg );
121
- }
122
-
123
- private String cacheGet (FileSignature key ) {
124
- Map .Entry <FileSignature , String > cached = SerializableMisc .fromFile (Map .Entry .class , getCacheFile (getSpotlessOutDirectory ().get ()));
125
- if (cached != null && cached .getKey ().equals (key )) {
126
- return cached .getValue ();
127
- } else {
128
- throw new IllegalStateException (getPath () + " is running but " + sourceTaskPath () + " was up-to-date and didn't run" );
129
- }
130
- }
131
- }
132
-
133
- private static void cachePut (File spotlessOut , FileSignature key , String msg ) {
134
- File cacheFile = getCacheFile (spotlessOut );
135
- if (key == null ) {
136
- cacheFile .delete ();
137
- } else {
138
- SerializableMisc .toFile ((Serializable ) Maps .immutableEntry (key , msg ), cacheFile );
139
- }
140
- }
141
-
142
- private static File getCacheFile (File spotlessOut ) {
143
- File parent = spotlessOut .getParentFile ();
144
- return new File (parent , spotlessOut .getName () + "-errorMsg" );
145
91
}
146
92
}
0 commit comments