-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[GR-49770] Restrict the Expressivity of Patterns in resource-config.json
#7487
Comments
Starting with Mandrel 23.1 and GraalVM for JDK 21 the use of `-H:ResourceConfigurationFiles` and `-H:ReflectionConfigurationFiles` is marked as experimental and requires the use of `-H::±UnlockExperimentalVMOptions` to avoid warnings (see oracle/graal#7190), while in the future (planned for the next release) the presence of this option will be mandatory when using experimental options (see oracle/graal#7370). Furthermore, as described in oracle/graal#7487 Mandrel and GraalVM will also adopt glob patterns in the future (planned for the next release) and gradually phase out the ability to use exclude patterns. The aim of this change is to discourage Quarkus users from creating their own configuration files.
Starting with Mandrel 23.1 and GraalVM for JDK 21 the use of `-H:ResourceConfigurationFiles` and `-H:ReflectionConfigurationFiles` is marked as experimental and requires the use of `-H::±UnlockExperimentalVMOptions` to avoid warnings (see oracle/graal#7190), while in the future (planned for the next release) the presence of this option will be mandatory when using experimental options (see oracle/graal#7370). Furthermore, as described in oracle/graal#7487 Mandrel and GraalVM will also adopt glob patterns in the future (planned for the next release) and gradually phase out the ability to use exclude patterns. The aim of this change is to inform Quarkus users that they are responsible for keeping such configuration files up to date and to make clear that they need to start using the `-H::±UnlockExperimentalVMOptions` option.
I support the idea of using globbing instead of allowing arbitrary regex for resource inclusion. However, we should ensure that this new format also allows per-module resource inclusion like the current format. See:
This new format give us the opportunity to have a dedicated field for per-module resource inclusion instead of encoding an optional module-name prefix into the pattern name like we did before. |
Also we should not break compatibility with the existing regex based solution but instead deprecate it. I.e. whenever we see a That requires that we use a different json substructure for the new resource inclusion approach. E.g. something like {
"include": [
{
"pattern": "assets/**"
},
{
"module": "myJavaModule",
"pattern": "images/**/*.png"
}
]
} that would not conflict with the existing data because there we do not allow |
I fully support the idea of the |
The reason I used But if we do not think that is a problem in practice we can indeed reuse the field name. |
Few notes regarding my discussions with both @vjovanov and @olpaw :
|
Looking int the implementations of Also not sure if we are willing to have the regex bits of JDK as a core part of every image. However, if we are willing to have the regex bits as a core image dependency then we would likely be better off with a single optimized regex that we create from all the glob patterns that we need to take into account. If this is done in an intelligent way I expect this to be the most space efficient representation of a resource-matcher we can have in the image.
we can create one regex like N.b Conceptually the effort to create such a single optimized regex out of all glob patterns is equivalent to the building of the trie from the glob patterns. TL;DR
Pick your poison ;-) |
I'd suggest using the Trie without |
Those are great points! I would implement the basic glob patterns from this article. Easy to link and explain, not system-specific, easy to index, and fast at run time. |
Yes, we will have to check these conditions at run time in the future so they need to be stored in the trie. If all descendants of the same ancestor would have the same condition we could hoist it up the tree, but I am not sure this optimization is worth the complexity. We will see this when we build the trees in practice. |
Starting with Mandrel 23.1 and GraalVM for JDK 21 the use of `-H:ResourceConfigurationFiles` and `-H:ReflectionConfigurationFiles` is marked as experimental and requires the use of `-H::±UnlockExperimentalVMOptions` to avoid warnings (see oracle/graal#7190), while in the future (planned for the next release) the presence of this option will be mandatory when using experimental options (see oracle/graal#7370). Furthermore, as described in oracle/graal#7487 Mandrel and GraalVM will also adopt glob patterns in the future (planned for the next release) and gradually phase out the ability to use exclude patterns. The aim of this change is to inform Quarkus users that they are responsible for keeping such configuration files up to date and to make clear that they need to start using the `-H::±UnlockExperimentalVMOptions` option.
resource-config.json
resource-config.json
TL;DR
Native Image currently accepts Java regular expressions as file patterns in
resource-config.json
. This is problematic for two reasons:\\Q
and\\E
characters.MissingResourceRegistrationError
or return anull
. With regular expressions, it is necessary to check all regular expressions in the build against the current resource path.In this proposal, we restrict the resource-matching patterns to a subset of the glob patterns to simplify pattern matching and reduce computational complexity. The patterns that would be supported are:
*
pattern that matches any number of characters including none within the current directory.**
as a name component to recursively match any number of layers of directories.Proposed patterns allow users to write queries to bulk-include resources, for example,
assets/**/*
orimages/**/*.png
. However, they can be canonicalized into a tree-like structure that allows fast checking of negative queries at run time.The new format will allow only the inclusion patterns:
Goals
Non-Goals
resource-config.json
.Backward Compatibility
The new format will be output by the agent and described in all documentation as the default. The reachability metadata will be migrated to the new format when the JDK 17 and JDK 21 version adopt the back-ported support for this feature.
The current format for resources will be supported until the majority of the ecosystem adopts the new format.
The text was updated successfully, but these errors were encountered: