From 7a7824d762b9878d509f4ff1837c6d3ccc8c3473 Mon Sep 17 00:00:00 2001 From: David Nestorovic Date: Fri, 8 Nov 2024 14:43:49 +0100 Subject: [PATCH] Properly add Input and Output anotations to the updater task --- .../org.graalvm.internal.tck-harness.gradle | 4 +- ...tingLibrariesWithNewerVersionsTask.groovy} | 5 +- .../tck/TestedVersionUpdaterTask.java | 57 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) rename tests/tck-build-logic/src/main/groovy/org/graalvm/internal/{tasks/FetchExistingLibrariesWithNewerVersions.groovy => tck/harness/tasks/FetchExistingLibrariesWithNewerVersionsTask.groovy} (97%) diff --git a/tests/tck-build-logic/src/main/groovy/org.graalvm.internal.tck-harness.gradle b/tests/tck-build-logic/src/main/groovy/org.graalvm.internal.tck-harness.gradle index 5d7dec14d..e26864c9b 100644 --- a/tests/tck-build-logic/src/main/groovy/org.graalvm.internal.tck-harness.gradle +++ b/tests/tck-build-logic/src/main/groovy/org.graalvm.internal.tck-harness.gradle @@ -10,13 +10,13 @@ plugins { } import groovy.json.JsonOutput -import org.graalvm.internal.tasks.FetchExistingLibrariesWithNewerVersions import org.graalvm.internal.tck.DockerTask import org.graalvm.internal.tck.ConfigFilesChecker import org.graalvm.internal.tck.ScaffoldTask import org.graalvm.internal.tck.GrypeTask import org.graalvm.internal.tck.TestedVersionUpdaterTask import org.graalvm.internal.tck.harness.tasks.CheckstyleInvocationTask +import org.graalvm.internal.tck.harness.tasks.FetchExistingLibrariesWithNewerVersionsTask import org.graalvm.internal.tck.harness.tasks.TestInvocationTask @@ -164,7 +164,7 @@ Provider generateMatrixDiffCoordinates = tasks.register("generateMatrixDif } // groovy tasks -tasks.register("fetchExistingLibrariesWithNewerVersions", FetchExistingLibrariesWithNewerVersions.class) { task -> +tasks.register("fetchExistingLibrariesWithNewerVersions", FetchExistingLibrariesWithNewerVersionsTask.class) { task -> task.setGroup(METADATA_GROUP) task.setDescription("Returns list of all libraries coordinates") task.setAllLibraryCoordinates(matchingCoordinates) diff --git a/tests/tck-build-logic/src/main/groovy/org/graalvm/internal/tasks/FetchExistingLibrariesWithNewerVersions.groovy b/tests/tck-build-logic/src/main/groovy/org/graalvm/internal/tck/harness/tasks/FetchExistingLibrariesWithNewerVersionsTask.groovy similarity index 97% rename from tests/tck-build-logic/src/main/groovy/org/graalvm/internal/tasks/FetchExistingLibrariesWithNewerVersions.groovy rename to tests/tck-build-logic/src/main/groovy/org/graalvm/internal/tck/harness/tasks/FetchExistingLibrariesWithNewerVersionsTask.groovy index 455f23223..67dbf2bfc 100644 --- a/tests/tck-build-logic/src/main/groovy/org/graalvm/internal/tasks/FetchExistingLibrariesWithNewerVersions.groovy +++ b/tests/tck-build-logic/src/main/groovy/org/graalvm/internal/tck/harness/tasks/FetchExistingLibrariesWithNewerVersionsTask.groovy @@ -1,4 +1,5 @@ -package org.graalvm.internal.tasks +package org.graalvm.internal.tck.harness.tasks + import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.core.type.TypeReference @@ -16,7 +17,7 @@ import java.util.regex.Matcher import java.util.regex.Pattern -abstract class FetchExistingLibrariesWithNewerVersions extends DefaultTask { +abstract class FetchExistingLibrariesWithNewerVersionsTask extends DefaultTask { @Input List allLibraryCoordinates diff --git a/tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/TestedVersionUpdaterTask.java b/tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/TestedVersionUpdaterTask.java index ad39ab896..26726a7b2 100644 --- a/tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/TestedVersionUpdaterTask.java +++ b/tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/TestedVersionUpdaterTask.java @@ -7,58 +7,57 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import org.graalvm.internal.tck.model.MetadataVersionsIndexEntry; + import org.gradle.api.DefaultTask; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.OutputFiles; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.options.Option; import org.gradle.util.internal.VersionNumber; import java.io.File; import java.io.IOException; -import java.util.Arrays; import java.util.Comparator; import java.util.List; public abstract class TestedVersionUpdaterTask extends DefaultTask { - private final ObjectMapper objectMapper = new ObjectMapper() - .enable(SerializationFeature.INDENT_OUTPUT) - .setSerializationInclusion(JsonInclude.Include.NON_NULL); - @Option(option = "coordinates", description = "GAV coordinates of the library") - void setCoordinates(String coordinates) { - this.coordinates = coordinates; - } - - @Option(option = "lastSupportedVersion", description = "Last version of the library that passed tests") - void setLastSupportedVersion(String version) { - this.lastSupportedVersion = version; - } - - private String coordinates; - private String lastSupportedVersion; - - - @TaskAction - void run() throws IllegalStateException, IOException { - String[] coordinatesParts = coordinates.split(":"); + void setCoordinates(String c) { + String[] coordinatesParts = c.split(":"); if (coordinatesParts.length != 3) { throw new IllegalArgumentException("Maven coordinates should have 3 parts"); } String group = coordinatesParts[0]; String artifact = coordinatesParts[1]; String version = coordinatesParts[2]; - Coordinates c = new Coordinates(group, artifact, version); - addToMetadataIndexJson(c); + Coordinates coordinates = new Coordinates(group, artifact, version); + + getIndexFile().set(getProject().file(CoordinateUtils.replace("metadata/$group$/$artifact$/index.json", coordinates))); + getNewVersion().set(version); } - private void addToMetadataIndexJson(Coordinates c) throws IOException { - File coordinatesMetadataIndex = getProject().file(CoordinateUtils.replace("metadata/$group$/$artifact$/index.json", c)); - List entries = objectMapper.readValue(coordinatesMetadataIndex, new TypeReference<>() { - }); + @Input + @Option(option = "lastSupportedVersion", description = "Last version of the library that passed tests") + protected abstract Property getLastSupportedVersion(); + + @Input + protected abstract Property getNewVersion(); + + @OutputFiles + protected abstract RegularFileProperty getIndexFile(); + + @TaskAction + void run() throws IllegalStateException, IOException { + File coordinatesMetadataIndex = getIndexFile().get().getAsFile(); + ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).setSerializationInclusion(JsonInclude.Include.NON_NULL); + List entries = objectMapper.readValue(coordinatesMetadataIndex, new TypeReference<>() {}); for (MetadataVersionsIndexEntry entry : entries) { - if (entry.testedVersions().contains(lastSupportedVersion)) { - entry.testedVersions().add(c.version()); + if (entry.testedVersions().contains(getLastSupportedVersion().get())) { + entry.testedVersions().add(getNewVersion().get()); entry.testedVersions().sort(Comparator.comparing(VersionNumber::parse)); } }