]> source.dussan.org Git - sonarqube.git/commitdiff
Sanitize code - remove commented-out code and dead code
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 24 Mar 2014 17:48:10 +0000 (18:48 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 24 Mar 2014 17:48:48 +0000 (18:48 +0100)
sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java

index 2c62146be3587727b8053fd0ccb72a1c3ce35787..8cc8c1922ddee5a1d70ed34fd61cfec5b4aeb102 100644 (file)
@@ -36,11 +36,6 @@ import java.util.*;
 
 public class ProfilesBackup {
 
-  private static final String OPERATOR = "operator";
-  private static final String VALUE_ERROR = "value-error";
-  private static final String VALUE_WARNING = "value-warning";
-  private static final String PERIOD = "period";
-  private static final String METRIC_KEY = "metric-key";
   private static final String KEY = "key";
   private static final String PLUGIN = "plugin";
   private static final String LEVEL = "level";
index df5cda6489c2c602514c0635382e28780ded0264..a8753c074ef54b1d2af6391b78ac5b435252be76 100644 (file)
@@ -25,7 +25,6 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.measures.Metrics;
@@ -44,11 +43,9 @@ public class RegisterMetrics {
 
   private final MeasuresDao measuresDao;
   private final Metrics[] metricsRepositories;
-  private final DatabaseSession session;
   private final QualityGateConditionDao conditionDao;
 
-  public RegisterMetrics(DatabaseSession session, MeasuresDao measuresDao, QualityGateConditionDao conditionDao, Metrics[] metricsRepositories) {
-    this.session = session;
+  public RegisterMetrics(MeasuresDao measuresDao, QualityGateConditionDao conditionDao, Metrics[] metricsRepositories) {
     this.measuresDao = measuresDao;
     this.metricsRepositories = metricsRepositories;
     this.conditionDao = conditionDao;
@@ -70,12 +67,12 @@ public class RegisterMetrics {
   List<Metric> getMetricsRepositories() {
     List<Metric> metricsToRegister = newArrayList();
     Map<String, Metrics> metricsByRepository = Maps.newHashMap();
-    if (metricsRepositories != null) {
-      for (Metrics metrics : metricsRepositories) {
-        checkMetrics(metricsByRepository, metrics);
-        metricsToRegister.addAll(removeExistingUserManagedMetrics(metrics.getMetrics()));
-      }
+
+    for (Metrics metrics : metricsRepositories) {
+      checkMetrics(metricsByRepository, metrics);
+      metricsToRegister.addAll(removeExistingUserManagedMetrics(metrics.getMetrics()));
     }
+
     return metricsToRegister;
   }
 
@@ -104,17 +101,8 @@ public class RegisterMetrics {
   }
 
   protected void cleanAlerts() {
-    LOG.info("cleaning alert thresholds...");
+    LOG.info("Cleaning quality gate conditions");
     conditionDao.deleteConditionsWithInvalidMetrics();
-/*
-    Query query = session.createQuery("delete from " + Alert.class.getSimpleName() + " a where NOT EXISTS(FROM Metric m WHERE m=a.metric))");
-    query.executeUpdate();
-
-    query = session.createQuery("delete from " + Alert.class.getSimpleName() + " a where NOT EXISTS(FROM Metric m WHERE m=a.metric and m.enabled=:enabled))");
-    query.setParameter("enabled", Boolean.TRUE);
-    query.executeUpdate();
-    session.commit();
-*/
   }
 
   protected void register(List<Metric> metrics) {
index 59a4e6d3ce138d59c395956168df4a21122a3d39..2fa115a8626d9583828b1314ed08c5f70ab18ff8 100644 (file)
@@ -32,7 +32,9 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 public class RegisterMetricsTest extends AbstractDbUnitTestCase {
 
@@ -41,21 +43,21 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
     setupData("shouldSaveIfNew");
 
     Metric metric1 = new Metric.Builder("new1", "short1", Metric.ValueType.FLOAT)
-        .setDescription("desc1")
-        .setDirection(1)
-        .setQualitative(true)
-        .setDomain("domain1")
-        .setUserManaged(false)
-        .create();
+      .setDescription("desc1")
+      .setDirection(1)
+      .setQualitative(true)
+      .setDomain("domain1")
+      .setUserManaged(false)
+      .create();
     Metric metric2 = new Metric.Builder("new2", "short2", Metric.ValueType.FLOAT)
-        .setDescription("desc2")
-        .setDirection(1)
-        .setQualitative(true)
-        .setDomain("domain2")
-        .setUserManaged(false)
-        .create();
-
-    RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), mock(QualityGateConditionDao.class), null);
+      .setDescription("desc2")
+      .setDirection(1)
+      .setQualitative(true)
+      .setDomain("domain2")
+      .setUserManaged(false)
+      .create();
+
+    RegisterMetrics synchronizer = new RegisterMetrics(new MeasuresDao(getSession()), mock(QualityGateConditionDao.class), new Metrics[0]);
     synchronizer.register(Arrays.asList(metric1, metric2));
     checkTables("shouldSaveIfNew", "metrics");
   }
@@ -64,14 +66,14 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
   public void shouldUpdateIfAlreadyExists() {
     setupData("shouldUpdateIfAlreadyExists");
 
-    RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), mock(QualityGateConditionDao.class), null);
+    RegisterMetrics synchronizer = new RegisterMetrics(new MeasuresDao(getSession()), mock(QualityGateConditionDao.class), new Metrics[0]);
     synchronizer.register(newArrayList(new Metric.Builder("key", "new short name", Metric.ValueType.FLOAT)
-        .setDescription("new description")
-        .setDirection(-1)
-        .setQualitative(true)
-        .setDomain("new domain")
-        .setUserManaged(false)
-        .create()));
+      .setDescription("new description")
+      .setDirection(-1)
+      .setQualitative(true)
+      .setDomain("new domain")
+      .setUserManaged(false)
+      .create()));
 
     checkTables("shouldUpdateIfAlreadyExists", "metrics");
   }
@@ -80,15 +82,15 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
   public void shouldAddUserManagesMetric() {
     Metrics metrics = mock(Metrics.class);
     when(metrics.getMetrics()).thenReturn(newArrayList(new Metric.Builder("key", "new short name", Metric.ValueType.FLOAT)
-        .setDescription("new description")
-        .setDirection(-1)
-        .setQualitative(true)
-        .setDomain("new domain")
-        .setUserManaged(true)
-        .create()));
+      .setDescription("new description")
+      .setDirection(-1)
+      .setQualitative(true)
+      .setDomain("new domain")
+      .setUserManaged(true)
+      .create()));
 
     MeasuresDao measuresDao = new MeasuresDao(getSession());
-    RegisterMetrics loader = new RegisterMetrics(getSession(), measuresDao, mock(QualityGateConditionDao.class), new Metrics[]{metrics});
+    RegisterMetrics loader = new RegisterMetrics(measuresDao, mock(QualityGateConditionDao.class), new Metrics[]{metrics});
     List<Metric> result = loader.getMetricsRepositories();
 
     assertThat(result).hasSize(1);
@@ -100,15 +102,15 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
 
     Metrics metrics = mock(Metrics.class);
     when(metrics.getMetrics()).thenReturn(newArrayList(new Metric.Builder("key", "new short name", Metric.ValueType.FLOAT)
-        .setDescription("new description")
-        .setDirection(-1)
-        .setQualitative(true)
-        .setDomain("new domain")
-        .setUserManaged(true)
-        .create()));
+      .setDescription("new description")
+      .setDirection(-1)
+      .setQualitative(true)
+      .setDomain("new domain")
+      .setUserManaged(true)
+      .create()));
 
     MeasuresDao measuresDao = new MeasuresDao(getSession());
