Skip to content

Commit fa6e4ff

Browse files
committed
API review
1 parent 2cb03dd commit fa6e4ff

File tree

7 files changed

+130
-164
lines changed

7 files changed

+130
-164
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import java.io.InputStream;
2323
import java.io.Serializable;
24-
import java.util.Collection;
2524
import org.sonar.api.Beta;
2625
import org.sonar.api.SonarRuntime;
2726
import org.sonar.api.batch.fs.FileSystem;
@@ -37,6 +36,7 @@
3736
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
3837
import org.sonar.api.batch.sensor.issue.ExternalIssue;
3938
import org.sonar.api.batch.sensor.issue.Issue;
39+
import org.sonar.api.batch.sensor.issue.IssueResolution;
4040
import org.sonar.api.batch.sensor.issue.NewExternalIssue;
4141
import org.sonar.api.batch.sensor.issue.NewIssue;
4242
import org.sonar.api.batch.sensor.measure.Measure;
@@ -46,7 +46,7 @@
4646
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
4747
import org.sonar.api.config.Configuration;
4848
import org.sonar.api.config.Settings;
49-
import org.sonar.api.issue.SonarResolveData;
49+
import org.sonar.api.batch.sensor.issue.NewIssueResolution;
5050
import org.sonar.api.scanner.fs.InputProject;
5151
import org.sonar.api.scanner.sensor.ProjectSensor;
5252
import org.sonar.api.utils.Version;
@@ -309,10 +309,9 @@ public interface SensorContext {
309309
boolean isFeatureAvailable(String featureName);
310310

311311
/**
312-
* Register sonar-resolve annotations for a file.
313-
* @param inputFile the file containing the annotations
314-
* @param data the annotation data parsed from the file
312+
* Builder to create a new {@link IssueResolution}.
313+
* Don't forget to call {@link NewIssueResolution#save()} once all parameters are provided.
315314
* @since 13.5
316315
*/
317-
void addSonarResolveData(InputFile inputFile, Collection<SonarResolveData> data);
316+
NewIssueResolution newIssueResolution();
318317
}

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
@@ -28,6 +28,7 @@
2828
import org.sonar.api.batch.sensor.issue.Issue;
2929
import org.sonar.api.batch.sensor.measure.Measure;
3030
import org.sonar.api.batch.sensor.rule.AdHocRule;
31+
import org.sonar.api.batch.sensor.issue.IssueResolution;
3132
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
3233
import org.sonar.api.scanner.ScannerSide;
3334

@@ -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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 javax.annotation.CheckForNull;
24+
import org.sonar.api.batch.fs.InputFile;
25+
import org.sonar.api.batch.fs.TextRange;
26+
import org.sonar.api.rule.RuleKey;
27+
28+
/**
29+
* Represents a request to resolve one or more issues at a given location.
30+
*
31+
* @since 13.5
32+
*/
33+
public interface IssueResolution {
34+
35+
enum Status {ACCEPT, FALSE_POSITIVE}
36+
37+
@CheckForNull
38+
InputFile inputFile();
39+
40+
@CheckForNull
41+
TextRange textRange();
42+
43+
Status status();
44+
45+
Set<RuleKey> ruleKeys();
46+
47+
String comment();
48+
}
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#ACCEPT}.
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+
}

plugin-api/src/main/java/org/sonar/api/issue/SonarResolveData.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

plugin-api/src/test/java/org/sonar/api/issue/SonarResolveDataTest.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)