com.danielsomerfield.cvecheck.gradle.handlers.BuildRulesScanResultHandler.groovy Maven / Gradle / Ivy
package com.danielsomerfield.cvecheck.gradle.handlers
import com.danielsomerfield.cvecheck.ScanResult
import com.danielsomerfield.cvecheck.ScanResultHandler
import com.danielsomerfield.cvecheck.gradle.handlers.buildRules.BuildRule
import com.danielsomerfield.cvecheck.gradle.handlers.buildRules.BuildRules
import com.danielsomerfield.cvecheck.gradle.handlers.buildRules.RuleOutcome
import org.gradle.api.GradleException
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class BuildRulesScanResultHandler implements ScanResultHandler {
private final Logger logger = LoggerFactory.getLogger(this.getClass())
private final BuildRules buildRules
public BuildRulesScanResultHandler(final BuildRules buildRules) {
this.buildRules = buildRules
}
@Override
void handleScanResult(final ScanResult scanResult) {
logger.debug("About to run against rules: ${buildRules}")
List failures = []
buildRules.each { BuildRule rule -> logger.debug("Executing build rule: ${rule.name}"); if (rule.execute(scanResult) == RuleOutcome.Failed) failures.add(rule.name) }
if (failures.size() > 0) {
throw new GradleException("The following rules failed: ${failures}")
} else {
logger.info("No rules failed")
}
}
}