Allow registration of resource hint for root directory
Prior to this commit, it was not possible to register the root directory as a native image resource; however, it is necessary to be able to register the root directory to enable classpath scanning of the root directory within a native image -- for example, to support resource patterns such as `classpath*:/*.properties`. This commit therefore relaxes the precondition check in the ResourcePatternHint constructor to allow explicit registration of the root directory. Closes gh-29402
This commit is contained in:
@@ -81,6 +81,13 @@ class ResourceHintsTests {
|
||||
.hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerRootDirectory() {
|
||||
this.resourceHints.registerPattern("/");
|
||||
assertThat(this.resourceHints.resourcePatternHints()).singleElement().satisfies(
|
||||
patternOf("/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerPattern() {
|
||||
this.resourceHints.registerPattern("com/example/*.properties");
|
||||
|
||||
@@ -33,7 +33,15 @@ class ResourcePatternHintTests {
|
||||
void patternWithLeadingSlashIsRejected() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ResourcePatternHint("/file.properties", null))
|
||||
.withMessage("Resource pattern [/file.properties] must not start with a '/'");
|
||||
.withMessage("Resource pattern [/file.properties] must not start with a '/' unless it is the root directory");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rootDirectory() {
|
||||
ResourcePatternHint hint = new ResourcePatternHint("/", null);
|
||||
assertThat(hint.toRegex().asMatchPredicate())
|
||||
.accepts("/")
|
||||
.rejects("/com/example", "/file.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user