Skip to content

Commit

Permalink
Move isAbsolutePath method to PathUtil.
Browse files Browse the repository at this point in the history
See #1021.
  • Loading branch information
uhafner committed Feb 19, 2024
1 parent 2b010e9 commit 8e26006
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.hm.hafner</groupId>
<artifactId>codingstyle-pom</artifactId>
<version>3.42.0</version>
<version>3.43.0</version>
<relativePath />
</parent>

Expand Down
27 changes: 5 additions & 22 deletions src/main/java/edu/hm/hafner/analysis/IssueBuilder.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
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 @@ -43,6 +39,7 @@ public class IssueBuilder implements AutoCloseable {
private static final String UNDEFINED = "-";
private static final TreeString UNDEFINED_TREE_STRING = TreeString.valueOf(UNDEFINED);
private static final TreeString EMPTY_TREE_STRING = TreeString.valueOf(StringUtils.EMPTY);
private static final PathUtil PATH_UTIL = new PathUtil();

private final TreeStringBuilder fileNameBuilder = new TreeStringBuilder();
private final TreeStringBuilder packageNameBuilder = new TreeStringBuilder();
Expand Down Expand Up @@ -89,7 +86,7 @@ public class IssueBuilder implements AutoCloseable {
private UUID id = UUID.randomUUID();

/**
* Sets the unique ID of the issue. If not set then an ID will be generated.
* Sets the unique ID of the issue. If not set, then an ID will be generated.
*
* @param id
* the ID
Expand All @@ -103,7 +100,7 @@ public IssueBuilder setId(final UUID id) {
}

/**
* Sets additional properties from the statical analysis tool. This object could be used to store tool specific
* Sets additional properties from the statical analysis tool. This object could be used to store tool-specific
* information.
*
* @param additionalProperties
Expand Down Expand Up @@ -154,11 +151,11 @@ TreeString internFileName(@CheckForNull final String unsafeFileName) {
return UNDEFINED_TREE_STRING;
}
else {
if (directory != null && isAbsolutePath(normalizeFileName(unsafeFileName))) {
if (directory != null && PATH_UTIL.isAbsolute(normalizeFileName(unsafeFileName))) {
return fileNameBuilder.intern(normalizeFileName(unsafeFileName));
}
return fileNameBuilder.intern(normalizeFileName(
new PathUtil().createAbsolutePath(directory, unsafeFileName)));
PATH_UTIL.createAbsolutePath(directory, unsafeFileName)));
}
}

Expand Down Expand Up @@ -615,20 +612,6 @@ 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) {
// 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
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void kotlin18WarningStyle() {
* Having a cmake directory switch log in between. Following duplicated Kotlin errors should still be treated as duplicates.
*/
@Test
void kotlinAndCmakeDirectoryOuptut() {
void kotlinAndCmakeDirectoryOutput() {
Report warnings = parse("kotlin-cmake.txt");

assertThat(warnings).hasSize(5);
Expand Down

0 comments on commit 8e26006

Please sign in to comment.