Update AOT resource hints with new GraalVM behavior
Prior to this commit, the resource hints for AOT applications would
generate JSON metadata with `java.util.regex.Pattern`, like:
```
{
"resources": {
"includes": [
{
"pattern": "\\Qbanner.txt\\E"
}
]
}
}
```
This regexp feature, as well as "includes" and "excludes" are not supported
anymore with the new metadata format. This commit removes the pattern
format which is now replaced by a "glob" format.
"globs" should only contain "*" (zero or more characters in a path
segment) or "**" (zero or more path segments).
Some instances of resource hint registration should be migrated as a
result.
For example, "/files/*.ext" matched both "/files/a.ext" and
"/files/folder/b.txt" in the past. The new behavior matches only the
former, unless the "/files/**/*.ext" glob pattern is used.
This commit also removes the "excludes" support, which was not widely
used and very often could lead to subtle behavior.
Closes gh-31340
This commit is contained in:
@@ -39,49 +39,55 @@ class ResourcePatternHintTests {
|
||||
@Test
|
||||
void rootDirectory() {
|
||||
ResourcePatternHint hint = new ResourcePatternHint("/", null);
|
||||
assertThat(hint.toRegex().asMatchPredicate())
|
||||
.accepts("/")
|
||||
.rejects("/com/example", "/file.txt");
|
||||
assertThat(hint.matches("/")).isTrue();
|
||||
assertThat(hint.matches("/com/example")).isFalse();
|
||||
assertThat(hint.matches("/file.txt")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void fileAtRoot() {
|
||||
ResourcePatternHint hint = new ResourcePatternHint("file.properties", null);
|
||||
assertThat(hint.toRegex().asMatchPredicate())
|
||||
.accepts("file.properties")
|
||||
.rejects("com/example/file.properties", "file.prop", "another-file.properties");
|
||||
assertThat(hint.matches("file.properties")).isTrue();
|
||||
assertThat(hint.matches("com/example/file.properties")).isFalse();
|
||||
assertThat(hint.matches("file.prop")).isFalse();
|
||||
assertThat(hint.matches("another-file.properties")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void fileInDirectory() {
|
||||
ResourcePatternHint hint = new ResourcePatternHint("com/example/file.properties", null);
|
||||
assertThat(hint.toRegex().asMatchPredicate())
|
||||
.accepts("com/example/file.properties")
|
||||
.rejects("file.properties", "com/file.properties", "com/example/another-file.properties");
|
||||
assertThat(hint.matches("com/example/file.properties")).isTrue();
|
||||
assertThat(hint.matches("file.properties")).isFalse();
|
||||
assertThat(hint.matches("com/file.properties")).isFalse();
|
||||
assertThat(hint.matches("com/example/another-file.properties")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void extension() {
|
||||
ResourcePatternHint hint = new ResourcePatternHint("*.properties", null);
|
||||
assertThat(hint.toRegex().asMatchPredicate())
|
||||
.accepts("file.properties", "com/example/file.properties")
|
||||
.rejects("file.prop", "com/example/file.prop");
|
||||
ResourcePatternHint hint = new ResourcePatternHint("**/*.properties", null);
|
||||
assertThat(hint.matches("file.properties")).isTrue();
|
||||
assertThat(hint.matches("com/example/file.properties")).isTrue();
|
||||
assertThat(hint.matches("file.prop")).isFalse();
|
||||
assertThat(hint.matches("com/example/file.prop")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void extensionInDirectoryAtAnyDepth() {
|
||||
ResourcePatternHint hint = new ResourcePatternHint("com/example/*.properties", null);
|
||||
assertThat(hint.toRegex().asMatchPredicate())
|
||||
.accepts("com/example/file.properties", "com/example/another/file.properties")
|
||||
.rejects("file.properties", "com/file.properties");
|
||||
assertThat(hint.matches("com/example/file.properties")).isTrue();
|
||||
assertThat(hint.matches("com/example/another/file.properties")).isFalse();
|
||||
assertThat(hint.matches("com/file.properties")).isFalse();
|
||||
assertThat(hint.matches("file.properties")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void anyFileInDirectoryAtAnyDepth() {
|
||||
ResourcePatternHint hint = new ResourcePatternHint("com/example/*", null);
|
||||
assertThat(hint.toRegex().asMatchPredicate())
|
||||
.accepts("com/example/file.properties", "com/example/another/file.properties", "com/example/another")
|
||||
.rejects("file.properties", "com/file.properties");
|
||||
ResourcePatternHint hint = new ResourcePatternHint("com/example/**", null);
|
||||
assertThat(hint.matches("com/example/file.properties")).isTrue();
|
||||
assertThat(hint.matches("com/example/another/file.properties")).isTrue();
|
||||
assertThat(hint.matches("com/example/another")).isTrue();
|
||||
assertThat(hint.matches("file.properties")).isFalse();
|
||||
assertThat(hint.matches("com/file.properties")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user