]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5094 Revert back to alert_status metric, will be renamed eventually
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 10 Mar 2014 10:18:22 +0000 (11:18 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 10 Mar 2014 15:51:26 +0000 (16:51 +0100)
sonar-batch/src/main/java/org/sonar/batch/qualitygate/LegacyQualityGateVerifier.java
sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
sonar-batch/src/test/java/org/sonar/batch/qualitygate/LegacyQualityGateVerifierTest.java
sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java

index 8f0ca3f6595e5373ae71b8ce0c94831cea82cc0a..77cfc969088dab4aee555a5a0886661c25490d42 100644 (file)
@@ -84,7 +84,7 @@ public class LegacyQualityGateVerifier implements Decorator {
   }
 
   public void decorate(final Resource resource, final DecoratorContext context) {
-    if (ResourceUtils.isRootProject(resource) && !projectAlerts.all().isEmpty()) {
+    if (ResourceUtils.isRootProject(resource) && !projectAlerts.all().isEmpty() && context.getMeasure(CoreMetrics.ALERT_STATUS) == null) {
       checkProjectAlerts(context);
     }
   }
index 4355b70cee0b6ef28af926d34276229872d1e2de..1be6f00867c1ca8ae7d1cabdb10a0396e1634f7d 100644 (file)
@@ -66,7 +66,7 @@ public class QualityGateVerifier implements Decorator {
 
   @DependedUpon
   public Metric generatesQualityGateStatus() {
-    return CoreMetrics.QUALITY_GATE_STATUS;
+    return CoreMetrics.ALERT_STATUS;
   }
 
   @DependsUpon
@@ -107,14 +107,14 @@ public class QualityGateVerifier implements Decorator {
         /*
          * This should probably be done only after migration from alerts
          */
-        //measure.setAlertStatus(level);
+        measure.setAlertStatus(level);
         String text = getText(condition, level);
         if (!StringUtils.isBlank(text)) {
-          //measure.setAlertText(text);
+          measure.setAlertText(text);
           labels.add(text);
         }
 
-        //context.saveMeasure(measure);
+        context.saveMeasure(measure);
 
         if (Metric.Level.WARN == level && globalLevel != Metric.Level.ERROR) {
           globalLevel = Metric.Level.WARN;
@@ -125,7 +125,7 @@ public class QualityGateVerifier implements Decorator {
       }
     }
 
-    Measure globalMeasure = new Measure(CoreMetrics.QUALITY_GATE_STATUS, globalLevel);
+    Measure globalMeasure = new Measure(CoreMetrics.ALERT_STATUS, globalLevel);
     globalMeasure.setAlertStatus(globalLevel);
     globalMeasure.setAlertText(StringUtils.join(labels, ", "));
     context.saveMeasure(globalMeasure);
index 543c7567948c493763017075628d1d1b0cba43ec..e05f86c7dc20e30e7092721710b69a2758eb8e1b 100644 (file)
@@ -129,6 +129,20 @@ public class LegacyQualityGateVerifierTest {
     verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
   }
 
+  @Test
+  public void not_run_when_alert_status_already_set() {
+    projectAlerts.addAll(Lists.newArrayList(
+      new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20"),
+      new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_GREATER, null, "35.0")));
+    when(context.getMeasure(CoreMetrics.ALERT_STATUS)).thenReturn(mock(Measure.class));
+
+    verifier.decorate(project, context);
+
+    verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.ALERT_STATUS, Metric.Level.OK.toString())));
+    verify(context, never()).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
+    verify(context, never()).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
+  }
+
   @Test
   public void check_root_modules_only() {
     projectAlerts.addAll(Lists.newArrayList(
index 4d770de9b3da55f44f1bd3fee450c93d7ab3d133..37306b8557fa6f82915c7d81158b6649dbebdfd1 100644 (file)
@@ -106,7 +106,7 @@ public class QualityGateVerifierTest {
 
   @Test
   public void generates_quality_gates_status() {
-    assertThat(verifier.generatesQualityGateStatus()).isEqualTo(CoreMetrics.QUALITY_GATE_STATUS);
+    assertThat(verifier.generatesQualityGateStatus()).isEqualTo(CoreMetrics.ALERT_STATUS);
   }
 
   @Test
@@ -129,9 +129,9 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.OK.toString())));
-    //verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.ALERT_STATUS, Metric.Level.OK.toString())));
+    verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
   }
 
   @Test
