]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 4 Apr 2014 15:31:31 +0000 (17:31 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 4 Apr 2014 15:31:31 +0000 (17:31 +0200)
sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoader.java
sonar-core/src/main/java/org/sonar/core/persistence/dialect/Oracle.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/text/JsonWriter.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/text/XmlWriter.java
sonar-server/src/main/java/org/sonar/server/platform/ClassLoaderUtils.java
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
sonar-server/src/test/java/org/sonar/server/platform/ClassLoaderUtilsTest.java

index 197acb1afbba09d98e88b03b1f3e861adaefe69e..23d678c7a67d5feafd0a01349495a4645a51e6df 100644 (file)
@@ -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;
-  }
 }
index 738e2fced51551b3b572ef13a90e83d13c0210e2..663fa45a1b6b3a2943d381f475d68f3ea7ef8d00 100644 (file)
@@ -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;
   }
index 8de36743edc0f8e07b84c34b3165fec2ce7cd5b5..0fa91ea3c938ed0dffc322eb6a72131b4c8eabfe 100644 (file)
@@ -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;
index 8fe0125ea29739aa556573bac447ae199137bada..7d2c6aa040fe997d0b0c13c393db8f29969559c2 100644 (file)
  */
 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
index 48b04d938e9a73eb0aeb039fc41b4ed2b1a00928..6d929a28daafed899967b7f66c05fd0339dfcd85 100644 (file)
@@ -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 <code>[</code>.
index fbd5d552960c56c1ccb20507b93ee250fab5b243..e9b53712bda938bf399e4296403406d4d5d108b4 100644 (file)
@@ -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();
index bf2e685a087ce7d82b06393a08e0ff458db90db4..0e8acf3757fb16c500799fc84fcb2544de4345ed 100644 (file)
@@ -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.<String>identity());
+    // only static methods
   }
 
   static File copyResources(ClassLoader classLoader, String rootPath, File toDir, Function<String, String> relocationFunction) {
@@ -80,17 +77,12 @@ class ClassLoaderUtils {
     });
   }
 
-
-  static Collection<String> listResources(ClassLoader classLoader, String rootPath) {
-    return listResources(classLoader, rootPath, Predicates.<String>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<String> listResources(ClassLoader classLoader, String rootPath, Predicate<String> predicate) {
@@ -98,8 +90,6 @@ class ClassLoaderUtils {
     JarFile jar = null;
     try {
       Collection<String> paths = Lists.newArrayList();
-      rootPath = StringUtils.removeStart(rootPath, "/");
-
       URL root = classLoader.getResource(rootPath);
       if (root != null) {
         checkJarFile(root);
index 98d8741014d15164b9f0c9ab0ecd51180ed84dcc..f480f7447ca41442b7dbe27c1809202476168c2b 100644 (file)
@@ -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) {
index 400da37c7332717618d28355a229f28a30a99cce..8d1038d9e9e66368685d57e919049ea930aef6d3 100644 (file)
@@ -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<String> strings = ClassLoaderUtils.listResources(classLoader, "unknown/directory");
+    Collection<String> strings = ClassLoaderUtils.listResources(classLoader, "unknown/directory", Predicates.<String>alwaysTrue());
     assertThat(strings.size(), Is.is(0));
   }
 
   @Test
   public void listResources_all() {
-    Collection<String> 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<String> strings = ClassLoaderUtils.listResources(classLoader, "/org/sonar/sqale");
+    Collection<String> strings = ClassLoaderUtils.listResources(classLoader, "org/sonar/sqale", Predicates.<String>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.<String>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));