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

Fix multi rooted path tree scanning in the Qute processor #40400

Merged
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 @@ -14,7 +14,6 @@
import java.io.UncheckedIOException;
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -2170,7 +2169,7 @@ private void scanPathTree(PathTree pathTree, TemplateRootsBuildItem templateRoot
// if template root is found in this tree then walk over its subtree
scanTemplateRootSubtree(
new FilteredPathTree(pathTree, PathFilter.forIncludes(List.of(templateRoot + "/**"))),
visit.getPath(), watchedPaths, templatePaths, nativeImageResources, config);
visit.getRelativePath(), watchedPaths, templatePaths, nativeImageResources, config);
}
});
}
Expand Down Expand Up @@ -3383,38 +3382,27 @@ private static void produceTemplateBuildItems(BuildProducer<TemplatePathBuildIte
readTemplateContent(originalPath, config.defaultCharset)));
}

private void scanTemplateRootSubtree(PathTree pathTree, Path templateRoot,
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());
String templatePath = toOsAgnosticPath(templateRoot.relativize(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,
visit.getRelativePath("/"),
templatePath, visit.getPath(), config);
relativePath, templatePath, visit.getPath(), config);
}
});
}

private static String toOsAgnosticPath(String path, FileSystem fs) {
String separator = fs.getSeparator();
if (!separator.equals("/")) {
path = path.replace(separator, "/");
}
return path;
}

private static String toOsAgnosticPath(Path path) {
return toOsAgnosticPath(path.toString(), path.getFileSystem());
}

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 @@ -44,6 +44,16 @@ default URL getUrl() {
}
}

/**
* Path relative to the root of the tree as a string with {@code /} as a path element separator.
* This method calls {@link #getRelativePath(String)} passing {@code /} as an argument.
*
* @return path relative to the root of the tree as a string with {@code /} as a path element separator
*/
default String getRelativePath() {
return getRelativePath("/");
ia3andy marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Path relative to the root of the tree as a string with a provided path element separator.
* For a {@link PathTree} created for an archive, the returned path will be relative to the root
Expand Down
Loading