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
Dennis Bauer committed Dec 21, 2023
1 parent 93172ec commit 2eb9975
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
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(unsafeFileName)) {
return fileNameBuilder.intern(normalizeFileName(unsafeFileName));
}
return fileNameBuilder.intern(normalizeFileName(
new PathUtil().createAbsolutePath(directory, unsafeFileName)));
}
Expand Down Expand Up @@ -553,6 +560,22 @@ public Optional<Issue> buildOptional() {
return Optional.of(buildAndClean());
}

private 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()) {

Check warning on line 572 in src/main/java/edu/hm/hafner/analysis/IssueBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 572 is only partially covered, one branch is missing
return true;

Check warning on line 573 in src/main/java/edu/hm/hafner/analysis/IssueBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 573 is not covered by tests

Check warning on line 573 in src/main/java/edu/hm/hafner/analysis/IssueBuilder.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/edu/hm/hafner/analysis/IssueBuilder.java#L573

Added line #L573 was not covered by tests
}
}
return false;
}

@SuppressWarnings("PMD.NullAssignment")
private void clean() {
id = UUID.randomUUID(); // make sure that multiple invocations will create different IDs
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(4);
}
}

11 changes: 11 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,11 @@
> 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> */
[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
[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
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> */

0 comments on commit 2eb9975

Please sign in to comment.