@@ -155,10 +155,10 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, null)));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, null)));
 
-    //verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.WARN)));
+    verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.WARN)));
 
   }
 
@@ -171,10 +171,10 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, null)));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, null)));
 
-    //verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.WARN)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.ERROR)));
+    verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.WARN)));
+    verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.ERROR)));
   }
 
   @Test
@@ -188,7 +188,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes < 10000, Coverages < 50.0")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "Classes < 10000, Coverages < 50.0")));
   }
 
   @Test
@@ -203,7 +203,7 @@ public class QualityGateVerifierTest {
     when(qualityGate.conditions()).thenReturn(conditions);
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "THE RATING < 10")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "THE RATING < 10")));
   }
 
   @Test
@@ -218,7 +218,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes < 10000")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "Classes < 10000")));
   }
 
   @Test
@@ -238,11 +238,11 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.OK, null)));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.OK, null)));
 
-    //verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureComplexity, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(hasLevel(measureComplexity, Metric.Level.OK)));
   }
 
   @Test
@@ -263,11 +263,11 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, null)));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, null)));
 
-    //verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.WARN)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.WARN)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureComplexity, Metric.Level.WARN)));
+    verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.WARN)));
+    verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.WARN)));
+    verify(context).saveMeasure(argThat(hasLevel(measureComplexity, Metric.Level.WARN)));
   }
 
   @Test
@@ -280,8 +280,8 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.OK, null)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.OK, null)));
+    verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
   }
 
   @Test
@@ -298,8 +298,8 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.OK, null)));
-    //verify(context).saveMeasure(argThat(hasLevel(measureRatingMetric, Metric.Level.OK)));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.OK, null)));
+    verify(context).saveMeasure(argThat(hasLevel(measureRatingMetric, Metric.Level.OK)));
   }
 
   @Test(expected = IllegalStateException.class)
@@ -343,7 +343,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "Classes variation > 30 since someday")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, "Classes variation > 30 since someday")));
   }
 
   @Test
@@ -365,7 +365,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "New Measure > 30 since someday")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, "New Measure > 30 since someday")));
   }
 
   @Test
@@ -381,7 +381,7 @@ public class QualityGateVerifierTest {
     when(qualityGate.conditions()).thenReturn(conditions);
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "The Debt < 1h")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "The Debt < 1h")));
   }
 
   private ArgumentMatcher<Measure> matchesMetric(final Metric metric, final Metric.Level alertStatus, final String alertText) {
index 9ab27ebde59f006f85ff7faef9ca89a381375d4e..655bcb73149bc61dc5213d42e4fd8d5361b980ba 100644 (file)
@@ -2210,14 +2210,6 @@ public final class CoreMetrics {
     .setDomain(DOMAIN_GENERAL)
     .create();
 
-  public static final String QUALITY_GATE_STATUS_KEY = "quality_gate_status";
-  public static final Metric QUALITY_GATE_STATUS = new Metric.Builder(QUALITY_GATE_STATUS_KEY, "Quality Gate Status", Metric.ValueType.LEVEL)
-    .setDescription("The project status with regard to it's quality thresholds.")
-    .setDirection(Metric.DIRECTION_BETTER)
-    .setQualitative(true)
-    .setDomain(DOMAIN_GENERAL)
-    .create();
-
   public static final String PROFILE_KEY = "profile";
   public static final Metric PROFILE = new Metric.Builder(PROFILE_KEY, "Profile", Metric.ValueType.DATA)
     .setDescription("Selected quality profile")
index dc05cca8d630ce71723dafb46a5ce714cc35431e..ac33cd953dd3977001f7c5a9e632a6d9022aee27 100644 (file)
@@ -31,7 +31,7 @@ public class CoreMetricsTest {
   @Test
   public void shouldReadMetricsFromClassReflection() {
     List<Metric> metrics = CoreMetrics.getMetrics();
-    assertThat(metrics).hasSize(151);
+    assertThat(metrics).hasSize(150);
     assertThat(metrics).contains(CoreMetrics.NCLOC, CoreMetrics.DIRECTORIES);
   }
 }