From 8d506cd232f2e35959e51b702efe6c88cc494c9d Mon Sep 17 00:00:00 2001 From: Wade Taylor Date: Mon, 17 Jul 2023 12:54:27 +1200 Subject: [PATCH] support invoking current-version goal via cli --- src/it/current-version-cli/pom.xml | 35 +++++++++++++++++++ src/it/current-version-cli/verify.bsh | 23 ++++++++++++ .../bounds/StickyCurrentVersionMojo.java | 11 +++++- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/it/current-version-cli/pom.xml create mode 100644 src/it/current-version-cli/verify.bsh diff --git a/src/it/current-version-cli/pom.xml b/src/it/current-version-cli/pom.xml new file mode 100644 index 0000000..22f8512 --- /dev/null +++ b/src/it/current-version-cli/pom.xml @@ -0,0 +1,35 @@ + + + + 4.0.0 + + net.stickycode.plugins.it + sticky-bounds-plugin-current-version-cli + 1.1-SNAPSHOT + pom + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + test + + exec + + + + + mvn + + net.stickycode.plugins:bounds-maven-plugin:@pom.version@:current-version + -Dartifact=net.stickycode:sticky-coercion:[2,3) + + + + + + diff --git a/src/it/current-version-cli/verify.bsh b/src/it/current-version-cli/verify.bsh new file mode 100644 index 0000000..cd9d89b --- /dev/null +++ b/src/it/current-version-cli/verify.bsh @@ -0,0 +1,23 @@ +import java.io.*; +import java.util.*; + +import org.codehaus.plexus.util.*; + +File buildLog = new File( basedir, "build.log" ); +System.out.println( "Checking for existence of first test file: " + buildLog ); +if (!buildLog.exists()) + throw new RuntimeException(buildLog.toString() + " not found" ); + +String logs = FileUtils.fileRead( buildLog, "UTF-8" ).trim(); + +if (!logs.contains("exec-maven-plugin")) { + System.err.println("Expected to invoke exec-maven-plugin"); + return false; +} + +if (!logs.contains("resolved net.stickycode:sticky-coercion:jar:[2,3) to 2.7")) { + System.err.println("Expected version to be 2.7"); + return false; +} + +return true; diff --git a/src/main/java/net/stickycode/plugin/bounds/StickyCurrentVersionMojo.java b/src/main/java/net/stickycode/plugin/bounds/StickyCurrentVersionMojo.java index 1800ed3..19e39e4 100644 --- a/src/main/java/net/stickycode/plugin/bounds/StickyCurrentVersionMojo.java +++ b/src/main/java/net/stickycode/plugin/bounds/StickyCurrentVersionMojo.java @@ -34,6 +34,13 @@ public class StickyCurrentVersionMojo @Parameter(required = false) private Map coordinates; + + /** + * Useful when using the maven cli to look up the current version of a single artifact. Version range is + * supported since the property is not split into a list. + */ + @Parameter(required = false, property = "artifact") + private String artifact; /** * The artifacts to get the current version for group:artifact:version @@ -56,9 +63,11 @@ public class StickyCurrentVersionMojo @Override public void execute() throws MojoExecutionException, MojoFailureException { - List lookup = new ArrayList<>(); + if (this.artifact != null) + lookup.add(new ArtifactLookup().withGav(this.artifact)); + if (artifacts != null) for (String artifact : artifacts) { lookup.add(new ArtifactLookup().withGav(artifact));