From: Simon Brandhof Date: Fri, 4 Apr 2014 15:31:31 +0000 (+0200) Subject: Fix some quality flaws X-Git-Tag: 4.3~126 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1335109eb1fd4a1df2b9d2043dd1a0a511a2bd61;p=sonarqube.git Fix some quality flaws --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java index 197acb1afbb..23d678c7a67 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java @@ -21,7 +21,6 @@ package org.sonar.batch.rule; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; -import org.codehaus.plexus.util.StringUtils; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; @@ -33,8 +32,6 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDao; import org.sonar.core.qualityprofile.db.ActiveRuleDto; import org.sonar.core.qualityprofile.db.ActiveRuleParamDto; -import javax.annotation.CheckForNull; - /** * Loads the rules that are activated on the Quality profiles * used by the current module and build {@link org.sonar.api.batch.rule.ActiveRules}. @@ -85,10 +82,4 @@ public class ActiveRulesProvider extends ProviderAdapter { } return builder.build(); } - - @CheckForNull - private String defaultParamValue(Rule rule, String paramKey) { - RuleParam param = rule.getParam(paramKey); - return param != null ? param.getDefaultValue() : null; - } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java index 738e2fced51..663fa45a1b6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java @@ -113,12 +113,10 @@ class LanguageDetection { return detectedLanguage; } - // Check if deprecated sonar.language is used and we are on a language without declared extensions - if (forcedLanguage != null) { - // Languages without declared suffixes match everything - if (patternsByLanguage.get(forcedLanguage).length == 0) { - return forcedLanguage; - } + // Check if deprecated sonar.language is used and we are on a language without declared extensions. + // Languages without declared suffixes match everything. + if (forcedLanguage != null && patternsByLanguage.get(forcedLanguage).length == 0) { + return forcedLanguage; } return null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java index 8de36743edc..0fa91ea3c93 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java @@ -20,7 +20,6 @@ package org.sonar.batch.scan.filesystem; import com.google.common.collect.Maps; -import org.picocontainer.Startable; import org.sonar.api.BatchComponent; import org.sonar.api.database.model.Snapshot; import org.sonar.api.utils.KeyValueFormat; @@ -30,8 +29,6 @@ import org.sonar.core.source.SnapshotDataTypes; import org.sonar.core.source.db.SnapshotDataDao; import org.sonar.core.source.db.SnapshotDataDto; -import javax.annotation.CheckForNull; - import java.util.Arrays; import java.util.Collection; import java.util.Map; diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java index 8fe0125ea29..7d2c6aa040f 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java @@ -19,13 +19,11 @@ */ package org.sonar.core.persistence.dialect; -import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.hibernate.dialect.Oracle10gDialect; import org.sonar.api.database.DatabaseProperties; import java.sql.Types; -import java.util.List; /** * @since 1.12 diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java index 48b04d938e9..6d929a28daa 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java @@ -51,10 +51,6 @@ import java.util.Date; */ public class JsonWriter { - public static JsonWriter of(Writer writer) { - return new JsonWriter(writer); - } - private final com.google.gson.stream.JsonWriter stream; private JsonWriter(Writer writer) { @@ -68,6 +64,10 @@ public class JsonWriter { this.stream = stream; } + public static JsonWriter of(Writer writer) { + return new JsonWriter(writer); + } + /** * Begins encoding a new array. Each call to this method must be paired with * a call to {@link #endArray}. Output is [. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/XmlWriter.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/XmlWriter.java index fbd5d552960..e9b53712bda 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/XmlWriter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/XmlWriter.java @@ -30,10 +30,6 @@ import java.io.Writer; */ public class XmlWriter { - public static XmlWriter of(Writer writer) { - return new XmlWriter(writer); - } - private final XMLStreamWriter stream; private XmlWriter(Writer writer) { @@ -45,6 +41,10 @@ public class XmlWriter { } } + public static XmlWriter of(Writer writer) { + return new XmlWriter(writer); + } + public XmlWriter declaration() { try { stream.writeStartDocument(); diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ClassLoaderUtils.java b/sonar-server/src/main/java/org/sonar/server/platform/ClassLoaderUtils.java index bf2e685a087..0e8acf3757f 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/ClassLoaderUtils.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/ClassLoaderUtils.java @@ -43,10 +43,7 @@ import java.util.jar.JarFile; class ClassLoaderUtils { private ClassLoaderUtils() { - } - - static File copyResources(ClassLoader classLoader, String rootPath, File toDir) { - return copyResources(classLoader, rootPath, toDir, Functions.identity()); + // only static methods } static File copyResources(ClassLoader classLoader, String rootPath, File toDir, Function relocationFunction) { @@ -80,17 +77,12 @@ class ClassLoaderUtils { }); } - - static Collection listResources(ClassLoader classLoader, String rootPath) { - return listResources(classLoader, rootPath, Predicates.alwaysTrue()); - } - /** * Finds directories and files within a given directory and its subdirectories. * * @param classLoader * @param rootPath the root directory, for example org/sonar/sqale, or a file in this root directory, for example org/sonar/sqale/index.txt - * @param + * @param predicate * @return a list of relative paths, for example {"org/sonar/sqale", "org/sonar/sqale/foo", "org/sonar/sqale/foo/bar.txt}. Never null. */ static Collection listResources(ClassLoader classLoader, String rootPath, Predicate predicate) { @@ -98,8 +90,6 @@ class ClassLoaderUtils { JarFile jar = null; try { Collection paths = Lists.newArrayList(); - rootPath = StringUtils.removeStart(rootPath, "/"); - URL root = classLoader.getResource(rootPath); if (root != null) { checkJarFile(root); diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 98d8741014d..f480f7447ca 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -239,6 +239,9 @@ public final class JRubyFacade { /* PROFILES CONSOLE : RULES AND METRIC THRESHOLDS */ + /** + * @deprecated in 4.2 + */ @Deprecated @CheckForNull public RuleRepositories.Repository getRuleRepository(String repositoryKey) { diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ClassLoaderUtilsTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ClassLoaderUtilsTest.java index 400da37c733..8d1038d9e9e 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/ClassLoaderUtilsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/ClassLoaderUtilsTest.java @@ -20,7 +20,9 @@ package org.sonar.server.platform; import com.google.common.base.Function; +import com.google.common.base.Functions; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; @@ -29,7 +31,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.server.platform.ClassLoaderUtils; import javax.annotation.Nullable; import java.io.File; @@ -59,24 +60,13 @@ public class ClassLoaderUtilsTest { @Test public void listResources_unknown_root() { - Collection strings = ClassLoaderUtils.listResources(classLoader, "unknown/directory"); + Collection strings = ClassLoaderUtils.listResources(classLoader, "unknown/directory", Predicates.alwaysTrue()); assertThat(strings.size(), Is.is(0)); } @Test public void listResources_all() { - Collection strings = ClassLoaderUtils.listResources(classLoader, "org/sonar/sqale"); - assertThat(strings, hasItems( - "org/sonar/sqale/", - "org/sonar/sqale/app/", - "org/sonar/sqale/app/copyright.txt", - "org/sonar/sqale/app/README.md")); - assertThat(strings.size(), Is.is(4)); - } - - @Test - public void listResources_root_path_starts_with_slash() { - Collection strings = ClassLoaderUtils.listResources(classLoader, "/org/sonar/sqale"); + Collection strings = ClassLoaderUtils.listResources(classLoader, "org/sonar/sqale", Predicates.alwaysTrue()); assertThat(strings, hasItems( "org/sonar/sqale/", "org/sonar/sqale/app/", @@ -108,7 +98,7 @@ public class ClassLoaderUtilsTest { @Test public void copyRubyRailsApp() { File toDir = temp.newFolder("dest"); - ClassLoaderUtils.copyResources(classLoader, "org/sonar/sqale", toDir); + ClassLoaderUtils.copyResources(classLoader, "org/sonar/sqale", toDir, Functions.identity()); assertThat(FileUtils.listFiles(toDir, null, true).size(), Is.is(2)); assertThat(new File(toDir, "org/sonar/sqale/app/copyright.txt").exists(), Is.is(true));