Don't replace forbidden pattern failures when found (#40710)

This commit fixes a bug in forbidden patterns where the failures for a
file replace the failures from the previous files instead of extending
them.
This commit is contained in:
Ryan Ernst 2019-04-03 16:55:03 -07:00
parent a28d5f35d9
commit 9d785e2b69
1 changed files with 2 additions and 2 deletions

View File

@ -111,13 +111,13 @@ public class ForbiddenPatternsTask extends DefaultTask {
.collect(Collectors.toList()); .collect(Collectors.toList());
String path = getProject().getRootProject().getProjectDir().toURI().relativize(f.toURI()).toString(); String path = getProject().getRootProject().getProjectDir().toURI().relativize(f.toURI()).toString();
failures = invalidLines.stream() failures.addAll(invalidLines.stream()
.map(l -> new AbstractMap.SimpleEntry<>(l+1, lines.get(l))) .map(l -> new AbstractMap.SimpleEntry<>(l+1, lines.get(l)))
.flatMap(kv -> patterns.entrySet().stream() .flatMap(kv -> patterns.entrySet().stream()
.filter(p -> Pattern.compile(p.getValue()).matcher(kv.getValue()).find()) .filter(p -> Pattern.compile(p.getValue()).matcher(kv.getValue()).find())
.map(p -> "- " + p.getKey() + " on line " + kv.getKey() + " of " + path) .map(p -> "- " + p.getKey() + " on line " + kv.getKey() + " of " + path)
) )
.collect(Collectors.toList()); .collect(Collectors.toList()));
} }
if (failures.isEmpty() == false) { if (failures.isEmpty() == false) {
throw new GradleException("Found invalid patterns:\n" + String.join("\n", failures)); throw new GradleException("Found invalid patterns:\n" + String.join("\n", failures));