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 54accae
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
24 changes: 24 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,23 @@ 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) {

Check warning on line 595 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 595 is not covered by tests
// Catch and ignore as system paths are not URI and we need to check them separately.
}
Path path = Paths.get(stringPath);
if (path.isAbsolute()) {
return true;
}

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

View check run for this annotation

ci.jenkins.io / PMD

SimplifyBooleanReturns

NORMAL: Avoid unnecessary if..then..else statements when returning booleans.
Raw output
Avoid unnecessary if-then-else statements when returning a boolean. The result of the conditional test can be returned instead. <pre> <code> public boolean isBarEqualTo(int x) { if (bar == x) { // this bit of code... return true; } else { return false; } } public boolean isBarEqualTo(int x) { return bar == x; // can be replaced with this } </code> </pre> <a href="https://pmd.github.io/pmd-6.55.0/pmd_rules_java_design.html#simplifybooleanreturns"> See PMD documentation. </a>
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 54accae

Please sign in to comment.