-    RegisterMetrics loader = new RegisterMetrics(getSession(), measuresDao, mock(QualityGateConditionDao.class), new Metrics[]{metrics});
+    RegisterMetrics loader = new RegisterMetrics(measuresDao, mock(QualityGateConditionDao.class), new Metrics[]{metrics});
     List<Metric> result = loader.getMetricsRepositories();
 
     assertThat(result).isEmpty();
@@ -119,7 +121,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
     setupData("shouldEnableOnlyLoadedMetrics");
 
     MeasuresDao measuresDao = new MeasuresDao(getSession());
-    RegisterMetrics loader = new RegisterMetrics(getSession(), measuresDao, mock(QualityGateConditionDao.class), null);
+    RegisterMetrics loader = new RegisterMetrics(measuresDao, mock(QualityGateConditionDao.class), new Metrics[0]);
     loader.start();
 
     assertThat(measuresDao.getMetric("deprecated").getEnabled()).isFalse();
@@ -127,9 +129,9 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
   }
 
   @Test
-  public void shouldCleanAlerts() {
+  public void clean_quality_gate_conditions() {
     QualityGateConditionDao conditionDao = mock(QualityGateConditionDao.class);
-    RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), conditionDao, null);
+    RegisterMetrics loader = new RegisterMetrics(new MeasuresDao(getSession()), conditionDao, new Metrics[0]);
     loader.cleanAlerts();
     verify(conditionDao).deleteConditionsWithInvalidMetrics();
   }