Skip to content

Commit

Permalink
Merge pull request #37224 from mkouba/issue-36692-next
Browse files Browse the repository at this point in the history
Qute: dev mode - debug a problem with no-restart-template
  • Loading branch information
mkouba committed Nov 21, 2023
2 parents 5fd4f01 + f90ca79 commit 914698e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,9 @@ private RuntimeUpdatesProcessor setWatchedFilePathsInternal(Map<String, Boolean>
// First find all matching paths from all roots
try (final Stream<Path> walk = Files.walk(root)) {
walk.forEach(path -> {
if (path.equals(root)) {
if (path.equals(root)
// Never watch directories
|| Files.isDirectory(path)) {
return;
}
// Use the relative path to match the watched file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import io.quarkus.qute.Location;
import io.quarkus.qute.Template;
import io.quarkus.vertx.web.Route;
import io.vertx.ext.web.RoutingContext;
Expand All @@ -15,12 +16,20 @@ public class NoRestartRoute {

private String id;

@Inject
@Location("foo/norestart")
Template norestart;

@Inject
Template bar;

@Route(path = "norestart")
public void test(RoutingContext ctx) {
ctx.end(norestart.data("foo", id).render());
ctx.end(norestart.data("id", id).render());
}

@Route(path = "bar")
public void testBar(RoutingContext ctx) {
ctx.end(bar.data("id", id).render());
}

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,39 @@ public class NoRestartTemplatesDevModeTest {
.withApplicationRoot(root -> root
.addClass(NoRestartRoute.class)
.addAsResource(new StringAsset(
"Hello {foo}!"),
"templates/norestart.html")
"Hello {id}!"),
"templates/foo/norestart.html")
.addAsResource(new StringAsset(
"quarkus.qute.dev-mode.no-restart-templates=templates/norestart.html"),
"Hi {id}!"),
"templates/bar.html")
.addAsResource(new StringAsset(
"quarkus.qute.dev-mode.no-restart-templates=templates/.+"),
"application.properties"));

@Test
public void testNoRestartTemplates() {
Response resp = given().get("norestart");
resp.then()
.statusCode(200);
String val = resp.getBody().asString();
assertTrue(val.startsWith("Hello "));
String val1 = resp.getBody().asString();
assertTrue(val1.startsWith("Hello "));

resp = given().get("bar");
resp.then()
.statusCode(200);
String val2 = resp.getBody().asString();
assertTrue(val2.startsWith("Hi "));

config.modifyResourceFile("templates/norestart.html", t -> t.concat("!!"));
config.modifyResourceFile("templates/foo/norestart.html", t -> t.concat("!!"));
config.modifyResourceFile("templates/bar.html", t -> t.concat("!!"));

resp = given().get("norestart");
resp.then().statusCode(200);
assertEquals(val + "!!", resp.getBody().asString());
assertEquals(val1 + "!!", resp.getBody().asString());

resp = given().get("bar");
resp.then().statusCode(200);
assertEquals(val2 + "!!", resp.getBody().asString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class QuteDevModeConfig {
* This regular expression can be used to specify the templates for which the application is not restarted.
* I.e. the templates are reloaded and only runtime validations are performed.
* <p>
* The matched input is the template path relative from the {@code templates} directory and the
* {@code /} is used as a path separator. For example, {@code templates/foo.html}.
* The matched input is the template path that starts with a template root, and the {@code /} is used as a path separator.
* For example, {@code templates/foo.html}.
*/
@ConfigItem
public Optional<Pattern> noRestartTemplates;
Expand Down

0 comments on commit 914698e

Please sign in to comment.