From 19cd09976f98ea9abda6738c378aa27ca623e11e Mon Sep 17 00:00:00 2001 From: gjoranv Date: Mon, 3 Jul 2023 14:38:14 +0200 Subject: Always set version for 'com.yahoo.vespa' artifacts to '*' + Simplify by implementing toString + Trim input string --- .../plugin/mojo/GenerateOsgiManifestMojo.java | 9 +++-- .../yahoo/container/plugin/util/ArtifactInfo.java | 40 +++++++++++++++++++--- 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'bundle-plugin') diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java index bec55ec0fc9..c524b233b73 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java @@ -248,13 +248,13 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { List providedArtifacts) throws MojoExecutionException { if (effectiveBundleType() == BundleType.CORE) return; - Set included = includedArtifacts.stream().map(ArtifactInfo::new).collect(Collectors.toSet()); + Set included = includedArtifacts.stream().map(ArtifactInfo::fromArtifact).collect(Collectors.toSet()); Set providedIncluded = Sets.intersection(included, new HashSet<>(providedArtifacts)); HashSet allowed = getAllowedEmbeddedArtifacts(providedIncluded); List violations = providedIncluded.stream() - .filter(a -> !allowed.contains(a)) + .filter(a -> ! allowed.contains(a)) .map(ArtifactInfo::stringValue) .sorted().toList(); @@ -276,10 +276,9 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { } var allowedButUnused = Sets.difference(allowed, providedIncluded); if (! allowedButUnused.isEmpty()) { - warnOrThrow("'allowEmbeddedArtifacts' contains artifact(s) not used in project: %s" - .formatted(allowedButUnused.stream().map(ArtifactInfo::stringValue).toList())); + warnOrThrow("Configuration parameter 'allowEmbeddedArtifacts' contains artifact(s) not used in project: " + allowedButUnused); } - getLog().info("Ignoring artifacts embedded in bundle: " + allowEmbeddedArtifacts); + getLog().info("Ignoring artifacts embedded in bundle: " + allowed); return allowed; } diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactInfo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactInfo.java index 32cc732241b..490a9241661 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactInfo.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactInfo.java @@ -2,20 +2,33 @@ package com.yahoo.container.plugin.util; import org.apache.maven.artifact.Artifact; +import java.util.Objects; + +import static com.yahoo.container.plugin.util.Artifacts.VESPA_GROUP_ID; + /** - * Helper class to work with artifacts. + * Helper class to work with artifacts. Vespa artifacts have their version set to '*'. * * @author gjoranv */ -public record ArtifactInfo(String groupId, String artifactId, String version) { +public class ArtifactInfo { + private final String groupId; + private final String artifactId; + private final String version; - public ArtifactInfo(Artifact artifact) { - this(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); + private ArtifactInfo(String groupId, String artifactId, String version) { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = VESPA_GROUP_ID.equals(groupId) ? "*" : version; + } + + public static ArtifactInfo fromArtifact(Artifact artifact) { + return new ArtifactInfo(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); } public static ArtifactInfo fromStringValue(String stringValue) { - var parts = stringValue.split(":"); + var parts = stringValue.trim().split(":"); if (parts.length != 3) { throw new IllegalArgumentException("Invalid artifact string: " + stringValue); } @@ -26,4 +39,21 @@ public record ArtifactInfo(String groupId, String artifactId, String version) { return groupId + ":" + artifactId + ":" + version; } + @Override + public String toString() { + return stringValue(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ArtifactInfo that = (ArtifactInfo) o; + return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId) && Objects.equals(version, that.version); + } + + @Override + public int hashCode() { + return Objects.hash(groupId, artifactId, version); + } } -- cgit v1.2.3