-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46273 from mkouba/issue-46270
Qute: add build item to exclude discovered templates
- Loading branch information
Showing
6 changed files
with
139 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ute/deployment/src/main/java/io/quarkus/qute/deployment/TemplatePathExcludeBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.qute.deployment; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* This build item is used to exclude template files found in template roots. Excluded templates are | ||
* neither parsed nor validated during build and are not available at runtime. | ||
* <p> | ||
* The matched input is the file path relative from the root directory and the {@code /} is used as a path separator. | ||
*/ | ||
public final class TemplatePathExcludeBuildItem extends MultiBuildItem { | ||
|
||
private final String regexPattern; | ||
|
||
public TemplatePathExcludeBuildItem(String regexPattern) { | ||
this.regexPattern = regexPattern; | ||
} | ||
|
||
public String getRegexPattern() { | ||
return regexPattern; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...nt/src/test/java/io/quarkus/qute/deployment/exclude/TemplatePathExcludeBuildItemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkus.qute.deployment.exclude; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.qute.Engine; | ||
import io.quarkus.qute.deployment.TemplatePathExcludeBuildItem; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class TemplatePathExcludeBuildItemTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addAsResource(new StringAsset("{@String name} Hi {name.nonexistent}!"), "templates/hi.txt") | ||
.addAsResource(new StringAsset("Hello {name}!"), "templates/hello.txt")) | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new TemplatePathExcludeBuildItem("hi.txt")); | ||
} | ||
}).produces(TemplatePathExcludeBuildItem.class) | ||
.build(); | ||
|
||
} | ||
}; | ||
} | ||
|
||
@Inject | ||
Engine engine; | ||
|
||
@Test | ||
public void testTemplate() { | ||
assertNull(engine.getTemplate("hi")); | ||
assertEquals("Hello M!", engine.getTemplate("hello").data("name", "M").render()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters