]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Sun, 2 Feb 2014 11:47:55 +0000 (12:47 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Sun, 2 Feb 2014 11:47:55 +0000 (12:47 +0100)
sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java
sonar-core/src/main/java/org/sonar/core/i18n/I18nClassloader.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDao.java
sonar-core/src/test/java/org/sonar/core/persistence/DaoUtilsTest.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
sonar-server/src/main/java/org/sonar/server/ws/ListingWs.java

index 9e9ea0400e876f737a48ba0f1d3d6c54eeee8aea..767a029042ababa25d7719042af48498fee4777e 100644 (file)
@@ -41,6 +41,7 @@ import java.util.List;
 public class RulesProfileWrapper extends RulesProfile {
 
   private static final Logger LOG = LoggerFactory.getLogger(RulesProfileWrapper.class);
+  private static final String DEPRECATED_USAGE_MESSAGE = "Please update your plugin to support multi-language analysis";
 
   private final Collection<RulesProfile> profiles;
   private final RulesProfile singleLanguageProfile;
@@ -62,7 +63,7 @@ public class RulesProfileWrapper extends RulesProfile {
 
   private RulesProfile getSingleProfileOrFail() {
     if (singleLanguageProfile == null) {
-      throw new IllegalStateException("Please update your plugin to support multi-language analysis");
+      throw new IllegalStateException(DEPRECATED_USAGE_MESSAGE);
     }
     return singleLanguageProfile;
   }
@@ -76,8 +77,8 @@ public class RulesProfileWrapper extends RulesProfile {
   public String getLanguage() {
     if (singleLanguageProfile == null) {
       // Multi-languages module
-      // FIXME This is a hack for CommonChecksDecorator that call this method in its constructor
-      LOG.debug("Please update your plugin to support multi-language analysis", new SonarException("Please update your plugin to support multi-language analysis"));
+      // This is a hack for CommonChecksDecorator that call this method in its constructor
+      LOG.debug(DEPRECATED_USAGE_MESSAGE, new SonarException(DEPRECATED_USAGE_MESSAGE));
       return "";
     }
     return singleLanguageProfile.getLanguage();
index 402621dadef1aa380e4cd0e4274c2df4ff2a895b..3ec7284ae1800eabd0a492430a2a0ace859a2ac0 100644 (file)
@@ -43,14 +43,9 @@ import org.sonar.api.utils.SonarException;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
-
 import java.io.File;
 import java.nio.charset.Charset;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Index input files into {@link InputFileCache}.
@@ -186,8 +181,7 @@ public class FileIndex implements BatchComponent {
   }
 
   private String computeFilePath(DefaultModuleFileSystem fileSystem, File file) {
-    String path = pathResolver.relativePath(fileSystem.baseDir(), file);
-    return path;
+    return pathResolver.relativePath(fileSystem.baseDir(), file);
   }
 
   @CheckForNull
index b55ff5dfaa2f508134fb858b885ac8bf2ff91eca..20e49e61074bb47e70fa63edbd3b12f14c2e2538 100644 (file)
@@ -60,7 +60,7 @@ class I18nClassloader extends URLClassLoader {
   }
 
   @Override
-  protected synchronized Class<?> loadClass(String s, boolean b) throws ClassNotFoundException {
+  protected synchronized Class loadClass(String s, boolean b) throws ClassNotFoundException {
     throw new UnsupportedOperationException("I18n classloader does support only resources, but not classes");
   }
 
index bd8f3bce7f59b5fb09da035f450b1c6b54144ed1..e293959824c050f7e27db329288591e652e6ae75 100644 (file)
@@ -78,9 +78,10 @@ public abstract class IssueStorage {
         if (issue.isNew()) {
           insert(issueMapper, now, issue);
           insertChanges(issueChangeMapper, issue);
-          if (count++ > BatchSession.MAX_BATCH_SIZE) {
+          if (count > BatchSession.MAX_BATCH_SIZE) {
             batchSession.commit();
           }
+          count++;
         } else if (issue.isChanged()) {
           toBeUpdated.add(issue);
         }
index 99ed13b1bc900bd6ca5a7c505594b82ef009fa80..05628a72ed0385b91f10c0f98642d1d2718035c6 100644 (file)
@@ -53,8 +53,8 @@ public final class DaoUtils {
   }
 
   @SuppressWarnings("unchecked")
-  public static List<Class<?>> getDaoClasses() {
-    return ImmutableList.of(
+  public static List<Class> getDaoClasses() {
+    return ImmutableList.<Class>of(
       ActionPlanDao.class,
       ActionPlanStatsDao.class,
       ActiveDashboardDao.class,
index c3f931249b6c769e7c00c2803266c648afb4474e..da73eaa709fe82721564efec102721c8c42eef1f 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.api.ServerComponent;
 import org.sonar.core.persistence.MyBatis;
 
 import javax.annotation.CheckForNull;
-
 import java.util.Collection;
 import java.util.List;
 
@@ -50,11 +49,12 @@ public class RuleDao implements BatchComponent, ServerComponent {
     return getMapper(session).selectNonManual();
   }
 
+  @CheckForNull
   public RuleDto selectById(Integer id, SqlSession session) {
     return getMapper(session).selectById(id);
   }
 
-
+  @CheckForNull
   public RuleDto selectById(Integer id) {
     SqlSession session = mybatis.openSession();
     try {
@@ -64,6 +64,7 @@ public class RuleDao implements BatchComponent, ServerComponent {
     }
   }
 
+  @CheckForNull
   public RuleDto selectByName(String name) {
     SqlSession session = mybatis.openSession();
     try {
index d4c7da35de947357b2182ab0e4146550efc154fb..f22e0cbb87a6dd20b6d679d4d357facacadb9233 100644 (file)
@@ -52,11 +52,11 @@ public class SnapshotSourceDao implements ServerComponent {
 
   @CheckForNull
   public String selectSnapshotSourceByComponentKey(String componentKey, SqlSession session) {
-      SnapshotSourceMapper mapper = session.getMapper(SnapshotSourceMapper.class);
-      return mapper.selectSnapshotSourceByComponentKey(componentKey);
+    SnapshotSourceMapper mapper = session.getMapper(SnapshotSourceMapper.class);
+    return mapper.selectSnapshotSourceByComponentKey(componentKey);
   }
 
-    @CheckForNull
+  @CheckForNull
   public String selectSnapshotSourceByComponentKey(String componentKey) {
     SqlSession session = mybatis.openSession();
     try {
index 996dc36c5d30a4fc06fa13135cd6b5624edc7939..c786fe62f0a6bc1c5895eec813b431dc552b79c5 100644 (file)
@@ -28,8 +28,8 @@ import static org.fest.assertions.Assertions.assertThat;
 public class DaoUtilsTest {
 
   @Test
-  public void should_list_all_dao_classes() {
-    List<Class<?>> daoClasses = DaoUtils.getDaoClasses();
+  public void list_all_dao_classes() {
+    List<Class> daoClasses = DaoUtils.getDaoClasses();
 
     assertThat(daoClasses).isNotEmpty();
   }
index 6226366829949a4494664e3ce091ad10c0d5ff67..04fea5cee06245d40bb3051a20e035475f56a785 100644 (file)
@@ -30,17 +30,14 @@ import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RulePriority;
 
 import javax.persistence.*;
-
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * This class is badly named. It should be "QualityProfile". Indeed it does not relate only to rules but to metric thresholds too.
- * @deprecated since 4.2. Replaced by {@link org.sonar.api.batch.rule.ModuleRules} for batch extensions.
  */
 @Entity
 @Table(name = "rules_profiles")
-@Deprecated
 public class RulesProfile implements Cloneable {
 
   /**
index ca5e8216135654e1a950b7de7a1b7539eb4b4a72..7f7a005bcba89792a22f3f9ac6cafd844d2e093f 100644 (file)
@@ -82,19 +82,17 @@ public class ListingWs implements WebService {
     writer.prop("path", controller.path());
     writer.prop("since", controller.since());
     writer.prop("description", controller.description());
-    if (!controller.actions().isEmpty()) {
-      // sort actions by key
-      Ordering<Action> ordering = Ordering.natural().onResultOf(new Function<Action, String>() {
-        public String apply(Action action) {
-          return action.key();
-        }
-      });
-      writer.name("actions").beginArray();
-      for (Action action : ordering.sortedCopy(controller.actions())) {
-        write(writer, action);
+    // sort actions by key
+    Ordering<Action> ordering = Ordering.natural().onResultOf(new Function<Action, String>() {
+      public String apply(Action action) {
+        return action.key();
       }
-      writer.endArray();
+    });
+    writer.name("actions").beginArray();
+    for (Action action : ordering.sortedCopy(controller.actions())) {
+      write(writer, action);
     }
+    writer.endArray();
     writer.endObject();
   }