Skip to content

Commit fecc1f8

Browse files
committed
more PR feedback
1 parent 29a8fc8 commit fecc1f8

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

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

+40-39
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,46 @@ public void performAction(IncrementalTaskInputs inputs) throws Exception {
175175
throw new GradleException("Don't call " + getName() + " directly, call " + getName() + SpotlessPlugin.CHECK + " or " + getName() + SpotlessPlugin.APPLY);
176176
}
177177

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+
178218
// create the formatter
179219
try (Formatter formatter = Formatter.builder()
180220
.lineEndingsPolicy(lineEndingsPolicy)
@@ -183,45 +223,6 @@ public void performAction(IncrementalTaskInputs inputs) throws Exception {
183223
.steps(steps)
184224
.exceptionPolicy(exceptionPolicy)
185225
.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-
}
225226

226227
if (apply) {
227228
List<File> changedFiles = applyAnyChanged(formatter, outOfDate);

0 commit comments

Comments
 (0)