summaryrefslogtreecommitdiffstats
path: root/bundle-plugin
diff options
context:
space:
mode:
authorgjoranv <gv@yahooinc.com>2023-06-09 16:55:56 +0200
committergjoranv <gv@yahooinc.com>2023-06-09 16:55:56 +0200
commitacd484916c47a0c158a29d3c77bb34b1f502b78f (patch)
tree308d12879f5e684de20c12bc6a5cd56cebe49789 /bundle-plugin
parent2794cc991a90a56cf519c171f4da61d5dc6e3928 (diff)
Generate manifest header for non-public exported packages.
Diffstat (limited to 'bundle-plugin')
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java9
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java21
2 files changed, 25 insertions, 5 deletions
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java
index 51fba228b41..699736195cf 100644
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java
+++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/PackageTally.java
@@ -8,7 +8,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -49,6 +48,14 @@ public class PackageTally {
.collect(Collectors.toSet());
}
+ public Set<String> nonPublicApiExportedPackages() {
+ return definedPackages.values().stream()
+ .filter(pkgInfo -> pkgInfo.exportPackage().isPresent())
+ .filter(pkgInfo -> ! pkgInfo.isPublicApi())
+ .map(PackageInfo::name)
+ .collect(Collectors.toSet());
+ }
+
/**
* Returns the set of packages that is referenced from this tally, but not included in the given set of available packages.
*
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 d217273e42b..9537fed420c 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
@@ -129,10 +129,11 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo {
logNonPublicApiUsage(nonPublicApiUsed);
Map<String, String> manifestContent = generateManifestContent(artifactSet.getJarArtifactsToInclude(), calculatedImports, includedPackages);
- addAdditionalManifestProperties(manifestContent, includedPackages);
+ addAdditionalManifestProperties(manifestContent);
+ addManifestPropertiesForInternalBundles(manifestContent, includedPackages);
addManifestPropertiesForUserBundles(manifestContent, nonPublicApiUsed);
- createManifestFile(Paths.get(project.getBuild().getOutputDirectory()), manifestContent);
+ createManifestFile(Paths.get(project.getBuild().getOutputDirectory()), manifestContent);
} catch (Exception e) {
throw new MojoExecutionException("Failed generating osgi manifest", e);
}
@@ -151,8 +152,7 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo {
return isVespaInternalGroupId(project.getGroupId()) ? BundleType.INTERNAL : BundleType.USER;
}
- private void addAdditionalManifestProperties(Map<String, String> manifestContent, PackageTally includedPackages) {
- addIfNotEmpty(manifestContent, "X-JDisc-PublicApi-Package", publicApi(includedPackages));
+ private void addAdditionalManifestProperties(Map<String, String> manifestContent) {
addIfNotEmpty(manifestContent, "Bundle-Activator", bundleActivator);
addIfNotEmpty(manifestContent, "X-JDisc-Privileged-Activator", jdiscPrivilegedActivator);
addIfNotEmpty(manifestContent, "Main-Class", mainClass);
@@ -161,6 +161,15 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo {
addIfNotEmpty(manifestContent, "WebInfUrl", webInfUrl);
}
+ private void addManifestPropertiesForInternalBundles(Map<String, String> manifestContent, PackageTally includedPackages) {
+ if (effectiveBundleType() == BundleType.USER) return;
+
+ // TODO: this attribute is not necessary, remove?
+ addIfNotEmpty(manifestContent, "X-JDisc-PublicApi-Package", publicApi(includedPackages));
+
+ addIfNotEmpty(manifestContent, "X-JDisc-Non-PublicApi-Export-Package", nonPublicApi(includedPackages));
+ }
+
private void addManifestPropertiesForUserBundles(Map<String, String> manifestContent, List<String> nonPublicApiUsed) {
if (effectiveBundleType() != BundleType.USER) return;
addIfNotEmpty(manifestContent, "X-JDisc-Non-PublicApi-Import-Package", String.join(",", nonPublicApiUsed));
@@ -175,6 +184,10 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo {
return tally.publicApiPackages().stream().sorted().collect(Collectors.joining(","));
}
+ private static String nonPublicApi(PackageTally tally) {
+ return tally.nonPublicApiExportedPackages().stream().sorted().collect(Collectors.joining(","));
+ }
+
private void logDebugPackageSets(List<Export> exportedPackagesFromProvidedJars, PackageTally includedPackages) {
if (getLog().isDebugEnabled()) {
getLog().debug("Referenced packages = " + includedPackages.referencedPackages());