FixTestNativeImageRun Gradle task to resolve test failures on Native Image run#787
Conversation
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.
Give it a more descriptive name.
There was a problem hiding this comment.
Maybe fixTestNativeImageRun or fixTestNativeImageRunFailure?
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public abstract class GenerateMetadataTask extends DefaultTask { |
There was a problem hiding this comment.
Explained in the added javadoc.
| import java.nio.file.Path; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public abstract class FixTestNativeImageRun extends DefaultTask { |
|
|
||
| @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.
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.
Isn't this set in index.json? We override here?
There was a problem hiding this comment.
This name is ambiguous, this refers to packages that are ‘allowed’ in the agent filter. In ContributeTask, the variable is named packages, but perhaps we should use a more descriptive name. What about includedPackages or agentAllowedPackages, agentFilterPackages?
| * 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.
These are general utils. Is there a lib that can do that?
There was a problem hiding this comment.
This is essentially a wrapper for org.gradle.process.ExecOperations#exec, handling all similar invocation preparations. Maybe we should create a GeneralUtils class for these types of methods, including printing methods for task progress: #787 (comment)?
| // 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.
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.
Yes, some test directories for the libraries in the repository don’t contain any files related to agent filters.
| 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"); |
| 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.
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 { |
0ae9765 to
af9be21
Compare
fef6e98 to
8ded7e5
Compare
AGENTS.md
Outdated
| - Write type annotations in all functions and most variables. | ||
| - Document code without being too verbose. | ||
| - In java, always import classes and use them without qualified names. | ||
| - Always use GradleException if possible. |
There was a problem hiding this comment.
Hmm, this should be in subprojects I think.
There was a problem hiding this comment.
Added AGENTS.md to the tests/src.
build.gradle
Outdated
| } | ||
|
|
||
| // Test metadata generation only for single coordinates (not batched like "1/64") | ||
| if (!coordinate.contains("/")) { |
There was a problem hiding this comment.
Actually, don't guard. Just run this task above for a single coordinate.
There was a problem hiding this comment.
Done, and reformatted the whole test so it is more clear and readable.
build.gradle
Outdated
| def artifact = parts[1] | ||
| def version = parts[2] | ||
|
|
||
| def versionDir = new File(tck.metadataRoot.get().asFile, "${group}/${artifact}/${version}") |
There was a problem hiding this comment.
We do this so many times, please reuse.
build.gradle
Outdated
| throw new GradleException("No metadata files found in ${versionDir} (besides index.json)") | ||
| } | ||
|
|
||
| def indexList = (List) new groovy.json.JsonSlurper().parse(indexFile) |
There was a problem hiding this comment.
We need more rules for qualified names.
There was a problem hiding this comment.
Fixed, and added to the AGENTS.md.
8ded7e5 to
51fb75a
Compare
7e213d9 to
9e7bdb6
Compare
| - Write type annotations in all functions and most variables. | ||
| - Document code without being too verbose. | ||
| - In java, always import classes and use them without qualified names. | ||
| - In Java and Groovy, always import classes and use them without qualified names. |
9e7bdb6 to
9dfa88e
Compare
What does this PR do?
Fixes: #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.