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 3594df36ea84e..1b91ef972fe0f 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 @@ -9,8 +9,9 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.io.UncheckedIOException; import java.lang.reflect.Modifier; -import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -80,6 +81,7 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.deployment.util.JandexUtil; +import io.quarkus.fs.util.ZipUtils; import io.quarkus.gizmo.ClassOutput; import io.quarkus.maven.dependency.Dependency; import io.quarkus.maven.dependency.ResolvedDependency; @@ -383,22 +385,17 @@ public CompletionStage resolve(SectionResolutionContext context) { public Optional locate(String id) { TemplatePathBuildItem found = templatePaths.stream().filter(p -> p.getPath().equals(id)).findAny().orElse(null); if (found != null) { - try { - byte[] content = Files.readAllBytes(found.getFullPath()); - return Optional.of(new TemplateLocation() { - @Override - public Reader read() { - return new StringReader(new String(content, StandardCharsets.UTF_8)); - } + return Optional.of(new TemplateLocation() { + @Override + public Reader read() { + return new StringReader(found.getContent()); + } - @Override - public Optional getVariant() { - return Optional.empty(); - } - }); - } catch (IOException e) { - LOGGER.warn("Unable to read the template from path: " + found.getFullPath(), e); - } + @Override + public Optional getVariant() { + return Optional.empty(); + } + }); } return Optional.empty(); } @@ -1234,15 +1231,27 @@ void collectTemplates(ApplicationArchivesBuildItem applicationArchives, // Skip extension archives that are also application archives continue; } - for (Path p : artifact.getResolvedPaths()) { - if (Files.isDirectory(p)) { + for (Path path : artifact.getResolvedPaths()) { + if (Files.isDirectory(path)) { // Try to find the templates in the root dir - Path basePath = Files.list(p).filter(QuteProcessor::isBasePath).findFirst().orElse(null); + Path basePath = Files.list(path).filter(QuteProcessor::isBasePath).findFirst().orElse(null); if (basePath != null) { - LOGGER.debugf("Found extension templates dir: %s", p); - basePaths.add(basePath); + LOGGER.debugf("Found extension templates dir: %s", path); + scan(basePath, basePath, BASE_PATH + "/", watchedPaths, templatePaths, nativeImageResources, + config.templatePathExclude); break; } + } else { + try (FileSystem artifactFs = ZipUtils.newFileSystem(path)) { + Path basePath = artifactFs.getPath(BASE_PATH); + if (Files.exists(basePath)) { + LOGGER.debugf("Found extension templates in: %s", path); + scan(basePath, basePath, BASE_PATH + "/", watchedPaths, templatePaths, nativeImageResources, + config.templatePathExclude); + } + } catch (IOException e) { + LOGGER.warnf(e, "Unable to create the file system from the path: %s", path); + } } } } @@ -1254,14 +1263,12 @@ void collectTemplates(ApplicationArchivesBuildItem applicationArchives, if (basePath != null) { LOGGER.debugf("Found templates dir: %s", basePath); basePaths.add(basePath); + scan(basePath, basePath, BASE_PATH + "/", watchedPaths, templatePaths, nativeImageResources, + config.templatePathExclude); break; } } } - for (Path base : basePaths) { - scan(base, base, BASE_PATH + "/", watchedPaths, templatePaths, nativeImageResources, - config.templatePathExclude); - } } @BuildStep @@ -2114,7 +2121,7 @@ private static void produceTemplateBuildItems(BuildProducer watchedPaths, @@ -2191,6 +2198,14 @@ private boolean isApplicationArchive(ResolvedDependency dependency, Set processVariants(List templatePaths, List variants) { Map variantsMap = new HashMap<>(); for (String variant : variants) { - String source = ""; - Path sourcePath = templatePaths.stream().filter(p -> p.getPath().equals(variant)) - .map(TemplatePathBuildItem::getFullPath).findFirst() + String source = templatePaths.stream().filter(p -> p.getPath().equals(variant)) + .map(TemplatePathBuildItem::getContent).findFirst() .orElse(null); - if (sourcePath != null) { - try { - byte[] content = Files.readAllBytes(sourcePath); - source = new String(content, StandardCharsets.UTF_8); - } catch (IOException e) { - LOG.warn("Unable to read the template from path: " + sourcePath, e); - } - } source = source.replace("\n", "\\n"); variantsMap.put(variant, source); }