From bd969599b3762891590f8d8b7ec51e9a7f177b68 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Mon, 8 May 2023 21:44:01 +0200 Subject: [PATCH] Resolves #951: DefaultArtifactVersion::getVersion can be null --- .../mojo/versions/api/ArtifactVersions.java | 9 ++++++- .../invoker.properties | 1 + .../pom.xml | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/pom.xml diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java index 89ab15be9c..6197066cc8 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java @@ -75,6 +75,9 @@ public ArtifactVersions(Artifact artifact, List versions, Versi this.versionComparator = versionComparator; this.versions = new TreeSet<>(versionComparator); this.versions.addAll(versions); + // DefaultArtifact objects are often built from raw model, without a version set + // (where the actual version is taken from parent or dependency/plugin management) + // this probably isn't the case in an actual Maven execution if (artifact.getVersion() != null) { setCurrentVersion(artifact.getVersion()); } @@ -119,8 +122,12 @@ public boolean equals(Object o) { ArtifactVersions that = (ArtifactVersions) o; + // can't just use Artifact::equals() since e.g. we can have an empty version here return new EqualsBuilder() - .append(getArtifact(), that.getArtifact()) + .append(getArtifact().getGroupId(), that.getGroupId()) + .append(getArtifact().getArtifactId(), that.getArtifact().getArtifactId()) + .append(getArtifact().getVersion(), that.getArtifact().getVersion()) + .append(getArtifact().getScope(), that.getArtifact().getScope()) .append(getVersions(true), that.getVersions(true)) .append(getVersionComparator(), that.getVersionComparator()) .isEquals(); diff --git a/versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/invoker.properties b/versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/invoker.properties new file mode 100644 index 0000000000..6832c404b6 --- /dev/null +++ b/versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependency-updates-report diff --git a/versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/pom.xml b/versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/pom.xml new file mode 100644 index 0000000000..56b976627f --- /dev/null +++ b/versions-maven-plugin/src/it/it-dependency-updates-report-issue-951/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + localhost + dummy-artifact + 1.0.0-SNAPSHOT + + + + + localhost + dummy-api + [1.0,2.3] + test + + + + + + localhost + dummy-api + compile + + + +