From eaf47ff6a1f8da4b07928aac167b1472c75a557c Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Sun, 25 Dec 2016 06:32:08 -0800 Subject: [PATCH] Issue #45: resolve MultipleStringLiterals violations --- checkstyle-sonar-plugin/config/pmd.xml | 3 ++- .../config/suppressions.xml | 7 +++--- checkstyle-sonar-plugin/pom.xml | 4 ++-- .../checkstyle/CheckstyleConstants.java | 2 +- .../checkstyle/CheckstyleSeverityUtils.java | 24 ++++++++++++------- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/checkstyle-sonar-plugin/config/pmd.xml b/checkstyle-sonar-plugin/config/pmd.xml index fa8049d2..6b243bfb 100644 --- a/checkstyle-sonar-plugin/config/pmd.xml +++ b/checkstyle-sonar-plugin/config/pmd.xml @@ -222,7 +222,8 @@ - + + diff --git a/checkstyle-sonar-plugin/config/suppressions.xml b/checkstyle-sonar-plugin/config/suppressions.xml index 08bd24f6..369d570f 100644 --- a/checkstyle-sonar-plugin/config/suppressions.xml +++ b/checkstyle-sonar-plugin/config/suppressions.xml @@ -15,7 +15,6 @@ - @@ -26,7 +25,6 @@ - @@ -34,7 +32,6 @@ - @@ -61,4 +58,8 @@ + + + + diff --git a/checkstyle-sonar-plugin/pom.xml b/checkstyle-sonar-plugin/pom.xml index 119b6468..243d6b4e 100644 --- a/checkstyle-sonar-plugin/pom.xml +++ b/checkstyle-sonar-plugin/pom.xml @@ -283,7 +283,7 @@ true 100 100 - 81 + 80 87 @@ -318,7 +318,7 @@ org.sonar.plugins.checkstyle.CheckstyleSeverityUtils - 76 + 75 91 diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java index 242e4505..da3ed1b4 100644 --- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java +++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java @@ -23,7 +23,7 @@ public final class CheckstyleConstants { public static final String REPOSITORY_NAME = "Checkstyle"; public static final String PLUGIN_KEY = "checkstyle"; - public static final String PLUGIN_NAME = "Checkstyle"; + public static final String PLUGIN_NAME = REPOSITORY_NAME; public static final String REPOSITORY_KEY = PLUGIN_KEY; public static final String FILTERS_KEY = "sonar.checkstyle.filters"; diff --git a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java index b6c87afa..6dbc61a2 100644 --- a/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java +++ b/checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSeverityUtils.java @@ -21,6 +21,8 @@ import org.sonar.api.rules.RulePriority; +import com.puppycrawl.tools.checkstyle.api.SeverityLevel; + public final class CheckstyleSeverityUtils { private CheckstyleSeverityUtils() { @@ -31,25 +33,31 @@ public static String toSeverity(RulePriority priority) { switch (priority) { case BLOCKER: case CRITICAL: - return "error"; + return SeverityLevel.ERROR.getName(); case MAJOR: - return "warning"; + return SeverityLevel.WARNING.getName(); case MINOR: case INFO: - return "info"; + return SeverityLevel.INFO.getName(); default: throw new IllegalArgumentException("Priority not supported: " + priority); } } public static RulePriority fromSeverity(String severity) { - switch (severity) { - case "error": + SeverityLevel severityLevel; + try { + severityLevel = SeverityLevel.getInstance(severity); + } catch (Exception exc) { + return null; + } + switch (severityLevel) { + case ERROR: return RulePriority.BLOCKER; - case "warning": + case WARNING: return RulePriority.MAJOR; - case "info": - case "ignore": + case INFO: + case IGNORE: return RulePriority.INFO; default: return null;