Skip to content

Conversation

@kimeta
Copy link
Collaborator

@kimeta kimeta commented Nov 19, 2025

What does this PR do?

Implements: #786

This task runs the Java agent on failed tests for a new library version, and creates a version-specific metadata directory.
It will be executed by automation script #769 to update the metadata for each failing library version.

Created MetadataGenerationUtils utility class for operations shared by ContributionTask and GenerateMetadataTask.
@kimeta kimeta requested a review from vjovanov as a code owner November 19, 2025 17:04
@kimeta kimeta force-pushed the mm/introduce-fixTestNIRun-task branch from 8454626 to 0ae9765 Compare November 19, 2025 17:05
@kimeta kimeta changed the title FixTestNIRun task which fixes test Native Image run fails FixTestNIRun Gradle task to resolve test failures on Native Image run Nov 19, 2025
task.setGroup(METADATA_GROUP)
}
// gradle fixTestNIRun --testLibraryCoordinates=<maven-coordinates> --newLibraryVersion=<library version which needs fix>
tasks.register("fixTestNIRun", FixTestNativeImageRun.class) { task ->
Copy link
Member

Choose a reason for hiding this comment

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

Give it a more descriptive name.

import java.util.List;
import java.util.stream.Collectors;

public abstract class GenerateMetadataTask extends DefaultTask {
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 it do?

import java.nio.file.Path;
import java.util.regex.Pattern;

public abstract class FixTestNativeImageRun extends DefaultTask {
Copy link
Member

Choose a reason for hiding this comment

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

Explain the usage.


@Option(option = "coordinates", description = "Coordinates in the form of group:artifact:version")
public void setCoordinates(String coordinates) {
this.coordinates = coordinates;
Copy link
Member

Choose a reason for hiding this comment

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

We have CoordinateUtils now and they should be handled correctly.

}

@Option(option = "allowedPackages", description = "Comma separated allowed packages (or - for none)")
public void setAllowedPackages(String allowedPackages) {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this set in index.json? We override here?

* Executes the given executable with arguments in an optional working directory via Gradle ExecOperations.
* Captures output and throws a RuntimeException if the exit code is non-zero.
*/
public static void invokeCommand(ExecOperations execOps, String executable, List<String> args, String errorMessage, Path workingDirectory) {
Copy link
Member

Choose a reason for hiding this comment

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

These are general utils. Is there a lib that can do that?

// Ensure the tests build.gradle has an agent block; if not, create user-code-filter.json and add the agent block.
Path buildFilePath = testsDirectory.resolve("build.gradle");
if (!Files.isRegularFile(buildFilePath)) {
throw new RuntimeException("Cannot find tests build file at: " + buildFilePath);
Copy link
Member

Choose a reason for hiding this comment

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

GradleException, we should also add this to AGENTS.md.

throw new RuntimeException("Cannot find tests build file at: " + buildFilePath);
}
String buildGradle = Files.readString(buildFilePath, java.nio.charset.StandardCharsets.UTF_8);
boolean hasAgentBlock = Pattern.compile("(?s)\\bagent\\s*\\{").matcher(buildGradle).find();
Copy link
Member

Choose a reason for hiding this comment

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

Can this even happen?

String buildGradle = Files.readString(buildFilePath, StandardCharsets.UTF_8);
boolean hasAgentBlock = Pattern.compile("(?s)\\bagent\\s*\\{").matcher(buildGradle).find();
if (hasAgentBlock) {
InteractiveTaskUtils.printUserInfo("Agent block already present in: " + BUILD_FILE + " - skipping");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe general utils?

If you already have the test project structure in this repository and need to generate or regenerate metadata, use the `generateMetadata` task:

```shell
./gradlew generateMetadata --coordinates=com.example:my-library:1.0.0
Copy link
Member

Choose a reason for hiding this comment

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

Add these to DEVELOPING.md and to testAllParallel.

/**
* Creates index.json inside the given version directory, listing all files present in that directory.
*/
public static void createIndexJsonSpecificVersion(Path metadataDirectory) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Very useful :) \cc @jormundur00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants