Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing for mixture of Kotlin and CMake output #991

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 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 @@
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,20 @@
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

Check warning on line 595 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#L595

Added line #L595 was 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);
return path.isAbsolute();
}

private static String normalizeFileName(@CheckForNull final String platformFileName) {
return defaultString(StringUtils.replace(
StringUtils.strip(platformFileName), "\\", "/"));
Expand Down
36 changes: 36 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 @@ -308,24 +308,24 @@
void kotlin18WarningStyle() {
Report warnings = parse("kotlin-1_8.txt");

assertThat(warnings).hasSize(7);

assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(214)
.hasColumnStart(35)
.hasFileName("/project/app/src/main/java/ui/Activity.kt");
assertThat(warnings.get(1)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(424)
.hasColumnStart(29)
.hasFileName("/project/app/src/main/java/ui/Activity.kt");
assertThat(warnings.get(2)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(425)
.hasColumnStart(29)
.hasFileName("/project/app/src/main/java/ui/Activity.kt")
.hasCategory("Deprecation")
.hasMessage("deprecated: Serializable! to kotlin.collections.HashMap<String, String> /* = java.util.HashMap<String, String> */");
assertThat(warnings.get(3)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(424)

Check warning on line 328 in src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(warnings).hasSize(7); assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(214) .hasColumnStart(35) .hasFileName(&#34;/project/app/src/main/java/ui/Activity.kt&#34;); assertThat(warnings.get(1)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(424) .hasColumnStart(29) .hasFileName(&#34;/project/app/src/main/java/ui/Activity.kt&#34;); assertThat(warnings.get(2)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(425) .hasColumnStart(29) .hasFileName(&#34;/project/app/src/main/java/ui/Activity.kt&#34;) .hasCategory(&#34;Deprecation&#34;) .hasMessage(&#34;deprecated: Serializable! to kotlin.collections.HashMap&lt;String, String&gt; /* &#61; java.util.HashMap&lt;String, String&gt; */&#34;); assertThat(warnings.get(3)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(424)</code></pre>
.hasColumnStart(29)
.hasFileName("/project/app/src/main/java/ui/Activity.kt");
assertThat(warnings.get(4)).hasSeverity(Severity.WARNING_NORMAL)
Expand All @@ -342,5 +342,41 @@
.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);
DennisBauer marked this conversation as resolved.
Show resolved Hide resolved

assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(214)
.hasColumnStart(35)
.hasFileName("/project/app/src/main/java/ui/Activity.kt");
assertThat(warnings.get(1)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(424)
.hasColumnStart(29)
.hasFileName("/project/app/src/main/java/ui/Activity.kt");
assertThat(warnings.get(2)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(425)
.hasColumnStart(29)
.hasFileName("/project/app/src/main/java/ui/Activity.kt")
.hasCategory("Deprecation")
.hasMessage("deprecated: Serializable! to kotlin.collections.HashMap<String, String> /* = java.util.HashMap<String, String> */");
assertThat(warnings.get(3)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(200)

Check warning on line 371 in src/test/java/edu/hm/hafner/analysis/parser/JavacParserTest.java

View check run for this annotation

ci.jenkins.io / CPD

CPD

LOW: Found duplicated code.
Raw output
<pre><code>assertThat(warnings).hasSize(7); assertThat(warnings.get(0)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(214) .hasColumnStart(35) .hasFileName(&#34;/project/app/src/main/java/ui/Activity.kt&#34;); assertThat(warnings.get(1)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(424) .hasColumnStart(29) .hasFileName(&#34;/project/app/src/main/java/ui/Activity.kt&#34;); assertThat(warnings.get(2)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(425) .hasColumnStart(29) .hasFileName(&#34;/project/app/src/main/java/ui/Activity.kt&#34;) .hasCategory(&#34;Deprecation&#34;) .hasMessage(&#34;deprecated: Serializable! to kotlin.collections.HashMap&lt;String, String&gt; /* &#61; java.util.HashMap&lt;String, String&gt; */&#34;); assertThat(warnings.get(3)).hasSeverity(Severity.WARNING_NORMAL) .hasLineStart(424)</code></pre>
.hasColumnStart(2)
.hasFileName("C:/project/app/src/main/java/ui/Activity.kt");
assertThat(warnings.get(4)).hasSeverity(Severity.WARNING_NORMAL)
.hasLineStart(8)
.hasColumnStart(27)
.hasCategory("Deprecation")
.hasFileName("file:///project/src/main/java/com/app/ui/model/Activity.kt")
.hasMessage("'PackageStats' is deprecated. Deprecated in Java");
}
}

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
Loading