Skip to content

Commit aaecf71

Browse files
committed
PLUGINAPI-180 New API for issue resolution
1 parent 7136815 commit aaecf71

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 13.5
4+
* Introduce support for issue resolution from sensors:
5+
* Introduce `org.sonar.api.batch.sensor.issue.NewIssueResolution`
6+
* Introduce `org.sonar.api.batch.sensor.issue.IssueResolution`
7+
* Introduce `org.sonar.api.batch.sensor.SensorContext.newIssueResolution()`
8+
* Introduce `org.sonar.api.batch.sensor.internal.SensorStorage.store(IssueResolution)`
9+
310
## 13.4
411
* Add `org.sonar.api.a3s.A3SContextCollector` (internal SonarSource usage)
512

plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
3737
import org.sonar.api.batch.sensor.issue.ExternalIssue;
3838
import org.sonar.api.batch.sensor.issue.Issue;
39+
import org.sonar.api.batch.sensor.issue.IssueResolution;
3940
import org.sonar.api.batch.sensor.issue.NewExternalIssue;
4041
import org.sonar.api.batch.sensor.issue.NewIssue;
42+
import org.sonar.api.batch.sensor.issue.NewIssueResolution;
4143
import org.sonar.api.batch.sensor.measure.Measure;
4244
import org.sonar.api.batch.sensor.measure.NewMeasure;
4345
import org.sonar.api.batch.sensor.rule.AdHocRule;
@@ -305,4 +307,11 @@ public interface SensorContext {
305307
*/
306308
@Beta
307309
boolean isFeatureAvailable(String featureName);
310+
311+
/**
312+
* Builder to create a new {@link IssueResolution}.
313+
* Don't forget to call {@link NewIssueResolution#save()} once all parameters are provided.
314+
* @since 13.5
315+
*/
316+
NewIssueResolution newIssueResolution();
308317
}

plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
2727
import org.sonar.api.batch.sensor.issue.ExternalIssue;
2828
import org.sonar.api.batch.sensor.issue.Issue;
29+
import org.sonar.api.batch.sensor.issue.IssueResolution;
2930
import org.sonar.api.batch.sensor.measure.Measure;
3031
import org.sonar.api.batch.sensor.rule.AdHocRule;
3132
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
@@ -82,4 +83,9 @@ public interface SensorStorage {
8283
* @since 7.2
8384
*/
8485
void store(NewSignificantCode significantCode);
86+
87+
/**
88+
* @since 13.5
89+
*/
90+
void store(IssueResolution issueResolution);
8591
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Sonar Plugin API
3+
* Copyright (C) 2009-2025 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.batch.sensor.issue;
21+
22+
import java.util.Set;
23+
import org.sonar.api.batch.fs.InputFile;
24+
import org.sonar.api.batch.fs.TextRange;
25+
import org.sonar.api.rule.RuleKey;
26+
27+
/**
28+
* Represents a request to resolve one or more issues at a given location.
29+
*
30+
* @since 13.5
31+
*/
32+
public interface IssueResolution {
33+
34+
enum Status {DEFAULT, FALSE_POSITIVE}
35+
36+
InputFile inputFile();
37+
38+
TextRange textRange();
39+
40+
Status status();
41+
42+
Set<RuleKey> ruleKeys();
43+
44+
String comment();
45+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Sonar Plugin API
3+
* Copyright (C) 2009-2025 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.batch.sensor.issue;
21+
22+
import java.util.Collection;
23+
import org.sonar.api.batch.fs.InputFile;
24+
import org.sonar.api.batch.fs.TextRange;
25+
import org.sonar.api.rule.RuleKey;
26+
27+
/**
28+
* Builder for an {@link IssueResolution}. Use {@code context.newIssueResolution()} to create.
29+
* {@link #save()} should be called once all parameters are provided.
30+
*
31+
* @since 13.5
32+
*/
33+
public interface NewIssueResolution {
34+
35+
/**
36+
* Set the target file.
37+
*/
38+
NewIssueResolution on(InputFile inputFile);
39+
40+
/**
41+
* Set the target text range within the file.
42+
*/
43+
NewIssueResolution at(TextRange textRange);
44+
45+
/**
46+
* Set the resolution status. Defaults to {@link IssueResolution.Status#DEFAULT}.
47+
*/
48+
NewIssueResolution status(IssueResolution.Status status);
49+
50+
/**
51+
* Set the target rule keys. At least one rule key is required.
52+
*/
53+
NewIssueResolution forRules(Collection<RuleKey> ruleKeys);
54+
55+
/**
56+
* Set a justification comment. Required.
57+
*/
58+
NewIssueResolution comment(String comment);
59+
60+
/**
61+
* Save the issue resolution.
62+
*/
63+
void save();
64+
}

0 commit comments

Comments
 (0)