-
Notifications
You must be signed in to change notification settings - Fork 109
FixTestNIRun Gradle task to resolve test failures on Native Image run #787
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
base: master
Are you sure you want to change the base?
Conversation
Created MetadataGenerationUtils utility class for operations shared by ContributionTask and GenerateMetadataTask.
8454626 to
0ae9765
Compare
| task.setGroup(METADATA_GROUP) | ||
| } | ||
| // gradle fixTestNIRun --testLibraryCoordinates=<maven-coordinates> --newLibraryVersion=<library version which needs fix> | ||
| tasks.register("fixTestNIRun", FixTestNativeImageRun.class) { task -> |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very useful :) \cc @jormundur00
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.