Automatically register directories for registered resource hints

When a hint such as `graphql/*.*` is registered for resources that are
looked up via classpath scanning using a pattern such as
`classpath*:graphql/**/*.graphqls`, an appropriate pattern is in fact
registered in the generated `resource-config.json` file for GraalVM
native images; however, classpath scanning fails since GraalVM
currently does not make the `graphql` directory automatically available
as a classpath resource.

This can be very confusing and cumbersome for users since a file such
as `graphql/schema.graphqls` will not be discovered via classpath
scanning even though the file is present in the native image filesystem.

To address this, this commit automatically registers resource hints for
enclosing directories for a registered pattern.

If the GraalVM team later decides to perform automatic directory
registration, we can then remove the code introduced in conjunction
with this issue.

Closes gh-29403
This commit is contained in:
Sam Brannen
2022-10-30 18:37:02 +01:00
parent d03102edc3
commit 29f085bd1a
7 changed files with 123 additions and 37 deletions

View File

@@ -149,7 +149,15 @@ class ConfigurationClassPostProcessorAotContributionTests {
.singleElement()
.satisfies(resourceHint -> assertThat(resourceHint.getIncludes())
.map(ResourcePatternHint::getPattern)
.containsOnly("org/springframework/context/testfixture/context/annotation/ImportConfiguration.class"));
.containsExactlyInAnyOrder(
"org",
"org/springframework",
"org/springframework/context",
"org/springframework/context/testfixture",
"org/springframework/context/testfixture/context",
"org/springframework/context/testfixture/context/annotation",
"org/springframework/context/testfixture/context/annotation/ImportConfiguration.class"
));
}
@SuppressWarnings("unchecked")