quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.64k stars 2.64k forks source link

Qute-Templates cannot be found in tests if directory "src/test/resources/templates" exist #40366

Closed mzellho closed 5 months ago

mzellho commented 5 months ago

Describe the bug

As soon as there is a directory src/test/resources/templates, Qute Templates can no longer be found when executing tests, resulting in a No template matching the path foo/bar could be found for: org.acme.FooTemplates.bar.

For more discussion, see https://github.com/quarkusio/quarkus/pull/40158

Expected behavior

The existence of a src/test/resources/templates should not break the resolution of the templates.

Actual behavior

No template matching the path foo/bar could be found for: org.acme.FooTemplates.bar when running tests.

How to Reproduce?

Reproducer project: https://github.com/mzellho/quarkus-quickstarts/tree/reproducer/40158

Output of uname -a or ver

Linux xxxxx 6.5.0-28-generic #29-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 28 23:46:48 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.3" 2024-04-16 LTS OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing)

Quarkus version or git rev

3.9.5

Build tool (ie. output of mvnw --version or gradlew --version)

Running /home/xxxxx/work/2/quarkus-quickstarts/mvnw... Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /home/xxxxx/.m2/wrapper/dists/apache-maven-3.8.6-bin/67568434/apache-maven-3.8.6 Java version: 21.0.3, vendor: Eclipse Adoptium, runtime: /home/xxxxx/.sdkman/candidates/java/21.0.3-tem Default locale: de_DE, platform encoding: UTF-8 OS name: "linux", version: "6.5.0-28-generic", arch: "amd64", family: "unix"

Additional information

No response

quarkus-bot[bot] commented 5 months ago

/cc @mkouba (qute)

mkouba commented 5 months ago

@aloubyansky Is it expected that MultiRootPathTree.accept(String, Consumer<PathVisit>) does not accept all roots; src/main/resources/templates and src/test/resources/templates in this particular case.

It seems to be a regression introduced in https://github.com/quarkusio/quarkus/pull/40158/commits/6014d5119451e6dfa9e22bd7b19b9ebeabf2477d.

We should definitely add a test with templates in the src/test/resources/templates directory.

aloubyansky commented 5 months ago

Ah, I see, it should be considered a bug. If the path was a file, I think we would pick the first found (like it is right now) but if it's a directory, so the content should be merged I guess.

mkouba commented 5 months ago

but if it's a directory, so the content should be merged I guess.

Yes, I would expect this behavior.

Would you care to send a fix?

aloubyansky commented 5 months ago

Yes, i'll look into it

aloubyansky commented 5 months ago

@mkouba i think https://github.com/quarkusio/quarkus/pull/40400 should fix it. Multi rooted path trees are walked over entirely. It's just the path object isn't a good to calculate the relative for all found template roots in this case.

So the accept call would be just a check whether a PathTree contains a template root and should be walked over to collect all the templates.

aloubyansky commented 5 months ago

I'll add some other API to PathTree to make it more convenient for these use-cases.

aloubyansky commented 5 months ago

The reproducer works with the linked PR

aloubyansky commented 5 months ago

In the meantime, Stuart also opened this PR that adds PathTree.acceptAll(String relativePath, Consumer<PathVisit> func), which is kind of relevant to the original issue but not necessary for the PR I linked as the fix.