Skip to content

Commit 831457f

Browse files
authored
resolve files relative to clippy report (#35)
1 parent bd825c5 commit 831457f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/clippy/ClippyJsonReportReader.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import javax.annotation.Nullable;
2424
import java.io.*;
25+
import java.nio.file.Paths;
2526
import java.util.stream.Stream;
2627
import java.util.function.Consumer;
2728

@@ -34,6 +35,7 @@
3435

3536
public class ClippyJsonReportReader {
3637
private final JSONParser jsonParser = new JSONParser();
38+
private final String projectDir;
3739
private final Consumer<ClippyIssue> consumer;
3840
private static final String RESULTS = "results";
3941
private static final String BEGINJSON = "{\"" + RESULTS + "\": [";
@@ -60,12 +62,13 @@ public static class ClippyIssue {
6062
String severity;
6163
}
6264

63-
private ClippyJsonReportReader(Consumer<ClippyIssue> consumer) {
65+
private ClippyJsonReportReader(String projectDir, Consumer<ClippyIssue> consumer) {
66+
this.projectDir = projectDir;
6467
this.consumer = consumer;
6568
}
6669

67-
static void read(InputStream in, Consumer<ClippyIssue> consumer) throws IOException, ParseException {
68-
new ClippyJsonReportReader(consumer).read(in);
70+
static void read(InputStream in, String projectDir, Consumer<ClippyIssue> consumer) throws IOException, ParseException {
71+
new ClippyJsonReportReader(projectDir, consumer).read(in);
6972
}
7073

7174
private void read(InputStream in) throws IOException, ParseException {
@@ -93,7 +96,7 @@ private void onResult(JSONObject result) {
9396
if ((spans == null) || spans.isEmpty()) return; //Exit silently when JSON is not compliant
9497

9598
JSONObject span = (JSONObject) spans.get(0);
96-
clippyIssue.filePath = (String) span.get("file_name");
99+
clippyIssue.filePath = Paths.get(this.projectDir, (String) span.get("file_name")).toString();
97100
clippyIssue.message = (String) message.get(MESSAGE);
98101
JSONArray children = (JSONArray) message.get("children");
99102

community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/clippy/ClippySensor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ private void importReport(File rawReport, SensorContext context, Set<String> unr
6565

6666
try {
6767
InputStream in = ClippyJsonReportReader.toJSON(rawReport);
68-
ClippyJsonReportReader.read(in, clippyIssue -> saveIssue(context, clippyIssue, unresolvedInputFiles));
68+
String projectDir = rawReport.getParent();
69+
ClippyJsonReportReader.read(in, projectDir, clippyIssue -> saveIssue(context, clippyIssue, unresolvedInputFiles));
6970
} catch (IOException | ParseException e) {
7071
LOG.error("No issues information will be saved as the report file '{}' can't be read. " +
7172
e.getClass().getSimpleName() + ": " + e.getMessage(), rawReport, e);

0 commit comments

Comments
 (0)