Skip to content

Commit c0d5ecb

Browse files
PLUGINAPI-189 Add new metrics
1 parent 98b2cff commit c0d5ecb

3 files changed

Lines changed: 175 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 13.6
44
* Deprecate `org.sonar.api.config.PropertyDefinitions`. Use `PropertyDefinition.builder(String)` to declare properties instead.
5+
* Add severity metric keys to `org.sonar.api.measures.CoreMetrics`:
6+
* MQR mode: `NEW_RELIABILITY_ISSUE_SEVERITY_KEY`, `NEW_SECURITY_ISSUE_SEVERITY_KEY`, `NEW_MAINTAINABILITY_ISSUE_SEVERITY_KEY`
7+
* Standard mode: `NEW_BUGS_SEVERITY_KEY`, `NEW_VULNERABILITIES_SEVERITY_KEY`, `NEW_CODE_SMELLS_SEVERITY_KEY`
8+
* Add `org.sonar.api.measures.SeverityValues` with integer constants for severity-based metric thresholds
59

610
## 13.5
711
* Introduce support for issue resolution from sensors:

plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,63 @@ public final class CoreMetrics {
10471047
.setDeleteHistoricalData(true)
10481048
.create();
10491049

1050+
/**
1051+
* @since 13.6
1052+
*/
1053+
public static final String NEW_RELIABILITY_ISSUE_SEVERITY_KEY = "new_reliability_issue_severity";
1054+
1055+
/**
1056+
* @since 13.6
1057+
*/
1058+
public static final Metric<Integer> NEW_RELIABILITY_ISSUE_SEVERITY = new Metric.Builder(NEW_RELIABILITY_ISSUE_SEVERITY_KEY,
1059+
"Reliability Issue Severity on New Code", Metric.ValueType.INT)
1060+
.setDescription("Worst severity of new reliability issues")
1061+
.setDomain(DOMAIN_RELIABILITY)
1062+
.setDirection(Metric.DIRECTION_WORST)
1063+
.setDeleteHistoricalData(true)
1064+
.setOptimizedBestValue(true)
1065+
.setBestValue((double) SeverityValues.NO_ISSUES)
1066+
.setWorstValue((double) SeverityValues.BLOCKER)
1067+
.create();
1068+
1069+
/**
1070+
* @since 13.6
1071+
*/
1072+
public static final String NEW_SECURITY_ISSUE_SEVERITY_KEY = "new_security_issue_severity";
1073+
1074+
/**
1075+
* @since 13.6
1076+
*/
1077+
public static final Metric<Integer> NEW_SECURITY_ISSUE_SEVERITY = new Metric.Builder(NEW_SECURITY_ISSUE_SEVERITY_KEY,
1078+
"Security Issue Severity on New Code", Metric.ValueType.INT)
1079+
.setDescription("Worst severity of new security issues")
1080+
.setDomain(DOMAIN_SECURITY)
1081+
.setDirection(Metric.DIRECTION_WORST)
1082+
.setDeleteHistoricalData(true)
1083+
.setOptimizedBestValue(true)
1084+
.setBestValue((double) SeverityValues.NO_ISSUES)
1085+
.setWorstValue((double) SeverityValues.BLOCKER)
1086+
.create();
1087+
1088+
/**
1089+
* @since 13.6
1090+
*/
1091+
public static final String NEW_MAINTAINABILITY_ISSUE_SEVERITY_KEY = "new_maintainability_issue_severity";
1092+
1093+
/**
1094+
* @since 13.6
1095+
*/
1096+
public static final Metric<Integer> NEW_MAINTAINABILITY_ISSUE_SEVERITY = new Metric.Builder(NEW_MAINTAINABILITY_ISSUE_SEVERITY_KEY,
1097+
"Maintainability Issue Severity on New Code", Metric.ValueType.INT)
1098+
.setDescription("Worst severity of new maintainability issues")
1099+
.setDomain(DOMAIN_MAINTAINABILITY)
1100+
.setDirection(Metric.DIRECTION_WORST)
1101+
.setDeleteHistoricalData(true)
1102+
.setOptimizedBestValue(true)
1103+
.setBestValue((double) SeverityValues.NO_ISSUES)
1104+
.setWorstValue((double) SeverityValues.BLOCKER)
1105+
.create();
1106+
10501107
/**
10511108
* @since 3.6
10521109
* @deprecated since 10.4. Use {@link #VIOLATIONS_KEY} instead.
@@ -1152,6 +1209,29 @@ public final class CoreMetrics {
11521209
.setDeleteHistoricalData(true)
11531210
.create();
11541211

1212+
/**
1213+
* SonarQube Quality Model
1214+
*
1215+
* @since 13.6
1216+
*/
1217+
public static final String NEW_CODE_SMELLS_SEVERITY_KEY = "new_code_smells_severity";
1218+
1219+
/**
1220+
* SonarQube Quality Model
1221+
*
1222+
* @since 13.6
1223+
*/
1224+
public static final Metric<Integer> NEW_CODE_SMELLS_SEVERITY = new Metric.Builder(NEW_CODE_SMELLS_SEVERITY_KEY,
1225+
"Code Smells Severity on New Code", Metric.ValueType.INT)
1226+
.setDescription("Worst severity of new code smell issues")
1227+
.setDomain(DOMAIN_MAINTAINABILITY)
1228+
.setDirection(Metric.DIRECTION_WORST)
1229+
.setDeleteHistoricalData(true)
1230+
.setOptimizedBestValue(true)
1231+
.setBestValue((double) SeverityValues.NO_ISSUES)
1232+
.setWorstValue((double) SeverityValues.BLOCKER)
1233+
.create();
1234+
11551235
/**
11561236
* SonarQube Quality Model
11571237
*
@@ -1195,6 +1275,28 @@ public final class CoreMetrics {
11951275
.setDeleteHistoricalData(true)
11961276
.create();
11971277

1278+
/**
1279+
* SonarQube Quality Model
1280+
*
1281+
* @since 13.6
1282+
*/
1283+
public static final String NEW_BUGS_SEVERITY_KEY = "new_bugs_severity";
1284+
1285+
/**
1286+
* SonarQube Quality Model
1287+
*
1288+
* @since 13.6
1289+
*/
1290+
public static final Metric<Integer> NEW_BUGS_SEVERITY = new Metric.Builder(NEW_BUGS_SEVERITY_KEY, "Bugs Severity on New Code", Metric.ValueType.INT)
1291+
.setDescription("Worst severity of new bug issues")
1292+
.setDomain(DOMAIN_RELIABILITY)
1293+
.setDirection(Metric.DIRECTION_WORST)
1294+
.setDeleteHistoricalData(true)
1295+
.setOptimizedBestValue(true)
1296+
.setBestValue((double) SeverityValues.NO_ISSUES)
1297+
.setWorstValue((double) SeverityValues.BLOCKER)
1298+
.create();
1299+
11981300
/**
11991301
* SonarQube Quality Model
12001302
*
@@ -1237,6 +1339,29 @@ public final class CoreMetrics {
12371339
.setDeleteHistoricalData(true)
12381340
.create();
12391341

1342+
/**
1343+
* SonarQube Quality Model
1344+
*
1345+
* @since 13.6
1346+
*/
1347+
public static final String NEW_VULNERABILITIES_SEVERITY_KEY = "new_vulnerabilities_severity";
1348+
1349+
/**
1350+
* SonarQube Quality Model
1351+
*
1352+
* @since 13.6
1353+
*/
1354+
public static final Metric<Integer> NEW_VULNERABILITIES_SEVERITY = new Metric.Builder(NEW_VULNERABILITIES_SEVERITY_KEY,
1355+
"Vulnerabilities Severity on New Code", Metric.ValueType.INT)
1356+
.setDescription("Worst severity of new vulnerability issues")
1357+
.setDomain(DOMAIN_SECURITY)
1358+
.setDirection(Metric.DIRECTION_WORST)
1359+
.setDeleteHistoricalData(true)
1360+
.setOptimizedBestValue(true)
1361+
.setBestValue((double) SeverityValues.NO_ISSUES)
1362+
.setWorstValue((double) SeverityValues.BLOCKER)
1363+
.create();
1364+
12401365
/**
12411366
* @since 7.8
12421367
*/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Sonar Plugin API
3+
* Copyright (C) SonarSource Sàrl
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.api.measures;
21+
22+
/**
23+
* Integer values that map to severity levels used by severity-based metrics.
24+
* Severities increase in numeric value; a higher value means a worse severity.
25+
*
26+
* <p>
27+
* When configuring a quality gate condition threshold in the UI, store the value
28+
* one less than the target level (e.g. {@code LOW - 1 = 9}) so that the
29+
* {@code GREATER_THAN} operator catches issues at or above that level.
30+
* </p>
31+
*
32+
* @since 13.6
33+
*/
34+
public final class SeverityValues {
35+
/** No issues present. */
36+
public static final int NO_ISSUES = 0;
37+
public static final int INFO = 5;
38+
public static final int LOW = 10;
39+
public static final int MEDIUM = 15;
40+
public static final int HIGH = 20;
41+
public static final int BLOCKER = 25;
42+
43+
private SeverityValues() {
44+
// constants only
45+
}
46+
}

0 commit comments

Comments
 (0)