summaryrefslogtreecommitdiffstats
path: root/bundle-plugin
diff options
context:
space:
mode:
authorgjoranv <gv@yahooinc.com>2023-06-28 16:24:09 +0200
committergjoranv <gv@yahooinc.com>2023-06-30 16:31:35 +0200
commitfa0ec3fac94720c5ecf7dfbd4207a1ee8c2d7422 (patch)
tree52551c7b513cc3a44ed7d5eafc8e7cc13e89987b /bundle-plugin
parent7b729a6f399bcc517a15a5b3e4dfcfab7ad1cebd (diff)
Add functions to extract and aggregate provided deps from manifest
Diffstat (limited to 'bundle-plugin')
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/bundle/AnalyzeBundle.java22
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ProvidedArtifact.java8
2 files changed, 30 insertions, 0 deletions
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/bundle/AnalyzeBundle.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/bundle/AnalyzeBundle.java
index 8b32c6c0d0d..6b3d96af1e5 100644
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/bundle/AnalyzeBundle.java
+++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/bundle/AnalyzeBundle.java
@@ -4,6 +4,7 @@ package com.yahoo.container.plugin.bundle;
import com.yahoo.container.plugin.osgi.ExportPackageParser;
import com.yahoo.container.plugin.osgi.ExportPackages.Export;
import com.yahoo.container.plugin.util.JarFiles;
+import com.yahoo.container.plugin.util.ProvidedArtifact;
import java.io.File;
import java.util.ArrayList;
@@ -59,6 +60,27 @@ public class AnalyzeBundle {
.orElseGet(ArrayList::new);
}
+ public static List<ProvidedArtifact> providedArtifactsAggregated(Collection<File> jarFiles) {
+ return jarFiles.stream()
+ .map(AnalyzeBundle::providedArtifacts)
+ .flatMap(List::stream)
+ .distinct()
+ .toList();
+ }
+
+ public static List<ProvidedArtifact> providedArtifacts(File jarFile) {
+ var manifest = getOsgiManifest(jarFile);
+ if (manifest == null) return Collections.emptyList();
+
+ return getMainAttributeValue(manifest, "X-JDisc-Provided-Artifact")
+ .map(s -> Arrays.stream(s.split(","))
+ .map(ProvidedArtifact::fromStringValue)
+ .toList())
+ .orElse(Collections.emptyList());
+
+
+ }
+
private static Manifest getOsgiManifest(File jarFile) {
Optional<Manifest> jarManifest = JarFiles.getManifest(jarFile);
if (jarManifest.isPresent()) {
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ProvidedArtifact.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ProvidedArtifact.java
index 76782148cf1..dbc006a4cb5 100644
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ProvidedArtifact.java
+++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ProvidedArtifact.java
@@ -14,6 +14,14 @@ public record ProvidedArtifact(String groupId, String artifactId, String version
this(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
}
+ public static ProvidedArtifact fromStringValue(String stringValue) {
+ var parts = stringValue.split(":");
+ if (parts.length != 3) {
+ throw new IllegalArgumentException("Invalid artifact string: " + stringValue);
+ }
+ return new ProvidedArtifact(parts[0], parts[1], parts[2]);
+ }
+
public String stringValue() {
return groupId + ":" + artifactId + ":" + version;
}