diff options
author | gjoranv <gv@yahooinc.com> | 2023-07-04 13:25:33 +0200 |
---|---|---|
committer | gjoranv <gv@yahooinc.com> | 2023-07-04 13:25:33 +0200 |
commit | bd719b81d00c7015b820c93f2d1ef460c97f64cc (patch) | |
tree | 90fa420264eed1c2b03d7cb6bb4274606dbc0293 /bundle-plugin/src | |
parent | 394c04ac5bdaea3a56ac01f123d09af75f8e550d (diff) |
Do not use version for allowed embedded artifacts.
- Rename ArtifactInfo -> ArtifactId and simply ignore versions.
Diffstat (limited to 'bundle-plugin/src')
5 files changed, 74 insertions, 71 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 304845d4dea..8f588ffa5b0 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 @@ -8,7 +8,7 @@ import com.yahoo.container.plugin.classanalysis.PackageTally; import com.yahoo.container.plugin.osgi.ExportPackages; import com.yahoo.container.plugin.osgi.ExportPackages.Export; import com.yahoo.container.plugin.osgi.ImportPackages.Import; -import com.yahoo.container.plugin.util.ArtifactInfo; +import com.yahoo.container.plugin.util.ArtifactId; import com.yahoo.container.plugin.util.Artifacts; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; @@ -245,17 +245,20 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { } private void logProvidedArtifactsIncluded(List<Artifact> includedArtifacts, - List<ArtifactInfo> providedArtifacts) throws MojoExecutionException { + List<ArtifactId> providedArtifacts) throws MojoExecutionException { if (effectiveBundleType() == BundleType.CORE) return; - Set<ArtifactInfo> included = includedArtifacts.stream().map(ArtifactInfo::fromArtifact).collect(Collectors.toSet()); - Set<ArtifactInfo> providedIncluded = Sets.intersection(included, new HashSet<>(providedArtifacts)); + Set<ArtifactId> included = includedArtifacts.stream().map(ArtifactId::fromArtifact).collect(Collectors.toSet()); + getLog().debug("Included artifacts: " + included); + getLog().debug("Provided artifacts: " + providedArtifacts); - HashSet<ArtifactInfo> allowed = getAllowedEmbeddedArtifacts(providedIncluded); + Set<ArtifactId> includedProvided = Sets.intersection(included, new HashSet<>(providedArtifacts)); + getLog().debug("Included provided artifacts: " + includedProvided); + HashSet<ArtifactId> allowed = getAllowedEmbeddedArtifacts(includedProvided); - List<String> violations = providedIncluded.stream() + List<String> violations = includedProvided.stream() .filter(a -> ! allowed.contains(a)) - .map(ArtifactInfo::stringValue) + .map(ArtifactId::stringValue) .sorted().toList(); if (! violations.isEmpty()) { @@ -265,12 +268,12 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { } } - private HashSet<ArtifactInfo> getAllowedEmbeddedArtifacts(Set<ArtifactInfo> providedIncluded) throws MojoExecutionException { + private HashSet<ArtifactId> getAllowedEmbeddedArtifacts(Set<ArtifactId> providedIncluded) throws MojoExecutionException { if (allowEmbeddedArtifacts.isEmpty()) return new HashSet<>(); - var allowed = new HashSet<ArtifactInfo>(); + var allowed = new HashSet<ArtifactId>(); try { - allowEmbeddedArtifacts.stream().map(ArtifactInfo::fromStringValue).forEach(allowed::add); + allowEmbeddedArtifacts.stream().map(ArtifactId::fromStringValue).forEach(allowed::add); } catch (Exception e) { throw new MojoExecutionException("In config parameter 'allowEmbeddedArtifacts': " + e.getMessage(), e); } diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateProvidedArtifactManifestMojo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateProvidedArtifactManifestMojo.java index ee35c559e48..b4c474fc72d 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateProvidedArtifactManifestMojo.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateProvidedArtifactManifestMojo.java @@ -24,6 +24,9 @@ import java.util.jar.JarOutputStream; import java.util.jar.Manifest; /** + * Replaces the Class-Path of a jar file manifest with a list of provided artifacts. + * The Class-Path is used because it is trivial to generate with the maven-jar-plugin. + * * @author gjoranv */ @Mojo(name = "generate-provided-artifact-manifest", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactId.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactId.java new file mode 100644 index 00000000000..2786a9c559f --- /dev/null +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactId.java @@ -0,0 +1,56 @@ +package com.yahoo.container.plugin.util; + +import org.apache.maven.artifact.Artifact; + +import java.util.Objects; + +/** + * Helper class to work with artifacts, where version does not matter. + * + * @author gjoranv + */ +public class ArtifactId { + + private final String groupId; + private final String artifactId; + + private ArtifactId(String groupId, String artifactId) { + this.groupId = groupId; + this.artifactId = artifactId; + } + + public static ArtifactId fromArtifact(Artifact artifact) { + return new ArtifactId(artifact.getGroupId(), artifact.getArtifactId()); + } + + public static ArtifactId fromStringValue(String stringValue) { + var parts = stringValue.trim().split(":"); + if (parts.length == 2 || parts.length == 3) { + return new ArtifactId(parts[0], parts[1]); + } + throw new IllegalArgumentException( + "An artifact should be represented in the format 'groupId:ArtifactId[:version]', not: " + stringValue); + } + + public String stringValue() { + return groupId + ":" + artifactId; + } + + @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; + ArtifactId that = (ArtifactId) o; + return Objects.equals(groupId, that.groupId) && Objects.equals(artifactId, that.artifactId); + } + + @Override + public int hashCode() { + return Objects.hash(groupId, artifactId); + } +} 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 deleted file mode 100644 index 490a9241661..00000000000 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ArtifactInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -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. Vespa artifacts have their version set to '*'. - * - * @author gjoranv - */ -public class ArtifactInfo { - - private final String groupId; - private final String artifactId; - private final String version; - - 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.trim().split(":"); - if (parts.length != 3) { - throw new IllegalArgumentException("Invalid artifact string: " + stringValue); - } - return new ArtifactInfo(parts[0], parts[1], parts[2]); - } - - public String stringValue() { - 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); - } -} diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/JarFiles.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/JarFiles.java index 846301ccd5c..3ef58fc87b6 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/JarFiles.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/JarFiles.java @@ -20,10 +20,10 @@ import static com.yahoo.container.plugin.mojo.GenerateProvidedArtifactManifestMo */ public class JarFiles { - public static List<ArtifactInfo> providedArtifactsFromManifest(File jarFile) { + public static List<ArtifactId> providedArtifactsFromManifest(File jarFile) { return getManifest(jarFile).map(mf -> getMainAttributeValue(mf, PROVIDED_ARTIFACTS_MANIFEST_ENTRY) .map(s -> Arrays.stream(s.split(",")) - .map(ArtifactInfo::fromStringValue) + .map(ArtifactId::fromStringValue) .toList()) .orElse(Collections.emptyList())) .orElse(Collections.emptyList()); |