From f0e75896a4c9a79d1cd4e414ae3fc7011268eb80 Mon Sep 17 00:00:00 2001 From: Baratali Izmailov Date: Wed, 26 Aug 2015 17:52:09 -0400 Subject: [PATCH] Issue #1566: Reducing CheckstyleAntTask's method length --- .../checkstyle/ant/CheckstyleAntTask.java | 76 +++++++++++-------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java b/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java index 30df0d8a8..82c09392d 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java @@ -294,39 +294,7 @@ public class CheckstyleAntTask extends Task { new SeverityLevelCounter(SeverityLevel.WARNING); checker.addListener(warningCounter); - // Process the files - long startTime = System.currentTimeMillis(); - final List files = scanFileSets(); - long endTime = System.currentTimeMillis(); - log("To locate the files took " + (endTime - startTime) + TIME_SUFFIX, - Project.MSG_VERBOSE); - - log("Running Checkstyle " + version + " on " + files.size() - + " files", Project.MSG_INFO); - log("Using configuration " + configLocation, Project.MSG_VERBOSE); - - startTime = System.currentTimeMillis(); - final int numErrs = checker.process(files); - endTime = System.currentTimeMillis(); - log("To process the files took " + (endTime - startTime) + TIME_SUFFIX, - Project.MSG_VERBOSE); - final int numWarnings = warningCounter.getCount(); - final boolean ok = numErrs <= maxErrors - && numWarnings <= maxWarnings; - - // Handle the return status - if (!ok) { - final String failureMsg = - "Got " + numErrs + " errors and " + numWarnings - + " warnings."; - if (failureProperty != null) { - getProject().setProperty(failureProperty, failureMsg); - } - - if (failOnViolation) { - throw new BuildException(failureMsg, getLocation()); - } - } + processFiles(checker, warningCounter, version); } finally { if (checker != null) { @@ -335,6 +303,48 @@ public class CheckstyleAntTask extends Task { } } + /** + * Scans and processes files by means given checker. + * @param checker Checker to process files + * @param warningCounter Checker's counter of warnings + * @param checkstyleVersion Checkstyle compile version + */ + private void processFiles(Checker checker, final SeverityLevelCounter warningCounter, + final String checkstyleVersion) { + long startTime = System.currentTimeMillis(); + final List files = scanFileSets(); + long endTime = System.currentTimeMillis(); + log("To locate the files took " + (endTime - startTime) + TIME_SUFFIX, + Project.MSG_VERBOSE); + + log("Running Checkstyle " + checkstyleVersion + " on " + files.size() + + " files", Project.MSG_INFO); + log("Using configuration " + configLocation, Project.MSG_VERBOSE); + + startTime = System.currentTimeMillis(); + final int numErrs = checker.process(files); + endTime = System.currentTimeMillis(); + log("To process the files took " + (endTime - startTime) + TIME_SUFFIX, + Project.MSG_VERBOSE); + final int numWarnings = warningCounter.getCount(); + final boolean ok = numErrs <= maxErrors + && numWarnings <= maxWarnings; + + // Handle the return status + if (!ok) { + final String failureMsg = + "Got " + numErrs + " errors and " + numWarnings + + " warnings."; + if (failureProperty != null) { + getProject().setProperty(failureProperty, failureMsg); + } + + if (failOnViolation) { + throw new BuildException(failureMsg, getLocation()); + } + } + } + /** * Creates new instance of {@code Checker}. * @return new instance of {@code Checker}