@@ -175,6 +175,46 @@ public void performAction(IncrementalTaskInputs inputs) throws Exception {
175
175
throw new GradleException ("Don't call " + getName () + " directly, call " + getName () + SpotlessPlugin .CHECK + " or " + getName () + SpotlessPlugin .APPLY );
176
176
}
177
177
178
+ Predicate <File > shouldInclude ;
179
+ if (this .filePatterns .isEmpty ()) {
180
+ shouldInclude = file -> true ;
181
+ } else {
182
+ // a list of files has been passed in via project property
183
+ final String [] includePatterns = this .filePatterns .split ("," );
184
+ final List <Pattern > compiledIncludePatterns = Arrays .stream (includePatterns )
185
+ .map (Pattern ::compile )
186
+ .collect (Collectors .toList ());
187
+ shouldInclude = file -> compiledIncludePatterns
188
+ .stream ()
189
+ .anyMatch (filePattern -> filePattern .matcher (file .getAbsolutePath ())
190
+ .matches ());
191
+ }
192
+ // find the outOfDate files
193
+ List <File > outOfDate = new ArrayList <>();
194
+ inputs .outOfDate (inputDetails -> {
195
+ File file = inputDetails .getFile ();
196
+ if (shouldInclude .test (file ) && file .isFile () && !file .equals (getCacheFile ())) {
197
+ outOfDate .add (file );
198
+ }
199
+ });
200
+ // load the files that were changed by the last run
201
+ // because it's possible the user changed them back to their
202
+ // unformatted form, so we need to treat them as dirty
203
+ // (see bug #144)
204
+ if (getCacheFile ().exists ()) {
205
+ LastApply lastApply = SerializableMisc .fromFile (LastApply .class , getCacheFile ());
206
+ for (File file : lastApply .changedFiles ) {
207
+ if (shouldInclude .test (file ) && !outOfDate .contains (file ) && file .exists () && Iterables .contains (target , file )) {
208
+ outOfDate .add (file );
209
+ }
210
+ }
211
+ }
212
+
213
+ if (outOfDate .isEmpty ()) {
214
+ // no work to do
215
+ return ;
216
+ }
217
+
178
218
// create the formatter
179
219
try (Formatter formatter = Formatter .builder ()
180
220
.lineEndingsPolicy (lineEndingsPolicy )
@@ -183,45 +223,6 @@ public void performAction(IncrementalTaskInputs inputs) throws Exception {
183
223
.steps (steps )
184
224
.exceptionPolicy (exceptionPolicy )
185
225
.build ()) {
186
- // determine if a list of files has been passed in
187
- Predicate <File > shouldInclude ;
188
- if (this .filePatterns != null && !this .filePatterns .isEmpty ()) {
189
- final String [] includePatterns = this .filePatterns .split ("," );
190
- final List <Pattern > compiledIncludePatterns = Arrays .stream (includePatterns )
191
- .map (Pattern ::compile )
192
- .collect (Collectors .toList ());
193
- shouldInclude = file -> compiledIncludePatterns
194
- .stream ()
195
- .anyMatch (filePattern -> filePattern .matcher (file .getAbsolutePath ())
196
- .matches ());
197
- } else {
198
- shouldInclude = file -> true ;
199
- }
200
- // find the outOfDate files
201
- List <File > outOfDate = new ArrayList <>();
202
- inputs .outOfDate (inputDetails -> {
203
- File file = inputDetails .getFile ();
204
- if (shouldInclude .test (file ) && file .isFile () && !file .equals (getCacheFile ())) {
205
- outOfDate .add (file );
206
- }
207
- });
208
- // load the files that were changed by the last run
209
- // because it's possible the user changed them back to their
210
- // unformatted form, so we need to treat them as dirty
211
- // (see bug #144)
212
- if (getCacheFile ().exists ()) {
213
- LastApply lastApply = SerializableMisc .fromFile (LastApply .class , getCacheFile ());
214
- for (File file : lastApply .changedFiles ) {
215
- if (shouldInclude .test (file ) && !outOfDate .contains (file ) && file .exists () && Iterables .contains (target , file )) {
216
- outOfDate .add (file );
217
- }
218
- }
219
- }
220
-
221
- if (outOfDate .isEmpty ()) {
222
- // no work to do
223
- return ;
224
- }
225
226
226
227
if (apply ) {
227
228
List <File > changedFiles = applyAnyChanged (formatter , outOfDate );
0 commit comments