Skip to content

Commit

Permalink
Only read file attributes once when creating Directory or ArchivePath…
Browse files Browse the repository at this point in the history
…Tree
  • Loading branch information
Postremus authored and aloubyansky committed Jan 4, 2022
1 parent 061c341 commit 90b63db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
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;

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 90b63db

Please sign in to comment.