|
| 1 | +/* |
| 2 | + * Copyright and related rights waived via CC0 |
| 3 | + * |
| 4 | + * You should have received a copy of the CC0 legalcode along with this |
| 5 | + * work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. |
| 6 | + */ |
| 7 | +package org.graalvm.internal.tck.harness.tasks; |
| 8 | + |
| 9 | +import org.gradle.api.GradleException; |
| 10 | +import org.gradle.api.tasks.TaskAction; |
| 11 | +import org.graalvm.internal.tck.MetadataFilesCheckerTask; |
| 12 | + |
| 13 | +import java.util.ArrayList; |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +/** |
| 17 | + * Executes MetadataFilesCheckerTask for all matching coordinates resolved via -Pcoordinates. |
| 18 | + * This unifies handling so the task itself performs coordinate resolution and iteration. |
| 19 | + */ |
| 20 | +@SuppressWarnings("unused") |
| 21 | +public abstract class CheckMetadataFilesAllTask extends CoordinatesAwareTask { |
| 22 | + |
| 23 | + @TaskAction |
| 24 | + public void runAll() { |
| 25 | + List<String> coords = resolveCoordinates(); |
| 26 | + if (coords.isEmpty()) { |
| 27 | + getLogger().lifecycle("No matching coordinates found for metadata checks. Nothing to do."); |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + List<String> failures = new ArrayList<>(); |
| 32 | + for (String c : coords) { |
| 33 | + if (c.startsWith("samples:") || c.startsWith("org.example:")) { |
| 34 | + continue; // skip samples/infrastructure |
| 35 | + } |
| 36 | + String tmpName = "checkMetadataFiles_" + c.replace(":", "_") + "_" + System.nanoTime(); |
| 37 | + MetadataFilesCheckerTask t = getProject().getTasks().create(tmpName, MetadataFilesCheckerTask.class); |
| 38 | + t.setCoordinates(c); |
| 39 | + try { |
| 40 | + t.run(); |
| 41 | + getLogger().lifecycle("Metadata files check passed for {}", c); |
| 42 | + } catch (Throwable ex) { |
| 43 | + failures.add(c + ": " + ex.getMessage()); |
| 44 | + getLogger().error("Metadata files check failed for {}: {}", c, ex.getMessage()); |
| 45 | + } finally { |
| 46 | + // Best effort cleanup to avoid cluttering the task graph |
| 47 | + t.setEnabled(false); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + if (!failures.isEmpty()) { |
| 52 | + String msg = "Metadata files check failed for the following coordinates:\n - " + String.join("\n - ", failures); |
| 53 | + throw new GradleException(msg); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments