diff --git a/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java b/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java index bb30006f1..c64f3d172 100644 --- a/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java +++ b/src/main/java/edu/hm/hafner/analysis/IssueBuilder.java @@ -3,6 +3,7 @@ import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; @@ -623,8 +624,13 @@ private static boolean isAbsolutePath(final String stringPath) { catch (URISyntaxException e) { // Catch and ignore as system paths are not URI and we need to check them separately. } - Path path = Paths.get(stringPath); - return path.isAbsolute(); + try { + Path path = Paths.get(stringPath); + return path.isAbsolute(); + } + catch (InvalidPathException e) { + return true; + } } private static String normalizeFileName(@CheckForNull final String platformFileName) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java b/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java index 35d68f943..05f50773d 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/ClangParser.java @@ -18,7 +18,7 @@ public class ClangParser extends LookaheadParser { private static final long serialVersionUID = -3015592762345283182L; - private static final String CLANG_WARNING_PATTERN = "^\\s*(?:\\d+%)?([^%]*?):(\\d+):(?:(\\d+):)?" + "(?:" + private static final String CLANG_WARNING_PATTERN = "^\\s*(?:\\d+%)?(C\\/C\\+\\+: )?([^%]*?):(\\d+):(?:(\\d+):)?" + "(?:" + "(?:\\{\\d+:\\d+-\\d+:\\d+\\})+:)?\\s*(warning|[^\\[\\]]*error):" + "\\s*(.*?)(?:\\[([^\\[]*)\\])?$"; private static final Pattern IGNORE_FORMAT = Pattern.compile("^-\\[.*\\].*$"); @@ -32,17 +32,17 @@ public ClangParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - String message = matcher.group(5); + String message = matcher.group(6); if (IGNORE_FORMAT.matcher(message).matches()) { return Optional.empty(); } - return builder.setFileName(matcher.group(1)) - .setLineStart(matcher.group(2)) - .setColumnStart(matcher.group(3)) - .setCategory(matcher.group(6)) + return builder.setFileName(matcher.group(2)) + .setLineStart(matcher.group(3)) + .setColumnStart(matcher.group(4)) + .setCategory(matcher.group(7)) .setMessage(message) - .setSeverity(mapPriority(matcher.group(4))) + .setSeverity(mapPriority(matcher.group(5))) .buildOptional(); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java index 53093dcca..ff0fc6e75 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/ClangParserTest.java @@ -196,4 +196,38 @@ void issue14333() { .hasSeverity(Severity.WARNING_NORMAL); } } + + @Test + void assertThatClangPathsAreCorrectForAllPlatforms() { + Report warnings = parse("llvm-clang.txt"); + + assertThat(warnings).hasSize(3); + + try (SoftAssertions softly = new SoftAssertions()) { + softly.assertThat(warnings.get(0)).hasLineStart(35) + .hasLineEnd(35) + .hasColumnStart(15) + .hasColumnEnd(15) + .hasMessage("unused parameter 'parameter1'") + .hasFileName("/project/src/cpp/MyClass.cpp") + .hasCategory("-Wunused-parameter") + .hasSeverity(Severity.WARNING_NORMAL); + softly.assertThat(warnings.get(1)).hasLineStart(35) + .hasLineEnd(35) + .hasColumnStart(15) + .hasColumnEnd(15) + .hasMessage("unused parameter 'parameter1'") + .hasFileName("C:/project/src/cpp/MyClass.cpp") + .hasCategory("-Wunused-parameter") + .hasSeverity(Severity.WARNING_NORMAL); + softly.assertThat(warnings.get(2)).hasLineStart(35) + .hasLineEnd(35) + .hasColumnStart(15) + .hasColumnEnd(15) + .hasMessage("unused parameter 'parameter1'") + .hasFileName("MyClass.cpp") + .hasCategory("-Wunused-parameter") + .hasSeverity(Severity.WARNING_NORMAL); + } + } } diff --git a/src/test/resources/edu/hm/hafner/analysis/parser/llvm-clang.txt b/src/test/resources/edu/hm/hafner/analysis/parser/llvm-clang.txt new file mode 100644 index 000000000..3989b74ea --- /dev/null +++ b/src/test/resources/edu/hm/hafner/analysis/parser/llvm-clang.txt @@ -0,0 +1,5 @@ +C/C++: /project/src/cpp/MyClass.cpp:35:15: warning: unused parameter 'parameter1' [-Wunused-parameter] + +C/C++: C:\project\src\cpp\MyClass.cpp:35:15: warning: unused parameter 'parameter1' [-Wunused-parameter] + +C/C++: MyClass.cpp:35:15: warning: unused parameter 'parameter1' [-Wunused-parameter] \ No newline at end of file