diff options
author | gjoranv <gv@yahooinc.com> | 2023-06-30 17:51:11 +0200 |
---|---|---|
committer | gjoranv <gv@yahooinc.com> | 2023-07-03 22:37:54 +0200 |
commit | d68aa292eec910fbfe339928eb62c993a41ac56d (patch) | |
tree | 48d60992ab503f2ee135d525d2fa16c82b1fceef /bundle-plugin/src | |
parent | c20cdd760660f59203a667be18e00d0fe3006723 (diff) |
Retrieve artifacts provided by jdisc only from container(-dev).
Diffstat (limited to 'bundle-plugin/src')
3 files changed, 26 insertions, 22 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 6b3d96af1e5..5da0b161a0a 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 @@ -60,14 +60,6 @@ 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(); @@ -77,8 +69,6 @@ public class AnalyzeBundle { .map(ProvidedArtifact::fromStringValue) .toList()) .orElse(Collections.emptyList()); - - } private static Manifest getOsgiManifest(File jarFile) { 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 55a29ea1535..a7276a7c7ed 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 @@ -29,11 +29,12 @@ import java.util.stream.Stream; import static com.yahoo.container.plugin.bundle.AnalyzeBundle.exportedPackagesAggregated; import static com.yahoo.container.plugin.bundle.AnalyzeBundle.nonPublicApiPackagesAggregated; -import static com.yahoo.container.plugin.bundle.AnalyzeBundle.providedArtifactsAggregated; +import static com.yahoo.container.plugin.bundle.AnalyzeBundle.providedArtifacts; import static com.yahoo.container.plugin.classanalysis.Packages.disallowedImports; import static com.yahoo.container.plugin.osgi.ExportPackages.exportsByPackageName; import static com.yahoo.container.plugin.osgi.ImportPackages.calculateImports; import static com.yahoo.container.plugin.util.Artifacts.VESPA_GROUP_ID; +import static com.yahoo.container.plugin.util.Artifacts.getVespaArtifact; import static com.yahoo.container.plugin.util.Files.allDescendantFiles; @@ -118,19 +119,20 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { logDebugPackageSets(exportedPackagesFromProvidedJars, includedPackages); - Optional<Artifact> jdiscCore = providedJarArtifacts.stream() - .filter(artifact -> artifact.getArtifactId().equals("jdisc_core")) - .findAny(); - - if (jdiscCore.isPresent()) { - // jdisc_core being provided guarantees that log output does not contain its exported packages + Optional<Artifact> jdisc_core = getVespaArtifact("jdisc_core", providedJarArtifacts); + Optional<Artifact> wantedProvidedArtifact = getVespaArtifact(wantedProvidedDependency(), providedJarArtifacts); + if (wantedProvidedArtifact.isPresent()) { + // Having our wanted artifact as provided guarantees that log output does not contain its exported packages logMissingPackages(exportedPackagesFromProvidedDeps, projectPackages, compileJarsPackages, includedPackages); - } else if (! suppressWarningMissingImportPackages) { + + logProvidedArtifactsIncluded(artifactsToInclude, providedArtifacts(wantedProvidedArtifact.get().getFile())); + } else if (! suppressWarningMissingImportPackages && jdisc_core.isEmpty()) { + // TODO: Remove jdisc_core clause above and instead add suppressWarning to necessary vespa modules. warnOrThrow(("This project does not have '%s' as provided dependency, so the generated 'Import-Package' " + "OSGi header may be missing important packages.").formatted(wantedProvidedDependency())); } + logOverlappingPackages(projectPackages, exportedPackagesFromProvidedDeps); - logProvidedArtifactsIncluded(artifactsToInclude, providedArtifactsAggregated(providedJarFiles)); Map<String, Import> calculatedImports = calculateImports(includedPackages.referencedPackages(), includedPackages.definedPackages(), @@ -142,7 +144,7 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { Map<String, String> manifestContent = generateManifestContent(artifactsToInclude, calculatedImports, includedPackages); addAdditionalManifestProperties(manifestContent); addManifestPropertiesForInternalAndCoreBundles(manifestContent, includedPackages, providedJarArtifacts); - addManifestPropertiesForUserBundles(manifestContent, jdiscCore, nonPublicApiUsed); + addManifestPropertiesForUserBundles(manifestContent, providedJarArtifacts, nonPublicApiUsed); createManifestFile(Paths.get(project.getBuild().getOutputDirectory()), manifestContent); } catch (Exception e) { @@ -186,11 +188,12 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { } private void addManifestPropertiesForUserBundles(Map<String, String> manifestContent, - Optional<Artifact> jdiscCore, + List<Artifact> providedArtifacts, List<String> nonPublicApiUsed) { if (effectiveBundleType() != BundleType.USER) return; - jdiscCore.ifPresent( + Optional<Artifact> jdisc_core = getVespaArtifact("jdisc_core", providedArtifacts); + jdisc_core.ifPresent( artifact -> addIfNotEmpty(manifestContent, "X-JDisc-Vespa-Build-Version", artifact.getVersion())); addIfNotEmpty(manifestContent, "X-JDisc-Non-PublicApi-Import-Package", String.join(",", nonPublicApiUsed)); } diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Artifacts.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Artifacts.java index a2789b682b9..a62fe4dfcd8 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Artifacts.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/Artifacts.java @@ -7,6 +7,7 @@ import org.apache.maven.project.MavenProject; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Optional; /** * @author Tony Vaagenes @@ -83,4 +84,14 @@ public class Artifacts { public static Collection<Artifact> getArtifactsToInclude(MavenProject project) { return getArtifacts(project, new NoopScopeTranslator()).getJarArtifactsToInclude(); } + + public static Optional<Artifact> getVespaArtifact(String artifactId, List<Artifact> availableArtifacts) { + for (Artifact artifact : availableArtifacts) { + if (artifactId.equals(artifact.getArtifactId()) && VESPA_GROUP_ID.equals(artifact.getGroupId())) { + return Optional.of(artifact); + } + } + return Optional.empty(); + } + } |