22
22
import java .util .Map ;
23
23
import java .util .Objects ;
24
24
25
- import javax .annotation .Nullable ;
26
-
27
25
import org .gradle .api .GradleException ;
28
26
import org .gradle .api .Task ;
29
27
@@ -36,24 +34,20 @@ private static GradleException cacheIsStale() {
36
34
"To make this workaround obsolete, please upvote https://github.com/diffplug/spotless/issues/987" );
37
35
}
38
36
39
- interface CacheKey <T > {
37
+ interface LiveCache <T > {
40
38
T get ();
41
39
42
40
void set (T value );
43
41
}
44
42
45
- static <T > CacheKey <T > createCacheKey (Task task , String keyName , @ Nullable T initialValue ) {
46
- CacheKeyImpl key = new CacheKeyImpl <T >(new InternalCacheKey (task .getProject ().getProjectDir (), task .getPath (), keyName ));
47
- if (initialValue != null ) {
48
- key .set (initialValue );
49
- }
50
- return key ;
43
+ static <T > LiveCache <T > createLive (Task task , String propertyName ) {
44
+ return new LiveCacheKeyImpl <T >(new InternalCacheKey (task .getProject ().getProjectDir (), task .getPath (), propertyName ));
51
45
}
52
46
53
- static class CacheKeyImpl <T > implements CacheKey <T >, Serializable {
47
+ static class LiveCacheKeyImpl <T > implements LiveCache <T >, Serializable {
54
48
InternalCacheKey internalKey ;
55
49
56
- CacheKeyImpl (InternalCacheKey internalKey ) {
50
+ LiveCacheKeyImpl (InternalCacheKey internalKey ) {
57
51
this .internalKey = internalKey ;
58
52
}
59
53
@@ -79,12 +73,12 @@ public T get() {
79
73
private static class InternalCacheKey implements Serializable {
80
74
private File projectDir ;
81
75
private String taskPath ;
82
- private String keyName ;
76
+ private String propertyName ;
83
77
84
78
InternalCacheKey (File projectDir , String taskPath , String keyName ) {
85
79
this .projectDir = projectDir ;
86
80
this .taskPath = taskPath ;
87
- this .keyName = keyName ;
81
+ this .propertyName = keyName ;
88
82
}
89
83
90
84
@ Override
@@ -94,12 +88,12 @@ public boolean equals(Object o) {
94
88
if (o == null || getClass () != o .getClass ())
95
89
return false ;
96
90
InternalCacheKey that = (InternalCacheKey ) o ;
97
- return projectDir .equals (that .projectDir ) && taskPath .equals (that .taskPath ) && keyName .equals (that .keyName );
91
+ return projectDir .equals (that .projectDir ) && taskPath .equals (that .taskPath ) && propertyName .equals (that .propertyName );
98
92
}
99
93
100
94
@ Override
101
95
public int hashCode () {
102
- return Objects .hash (projectDir , taskPath , keyName );
96
+ return Objects .hash (projectDir , taskPath , propertyName );
103
97
}
104
98
}
105
99
}
0 commit comments