diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-08-28 18:14:14 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-08-28 18:14:14 +0200 |
commit | 0264a155e42c32c812807e9155ffee6e6e9de3b2 (patch) | |
tree | 1e9bed6876d2cf83b9f44dcbd6886efb3298a853 /sonar-plugin-api/src | |
parent | 1e5c57b590d1caded7ffbc846e4699b361779f4a (diff) | |
download | sonarqube-0264a155e42c32c812807e9155ffee6e6e9de3b2.tar.gz sonarqube-0264a155e42c32c812807e9155ffee6e6e9de3b2.zip |
Fix some quality flaws
Diffstat (limited to 'sonar-plugin-api/src')
15 files changed, 122 insertions, 76 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java index 318868e15c2..dbb2e2e2132 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java @@ -25,14 +25,16 @@ import org.sonar.api.resources.JavaPackage; public final class SquidUtils { + private static final String JAVA_FILE_SUFFIX = ".java"; + private SquidUtils() { // only static methods } public static JavaFile convertJavaFileKeyFromSquidFormat(String key) { - boolean isJavaFile = key.endsWith(".java"); + boolean isJavaFile = key.endsWith(JAVA_FILE_SUFFIX); if (isJavaFile) { - key = key.substring(0, key.length() - ".java".length()); + key = key.substring(0, key.length() - JAVA_FILE_SUFFIX.length()); } String convertedKey = key.replace('/', '.'); @@ -53,11 +55,11 @@ public final class SquidUtils { public static String convertToSquidKeyFormat(JavaFile file) { String key = file.getKey(); - if (file.getParent()==null || file.getParent().isDefault()) { + if (file.getParent() == null || file.getParent().isDefault()) { key = StringUtils.substringAfterLast(file.getKey(), "."); } else { key = StringUtils.replace(key, ".", "/"); } - return key + ".java"; + return key + JAVA_FILE_SUFFIX; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java index f8217841cbf..fad61ba028e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenPlugin.java @@ -37,6 +37,7 @@ import java.util.List; */ public class MavenPlugin { + private static final String CONFIGURATION_ELEMENT = "configuration"; private Plugin plugin; private Xpp3Dom configuration; @@ -49,7 +50,7 @@ public class MavenPlugin { this.plugin = plugin; this.configuration = (Xpp3Dom) plugin.getConfiguration(); if (this.configuration == null) { - configuration = new Xpp3Dom("configuration"); + configuration = new Xpp3Dom(CONFIGURATION_ELEMENT); plugin.setConfiguration(this.configuration); } } @@ -66,7 +67,7 @@ public class MavenPlugin { plugin.setGroupId(groupId); plugin.setArtifactId(artifactId); plugin.setVersion(version); - configuration = new Xpp3Dom("configuration"); + configuration = new Xpp3Dom(CONFIGURATION_ELEMENT); plugin.setConfiguration(this.configuration); } @@ -163,7 +164,7 @@ public class MavenPlugin { * Removes all parameters from the maven plugin */ public void removeParameters() { - configuration = new Xpp3Dom("configuration"); + configuration = new Xpp3Dom(CONFIGURATION_ELEMENT); plugin.setConfiguration(this.configuration); } @@ -200,7 +201,7 @@ public class MavenPlugin { } private static int getIndex(String key) { - //parsing index-syntax (e.g. item[1]) + // parsing index-syntax (e.g. item[1]) if (key.matches(".*?\\[\\d+\\]")) { return Integer.parseInt(StringUtils.substringBetween(key, "[", "]")); } @@ -231,7 +232,7 @@ public class MavenPlugin { Xpp3Dom node = configuration; for (String keyPart : keyParts) { - if(node.getChildren(removeIndexSnippet(keyPart)).length <= getIndex(keyPart)) { + if (node.getChildren(removeIndexSnippet(keyPart)).length <= getIndex(keyPart)) { return null; } @@ -258,7 +259,7 @@ public class MavenPlugin { * @return whether the maven plugin has got configuration */ public boolean hasConfiguration() { - return configuration.getChildCount()>0; + return configuration.getChildCount() > 0; } private static void checkKeyArgument(String key) { @@ -416,13 +417,12 @@ public class MavenPlugin { } } - @Override public String toString() { return new ToStringBuilder(this) - .append("groupId", plugin.getGroupId()) - .append("artifactId", plugin.getArtifactId()) - .append("version", plugin.getVersion()) - .toString(); + .append("groupId", plugin.getGroupId()) + .append("artifactId", plugin.getArtifactId()) + .append("version", plugin.getVersion()) + .toString(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java index 16806f1d7a6..3b4c9120f55 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/maven/MavenUtils.java @@ -30,11 +30,12 @@ import java.util.Collection; /** * An utility class to manipulate Maven concepts - * + * * @since 1.10 */ public final class MavenUtils { + private static final String MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin"; public static final String GROUP_ID_APACHE_MAVEN = "org.apache.maven.plugins"; public static final String GROUP_ID_CODEHAUS_MOJO = "org.codehaus.mojo"; @@ -44,12 +45,12 @@ public final class MavenUtils { /** * Returns the version of Java used by the maven compiler plugin - * + * * @param pom the project pom * @return the java version */ public static String getJavaVersion(MavenProject pom) { - MavenPlugin compilerPlugin = MavenPlugin.getPlugin(pom, GROUP_ID_APACHE_MAVEN, "maven-compiler-plugin"); + MavenPlugin compilerPlugin = MavenPlugin.getPlugin(pom, GROUP_ID_APACHE_MAVEN, MAVEN_COMPILER_PLUGIN); if (compilerPlugin != null) { return compilerPlugin.getParameter("target"); } @@ -57,7 +58,7 @@ public final class MavenUtils { } public static String getJavaSourceVersion(MavenProject pom) { - MavenPlugin compilerPlugin = MavenPlugin.getPlugin(pom, GROUP_ID_APACHE_MAVEN, "maven-compiler-plugin"); + MavenPlugin compilerPlugin = MavenPlugin.getPlugin(pom, GROUP_ID_APACHE_MAVEN, MAVEN_COMPILER_PLUGIN); if (compilerPlugin != null) { return compilerPlugin.getParameter("source"); } @@ -66,7 +67,7 @@ public final class MavenUtils { /** * Queries a collection of plugins based on a group id and an artifact id and returns the plugin if it exists - * + * * @param plugins the plugins collection * @param groupId the group id * @param artifactId the artifact id @@ -85,7 +86,7 @@ public final class MavenUtils { /** * Tests whether a plugin has got a given artifact id and group id - * + * * @param plugin the plugin to test * @param groupId the group id * @param artifactId the artifact id @@ -103,7 +104,7 @@ public final class MavenUtils { /** * Tests whether a ReportPlugin has got a given artifact id and group id - * + * * @param plugin the ReportPlugin to test * @param groupId the group id * @param artifactId the artifact id @@ -128,7 +129,7 @@ public final class MavenUtils { /** * Returns the charset of a pom - * + * * @param pom the project pom * @return the charset */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java index b231829e8f5..e706da53015 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java @@ -40,6 +40,7 @@ import java.util.Map; */ public final class AnnotationCheckFactory extends CheckFactory { + private static final String CAN_NOT_INSTANTIATE_THE_CHECK_RELATED_TO_THE_RULE = "Can not instantiate the check related to the rule "; private Map<String, Object> checksByKey = Maps.newHashMap(); private AnnotationCheckFactory(RulesProfile profile, String repositoryKey, Collection checks) { @@ -81,10 +82,10 @@ public final class AnnotationCheckFactory extends CheckFactory { return check; } catch (InstantiationException e) { - throw new SonarException("Can not instantiate the check related to the rule " + activeRule, e); + throw new SonarException(CAN_NOT_INSTANTIATE_THE_CHECK_RELATED_TO_THE_RULE + activeRule, e); } catch (IllegalAccessException e) { - throw new SonarException("Can not instantiate the check related to the rule " + activeRule, e); + throw new SonarException(CAN_NOT_INSTANTIATE_THE_CHECK_RELATED_TO_THE_RULE + activeRule, e); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java index c08ad379867..f286c28790f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java @@ -36,6 +36,8 @@ import java.util.Date; * @since 1.10 */ public class Measure { + private static final String INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5 = "Index should be in range from 1 to 5"; + protected static final int MAX_TEXT_SIZE = 96; /** @@ -531,7 +533,7 @@ public class Measure { case 5: return variation5; default: - throw new IndexOutOfBoundsException("Index should be in range from 1 to 5"); + throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5); } } @@ -558,7 +560,7 @@ public class Measure { variation5 = d; break; default: - throw new IndexOutOfBoundsException("Index should be in range from 1 to 5"); + throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5); } return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java index 2a42997edf2..ea6f038e4f3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java @@ -45,7 +45,7 @@ import java.util.Map; /** * TODO should be an interface - * + * * @since 2.3 */ public final class XMLProfileParser implements ServerComponent { @@ -55,7 +55,7 @@ public final class XMLProfileParser implements ServerComponent { /** * For backward compatibility. - * + * * @deprecated since 2.5. Plugins shouldn't directly instantiate this class, * because it should be retrieved as an IoC dependency. */ @@ -163,14 +163,13 @@ public final class XMLProfileParser implements ServerComponent { Rule rule = ruleFinder.findByKey(repositoryKey, key); if (rule == null) { - messages.addWarningText("Rule not found: [repository=" + repositoryKey + ", key=" + key + "]"); + messages.addWarningText("Rule not found: " + ruleToString(repositoryKey, key)); } else { ActiveRule activeRule = profile.activateRule(rule, priority); for (Map.Entry<String, String> entry : parameters.entrySet()) { if (rule.getParam(entry.getKey()) == null) { - messages.addWarningText("The parameter '" + entry.getKey() + "' does not exist in the rule: [repository=" + repositoryKey - + ", key=" + key + "]"); + messages.addWarningText("The parameter '" + entry.getKey() + "' does not exist in the rule: " + ruleToString(repositoryKey, key)); } else { activeRule.setParameter(entry.getKey(), entry.getValue()); } @@ -179,6 +178,10 @@ public final class XMLProfileParser implements ServerComponent { } } + private String ruleToString(String repositoryKey, String key) { + return "[repository=" + repositoryKey + ", key=" + key + "]"; + } + private void processParameters(SMInputCursor propsCursor, Map<String, String> parameters) throws XMLStreamException { while (propsCursor.getNext() != null) { SMInputCursor propCursor = propsCursor.childElementCursor(); @@ -222,7 +225,7 @@ public final class XMLProfileParser implements ServerComponent { if (StringUtils.isNotBlank(periodParameter)) { period = Integer.parseInt(periodParameter); } - }else if (StringUtils.equals("operator", nodeName)) { + } else if (StringUtils.equals("operator", nodeName)) { operator = StringUtils.trim(alertCursor.collectDescendantText(false)); } else if (StringUtils.equals("warning", nodeName)) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java index 0e93c6a00b8..68c9b62e7fb 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java @@ -34,11 +34,14 @@ import java.util.List; /** * A class that manipulates Projects in the Sonar way. - * + * * @since 1.10 */ public class Project extends Resource implements Component { + private static final String MAVEN_KEY_FORMAT = "%s:%s"; + private static final String BRANCH_KEY_FORMAT = "%s:%s"; + public static final String SCOPE = Scopes.PROJECT; /** @@ -86,7 +89,7 @@ public class Project extends Resource implements Component { public Project(String key, String branch, String name) { if (StringUtils.isNotBlank(branch)) { - setKey(String.format("%s:%s", key, branch)); + setKey(String.format(BRANCH_KEY_FORMAT, key, branch)); this.name = String.format("%s %s", name, branch); } else { setKey(key); @@ -158,7 +161,7 @@ public class Project extends Resource implements Component { /** * For internal use only. - * + * * @deprecated in 2.8. See http://jira.codehaus.org/browse/SONAR-2341 */ @Deprecated @@ -199,7 +202,7 @@ public class Project extends Resource implements Component { /** * whether it's the latest analysis done on this project (displayed in sonar dashboard) or an analysis on a past revision. - * + * * @since 2.0 * @deprecated in 3.6. The analysis is now always the latest one (past analysis must be done in a chronological order). See http://jira.codehaus.org/browse/SONAR-4334 */ @@ -396,7 +399,7 @@ public class Project extends Resource implements Component { /** * For internal use only. - * + * * @deprecated since 2.6. See http://jira.codehaus.org/browse/SONAR-2126 */ @Deprecated @@ -457,7 +460,7 @@ public class Project extends Resource implements Component { } public static Project createFromMavenIds(String groupId, String artifactId) { - return new Project(String.format("%s:%s", groupId, artifactId)); + return new Project(String.format(MAVEN_KEY_FORMAT, groupId, artifactId)); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java index d5aa6d2e402..3d7f4f6b8fa 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java @@ -59,6 +59,7 @@ public class ResourceType { * Builder used to create {@link ResourceType} objects. */ public static class Builder { + private static final String SUPPORTS_MEASURE_FILTERS = "supportsMeasureFilters"; private String qualifier; private String iconPath; private boolean hasSourceCode = false; @@ -88,7 +89,7 @@ public class ResourceType { */ @Deprecated public Builder availableForFilters() { - setProperty("supportsMeasureFilters", "true"); + setProperty(SUPPORTS_MEASURE_FILTERS, "true"); return this; } @@ -112,7 +113,7 @@ public class ResourceType { // for backward-compatibility since version 3.4 if ("availableForFilters".equals(key)) { - properties.put("supportsMeasureFilters", value); + properties.put(SUPPORTS_MEASURE_FILTERS, value); } return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java index 02612902def..afa876940d6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java @@ -34,7 +34,19 @@ import org.sonar.check.Cardinality; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import java.util.ArrayList; import java.util.Date; @@ -70,7 +82,6 @@ public final class Rule { */ private static final Set<String> STATUS_LIST = ImmutableSet.of(STATUS_READY, STATUS_BETA, STATUS_DEPRECATED, STATUS_REMOVED); - @Id @Column(name = "id") @GeneratedValue @@ -282,7 +293,7 @@ public final class Rule { } public Boolean isEnabled() { - return !"REMOVED".equals(status); + return !STATUS_REMOVED.equals(status); } public List<RuleParam> getParams() { @@ -450,7 +461,6 @@ public final class Rule { return this; } - /** * @since 3.6 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java index f62d342a0eb..faf640d4ac1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriority.java @@ -32,6 +32,9 @@ public enum RulePriority { */ INFO, MINOR, MAJOR, CRITICAL, BLOCKER; + private static final String UNKNOWN_PRIORITY = "Unknown priority "; + + /** * A class to map priority level prior to Sonar 1.10 to the new ones * @@ -52,7 +55,7 @@ public enum RulePriority { return RulePriority.INFO; } } - throw new IllegalArgumentException("Unknown priority " + level); + throw new IllegalArgumentException(UNKNOWN_PRIORITY + level); } @@ -72,6 +75,6 @@ public enum RulePriority { if (checkPriority == Priority.INFO) { return RulePriority.INFO; } - throw new IllegalArgumentException("Unknown priority " + checkPriority); + throw new IllegalArgumentException(UNKNOWN_PRIORITY + checkPriority); } -}
\ No newline at end of file +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java index 00fa4c82678..bfcb689b2c7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java @@ -143,9 +143,13 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo } public static class BaseHttpDownloader { + + private static final String HTTP_PROXY_USER = "http.proxyUser"; + private static final String HTTP_PROXY_PASSWORD = "http.proxyPassword"; + private static final List<String> PROXY_SETTINGS = ImmutableList.of( - "http.proxyHost", "http.proxyPort", "http.nonProxyHosts", - "http.auth.ntlm.domain", "socksProxyHost", "socksProxyPort"); + "http.proxyHost", "http.proxyPort", "http.nonProxyHosts", + "http.auth.ntlm.domain", "socksProxyHost", "socksProxyPort"); private String userAgent; @@ -189,12 +193,12 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo private void registerProxyCredentials(Map<String, String> settings) { Authenticator.setDefault(new ProxyAuthenticator( - settings.get("http.proxyUser"), - settings.get("http.proxyPassword"))); + settings.get(HTTP_PROXY_USER), + settings.get(HTTP_PROXY_PASSWORD))); } private boolean requiresProxyAuthentication(Map<String, String> settings) { - return settings.containsKey("http.proxyUser"); + return settings.containsKey(HTTP_PROXY_USER); } private void propagateProxySystemProperties(Map<String, String> settings) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java index 0b156cd2c48..d451aad884c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java @@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory; /** * A very simple profiler to log the time elapsed performing some tasks. * This implementation is not thread-safe. - * + * * @since 2.0 */ public class TimeProfiler { @@ -80,10 +80,11 @@ public class TimeProfiler { public TimeProfiler stop() { if (start > 0) { + String format = "{} done: {} ms"; if (debug) { - logger.debug("{} done: {} ms", name, System.currentTimeMillis() - start); + logger.debug(format, name, System.currentTimeMillis() - start); } else { - logger.info("{} done: {} ms", name, System.currentTimeMillis() - start); + logger.info(format, name, System.currentTimeMillis() - start); } } start = 0; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java index 65487c327a3..f48cd8e450e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java @@ -28,18 +28,29 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import java.io.*; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.*; /** * XML Parsing tool using XPATH. It's recommended to use StaxParser when parsing big XML files. @@ -48,6 +59,7 @@ import javax.xml.xpath.*; */ public class XpathParser { + private static final String CAN_NOT_PARSE_XML = "can not parse xml : "; private Element root = null; private Document doc = null; private DocumentBuilder builder; @@ -120,9 +132,9 @@ public class XpathParser { xpath = factory.newXPath(); } catch (SAXException e) { - throw new XmlParserException("can not parse xml : " + xml, e); + throw new XmlParserException(CAN_NOT_PARSE_XML + xml, e); } catch (IOException e) { - throw new XmlParserException("can not parse xml : " + xml, e); + throw new XmlParserException(CAN_NOT_PARSE_XML + xml, e); } } @@ -265,4 +277,4 @@ public class XpathParser { } return replace.toString(); } -}
\ No newline at end of file +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java index 0b6dfae9842..e367fcc2435 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java @@ -39,6 +39,8 @@ import java.util.zip.ZipOutputStream; */ public final class ZipUtils { + private static final String ERROR_CREATING_DIRECTORY = "Error creating directory: "; + private ZipUtils() { // only static methods } @@ -86,12 +88,12 @@ public final class ZipUtils { File to = new File(toDir, entry.getName()); if (entry.isDirectory()) { if (!to.exists() && !to.mkdirs()) { - throw new IOException("Error creating directory: " + to); + throw new IOException(ERROR_CREATING_DIRECTORY + to); } } else { File parent = to.getParentFile(); if (parent != null && !parent.exists() && !parent.mkdirs()) { - throw new IOException("Error creating directory: " + parent); + throw new IOException(ERROR_CREATING_DIRECTORY + parent); } FileOutputStream fos = new FileOutputStream(to); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java index a1e8cba29fa..1eaf10eb920 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java @@ -20,7 +20,6 @@ package org.sonar.api.web; import com.google.common.base.Joiner; - import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSortedSet; @@ -32,6 +31,8 @@ import java.util.Set; * @since 3.1 */ public final class Criterion { + private static final String METRIC_FAMILY = "metric"; + private static final String QUALIFIER_FAMILY = "qualifier"; public static final String EQ = "eq"; public static final String GT = "gt"; public static final String GTE = "gte"; @@ -87,7 +88,7 @@ public final class Criterion { * @throws IllegalArgumentException if {@code operator} is not valid */ public static Criterion createForMetric(String key, String operator, Float value, boolean variation) { - return new Criterion("metric", key, operator, value, null, variation); + return new Criterion(METRIC_FAMILY, key, operator, value, null, variation); } /** @@ -98,19 +99,19 @@ public final class Criterion { * @throws IllegalArgumentException if {@code operator} is not valid */ public static Criterion createForMetric(String key, String operator, String textValue, boolean variation) { - return new Criterion("metric", key, operator, null, textValue, variation); + return new Criterion(METRIC_FAMILY, key, operator, null, textValue, variation); } /** * Creates a new {@link Criterion} on a qualifier. */ public static Criterion createForQualifier(Object... values) { - return new Criterion("qualifier", null, EQ, null, Joiner.on(',').join(values), false); + return new Criterion(QUALIFIER_FAMILY, null, EQ, null, Joiner.on(',').join(values), false); } /** * Get the the criterion's family. - * + * * @return the family */ public String getFamily() { @@ -119,7 +120,7 @@ public final class Criterion { /** * Get the the criterion's key. - * + * * @return the key */ public String getKey() { @@ -139,7 +140,7 @@ public final class Criterion { /** * Get the the criterion's value. - * + * * @return the value */ public Float getValue() { @@ -148,7 +149,7 @@ public final class Criterion { /** * Get the the criterion's value as text. - * + * * @return the value as text */ public String getTextValue() { @@ -157,7 +158,7 @@ public final class Criterion { /** * A criterion can be based on the varation of a value rather than on the value itself. - * + * * @return <code>true</code> when the variation is used rather than the value */ public boolean isVariation() { |