Skip to content

Add check if correct schemas are present in the reachability metadata repository provided to buildtools#821

Merged
jormundur00 merged 7 commits intomasterfrom
jormundur00/gh-820
Jan 23, 2026
Merged

Add check if correct schemas are present in the reachability metadata repository provided to buildtools#821
jormundur00 merged 7 commits intomasterfrom
jormundur00/gh-820

Conversation

@jormundur00
Copy link
Member

@jormundur00 jormundur00 commented Jan 20, 2026

In this PR we introduce validation that correct schemas (that are of a certain major version) are present in the reachability metadata repository provided to the buildtools. With this check, we can warn the user if the format of the metadata repository they are using is outdated and will not work with the current buildtools.

As the changes within the schemas might not require changes in the buildtools repo, we only check if the major version matches, as those version changes represent changes that are not compatible with previous buildtools releases (e.g., adding a new field to a schema that isn't used by buildtools doesn't require buildtools changes).

This PR is a prerequisite for changing the index.json parsing done by the buildtools, as not having this check could lead to projects who use older metadata snapshots breaking without knowing why.

Fixes: #820

@jormundur00 jormundur00 requested a review from vjovanov January 20, 2026 09:58
@jormundur00 jormundur00 self-assigned this Jan 20, 2026
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 20, 2026
@jormundur00 jormundur00 force-pushed the jormundur00/gh-820 branch 2 times, most recently from 0bba771 to 7101367 Compare January 20, 2026 10:37

private FileSystemRepository newRepositoryFromDirectory(Path path, LogLevel logLevel) {
if (Files.isDirectory(path)) {
SchemaValidationUtils.validateSchemas(path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have GraalVM home at this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens pretty early on and we don't have the knowledge of GraalVM home here.

"Note: Since the repository is enabled by default, you can disable it manually in your pom.xml file (see this: " +
"https://graalvm.github.io/native-build-tools/latest/maven-plugin.html#_configuring_the_metadata_repository)");
} else {
SchemaValidationUtils.validateSchemas(repoPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we have a single place where we validate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the validation to inside of the FileSystemRepository constructor, so we can now do it in one place for both of the plugins. This required me to add a dependency from the common/graalvm-reachability-metadata project to the common/utils project, but that seems like a reasonable addition to me, as I see no reason to not have a dependency on Utils.

@@ -0,0 +1,4 @@
{
"name": "library-and-framework-list-schema-v1.0.0",
"note": "placeholder for tests"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now require schemas, we have to also add them to all the "custom" repositories that the tests use. As not to have to always copy the exact schema content (as I don't see a reason to), I just left a placeholder text.

To avoid even more confusion, I changed the content of these schemas to just being [].

// Validate required files in the schemas directory (accepting minimal versions or newer)
List<String> missing = new ArrayList<>();
String prefix = repoRoot.relativize(schemasDir).toString();
for (RequiredSchema required : REQUIRED_SCHEMAS) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we add a new schema in the metadata repo? We should match the two sets I believe and if there is an extra version, or the version in the repo is bigger you should update the build tools.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Counting the number of schemas provided by the metadata repo seems reasonable to me (since changing the number of packaged schemas SHOULD require buildtools changes), so I added that.

I don't think we should necessarily fail if the schema version provided by the metadata repo is higher than the one in build tools: adding some field in an index.json which is not used by buildtools (for example, the field denoting metadata has been generated by AI, which we plan to add) should not necessitate buildtools updates (as it has no effect on them). If we were to go the EXACT match route, we would have to update buildtools every time any small change happens to any of the schemas, which I don't think is maintainable. A solution I came up with was to just keep the minimal version in buildtools, and fail if the metadata provided schemas are lower than the minimal required. Buildtools releases generally come with hardcoded metadata repo versions, so users using an old buildtools release with new metadata versions should do that at their own peril IMO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we need to make the changes to the schemas forward compatible right so we need to have a way to tell to the build tools you need to update. Are we going to be backwards compatible in the repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our offline discussion, I changed it so we now check for EXACT matches in the major version of the schemas. If either the metadata repo or the buildtools-requires have a higher major version, we now fail the builds and leave the appropriate update suggestion in the error message (so now we have a message for every different scenario of version mismatches).

this.rootDirectory = rootDirectory;
}
SchemaValidationUtils.validateSchemas(rootDirectory);
this.moduleIndex = new FileSystemModuleToConfigDirectoryIndex(rootDirectory);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks bad.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@@ -0,0 +1 @@
{} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why even have a file, especially a file with a missing end-of-line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These /resources/repos directories are "mock" metadata repositories used in testing. As we now require the metadata repositories to have certain schemas packaged with them (and we check this), we need to add this "mock" schema directory inside of them.

The missing end-of-line got mixed in somehow with AI generation, I've added them now.

/**
* Represents a required schema by base name with an exact required major version.
*/
private record RequiredSchema(String baseName, int requiredMajor) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requiredMajorVersion

vjovanov
vjovanov previously approved these changes Jan 23, 2026
@jormundur00 jormundur00 merged commit f8eb50d into master Jan 23, 2026
560 checks passed
@jormundur00 jormundur00 deleted the jormundur00/gh-820 branch January 23, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify the schemas and fail the build if the user is using an outdated version of the reachability metadata repository

3 participants