From 88bb10240161dec49b24c90a318326cfa4a07057 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Sun, 24 Mar 2024 00:01:12 +0100 Subject: [PATCH] WIP --- .../maveniverse/maven/toolbox/plugin/CLI.java | 3 +- .../maven/toolbox/plugin/gav/GavCopyMojo.java | 9 +++ .../plugin/gav/GavCopyTransitiveMojo.java | 68 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyTransitiveMojo.java diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/CLI.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/CLI.java index b7c6bef9..854eeba8 100644 --- a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/CLI.java +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/CLI.java @@ -9,6 +9,7 @@ import eu.maveniverse.maven.toolbox.plugin.gav.GavClasspathMojo; import eu.maveniverse.maven.toolbox.plugin.gav.GavCopyMojo; +import eu.maveniverse.maven.toolbox.plugin.gav.GavCopyTransitiveMojo; import eu.maveniverse.maven.toolbox.plugin.gav.GavDumpMojo; import eu.maveniverse.maven.toolbox.shared.Output; import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; @@ -19,7 +20,7 @@ */ @CommandLine.Command( name = "toolbox", - subcommands = {GavClasspathMojo.class, GavCopyMojo.class, GavDumpMojo.class}, + subcommands = {GavClasspathMojo.class, GavCopyMojo.class, GavCopyTransitiveMojo.class, GavDumpMojo.class}, versionProvider = CLI.class, description = "Toolbox CLI", mixinStandardHelpOptions = true) diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyMojo.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyMojo.java index 6beb1fb1..d93d8fc9 100644 --- a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyMojo.java +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyMojo.java @@ -22,14 +22,23 @@ @CommandLine.Command(name = "copy", description = "Resolves Maven Artifact and copies it to target") @Mojo(name = "gav-copy", requiresProject = false, threadSafe = true) public final class GavCopyMojo extends GavMojoSupport { + /** + * The target spec. + */ @CommandLine.Parameters(index = "0", description = "The target spec", arity = "1") @Parameter(property = "targetSpec", required = true) private String targetSpec; + /** + * The comma separated GAVs to resolve. + */ @CommandLine.Parameters(index = "1", description = "The comma separated GAVs to resolve", arity = "1") @Parameter(property = "gav", required = true) private String gav; + /** + * Comma separated list of BOMs to apply. + */ @CommandLine.Option( names = {"--boms"}, defaultValue = "", diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyTransitiveMojo.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyTransitiveMojo.java new file mode 100644 index 00000000..ba92a486 --- /dev/null +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavCopyTransitiveMojo.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023-2024 Maveniverse Org. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + */ +package eu.maveniverse.maven.toolbox.plugin.gav; + +import eu.maveniverse.maven.toolbox.plugin.GavMojoSupport; +import eu.maveniverse.maven.toolbox.shared.Output; +import eu.maveniverse.maven.toolbox.shared.ResolutionScope; +import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import picocli.CommandLine; + +/** + * Resolves Maven Artifact transitively and copies all of them to target. + */ +@CommandLine.Command( + name = "copy-transitive", + description = "Resolves Maven Artifact transitively and copies all of them to target") +@Mojo(name = "gav-copy-transitive", requiresProject = false, threadSafe = true) +public final class GavCopyTransitiveMojo extends GavMojoSupport { + /** + * The target spec. + */ + @CommandLine.Parameters(index = "0", description = "The target spec", arity = "1") + @Parameter(property = "targetSpec", required = true) + private String targetSpec; + + /** + * The comma separated GAVs to resolve. + */ + @CommandLine.Parameters(index = "1", description = "The comma separated GAVs to resolve", arity = "1") + @Parameter(property = "gav", required = true) + private String gav; + + /** + * The resolution scope to resolve (default is 'runtime'). + */ + @CommandLine.Option( + names = {"--scope"}, + defaultValue = "runtime", + description = "Resolution scope to resolve (default 'runtime')") + @Parameter(property = "scope", defaultValue = "runtime", required = true) + private String scope; + + /** + * Comma separated list of BOMs to apply. + */ + @CommandLine.Option( + names = {"--boms"}, + defaultValue = "", + description = "Comma separated list of BOMs to apply") + @Parameter(property = "boms") + private String boms; + + @Override + protected boolean doExecute(Output output, ToolboxCommando toolboxCommando) throws Exception { + return toolboxCommando.copyTransitive( + ResolutionScope.parse(scope), + toolboxCommando.loadGavs(csv(gav), csv(boms)), + toolboxCommando.artifactSink(output, targetSpec), + output); + } +}