Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that index.html works in any directory in native mode #39878

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void runtimeInit(Optional<StaticResourcesBuildItem> staticResources, Stat

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
public void nativeImageResource(Optional<StaticResourcesBuildItem> staticResources,
BuildProducer<NativeImageResourceBuildItem> producer) {
BuildProducer<NativeImageResourceBuildItem> producer) throws IOException {
if (staticResources.isPresent()) {
Set<StaticResourcesBuildItem.Entry> entries = staticResources.get().getEntries();
List<String> metaInfResources = new ArrayList<>(entries.size());
Expand All @@ -75,10 +75,34 @@ public void nativeImageResource(Optional<StaticResourcesBuildItem> staticResourc
// TODO: do we perhaps want to register the whole directory?
continue;
}

String metaInfResourcesPath = StaticResourcesRecorder.META_INF_RESOURCES + entry.getPath();
metaInfResources.add(metaInfResourcesPath);
}
producer.produce(new NativeImageResourceBuildItem(metaInfResources));

// register all directories under META-INF/resources for reflection in order to enable
// the serving of index.html in arbitrarily nested directories
ClassPathUtils.consumeAsPaths(StaticResourcesRecorder.META_INF_RESOURCES, resource -> {
try {
Files.walkFileTree(resource, new SimpleFileVisitor<>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
if (e != null) {
throw e;
}
int index = dir.toString().indexOf(StaticResourcesRecorder.META_INF_RESOURCES);
if (index > 0) {
producer.produce(new NativeImageResourceBuildItem(dir.toString().substring(index)));
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});

}
}

Expand All @@ -89,7 +113,8 @@ public void nativeImageResource(Optional<StaticResourcesBuildItem> staticResourc
* @return the set of static resources
* @throws Exception
*/
private Set<StaticResourcesBuildItem.Entry> getClasspathResources(ApplicationArchivesBuildItem applicationArchivesBuildItem)
private Set<StaticResourcesBuildItem.Entry> getClasspathResources(
ApplicationArchivesBuildItem applicationArchivesBuildItem)
throws Exception {
Set<StaticResourcesBuildItem.Entry> knownPaths = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
<title>Hello world</title></head>
<body>
Hello World
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
<title>Hello world</title></head>
<body>
Hello World
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.it.vertx;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class StaticResourcesIT extends StaticResourcesTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkus.it.vertx;

import static io.restassured.RestAssured.when;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class StaticResourcesTest {

@Test
public void testExisting() {
when().get("/test.txt").then().statusCode(200);
}

@Test
public void testNonExisting() {
when().get("/test2.txt").then().statusCode(404);
}

@Test
public void testIndexInDirectory() {
when().get("/dummy/").then().statusCode(200);
geoand marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testIndexInNestedDirectory() {
when().get("/l1/l2/").then().statusCode(200);
geoand marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testNonIndexInDirectory() {
when().get("/dummy2/").then().statusCode(404);
zakkak marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testIndexInNonExistingDirectory() {
when().get("/dummy3/").then().statusCode(404);
}
}