aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2022-03-28 14:48:43 +0200
committersonartech <sonartech@sonarsource.com>2022-03-31 20:02:59 +0000
commitb7df67a2d8bed8bd01baf11368b26ac417a2868b (patch)
tree9c9e9f226afcb908dbd2c10eb36e6bd4bdca6eb1
parentbce6add11a177ce8839ef9d4c7e29c7869a243ec (diff)
downloadsonarqube-b7df67a2d8bed8bd01baf11368b26ac417a2868b.tar.gz
sonarqube-b7df67a2d8bed8bd01baf11368b26ac417a2868b.zip
SONAR-16039 added new metric analysis_from_sonarqube_9_4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/CoreMetricsTest.java6
3 files changed, 28 insertions, 1 deletions
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<Integer> 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<Metric> 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<G extends Serializable> 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();
+ }
}