From b7df67a2d8bed8bd01baf11368b26ac417a2868b Mon Sep 17 00:00:00 2001 From: Lukasz Jarocki Date: Mon, 28 Mar 2022 14:48:43 +0200 Subject: [PATCH] SONAR-16039 added new metric analysis_from_sonarqube_9_4 --- .../org/sonar/api/measures/CoreMetrics.java | 21 +++++++++++++++++++ .../java/org/sonar/api/measures/Metric.java | 2 +- .../sonar/api/resources/CoreMetricsTest.java | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index 59da67cd785..dcde928286b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.NoSuchElementException; import org.sonar.api.utils.SonarException; +import static org.sonar.api.measures.Metric.ValueType.BOOL; + /** * @since 1.10 */ @@ -1809,6 +1811,25 @@ public final class CoreMetrics { .setHidden(true) .create(); + /** + * @since 9.4 + */ + public static final String ANALYSIS_FROM_SONARQUBE_9_4_KEY = "analysis_from_sonarqube_9_4"; + + /** + * @since 9.4 + * + * This hidden metric that is only needed to fully fix the issue with identifying new issues when using reference branch + * that was haunting us in 9.3 and before. More details in the ticket SONAR-16039 + */ + public static final Metric ANALYSIS_FROM_SONARQUBE_9_4 = new Metric.Builder(ANALYSIS_FROM_SONARQUBE_9_4_KEY, + "Analysis From SonarQube 9.4", BOOL) + .setDescription("Indicates whether the analysis has been run after the upgrade to SonarQube 9.4. It affects how the issues " + + "will be detected for branches that use reference branch as the strategy for detecting new code.") + .setDomain(CoreMetrics.DOMAIN_ISSUES) + .setHidden(true) + .create(); + private static final List METRICS; static { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java index 4ebd3f6f3dc..c8fb2d55778 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java @@ -681,7 +681,7 @@ public class Metric implements Serializable, org.sonar.a } /** - * Sets whether the metric should be hidden in Web UI (e.g. in Time Machine). Default is false. + * Sets whether the metric should be hidden in Web UI. Default is false. * * @param b true if the metric should be hidden. * @return the builder diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java index c7e171ea1b6..647cd3afad9 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java @@ -51,4 +51,10 @@ public class CoreMetricsTest { assertThatThrownBy(() -> getMetric("unknown")) .isInstanceOf(NoSuchElementException.class); } + + @Test + public void someMetricsAreMeantToBeHidden() { + Metric metric = getMetric("analysis_from_sonarqube_9_4"); + assertThat(metric.isHidden()).isTrue(); + } } -- 2.39.5