]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 24 Mar 2016 19:26:11 +0000 (20:26 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 24 Mar 2016 19:26:11 +0000 (20:26 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/EmbeddedDatabaseFactory.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/Version.java
sonar-scanner-engine/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java
sonar-scanner-engine/src/main/java/org/sonar/batch/report/ComponentsPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java
sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
sonar-scanner-engine/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java

index 107dabad1aa4549f206c81afbba2e9d2e9e78ef3..52c6aacbaac28356e9d6e66163340787f4be7fee 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.db;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.lang.StringUtils;
 import org.picocontainer.Startable;
 import org.sonar.api.config.Settings;
 import org.sonar.api.database.DatabaseProperties;
index f79c5b32e788efd92bfc14a64fabcb1dfb6a7840..472c048246b578ee9b43ef80fe7416e1092748b9 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.db.qualityprofile.ActiveRuleKey;
 import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.search.BaseDoc;
 
+import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
 import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY;
@@ -77,11 +78,11 @@ public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
   public ActiveRule.Inheritance inheritance() {
     String inheritance = getNullableField(FIELD_ACTIVE_RULE_INHERITANCE);
     if (inheritance == null || inheritance.isEmpty() ||
-      inheritance.toLowerCase().contains("none")) {
+      containsIgnoreCase(inheritance, "none")) {
       return Inheritance.NONE;
-    } else if (inheritance.toLowerCase().contains("herit")) {
+    } else if (containsIgnoreCase(inheritance, "herit")) {
       return Inheritance.INHERITED;
-    } else if (inheritance.toLowerCase().contains("over")) {
+    } else if (containsIgnoreCase(inheritance, "over")) {
       return Inheritance.OVERRIDES;
     } else {
       throw new IllegalStateException("Value \"" + inheritance + "\" is not valid for rule's inheritance");
index f009dc61756ce78c807f3b1e7d589381df98571a..dcd96d9cbb403a8a655e888505f3d35a138e8606 100644 (file)
@@ -109,13 +109,14 @@ public class Version implements Comparable<Version> {
     int major = 0;
     int minor = 0;
     int patch = 0;
-    if (split.size() > 0) {
+    int size = split.size();
+    if (size > 0) {
       major = parseSequence(split.get(0));
-      if (split.size() > 1) {
+      if (size > 1) {
         minor = parseSequence(split.get(1));
-        if (split.size() > 2) {
+        if (size > 2) {
           patch = parseSequence(split.get(2));
-          if (split.size() > 3) {
+          if (size > 3) {
             throw new IllegalArgumentException("Only 3 sequences are accepted");
           }
         }
index 7c04dcff55e96cc803bd66fcd582b604939e8f9a..c31e190226ea86c24f0fa8260f68fea1a05e254e 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.batch.profiling;
 
 import com.google.common.collect.Maps;
-import java.util.HashMap;
+import java.util.EnumMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -31,7 +31,7 @@ import org.sonar.api.utils.System2;
 
 public class ModuleProfiling extends AbstractTimeProfiling {
 
-  private Map<Phase, PhaseProfiling> profilingPerPhase = new HashMap<>();
+  private Map<Phase, PhaseProfiling> profilingPerPhase = new EnumMap<>(Phase.class);
   private Map<String, ItemProfiling> profilingPerBatchStep = new LinkedHashMap<>();
   private final Project module;
 
index 27d46165d227be3b3700a484610c679d274339e2..2e6a25d791a203ca20f8f183bb0f3a75c1631d81 100644 (file)
@@ -159,7 +159,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
     return ResourceUtils.isProject(r) ? r.getDescription() : null;
   }
 
-  private ComponentType getType(Resource r) {
+  private static ComponentType getType(Resource r) {
     if (ResourceUtils.isFile(r)) {
       return ComponentType.FILE;
     } else if (ResourceUtils.isDirectory(r)) {
index de29cc352fc8648118a3c7dda514cfc607098cfe..a1c1f1c2dda4ebc62765e6a2135ba18a3e4f14a0 100644 (file)
@@ -70,7 +70,6 @@ public class RulesProfileProvider extends ProviderAdapter {
 
   private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) {
     RulesProfile deprecatedProfile = new RulesProfile();
-    // TODO deprecatedProfile.setVersion(qProfile.version());
     deprecatedProfile.setName(qProfile.getName());
     deprecatedProfile.setLanguage(qProfile.getLanguage());
     for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.getLanguage())) {
index 2a2952884f5bd3bf8bf35a21ebff248f13625e98..256688ef3643c64199ab181d5359213b7b2eec74 100644 (file)
@@ -58,7 +58,7 @@ public class ExclusionFilters {
     return mainInclusions.length > 0 || mainExclusions.length > 0 || testInclusions.length > 0 || testExclusions.length > 0;
   }
 
-  private void log(String title, PathPattern[] patterns) {
+  private static void log(String title, PathPattern[] patterns) {
     if (patterns.length > 0) {
       LOG.info(title);
       for (PathPattern pattern : patterns) {
index c0f9fd3c06228d1fbb42e0af29e64e1039ffe455..c093056c2ebebf8fecb13078263a6d1f0cacf6a1 100644 (file)
@@ -19,9 +19,7 @@
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.FilePredicate;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 
@@ -29,9 +27,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class AdditionalFilePredicatesTest {
 
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
   @Test
   public void key() {
     FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java");