Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Also add total number of violations to the output
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
tasomaniac committed Dec 11, 2018
1 parent a0cba26 commit 2064cb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ class DefaultViolationsEvaluator implements ViolationsEvaluator {

@Override
void evaluate(Set<Violations> allViolations) {
Map<String, Integer> total = [errors: 0, warnings: 0]
String fullMessage = ''
allViolations.each { Violations violations ->
if (!violations.isEmpty()) {
fullMessage += "> ${getViolationsMessage(violations, reportUrlRenderer)}\n"
}
}
total['errors'] = allViolations.collect { it.errors }.sum() as int
total['warnings'] = allViolations.collect { it.warnings }.sum() as int
int totalErrors = allViolations.collect { it.errors }.sum() as int
int totalWarnings = allViolations.collect { it.warnings }.sum() as int

int errorsDiff = Math.max(0, total['errors'] - penalty.maxErrors)
int warningsDiff = Math.max(0, total['warnings'] - penalty.maxWarnings)
int errorsDiff = Math.max(0, totalErrors - penalty.maxErrors)
int warningsDiff = Math.max(0, totalWarnings - penalty.maxWarnings)
if (errorsDiff > 0 || warningsDiff > 0) {
throw new GradleException("Violations limit exceeded by $errorsDiff errors, $warningsDiff warnings.\n\n$fullMessage")
} else if (!fullMessage.isEmpty()) {
logger.warn "\n$fullMessage"
logger.warn "\nViolations found ($totalErrors errors, $totalWarnings warnings)\n\n$fullMessage"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class DefaultViolationsEvaluatorTest {

evaluator.evaluate(allViolations)

def expected = """
def expected = """
Violations found (1 errors, 0 warnings)
> $TOOL_NAME violations found (1 errors, 0 warnings). See the reports at:
- $consoleClickableFileUrl
"""
Expand Down

0 comments on commit 2064cb6

Please sign in to comment.