]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4366 Fix display of conditions defined on deprecated (hidden) metrics
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 9 Apr 2014 15:37:18 +0000 (17:37 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 9 Apr 2014 15:37:24 +0000 (17:37 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-conditions-view.coffee
sonar-server/src/main/hbs/quality-gates/quality-gate-detail-condition.hbs
sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
sonar-server/src/main/less/quality-gates.less
sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java
sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java

index aff091a2fdd04ae2445195385c4304c495ea84db..8f699f7c755b1d2f4693f1bbcfd4febf66a14b03 100644 (file)
@@ -52,6 +52,7 @@ date=Date
 days=Days
 default=Default
 delete=Delete
+deprecated=Deprecated
 descending=Descending
 description=Description
 directories=Directories
index 7b76a55ae610080689b8bc9e5e346f2f01099cf6..c7d2e4dcd99e31061982a329fc9ec5190a786cb5 100644 (file)
@@ -54,6 +54,8 @@ define [
 
     groupedMetrics: ->
       metrics = @options.app.metrics
+      metrics = _.filter metrics, (metric) ->
+        !metric.hidden
       metrics = _.groupBy metrics, 'domain'
       metrics = _.map metrics, (metrics, domain) ->
         domain: domain, metrics: _.sortBy metrics, 'short_name'
index 572bdb2af799bde01a418afb75b0b72d30258be1..6ec2c6200f1015a687bf763d8b9d06428b68527e 100644 (file)
@@ -1,5 +1,8 @@
 <td nowrap>
   {{metric.name}}
+  {{#if metric.hidden}}
+    <span class="deprecated">{{t 'deprecated'}}</span>
+  {{/if}}
 </td>
 <td width="10%" nowrap>
   {{#if canEdit}}
index 17df95cedc797c6db87651f66cd5a947d7d7a982..c0682042c09236c1c4ab0935728c09195710b573 100644 (file)
@@ -229,7 +229,7 @@ public class QualityGates {
     return Collections2.filter(metricFinder.findAll(), new Predicate<Metric>() {
       @Override
       public boolean apply(Metric metric) {
-        return isAlertable(metric);
+        return isAvailableForInit(metric);
       }
     });
   }
@@ -284,8 +284,12 @@ public class QualityGates {
     }
   }
 
+  private boolean isAvailableForInit(Metric metric) {
+    return !metric.isDataType() && !CoreMetrics.ALERT_STATUS.equals(metric) && ValueType.RATING != metric.getType();
+  }
+
   private boolean isAlertable(Metric metric) {
-    return !metric.isDataType() && BooleanUtils.isFalse(metric.isHidden()) && !CoreMetrics.ALERT_STATUS.equals(metric) && ValueType.RATING != metric.getType();
+    return isAvailableForInit(metric) && BooleanUtils.isFalse(metric.isHidden());
   }
 
   private boolean isDefault(QualityGateDto qGate) {
index 5faf20aa64c58e8233d8f1db07dc5dcd3c58c9ed..ea7765f7921e25144402ebe407bcfbfb28011345 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.qualitygate.ws;
 
+import org.apache.commons.lang.BooleanUtils;
 import org.sonar.api.i18n.I18n;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.server.ws.Request;
@@ -46,6 +47,7 @@ public class QgateAppHandler implements RequestHandler {
       "create",
       "default",
       "delete",
+      "deprecated",
       "more",
       "name",
       "quality_gates.add_condition",
@@ -136,6 +138,7 @@ public class QgateAppHandler implements RequestHandler {
         .prop("name", metric.getName())
         .prop("type", metric.getType().toString())
         .prop("domain", metric.getDomain())
+        .prop("hidden", BooleanUtils.isNotFalse(metric.isHidden()))
       .endObject();
     }
     writer.endArray();
index 5901f29c35c23ce4a3c07c6cdc3ef36b0dfe8755..ab7bdebb504e33ae571f762601350b96fe40ae29 100644 (file)
   border: 1px solid #ddd;
   background-color: #efefef;
 }
+
+.quality-gate-conditions {
+  & .deprecated {
+    color: #777;
+    text-transform: lowercase;
+    font-variant: small-caps;
+  }
+}
\ No newline at end of file
index 6fa7412d47d0a9abb2583e674e3c4e78533b9a0f..435ed2c0a26d72f67a54dbb1e6e83509e3a63814 100644 (file)
@@ -569,6 +569,6 @@ public class QualityGatesTest {
     when(classicMetric.getType()).thenReturn(ValueType.BOOL);
     when(metricFinder.findAll()).thenReturn(ImmutableList.of(
       dataMetric, hiddenMetric, nullHiddenMetric, alertMetric, ratingMetric, classicMetric));
-    assertThat(qGates.gateMetrics()).hasSize(1).containsOnly(classicMetric);
+    assertThat(qGates.gateMetrics()).hasSize(3).containsOnly(classicMetric, hiddenMetric, nullHiddenMetric);
   }
 }
index dd5c8645817bc7774e77df4518b824441b3c5966..f46bb137b40d261c760ab892fcfc0a44a56f0da6 100644 (file)
@@ -79,6 +79,7 @@ public class QgateAppHandlerTest {
     when(metric.getName()).thenReturn("Metric");
     when(metric.getType()).thenReturn(ValueType.BOOL);
     when(metric.getDomain()).thenReturn("General");
+    when(metric.isHidden()).thenReturn(false);
     when(qGates.gateMetrics()).thenReturn(ImmutableList.of(metric));
 
     String json = tester.newRequest("app").execute().outputAsString();
@@ -88,12 +89,18 @@ public class QgateAppHandlerTest {
     Collection<Map> periods = (Collection<Map>) responseJson.get("periods");
     assertThat(periods).hasSize(3);
     Map messages = (Map) responseJson.get("messages");
-    assertThat(messages).isNotNull().isNotEmpty().hasSize(50);
+    assertThat(messages).isNotNull().isNotEmpty().hasSize(51);
     for (Entry message: (Set<Entry>) messages.entrySet()) {
       assertThat(message.getKey()).isEqualTo(message.getValue());
     }
     Collection<Map> metrics = (Collection<Map>) responseJson.get("metrics");
     assertThat(metrics).hasSize(1);
-    assertThat(metrics.iterator().next().get("key")).isEqualTo("metric");
+    Map metricMap = metrics.iterator().next();
+    assertThat(metricMap.get("id").toString()).isEqualTo("42");
+    assertThat(metricMap.get("key")).isEqualTo("metric");
+    assertThat(metricMap.get("name")).isEqualTo("Metric");
+    assertThat(metricMap.get("type")).isEqualTo("BOOL");
+    assertThat(metricMap.get("domain")).isEqualTo("General");
+    assertThat(metricMap.get("hidden")).isEqualTo(false);
   }
 }