diff --git a/CHANGELOG.md b/CHANGELOG.md index d7df2fa2..1024b560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 13.5 +* Introduce support for issue resolution from sensors: + * Introduce `org.sonar.api.batch.sensor.issue.NewIssueResolution` + * Introduce `org.sonar.api.batch.sensor.issue.IssueResolution` + * Introduce `org.sonar.api.batch.sensor.SensorContext.newIssueResolution()` + * Introduce `org.sonar.api.batch.sensor.internal.SensorStorage.store(IssueResolution)` + ## 13.4 * Add `org.sonar.api.a3s.A3SContextCollector` (internal SonarSource usage) diff --git a/plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index 56a6a01d..fbef54bf 100644 --- a/plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -36,8 +36,10 @@ import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.issue.ExternalIssue; import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.issue.IssueResolution; import org.sonar.api.batch.sensor.issue.NewExternalIssue; import org.sonar.api.batch.sensor.issue.NewIssue; +import org.sonar.api.batch.sensor.issue.NewIssueResolution; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.NewMeasure; import org.sonar.api.batch.sensor.rule.AdHocRule; @@ -305,4 +307,11 @@ public interface SensorContext { */ @Beta boolean isFeatureAvailable(String featureName); + + /** + * Builder to create a new {@link IssueResolution}. + * Don't forget to call {@link NewIssueResolution#save()} once all parameters are provided. + * @since 13.5 + */ + NewIssueResolution newIssueResolution(); } diff --git a/plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java b/plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java index 73d2a001..519ccac5 100644 --- a/plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java +++ b/plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java @@ -26,6 +26,7 @@ import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.issue.ExternalIssue; import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.issue.IssueResolution; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.rule.AdHocRule; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; @@ -82,4 +83,9 @@ public interface SensorStorage { * @since 7.2 */ void store(NewSignificantCode significantCode); + + /** + * @since 13.5 + */ + void store(IssueResolution issueResolution); } diff --git a/plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueResolution.java b/plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueResolution.java new file mode 100644 index 00000000..f4bd0f08 --- /dev/null +++ b/plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueResolution.java @@ -0,0 +1,45 @@ +/* + * Sonar Plugin API + * Copyright (C) 2009-2025 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.batch.sensor.issue; + +import java.util.Set; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.TextRange; +import org.sonar.api.rule.RuleKey; + +/** + * Represents a request to resolve one or more issues at a given location. + * + * @since 13.5 + */ +public interface IssueResolution { + + enum Status {DEFAULT, FALSE_POSITIVE} + + InputFile inputFile(); + + TextRange textRange(); + + Status status(); + + Set ruleKeys(); + + String comment(); +} diff --git a/plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssueResolution.java b/plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssueResolution.java new file mode 100644 index 00000000..18b3adf1 --- /dev/null +++ b/plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssueResolution.java @@ -0,0 +1,64 @@ +/* + * Sonar Plugin API + * Copyright (C) 2009-2025 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.batch.sensor.issue; + +import java.util.Collection; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.TextRange; +import org.sonar.api.rule.RuleKey; + +/** + * Builder for an {@link IssueResolution}. Use {@code context.newIssueResolution()} to create. + * {@link #save()} should be called once all parameters are provided. + * + * @since 13.5 + */ +public interface NewIssueResolution { + + /** + * Set the target file. + */ + NewIssueResolution on(InputFile inputFile); + + /** + * Set the target text range within the file. + */ + NewIssueResolution at(TextRange textRange); + + /** + * Set the resolution status. Defaults to {@link IssueResolution.Status#DEFAULT}. + */ + NewIssueResolution status(IssueResolution.Status status); + + /** + * Set the target rule keys. At least one rule key is required. + */ + NewIssueResolution forRules(Collection ruleKeys); + + /** + * Set a justification comment. Required. + */ + NewIssueResolution comment(String comment); + + /** + * Save the issue resolution. + */ + void save(); +}