Skip to content

Commit 966c890

Browse files
authored
Add new tasks to enhance AI workflow. (#837)
1 parent 03367f1 commit 966c890

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

tests/tck-build-logic/src/main/groovy/org.graalvm.internal.tck-harness.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.graalvm.internal.tck.harness.tasks.FetchExistingLibrariesWithNewerVer
3030
import org.gradle.util.internal.VersionNumber
3131
import org.graalvm.internal.tck.harness.tasks.ComputeAndPullAllowedDockerImagesTask
3232
import org.graalvm.internal.tck.utils.CoordinateUtils
33+
import org.graalvm.internal.tck.utils.MetadataGenerationUtils
3334

3435

3536
import static org.graalvm.internal.tck.Utils.generateTaskName
@@ -334,3 +335,31 @@ tasks.register("fixTestNativeImageRun", FixTestNativeImageRun.class) { task ->
334335
task.setDescription("Fix test that fails Native Image run for new library version.")
335336
task.setGroup(METADATA_GROUP)
336337
}
338+
339+
// gradle addNewEntryTestsIndexJson -Pcoordinates=<maven-coordinates>
340+
tasks.register("addNewEntryTestsIndexJson", DefaultTask) { task ->
341+
task.setDescription("Adds a new entry to tests/src/index.json for a new library version.")
342+
task.setGroup(METADATA_GROUP)
343+
task.doFirst {
344+
if (!project.hasProperty("coordinates")) {
345+
throw new GradleException("Missing 'coordinates' property! Rerun Gradle with -Pcoordinates=<group:artifact:version>")
346+
}
347+
def coordsStr = project.findProperty("coordinates").toString()
348+
def coords = CoordinateUtils.fromString(coordsStr)
349+
MetadataGenerationUtils.addNewEntryToTestsIndex(project.layout, coords)
350+
}
351+
}
352+
353+
// gradle addLibraryAsLatestMetadataIndexJson -Pcoordinates=<maven-coordinates>
354+
tasks.register("addLibraryAsLatestMetadataIndexJson", DefaultTask) { task ->
355+
task.setDescription("Marks given coordinates as latest in metadata/group/artifact/index.json")
356+
task.setGroup(METADATA_GROUP)
357+
task.doFirst {
358+
if (!project.hasProperty("coordinates")) {
359+
throw new GradleException("Missing 'coordinates' property! Rerun Gradle with -Pcoordinates=<group:artifact:version>")
360+
}
361+
def coordsStr = project.findProperty("coordinates").toString()
362+
def coords = CoordinateUtils.fromString(coordsStr)
363+
MetadataGenerationUtils.makeVersionLatestInIndexJson(project.layout, coords)
364+
}
365+
}

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/utils/MetadataGenerationUtils.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,65 @@ public static void addNewVersionToTestsIndex(ProjectLayout layout, Coordinates t
251251
}
252252
Files.writeString(indexPath, json, StandardCharsets.UTF_8);
253253
}
254+
255+
/**
256+
* Adds a new entry to tests/src/index.json for the given coordinates.
257+
* The entry is inserted by lexicographic order of test-project-path value.
258+
*/
259+
public static void addNewEntryToTestsIndex(ProjectLayout layout, Coordinates newCoords) throws IOException {
260+
Path indexPath = GeneralUtils.getPathFromProject(layout, "tests/src/index.json");
261+
if (!Files.exists(indexPath)) {
262+
return;
263+
}
264+
265+
ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
266+
267+
String content = Files.readString(indexPath, StandardCharsets.UTF_8);
268+
if (content == null || content.isBlank()) {
269+
throw new GradleException("Cannot find test index file at: " + indexPath);
270+
}
271+
272+
List<TestIndexEntry> entries = mapper.readValue(content, new TypeReference<>() {});
273+
String group = newCoords.group();
274+
String artifact = newCoords.artifact();
275+
String newVersion = newCoords.version();
276+
String prefix = group + "/" + artifact + "/";
277+
String newTestProjectPath = prefix + newVersion;
278+
279+
// If the new entry already exists, do nothing
280+
for (TestIndexEntry e : entries) {
281+
if (newTestProjectPath.equals(e.testProjectPath())) {
282+
return;
283+
}
284+
}
285+
286+
// Build new entry
287+
String libName = group + ":" + artifact;
288+
List<String> versions = new ArrayList<>();
289+
versions.add(newVersion);
290+
LibraryEntry libraryEntry = new LibraryEntry(libName, versions);
291+
List<LibraryEntry> libraries = new ArrayList<>();
292+
libraries.add(libraryEntry);
293+
TestIndexEntry newEntry = new TestIndexEntry(newTestProjectPath, libraries);
294+
295+
// Insert lexicographic order of test-project-path
296+
int insertAt = entries.size();
297+
for (int i = 0; i < entries.size(); i++) {
298+
String tp = entries.get(i).testProjectPath();
299+
if (tp != null && newTestProjectPath.compareTo(tp) < 0) {
300+
insertAt = i;
301+
break;
302+
}
303+
}
304+
305+
entries.add(insertAt, newEntry);
306+
307+
DefaultPrettyPrinter prettyPrinterNew = new DefaultPrettyPrinter();
308+
prettyPrinterNew.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
309+
String jsonNew = mapper.writer(prettyPrinterNew).writeValueAsString(entries);
310+
if (!jsonNew.endsWith(System.lineSeparator())) {
311+
jsonNew = jsonNew + System.lineSeparator();
312+
}
313+
Files.writeString(indexPath, jsonNew, StandardCharsets.UTF_8);
314+
}
254315
}

0 commit comments

Comments
 (0)