@@ -48,6 +48,12 @@ public abstract class SpotlessTask extends DefaultTask {
48
48
@ Internal
49
49
abstract Property <SpotlessTaskService > getTaskService ();
50
50
51
+ private void hydrateIfNull (Object o ) {
52
+ if (o == null ) {
53
+ getTaskService ().get ().hydrate (this );
54
+ }
55
+ }
56
+
51
57
// set by SpotlessExtension, but possibly overridden by FormatExtension
52
58
protected String encoding = "UTF-8" ;
53
59
@@ -64,6 +70,7 @@ public void setEncoding(String encoding) {
64
70
65
71
@ Input
66
72
public LineEnding .Policy getLineEndingsPolicy () {
73
+ hydrateIfNull (lineEndingsPolicy );
67
74
return lineEndingsPolicy ;
68
75
}
69
76
@@ -82,12 +89,19 @@ public void setLineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) {
82
89
* compared to using the project root.
83
90
*/
84
91
private transient ObjectId subtreeSha = ObjectId .zeroId ();
92
+ /** Stored so that the configuration cache can recreate the GitRatchetGradle state. */
93
+ protected transient String ratchetFrom ;
85
94
86
95
public void setupRatchet (String ratchetFrom ) {
87
- ratchet = getTaskService ().get ().getRatchet ();
88
- File projectDir = getProjectDir ().get ().getAsFile ();
89
- rootTreeSha = ratchet .rootTreeShaOf (projectDir , ratchetFrom );
90
- subtreeSha = ratchet .subtreeShaOf (projectDir , rootTreeSha );
96
+ this .ratchetFrom = ratchetFrom ;
97
+ if (!ratchetFrom .isEmpty ()) {
98
+ ratchet = getTaskService ().get ().getRatchet ();
99
+ File projectDir = getProjectDir ().get ().getAsFile ();
100
+ rootTreeSha = ratchet .rootTreeShaOf (projectDir , ratchetFrom );
101
+ subtreeSha = ratchet .subtreeShaOf (projectDir , rootTreeSha );
102
+ } else {
103
+ subtreeSha = ObjectId .zeroId ();
104
+ }
91
105
}
92
106
93
107
@ Internal
@@ -105,6 +119,7 @@ ObjectId getRootTreeSha() {
105
119
106
120
@ Input
107
121
public ObjectId getRatchetSha () {
122
+ hydrateIfNull (subtreeSha );
108
123
return subtreeSha ;
109
124
}
110
125
@@ -147,6 +162,7 @@ public File getOutputDirectory() {
147
162
148
163
@ Input
149
164
public List <FormatterStep > getSteps () {
165
+ hydrateIfNull (steps );
150
166
return Collections .unmodifiableList (steps );
151
167
}
152
168
0 commit comments