From d8aed7fe8001a8d15c11f3175667873033ac9659 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Fri, 29 Apr 2016 01:52:40 +0200 Subject: [PATCH] Bump Checkstyle version from 6.2 to 6.16 made required code changes in CheckLoggingUtil & CheckstyleTest Change-Id: I59da3d9c09b1a22a1f8266a2c6875ba10fc881e9 Signed-off-by: Michael Vorburger --- .../checkstyle/CheckLoggingUtil.java | 9 +++--- .../yangtools/checkstyle/CheckstyleTest.java | 32 +++++++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/CheckLoggingUtil.java b/common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/CheckLoggingUtil.java index 2ff30eb196..17e98a547e 100644 --- a/common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/CheckLoggingUtil.java +++ b/common/checkstyle-logging/src/main/java/org/opendaylight/yangtools/checkstyle/CheckLoggingUtil.java @@ -16,14 +16,15 @@ import com.google.common.collect.Lists; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.FullIdent; import com.puppycrawl.tools.checkstyle.api.TokenTypes; -import com.puppycrawl.tools.checkstyle.checks.CheckUtils; +import com.puppycrawl.tools.checkstyle.utils.CheckUtils; public final class CheckLoggingUtil { public static final String LOGGER_TYPE_NAME = Logger.class.getSimpleName(); public static final String LOGGER_TYPE_FULL_NAME = Logger.class.getName(); public static final String LOGGER_VAR_NAME = "LOG"; - private static final List LOG_METHODS = Lists.newArrayList("LOG.debug", "LOG.info", "LOG.error", "LOG.warn", "LOG.trace"); + private static final List LOG_METHODS = + Lists.newArrayList("LOG.debug", "LOG.info", "LOG.error", "LOG.warn", "LOG.trace"); private CheckLoggingUtil() { throw new UnsupportedOperationException("Utility class should not be instantiated!"); @@ -49,7 +50,7 @@ public final class CheckLoggingUtil { } public static String getMethodName(final DetailAST aAST) { - if(aAST.getFirstChild().getLastChild() != null) { + if (aAST.getFirstChild().getLastChild() != null) { return aAST.getFirstChild().getFirstChild().getText() + "." + aAST.getFirstChild().getLastChild().getText(); } return aAST.getFirstChild().getText(); @@ -61,7 +62,7 @@ public final class CheckLoggingUtil { public static String getClassName(final DetailAST aAST) { DetailAST parent = aAST.getParent(); - while(parent.getType() != TokenTypes.CLASS_DEF && parent.getType() != TokenTypes.ENUM_DEF) { + while (parent.getType() != TokenTypes.CLASS_DEF && parent.getType() != TokenTypes.ENUM_DEF) { parent = parent.getParent(); } return parent.findFirstToken(TokenTypes.IDENT).getText(); diff --git a/common/checkstyle-logging/src/test/java/org/opendaylight/yangtools/checkstyle/CheckstyleTest.java b/common/checkstyle-logging/src/test/java/org/opendaylight/yangtools/checkstyle/CheckstyleTest.java index bf59c594b4..0fe027b0af 100644 --- a/common/checkstyle-logging/src/test/java/org/opendaylight/yangtools/checkstyle/CheckstyleTest.java +++ b/common/checkstyle-logging/src/test/java/org/opendaylight/yangtools/checkstyle/CheckstyleTest.java @@ -54,21 +54,33 @@ public class CheckstyleTest { @Test public void testLoggerChecks() throws Exception { - verify(CheckLoggingTestClass.class, true, "15: Logger must be declared as private static final.", "15: Logger name should be LOG.", - "15: LoggerFactory.getLogger Class argument is incorrect.", - "17: Logger might be declared only once.", "16: Logger must be slf4j.", "22: Line contains printStacktrace", - "23: Line contains console output", "24: Line contains console output", "26: Log message placeholders count is incorrect.", - "32: Log message placeholders count is incorrect", "41: Log message contains string concatenation."); + verify(CheckLoggingTestClass.class, true, + "15: Logger must be declared as private static final", + "15: Logger name should be LOG", + "15: LoggerFactory.getLogger Class argument is incorrect", + "17: Logger might be declared only once", + "16: Logger must be slf4j", + "22: Line contains printStacktrace", + "23: Line contains console output", + "24: Line contains console output", + "26: Log message placeholders count is incorrect", + "32: Log message placeholders count is incorrect", + "41: Log message contains string concatenation"); } @Test - public void testCodingChecks() { - verify(CheckCodingStyleTestClass.class, false, "9: Line has Windows line delimiter.", "14: Wrong order for", "24:1: Line contains a tab character.", - "22: Line has trailing spaces.", "22: 'ctor def' child have incorrect indentation level 16, expected level should be 8.", "17:8: Unused import", + public void testCodingChecks() throws Exception { + verify(CheckCodingStyleTestClass.class, false, + "9: Line has Windows line delimiter.", + "14: Wrong order for", + "24:1: Line contains a tab character.", + "22: Line has trailing spaces.", + "22: 'ctor def' child have incorrect indentation level 16, expected level should be 8.", + "17:8: Unused import", "23: Line has trailing spaces."); } - private void verify(final Class testClass, final boolean checkCount, final String... expectedMessages) { + private void verify(final Class testClass, final boolean checkCount, final String... expectedMessages) throws CheckstyleException { final String filePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "java" + File.separator + testClass.getName().replaceAll("\\.", "/") + ".java"; final File testFile = new File(filePath); checker.process(Lists.newArrayList(testFile)); @@ -79,7 +91,7 @@ public class CheckstyleTest { assertEquals(expectedMessages.length, count); } for(final String message : expectedMessages) { - assertTrue("Expected message not found: " + message, output.contains(message)); + assertTrue("Expected message not found: " + message + "; output: " + output, output.contains(message)); } } } -- 2.36.6