aboutsummaryrefslogtreecommitdiffstats
path: root/bundle-plugin
diff options
context:
space:
mode:
authorgjoranv <gv@yahooinc.com>2023-07-03 14:38:14 +0200
committergjoranv <gv@yahooinc.com>2023-07-03 22:37:54 +0200
commit19cd09976f98ea9abda6738c378aa27ca623e11e (patch)
treec569b289b9a537f81a9bccd4b4ca42a02ade0f4a /bundle-plugin
parent8bea86a68f61d97c8fc005f9f94815aec4a1d8ca (diff)
Always set version for 'com.yahoo.vespa' artifacts to '*'
+ Simplify by implementing toString + Trim input string
Diffstat (limited to 'bundle-plugin')
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java9
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactInfo.java40
2 files changed, 39 insertions, 10 deletions
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<ArtifactInfo> providedArtifacts) throws MojoExecutionException {
if (effectiveBundleType() == BundleType.CORE) return;
- Set<ArtifactInfo> included = includedArtifacts.stream().map(ArtifactInfo::new).collect(Collectors.toSet());
+ Set<ArtifactInfo> included = includedArtifacts.stream().map(ArtifactInfo::fromArtifact).collect(Collectors.toSet());
Set<ArtifactInfo> providedIncluded = Sets.intersection(included, new HashSet<>(providedArtifacts));
HashSet<ArtifactInfo> allowed = getAllowedEmbeddedArtifacts(providedIncluded);
List<String> 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);
+ }
}