diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ResolvedDependency.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ResolvedDependency.java index c59d7a0055e75..ddaace060a9c9 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ResolvedDependency.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ResolvedDependency.java @@ -2,12 +2,10 @@ import io.quarkus.bootstrap.workspace.ArtifactSources; import io.quarkus.bootstrap.workspace.WorkspaceModule; -import io.quarkus.paths.DirectoryPathTree; import io.quarkus.paths.EmptyPathTree; import io.quarkus.paths.MultiRootPathTree; import io.quarkus.paths.PathCollection; import io.quarkus.paths.PathTree; -import java.nio.file.Files; import java.nio.file.Path; public interface ResolvedDependency extends Dependency { @@ -40,12 +38,12 @@ default PathTree getContentTree() { } if (paths.isSinglePath()) { final Path p = paths.getSinglePath(); - return Files.isDirectory(p) ? new DirectoryPathTree(p) : PathTree.ofArchive(p); + return PathTree.ofDirectoryOrArchive(p); } final PathTree[] trees = new PathTree[paths.size()]; int i = 0; for (Path p : paths) { - trees[i++] = Files.isDirectory(p) ? new DirectoryPathTree(p) : PathTree.ofArchive(p); + trees[i++] = PathTree.ofDirectoryOrArchive(p); } return new MultiRootPathTree(trees); } diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathTree.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathTree.java index 64ce8d3110509..5acc965350128 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathTree.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathTree.java @@ -1,7 +1,9 @@ package io.quarkus.paths; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; import java.util.Collection; import java.util.function.Function; import java.util.jar.Manifest; @@ -9,13 +11,29 @@ public interface PathTree { static PathTree of(Path p) { - if (Files.isDirectory(p)) { - return new DirectoryPathTree(p); - } - if (Files.exists(p)) { + try { + BasicFileAttributes fileAttributes = Files.readAttributes(p, BasicFileAttributes.class); + if (fileAttributes.isDirectory()) { + return new DirectoryPathTree(p); + } + return new FilePathTree(p); + } catch (IOException e) { + throw new IllegalArgumentException(p + " does not exist", e); + } + } + + static PathTree ofDirectoryOrArchive(Path p) { + try { + BasicFileAttributes fileAttributes = Files.readAttributes(p, BasicFileAttributes.class); + if (fileAttributes.isDirectory()) { + return new DirectoryPathTree(p); + } + + return new ArchivePathTree(p); + } catch (IOException e) { + throw new IllegalArgumentException(p + " does not exist", e); } - throw new IllegalArgumentException(p + " does not exist"); } static PathTree ofArchive(Path archive) { diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java index 5a139c8791e7e..8018b08c48b52 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/ClassPathElement.java @@ -2,12 +2,10 @@ import io.quarkus.maven.dependency.ArtifactKey; import io.quarkus.maven.dependency.ResolvedDependency; -import io.quarkus.paths.DirectoryPathTree; import io.quarkus.paths.EmptyPathTree; import io.quarkus.paths.OpenPathTree; import io.quarkus.paths.PathTree; import java.io.Closeable; -import java.nio.file.Files; import java.nio.file.Path; import java.security.ProtectionDomain; import java.util.Collections; @@ -81,7 +79,7 @@ default ArtifactKey getDependencyKey() { * Creates an element from a file system path */ static ClassPathElement fromPath(Path path, boolean runtime) { - return new PathTreeClassPathElement(Files.isDirectory(path) ? new DirectoryPathTree(path) : PathTree.ofArchive(path), + return new PathTreeClassPathElement(PathTree.ofDirectoryOrArchive(path), runtime); }