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

Reuse already created FileSystems during collection of ApplicationArchive #21660

Merged
merged 1 commit into from
Nov 29, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private List<ApplicationArchive> scanForOtherIndexes(QuarkusBuildCloseablesBuild
return appArchives;
}

public void addIndexDependencyPaths(List<IndexDependencyBuildItem> indexDependencyBuildItems,
private void addIndexDependencyPaths(List<IndexDependencyBuildItem> indexDependencyBuildItems,
ClassLoader classLoader, ArchiveRootBuildItem root, Set<Path> indexedDeps, List<ApplicationArchive> appArchives,
QuarkusBuildCloseablesBuildItem buildCloseables, IndexCache indexCache,
CurateOutcomeBuildItem curateOutcomeBuildItem,
Expand Down Expand Up @@ -189,17 +189,19 @@ private static ApplicationArchive createApplicationArchive(QuarkusBuildCloseable
IndexCache indexCache, Path dep, ArtifactKey artifactKey, Map<ArtifactKey, Set<String>> removedResources)
throws IOException {
Path rootDir = dep;
if (!Files.isDirectory(dep)) {
boolean isDirectory = Files.isDirectory(dep);
if (!isDirectory) {
final FileSystem fs = buildCloseables.add(FileSystems.newFileSystem(dep, classLoader));
rootDir = fs.getRootDirectories().iterator().next();
}
final IndexView index = indexPath(indexCache, dep, removedResources.get(artifactKey));
final IndexView index = indexPath(indexCache, dep, removedResources.get(artifactKey), isDirectory);
return new ApplicationArchiveImpl(index, rootDir, dep, artifactKey);
}

private static IndexView indexPath(IndexCache indexCache, Path dep, Set<String> removed) throws IOException {
private static IndexView indexPath(IndexCache indexCache, Path dep, Set<String> removed, boolean isWorkspaceModule)
throws IOException {
LOGGER.debugf("Indexing dependency: %s", dep);
return Files.isDirectory(dep) ? handleFilePath(dep, removed) : handleJarPath(dep, indexCache, removed);
return isWorkspaceModule ? handleFilePath(dep, removed) : handleJarPath(dep, indexCache, removed);
}

private static void addMarkerFilePaths(Set<String> applicationArchiveFiles,
Expand All @@ -213,6 +215,7 @@ private static void addMarkerFilePaths(Set<String> applicationArchiveFiles,
}
final PathCollection artifactPaths = dep.getResolvedPaths();
boolean containsMarker = false;
FileSystem fs = null;
for (Path p : artifactPaths) {
if (root.isExcludedFromIndexing(p)) {
continue;
Expand All @@ -222,15 +225,22 @@ private static void addMarkerFilePaths(Set<String> applicationArchiveFiles,
break;
}
} else {
try (FileSystem fs = FileSystems.newFileSystem(p, classLoader)) {
boolean close = true;
try {
fs = FileSystems.newFileSystem(p, classLoader);
if (containsMarker = containsMarker(fs.getPath("/"), applicationArchiveFiles)) {
close = false;
break;
}
} catch (ProviderNotFoundException | FileSystemNotFoundException e) {
// that is pretty much an exceptional case
// it's not a dir and not a jar, it could be anything (e.g. a pom file that
// ended up in some project deps)
// not necessarily a wrong state
} finally {
if (close && fs != null) {
fs.close();
}
}
}
}
Expand All @@ -239,13 +249,17 @@ private static void addMarkerFilePaths(Set<String> applicationArchiveFiles,
final PathList.Builder rootDirs = PathList.builder();
final List<IndexView> indexes = new ArrayList<>(artifactPaths.size());
for (Path p : artifactPaths) {
if (Files.isDirectory(p)) {
boolean isDirectory = Files.isDirectory(p);
if (isDirectory) {
rootDirs.add(p);
} else {
final FileSystem fs = buildCloseables.add(FileSystems.newFileSystem(p, classLoader));
if (fs == null) {
fs = FileSystems.newFileSystem(p, classLoader);
}
buildCloseables.add(fs);
fs.getRootDirectories().forEach(rootDirs::add);
}
indexes.add(indexPath(indexCache, p, removed.get(dep.getKey())));
indexes.add(indexPath(indexCache, p, removed.get(dep.getKey()), isDirectory));
indexedPaths.add(p);
}
appArchives
Expand All @@ -255,7 +269,7 @@ private static void addMarkerFilePaths(Set<String> applicationArchiveFiles,
}
}

private static boolean containsMarker(Path dir, Set<String> applicationArchiveFiles) throws IOException {
private static boolean containsMarker(Path dir, Set<String> applicationArchiveFiles) {
for (String file : applicationArchiveFiles) {
if (Files.exists(dir.resolve(file))) {
return true;
Expand All @@ -265,10 +279,6 @@ private static boolean containsMarker(Path dir, Set<String> applicationArchiveFi
}

private static Index handleFilePath(Path path, Set<String> removed) throws IOException {
return indexFilePath(path, removed);
}

private static Index indexFilePath(Path path, Set<String> removed) throws IOException {
Indexer indexer = new Indexer();
try (Stream<Path> stream = Files.walk(path)) {
stream.forEach(path1 -> {
Expand Down