Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 13.6
* Deprecate `org.sonar.api.config.PropertyDefinitions`. Use `PropertyDefinition.builder(String)` to declare properties instead.
* Add severity metric keys to `org.sonar.api.measures.CoreMetrics`:
Comment thread
OrlovAlexander85 marked this conversation as resolved.
* MQR mode: `NEW_RELIABILITY_ISSUE_SEVERITY_KEY`, `NEW_SECURITY_ISSUE_SEVERITY_KEY`, `NEW_MAINTAINABILITY_ISSUE_SEVERITY_KEY`
* Standard mode: `NEW_BUGS_SEVERITY_KEY`, `NEW_VULNERABILITIES_SEVERITY_KEY`, `NEW_CODE_SMELLS_SEVERITY_KEY`
* Add `org.sonar.api.measures.SeverityValues` with integer constants for severity-based metric thresholds

## 13.5
* Introduce support for issue resolution from sensors:
Expand Down
125 changes: 125 additions & 0 deletions plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,63 @@ public final class CoreMetrics {
.setDeleteHistoricalData(true)
.create();

/**
* @since 13.6
*/
public static final String NEW_RELIABILITY_ISSUE_SEVERITY_KEY = "new_reliability_issue_severity";
Comment thread
OrlovAlexander85 marked this conversation as resolved.

/**
* @since 13.6
*/
public static final Metric<Integer> NEW_RELIABILITY_ISSUE_SEVERITY = new Metric.Builder(NEW_RELIABILITY_ISSUE_SEVERITY_KEY,
"Reliability Issue Severity on New Code", Metric.ValueType.INT)
.setDescription("Worst severity of new reliability issues")
.setDomain(DOMAIN_RELIABILITY)
.setDirection(Metric.DIRECTION_WORST)
.setDeleteHistoricalData(true)
.setOptimizedBestValue(true)
.setBestValue((double) SeverityValues.NO_ISSUES)
.setWorstValue((double) SeverityValues.BLOCKER)
.create();

/**
* @since 13.6
*/
public static final String NEW_SECURITY_ISSUE_SEVERITY_KEY = "new_security_issue_severity";

/**
* @since 13.6
*/
public static final Metric<Integer> NEW_SECURITY_ISSUE_SEVERITY = new Metric.Builder(NEW_SECURITY_ISSUE_SEVERITY_KEY,
"Security Issue Severity on New Code", Metric.ValueType.INT)
.setDescription("Worst severity of new security issues")
.setDomain(DOMAIN_SECURITY)
.setDirection(Metric.DIRECTION_WORST)
.setDeleteHistoricalData(true)
.setOptimizedBestValue(true)
.setBestValue((double) SeverityValues.NO_ISSUES)
.setWorstValue((double) SeverityValues.BLOCKER)
.create();

/**
* @since 13.6
*/
public static final String NEW_MAINTAINABILITY_ISSUE_SEVERITY_KEY = "new_maintainability_issue_severity";

/**
* @since 13.6
*/
public static final Metric<Integer> NEW_MAINTAINABILITY_ISSUE_SEVERITY = new Metric.Builder(NEW_MAINTAINABILITY_ISSUE_SEVERITY_KEY,
"Maintainability Issue Severity on New Code", Metric.ValueType.INT)
.setDescription("Worst severity of new maintainability issues")
.setDomain(DOMAIN_MAINTAINABILITY)
.setDirection(Metric.DIRECTION_WORST)
.setDeleteHistoricalData(true)
.setOptimizedBestValue(true)
.setBestValue((double) SeverityValues.NO_ISSUES)
.setWorstValue((double) SeverityValues.BLOCKER)
.create();

/**
* @since 3.6
* @deprecated since 10.4. Use {@link #VIOLATIONS_KEY} instead.
Expand Down Expand Up @@ -1152,6 +1209,29 @@ public final class CoreMetrics {
.setDeleteHistoricalData(true)
.create();

/**
* SonarQube Quality Model
*
* @since 13.6
*/
public static final String NEW_CODE_SMELLS_SEVERITY_KEY = "new_code_smells_severity";

/**
* SonarQube Quality Model
*
* @since 13.6
*/
public static final Metric<Integer> NEW_CODE_SMELLS_SEVERITY = new Metric.Builder(NEW_CODE_SMELLS_SEVERITY_KEY,
"Code Smells Severity on New Code", Metric.ValueType.INT)
.setDescription("Worst severity of new code smell issues")
.setDomain(DOMAIN_MAINTAINABILITY)
.setDirection(Metric.DIRECTION_WORST)
.setDeleteHistoricalData(true)
.setOptimizedBestValue(true)
.setBestValue((double) SeverityValues.NO_ISSUES)
.setWorstValue((double) SeverityValues.BLOCKER)
.create();

/**
* SonarQube Quality Model
*
Expand Down Expand Up @@ -1195,6 +1275,28 @@ public final class CoreMetrics {
.setDeleteHistoricalData(true)
.create();

/**
* SonarQube Quality Model
*
* @since 13.6
*/
public static final String NEW_BUGS_SEVERITY_KEY = "new_bugs_severity";

/**
* SonarQube Quality Model
*
* @since 13.6
*/
public static final Metric<Integer> NEW_BUGS_SEVERITY = new Metric.Builder(NEW_BUGS_SEVERITY_KEY, "Bugs Severity on New Code", Metric.ValueType.INT)
.setDescription("Worst severity of new bug issues")
.setDomain(DOMAIN_RELIABILITY)
.setDirection(Metric.DIRECTION_WORST)
.setDeleteHistoricalData(true)
.setOptimizedBestValue(true)
.setBestValue((double) SeverityValues.NO_ISSUES)
.setWorstValue((double) SeverityValues.BLOCKER)
.create();

/**
* SonarQube Quality Model
*
Expand Down Expand Up @@ -1237,6 +1339,29 @@ public final class CoreMetrics {
.setDeleteHistoricalData(true)
.create();

/**
* SonarQube Quality Model
*
* @since 13.6
*/
public static final String NEW_VULNERABILITIES_SEVERITY_KEY = "new_vulnerabilities_severity";

/**
* SonarQube Quality Model
*
* @since 13.6
*/
public static final Metric<Integer> NEW_VULNERABILITIES_SEVERITY = new Metric.Builder(NEW_VULNERABILITIES_SEVERITY_KEY,
"Vulnerabilities Severity on New Code", Metric.ValueType.INT)
.setDescription("Worst severity of new vulnerability issues")
.setDomain(DOMAIN_SECURITY)
.setDirection(Metric.DIRECTION_WORST)
.setDeleteHistoricalData(true)
.setOptimizedBestValue(true)
.setBestValue((double) SeverityValues.NO_ISSUES)
.setWorstValue((double) SeverityValues.BLOCKER)
.create();

/**
* @since 7.8
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Sonar Plugin API
* Copyright (C) SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.measures;

/**
* Integer values that map to severity levels used by severity-based metrics.
* Severities increase in numeric value; a higher value means a worse severity.
*
* <p>
* When configuring a quality gate condition threshold in the UI, store the value
* one less than the target level (e.g. {@code LOW - 1 = 9}) so that the
* {@code GREATER_THAN} operator catches issues at or above that level.
* </p>
*
* @since 13.6
*/
public final class SeverityValues {
Comment thread
OrlovAlexander85 marked this conversation as resolved.
/** No issues present. */
public static final int NO_ISSUES = 0;
public static final int INFO = 5;
public static final int LOW = 10;
public static final int MEDIUM = 15;
public static final int HIGH = 20;
public static final int BLOCKER = 25;
Comment thread
OrlovAlexander85 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library is used in all our products, we need to add mapping with RuleSeverity and ImpactSeverity here.

private SeverityValues() {
// constants only
}
}
Loading