From 80bc644fa9b9079f025d1434ba59b4faaa915382 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Mon, 26 Feb 2024 08:08:40 +0100 Subject: [PATCH] Removed the unnecessary duplicated properties in ArtifactAssociation. Removed deprecated StringUtils from Plexus in SetMojo. --- .../versions/api/ArtifactAssociation.java | 4 ---- .../api/DefaultArtifactAssociation.java | 20 ++++++------------- .../versions/api/DefaultVersionsHelper.java | 14 ++++++------- .../mojo/versions/api/PropertyVersions.java | 8 ++++---- .../org/codehaus/mojo/versions/SetMojo.java | 4 ++-- .../xml/PropertyUpdatesXmlReportRenderer.java | 4 ++-- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactAssociation.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactAssociation.java index 794db9d4a8..530068f5a3 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactAssociation.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactAssociation.java @@ -28,10 +28,6 @@ * @since 1.0-alpha-3 */ public interface ArtifactAssociation extends Comparable { - String getGroupId(); - - String getArtifactId(); - boolean isUsePluginRepositories(); Artifact getArtifact(); diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultArtifactAssociation.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultArtifactAssociation.java index 69e281ef00..278b083bf4 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultArtifactAssociation.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultArtifactAssociation.java @@ -41,14 +41,6 @@ final class DefaultArtifactAssociation implements ArtifactAssociation { this.usePluginRepositories = usePluginRepositories; } - public String getGroupId() { - return artifact.getGroupId(); - } - - public String getArtifactId() { - return artifact.getArtifactId(); - } - public Artifact getArtifact() { return artifact; } @@ -66,11 +58,11 @@ public int compareTo(ArtifactAssociation o) { } DefaultArtifactAssociation that = (DefaultArtifactAssociation) o; - int rv = getGroupId().compareTo(that.getGroupId()); + int rv = getArtifact().getGroupId().compareTo(that.getArtifact().getGroupId()); if (rv != 0) { return rv; } - rv = getArtifactId().compareTo(that.getArtifactId()); + rv = getArtifact().getArtifactId().compareTo(that.getArtifact().getArtifactId()); if (rv != 0) { return rv; } @@ -93,15 +85,15 @@ public boolean equals(Object o) { if (usePluginRepositories != that.usePluginRepositories) { return false; } - if (!getArtifactId().equals(that.getArtifactId())) { + if (!getArtifact().getArtifactId().equals(that.getArtifact().getArtifactId())) { return false; } - return getGroupId().equals(that.getGroupId()); + return getArtifact().getGroupId().equals(that.getArtifact().getGroupId()); } public int hashCode() { - int result = getGroupId().hashCode(); - result = 31 * result + getArtifactId().hashCode(); + int result = getArtifact().getGroupId().hashCode(); + result = 31 * result + getArtifact().getArtifactId().hashCode(); result = 31 * result + (usePluginRepositories ? 1 : 0); return result; } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java index 8f10bc99c3..1abc65f201 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java @@ -636,14 +636,14 @@ public Map getVersionPropertiesMap(VersionProperties } for (PropertyVersionsBuilder propertyVersionsBuilder : propertyVersionsBuilders) { - final String name = propertyVersionsBuilder.getName(); - builders.put(name, propertyVersionsBuilder); - if (!properties.containsKey(name)) { - final Property value = new Property(name); - getLog().debug("Property ${" + name + "}: Adding inferred version range of " + final String propertyName = propertyVersionsBuilder.getName(); + builders.put(propertyName, propertyVersionsBuilder); + if (!properties.containsKey(propertyName)) { + final Property property = new Property(propertyName); + getLog().debug("Property ${" + propertyName + "}: Adding inferred version range of " + propertyVersionsBuilder.getVersionRange()); - value.setVersion(propertyVersionsBuilder.getVersionRange()); - properties.put(name, value); + property.setVersion(propertyVersionsBuilder.getVersionRange()); + properties.put(propertyName, property); } } } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java index bc695c9e39..9ec604d40f 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java @@ -155,8 +155,8 @@ public ArtifactVersion[] getVersions(Collection artifacts) { // see if the version is available for all associations for (ArtifactAssociation association : associations) { for (Artifact artifact : artifacts) { - if (association.getGroupId().equals(artifact.getGroupId()) - && association.getArtifactId().equals(artifact.getArtifactId())) { + if (association.getArtifact().getGroupId().equals(artifact.getGroupId()) + && association.getArtifact().getArtifactId().equals(artifact.getArtifactId())) { try { result.add(artifact.getSelectedVersion()); } catch (OverConstrainedVersionException e) { @@ -173,8 +173,8 @@ public ArtifactVersion[] getVersions(Collection artifacts) { associations: for (ArtifactAssociation association : associations) { for (Artifact artifact : artifacts) { - if (association.getGroupId().equals(artifact.getGroupId()) - && association.getArtifactId().equals(artifact.getArtifactId())) { + if (association.getArtifact().getGroupId().equals(artifact.getGroupId()) + && association.getArtifact().getArtifactId().equals(artifact.getArtifactId())) { try { if (candidate .toString() diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java index 6af235e9f9..f2ed13bca5 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java @@ -39,6 +39,7 @@ import java.util.TreeMap; import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.artifact.ArtifactUtils; @@ -63,9 +64,8 @@ import org.codehaus.mojo.versions.utils.RegexUtils; import org.codehaus.plexus.components.interactivity.Prompter; import org.codehaus.plexus.components.interactivity.PrompterException; -import org.codehaus.plexus.util.StringUtils; -import static org.codehaus.plexus.util.StringUtils.isEmpty; +import static org.apache.commons.lang.StringUtils.isEmpty; /** * Sets the current project's version and based on that change propagates that change onto any child modules as diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java index 8ad0e612f9..710e2596f4 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java @@ -121,8 +121,8 @@ private static List createPropertyInfo( setPropertyAssociations(Arrays.stream(e.getValue().getAssociations()) .map(a -> { PropertyAssociation pa = new PropertyAssociation(); - pa.setGroupId(a.getGroupId()); - pa.setArtifactId(a.getArtifactId()); + pa.setGroupId(a.getArtifact().getGroupId()); + pa.setArtifactId(a.getArtifact().getArtifactId()); return pa; }) .collect(Collectors.toList()));