From 29de1e265dd6bf98ca398dd2b95927d3a0d2c6f5 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Fri, 8 Mar 2024 15:31:38 +0100 Subject: [PATCH] Qute: add correct NativeImageResourceBuildItem for custom template root - fixes #39197 --- .../qute/deployment/QuteProcessor.java | 2 +- .../AdditionalTemplateRootTest.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java index e2ab7c880eaed..1b8e728a13d53 100644 --- a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java +++ b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java @@ -2194,7 +2194,7 @@ private void scanPath(Path rootPath, Path path, QuteConfig config, TemplateRoots Path relativePath = rootPath.relativize(file); if (templateRoots.isRoot(relativePath)) { LOGGER.debugf("Found templates dir: %s", file); - scan(file, file, file.getFileName() + "/", watchedPaths, templatePaths, + scan(file, file, relativePath.toString() + File.separatorChar, watchedPaths, templatePaths, nativeImageResources, config); } else if (templateRoots.maybeRoot(relativePath)) { diff --git a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/templateroot/AdditionalTemplateRootTest.java b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/templateroot/AdditionalTemplateRootTest.java index 202cdbfc8b7e4..7e26be68d7834 100644 --- a/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/templateroot/AdditionalTemplateRootTest.java +++ b/extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/templateroot/AdditionalTemplateRootTest.java @@ -2,7 +2,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.List; import java.util.function.Consumer; +import java.util.stream.Collectors; import jakarta.inject.Inject; @@ -13,6 +15,8 @@ import io.quarkus.builder.BuildChainBuilder; import io.quarkus.builder.BuildContext; import io.quarkus.builder.BuildStep; +import io.quarkus.deployment.builditem.ServiceStartBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.qute.Engine; import io.quarkus.qute.Template; import io.quarkus.qute.deployment.TemplateRootBuildItem; @@ -38,6 +42,29 @@ public void execute(BuildContext context) { } }).produces(TemplateRootBuildItem.class) .build(); + + builder.addBuildStep(new BuildStep() { + @Override + public void execute(BuildContext context) { + int found = 0; + List items = context.consumeMulti(NativeImageResourceBuildItem.class); + for (NativeImageResourceBuildItem item : items) { + if (item.getResources().contains("web/public/hello.txt") + || item.getResources().contains("web\\public\\hello.txt") + || item.getResources().contains("templates/hi.txt") + || item.getResources().contains("templates\\hi.txt")) { + found++; + } + } + if (found != 2) { + throw new IllegalStateException(items.stream().flatMap(i -> i.getResources().stream()) + .collect(Collectors.toList()).toString()); + } + context.produce(new ServiceStartBuildItem("foo")); + } + }).produces(ServiceStartBuildItem.class) + .consumes(NativeImageResourceBuildItem.class) + .build(); } }; }