]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Sat, 21 Sep 2013 12:38:19 +0000 (14:38 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Sat, 21 Sep 2013 12:38:19 +0000 (14:38 +0200)
sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java
sonar-server/src/main/java/org/sonar/server/db/migrations/violation/Referentials.java
sonar-server/src/main/java/org/sonar/server/db/migrations/violation/ViolationConverter.java
sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java
sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java

index d20ef966380d8bba01911d464643d035cd4c574a..982042cec98655fa77c2792b731fd65ceaf1f1cd 100644 (file)
  */
 package org.sonar.server.db.migrations;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.server.db.migrations.violation.ViolationMigration;
 
+import java.util.List;
+
 public interface DatabaseMigrations {
 
-  Class<? extends DatabaseMigration>[] CLASSES = new Class[]{
+  List<Class<? extends DatabaseMigration>> CLASSES = ImmutableList.<Class<? extends DatabaseMigration>>of(
     ViolationMigration.class
-  };
+  );
+
 }
index c7accede5628fce5124a6d3867c4bf931387e05a..2260b160f4d2851fdd9d6f370116e863b075e7af 100644 (file)
@@ -70,15 +70,14 @@ class Referentials {
     return totalViolations;
   }
 
-  @CheckForNull
   Long[] pollGroupOfViolationIds() {
     long[] longs = groupsOfViolationIds.poll();
     if (longs == null) {
-      return null;
+      return new Long[0];
     }
     Long[] objects = new Long[longs.length];
     for (int i = 0; i < longs.length; i++) {
-      objects[i] = new Long(longs[i]);
+      objects[i] = Long.valueOf(longs[i]);
     }
     return objects;
   }
@@ -103,10 +102,10 @@ class Referentials {
 
   private Queue<long[]> initGroupOfViolationIds(Database database) throws SQLException {
     Connection connection = database.getDataSource().getConnection();
-    connection.setAutoCommit(false);
     Statement stmt = null;
     ResultSet rs = null;
     try {
+      connection.setAutoCommit(false);
       stmt = connection.createStatement();
       stmt.setFetchSize(10000);
       rs = stmt.executeQuery("select id from rule_failures");
index e0d39f1c7fc257c2af9d5b77dcbad2c5dc305e62..de525fc2b3136cb502bffcfbd831df7a7d40b458 100644 (file)
@@ -138,7 +138,7 @@ class ViolationConverter implements Callable<Object> {
     //   -- delete violations
 
     Long[] violationIds = referentials.pollGroupOfViolationIds();
-    while (violationIds != null) {
+    while (violationIds.length>0) {
       List<Map<String, Object>> rows = selectRows(violationIds);
       convert(rows, violationIds);
 
index df7b84c6d0a4503189f667f20d6a6e7dd22d7bd4..c59d73ecbf1a23c528de606e2de5f2071cca9685 100644 (file)
@@ -89,10 +89,8 @@ public class NotificationCenter implements ServerComponent {
     for (NotificationDispatcherMetadata metadata : dispatchersMetadata) {
       String dispatcherKey = metadata.getDispatcherKey();
       String value = metadata.getProperty(propertyKey);
-      if (value != null) {
-        if (propertyValue == null || value.equals(propertyValue)) {
+      if (value != null && (propertyValue == null || value.equals(propertyValue))) {
           keys.add(dispatcherKey);
-        }
       }
     }
     return keys;
index 3c73db9cf532405d17b6bc5342577e8706e8ac9d..55245b5f56b547597c8180b6f111b71c44e346ca 100644 (file)
@@ -133,13 +133,13 @@ public final class TestUtils {
     assertThat(file.exists(), is(true));
   }
 
-  public static void assertSimilarXml(String expectedXml, String xml) throws IOException, SAXException {
+  public static void assertSimilarXml(String expectedXml, String xml) throws Exception {
     Diff diff = isSimilarXml(expectedXml, xml);
     String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
     assertTrue(message, diff.similar());
   }
 
-  static Diff isSimilarXml(String expectedXml, String xml) throws IOException, SAXException {
+  static Diff isSimilarXml(String expectedXml, String xml) throws Exception {
     XMLUnit.setIgnoreWhitespace(true);
     return XMLUnit.compareXML(xml, expectedXml);
   }