Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to specify threshold. Task will throw an exception if t… #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ check {
// fails build if Checkstyle rule violation is found, false by default
abortOnError true/false

// fails build if threshold is breached. -1 by default, meaning threshold not checked
threshold -1

// configuration file
config project.file('path/to/checkstyle.xml')
// configuration resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ abstract class CommonCheck<Config extends CommonConfig> {

boolean skip = config.resolveSkip(extension.skip)
boolean abortOnError = config.resolveAbortOnError(extension.abortOnError)
int threshold = config.threshold
File configFile = config.resolveConfigFile(taskCode)
File styleFile = config.resolveStyleFile(taskCode)
File xmlReportFile = config.resolveXmlReportFile(taskCode)
Expand All @@ -88,7 +89,8 @@ abstract class CommonCheck<Config extends CommonConfig> {
int errorCount = getErrorCount(xmlReportFile)
if (errorCount) {
String errorMessage = getErrorMessage(errorCount, htmlReportFile)
if (abortOnError) {
boolean thresholdBreached = -1 < threshold && threshold < errorCount
if (abortOnError || thresholdBreached) {
throw new GradleException(errorMessage)
} else {
target.logger.warn errorMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class CommonConfig {

void abortOnError(boolean abortOnError) { this.abortOnError = abortOnError }

int threshold = -1

void threshold(int threshold) { this.threshold = threshold }

private TextResource configResource = null
private File configFile = null
private Severity configSeverity = null
Expand Down