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

Added a method to walk a subtree of a given PathTree #40415

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
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 @@ -97,9 +97,8 @@
import io.quarkus.maven.dependency.DependencyFlags;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.panache.common.deployment.PanacheEntityClassesBuildItem;
import io.quarkus.paths.FilteredPathTree;
import io.quarkus.paths.PathFilter;
import io.quarkus.paths.PathTree;
import io.quarkus.paths.PathTreeUtils;
import io.quarkus.qute.CheckedTemplate;
import io.quarkus.qute.Engine;
import io.quarkus.qute.EngineBuilder;
Expand Down Expand Up @@ -2164,14 +2163,22 @@ private void scanPathTree(PathTree pathTree, TemplateRootsBuildItem templateRoot
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
QuteConfig config) {
for (String templateRoot : templateRoots) {
pathTree.accept(templateRoot, visit -> {
if (visit != null) {
// if template root is found in this tree then walk over its subtree
scanTemplateRootSubtree(
new FilteredPathTree(pathTree, PathFilter.forIncludes(List.of(templateRoot + "/**"))),
visit.getRelativePath(), watchedPaths, templatePaths, nativeImageResources, config);
}
});
if (PathTreeUtils.containsCaseSensitivePath(pathTree, templateRoot)) {
pathTree.walkIfContains(templateRoot, visit -> {
if (Files.isRegularFile(visit.getPath())) {
LOGGER.debugf("Found template: %s", visit.getPath());
// remove templateRoot + /
final String relativePath = visit.getRelativePath();
String templatePath = relativePath.substring(templateRoot.length() + 1);
if (config.templatePathExclude.matcher(templatePath).matches()) {
LOGGER.debugf("Template file excluded: %s", visit.getPath());
return;
}
produceTemplateBuildItems(templatePaths, watchedPaths, nativeImageResources,
relativePath, templatePath, visit.getPath(), config);
}
});
}
}
}

Expand Down Expand Up @@ -3382,27 +3389,6 @@ private static void produceTemplateBuildItems(BuildProducer<TemplatePathBuildIte
readTemplateContent(originalPath, config.defaultCharset)));
}

private void scanTemplateRootSubtree(PathTree pathTree, String templateRoot,
BuildProducer<HotDeploymentWatchedFileBuildItem> watchedPaths,
BuildProducer<TemplatePathBuildItem> templatePaths,
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
QuteConfig config) {
pathTree.walk(visit -> {
if (Files.isRegularFile(visit.getPath())) {
LOGGER.debugf("Found template: %s", visit.getPath());
// remove templateRoot + /
final String relativePath = visit.getRelativePath();
String templatePath = relativePath.substring(templateRoot.length() + 1);
if (config.templatePathExclude.matcher(templatePath).matches()) {
LOGGER.debugf("Template file excluded: %s", visit.getPath());
return;
}
produceTemplateBuildItems(templatePaths, watchedPaths, nativeImageResources,
relativePath, templatePath, visit.getPath(), config);
}
});
}

private static boolean isExcluded(TypeCheck check, Iterable<Predicate<TypeCheck>> excludes) {
for (Predicate<TypeCheck> exclude : excludes) {
if (exclude.test(check)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
import io.quarkus.paths.FilteredPathTree;
import io.quarkus.paths.PathFilter;
import io.quarkus.paths.PathVisitor;
import io.quarkus.vertx.core.deployment.CoreVertxBuildItem;
import io.quarkus.vertx.http.deployment.spi.AdditionalStaticResourceBuildItem;
Expand Down Expand Up @@ -86,7 +84,7 @@ public void nativeImageResource(Optional<StaticResourcesBuildItem> staticResourc
final Set<String> collectedDirs = new HashSet<>();
visitRuntimeMetaInfResources(visit -> {
if (Files.isDirectory(visit.getPath())) {
final String relativePath = visit.getRelativePath("/");
final String relativePath = visit.getRelativePath();
if (collectedDirs.add(relativePath)) {
producer.produce(new NativeImageResourceBuildItem(relativePath));
}
Expand All @@ -105,7 +103,7 @@ private Set<StaticResourcesBuildItem.Entry> getClasspathResources() {
visitRuntimeMetaInfResources(visit -> {
if (!Files.isDirectory(visit.getPath())) {
knownPaths.add(new StaticResourcesBuildItem.Entry(
visit.getRelativePath("/").substring(StaticResourcesRecorder.META_INF_RESOURCES.length()),
visit.getRelativePath().substring(StaticResourcesRecorder.META_INF_RESOURCES.length()),
false));
}
});
Expand All @@ -121,13 +119,10 @@ private static void visitRuntimeMetaInfResources(PathVisitor visitor) {
final List<ClassPathElement> elements = QuarkusClassLoader.getElements(StaticResourcesRecorder.META_INF_RESOURCES,
false);
if (!elements.isEmpty()) {
final PathFilter filter = PathFilter.forIncludes(List.of(
StaticResourcesRecorder.META_INF_RESOURCES + "/**",
StaticResourcesRecorder.META_INF_RESOURCES));
for (var element : elements) {
if (element.isRuntime()) {
element.apply(tree -> {
new FilteredPathTree(tree, filter).walk(visitor);
tree.walkIfContains(StaticResourcesRecorder.META_INF_RESOURCES, visitor);
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,25 @@ public Collection<Path> getRoots() {
public void walk(PathVisitor visitor) {
try (FileSystem fs = openFs()) {
final Path dir = fs.getPath("/");
PathTreeVisit.walk(archive, dir, pathFilter, getMultiReleaseMapping(), visitor);
PathTreeVisit.walk(archive, dir, dir, pathFilter, getMultiReleaseMapping(), visitor);
} catch (IOException e) {
throw new UncheckedIOException("Failed to read " + archive, e);
}
}

@Override
public void walkIfContains(String relativePath, PathVisitor visitor) {
ensureResourcePath(relativePath);
if (!PathFilter.isVisible(pathFilter, relativePath)) {
return;
}
try (FileSystem fs = openFs()) {
for (Path root : fs.getRootDirectories()) {
final Path walkDir = root.resolve(relativePath);
if (Files.exists(walkDir)) {
PathTreeVisit.walk(archive, root, walkDir, pathFilter, getMultiReleaseMapping(), visitor);
}
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to read " + archive, e);
}
Expand Down Expand Up @@ -287,6 +305,17 @@ public void walk(PathVisitor visitor) {
}
}

@Override
public void walkIfContains(String relativePath, PathVisitor visitor) {
lock.readLock().lock();
try {
ensureOpen();
super.walkIfContains(relativePath, visitor);
} finally {
lock.readLock().unlock();
}
}

@Override
public boolean contains(String relativePath) {
lock.readLock().lock();
Expand Down

This file was deleted.

Loading
Loading