Skip to content

Commit

Permalink
Fix PathTreeClassPathElement#toString() implementation
Browse files Browse the repository at this point in the history
It was relying on some internal behavior of the path trees and not
calling the `getOriginalTree()` method.
But rather than fixing it this way, I think it's more future proof to
properly implement `toString()` in the `PathTree` implementations.

Fixes quarkusio#45650
  • Loading branch information
gsmet committed Jan 22, 2025
1 parent 3f6f477 commit 64a72be
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public boolean equals(Object obj) {
&& manifestEnabled == other.manifestEnabled;
}

@Override
public String toString() {
return archive.toString();
}

protected class OpenArchivePathTree extends OpenContainerPathTree {

private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
Expand Down Expand Up @@ -403,5 +408,10 @@ public void close() throws IOException {
public PathTree getOriginalTree() {
return ArchivePathTree.this;
}

@Override
public String toString() {
return ArchivePathTree.this.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public void close() throws IOException {
public PathTree getOriginalTree() {
return this;
}

@Override
public String toString() {
return "<empty>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,13 @@ public boolean equals(Object obj) {
FilePathTree other = (FilePathTree) obj;
return Objects.equals(file, other.file) && Objects.equals(pathFilter, other.pathFilter);
}

@Override
public String toString() {
if (pathFilter == null) {
return file.toString();
}

return file + " (filtered)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public OpenPathTree open() {
return new OpenFilteredPathTree(original.open(), filter);
}

@Override
public String toString() {
return original.toString() + " (filtered)";
}

private static class OpenFilteredPathTree extends FilteredPathTree implements OpenPathTree {

private final OpenPathTree original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

public class MultiRootPathTree implements OpenPathTree {

Expand Down Expand Up @@ -192,4 +193,9 @@ public boolean equals(Object obj) {
MultiRootPathTree other = (MultiRootPathTree) obj;
return Arrays.equals(trees, other.trees);
}

@Override
public String toString() {
return roots.stream().map(p -> p.toString()).collect(Collectors.joining(", ", "[", "]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,9 @@ public boolean equals(Object obj) {
&& Objects.equals(pathFilter, other.pathFilter)
&& manifestEnabled == other.manifestEnabled;
}

@Override
public String toString() {
return getContainerPath().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public OpenPathTree open() {
return new CallerOpenPathTree(lastOpen);
}
try {
this.lastOpen = new SharedOpenArchivePathTree(archive, openFs());
this.lastOpen = new SharedOpenArchivePathTree(openFs());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -68,7 +68,7 @@ private class SharedOpenArchivePathTree extends OpenArchivePathTree {

private final AtomicInteger users = new AtomicInteger(1);

protected SharedOpenArchivePathTree(Path archivePath, FileSystem fs) {
protected SharedOpenArchivePathTree(FileSystem fs) {
super(fs);
openCount.incrementAndGet();
}
Expand Down Expand Up @@ -106,6 +106,11 @@ public void close() throws IOException {
writeLock().unlock();
}
}

@Override
public String toString() {
return SharedArchivePathTree.this.toString();
}
}

/**
Expand Down Expand Up @@ -202,5 +207,10 @@ public void close() throws IOException {
delegate.writeLock().unlock();
}
}

@Override
public String toString() {
return delegate.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -216,13 +215,7 @@ public String toString() {
if (getDependencyKey() != null) {
sb.append(getDependencyKey().toGacString()).append(" ");
}
final Iterator<Path> i = pathTree.getRoots().iterator();
if (i.hasNext()) {
sb.append(i.next());
while (i.hasNext()) {
sb.append(",").append(i.next());
}
}
sb.append(pathTree.toString());
sb.append(" runtime=").append(isRuntime());
final Set<String> resources = this.resources;
sb.append(" resources=").append(resources == null ? "null" : resources.size());
Expand Down

0 comments on commit 64a72be

Please sign in to comment.