From: Jean-Baptiste Lievremont Date: Wed, 9 Apr 2014 15:37:18 +0000 (+0200) Subject: SONAR-4366 Fix display of conditions defined on deprecated (hidden) metrics X-Git-Tag: 4.3~75 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7fbccc246de0a2629eed933e2b9ede0d678ef4dd;p=sonarqube.git SONAR-4366 Fix display of conditions defined on deprecated (hidden) metrics --- diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index aff091a2fdd..8f699f7c755 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -52,6 +52,7 @@ date=Date days=Days default=Default delete=Delete +deprecated=Deprecated descending=Descending description=Description directories=Directories diff --git a/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-conditions-view.coffee b/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-conditions-view.coffee index 7b76a55ae61..c7d2e4dcd99 100644 --- a/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-conditions-view.coffee +++ b/sonar-server/src/main/coffee/quality-gate/views/quality-gate-detail-conditions-view.coffee @@ -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' diff --git a/sonar-server/src/main/hbs/quality-gates/quality-gate-detail-condition.hbs b/sonar-server/src/main/hbs/quality-gates/quality-gate-detail-condition.hbs index 572bdb2af79..6ec2c6200f1 100644 --- a/sonar-server/src/main/hbs/quality-gates/quality-gate-detail-condition.hbs +++ b/sonar-server/src/main/hbs/quality-gates/quality-gate-detail-condition.hbs @@ -1,5 +1,8 @@ {{metric.name}} + {{#if metric.hidden}} + {{t 'deprecated'}} + {{/if}} {{#if canEdit}} diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java index 17df95cedc7..c0682042c09 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java +++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java @@ -229,7 +229,7 @@ public class QualityGates { return Collections2.filter(metricFinder.findAll(), new Predicate() { @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) { diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java index 5faf20aa64c..ea7765f7921 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java @@ -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(); diff --git a/sonar-server/src/main/less/quality-gates.less b/sonar-server/src/main/less/quality-gates.less index 5901f29c35c..ab7bdebb504 100644 --- a/sonar-server/src/main/less/quality-gates.less +++ b/sonar-server/src/main/less/quality-gates.less @@ -104,3 +104,11 @@ 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 diff --git a/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java b/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java index 6fa7412d47d..435ed2c0a26 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java @@ -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); } } diff --git a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java index dd5c8645817..f46bb137b40 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java @@ -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 periods = (Collection) 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) messages.entrySet()) { assertThat(message.getKey()).isEqualTo(message.getValue()); } Collection metrics = (Collection) 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); } }