Skip to content

Commit

Permalink
Resolves #951: DefaultArtifactVersion::getVersion can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 authored and slawekjaranowski committed May 10, 2023
1 parent b3a4037 commit bb0117f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public ArtifactVersions(Artifact artifact, List<ArtifactVersion> 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());
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependency-updates-report
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>dummy-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>[1.0,2.3]</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

</project>

0 comments on commit bb0117f

Please sign in to comment.