Skip to content

Commit

Permalink
Merge pull request #39294 from mkouba/issue-39197
Browse files Browse the repository at this point in the history
Qute: add correct NativeImageResourceBuildItem for custom template root
  • Loading branch information
gsmet authored Mar 13, 2024
2 parents 4007002 + 29de1e2 commit df72bbc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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<NativeImageResourceBuildItem> 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();
}
};
}
Expand Down

0 comments on commit df72bbc

Please sign in to comment.