Skip to content

Commit

Permalink
Fix parsing for mixture of Kotlin and CMake output
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisBauer committed Dec 22, 2023
1 parent 93172ec commit 2259f63
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SUPPORTED-FORMATS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--- DO NOT EDIT -- Generated at 2023-11-20T16:59:30.040364100 - Run the `main` method of `ParserRegistry` to regenerate after changing parsers -- DO NOT EDIT --->
<!--- DO NOT EDIT -- Generated at 2023-12-22T10:09:01.965874 - Run the `main` method of `ParserRegistry` to regenerate after changing parsers -- DO NOT EDIT --->
# Supported Report Formats

The static analysis model supports the following report formats.
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/IssueBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package edu.hm.hafner.analysis;

import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.UUID;

Expand Down Expand Up @@ -142,6 +146,9 @@ TreeString internFileName(@CheckForNull final String unsafeFileName) {
return UNDEFINED_TREE_STRING;
}
else {
if (directory != null && isAbsolutePath(normalizeFileName(unsafeFileName))) {
return fileNameBuilder.intern(normalizeFileName(unsafeFileName));
}
return fileNameBuilder.intern(normalizeFileName(
new PathUtil().createAbsolutePath(directory, unsafeFileName)));
}
Expand Down Expand Up @@ -578,6 +585,22 @@ private void clean() {
additionalProperties = null;
}

private static boolean isAbsolutePath(final String stringPath) {
try {
URI uri = new URI(stringPath);
if (uri.isAbsolute()) {
return true;
}
}
catch (URISyntaxException e) {
}
Path path = Paths.get(stringPath);
if (path.isAbsolute()) {
return true;
}
return false;
}

private static String normalizeFileName(@CheckForNull final String platformFileName) {
return defaultString(StringUtils.replace(
StringUtils.strip(platformFileName), "\\", "/"));
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,16 @@ void kotlin18WarningStyle() {
.hasFileName("file:///project/src/main/java/com/app/ui/model/Activity.kt")
.hasMessage("'PackageStats' is deprecated. Deprecated in Java");
}

/**
* Parses a warning log written by Gradle containing 3 Kotlin warnings and 1 error.
* Having a cmake directory switch log in between. Following duplicated Kotlin errors should still be treated as duplicates.
*/
@Test
void kotlinAndCmakeDirectoryOuptut() {
Report warnings = parse("kotlin-cmake.txt");

assertThat(warnings).hasSize(5);
}
}

14 changes: 14 additions & 0 deletions src/test/resources/edu/hm/hafner/analysis/parser/kotlin-cmake.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.0.1'.
w: /project/app/src/main/java/ui/Activity.kt: (214, 35): Unchecked cast: Serializable! to kotlin.collections.HashMap<String, String> /* = java.util.HashMap<String, String> */
w: /project/app/src/main/java/ui/Activity.kt:424:29 Unchecked cast: Serializable! to kotlin.collections.HashMap<String, String> /* = java.util.HashMap<String, String> */
e: /project/app/src/main/java/ui/Activity.kt:425:29 deprecated: Serializable! to kotlin.collections.HashMap<String, String> /* = java.util.HashMap<String, String> */
w: C:\project\app\src\main\java\ui\Activity.kt:200:2 'PackageStats' is deprecated. Deprecated in Java
[2023-12-20T15:50:19.997Z] w: file:///project/src/main/java/com/app/ui/model/Activity.kt:8:27 'PackageStats' is deprecated. Deprecated in Java
[2023-12-20T15:50:18.292Z] C/C++: -- Build files have been written to: /project/.cxx/Debug/365u2g4u/arm64-v8a
C/C++: /project/src/cpp/MyClass.cpp:35:15: warning: unused parameter 'parameter1' [-Wunused-parameter]
[2023-12-20T15:50:20.997Z] w: file:///project/src/main/java/com/app/ui/model/Activity.kt:8:27 'PackageStats' is deprecated. Deprecated in Java
w: /project/app/src/main/java/ui/Activity.kt:424:29 Unchecked cast: Serializable! to kotlin.collections.HashMap<String, String> /* = java.util.HashMap<String, String> */
w: C:\project\app\src\main\java\ui\Activity.kt:200:2 'PackageStats' is deprecated. Deprecated in Java

0 comments on commit 2259f63

Please sign in to comment.