diff options
author | gjoranv <gv@yahooinc.com> | 2023-06-28 17:01:39 +0200 |
---|---|---|
committer | gjoranv <gv@yahooinc.com> | 2023-07-03 22:37:54 +0200 |
commit | 4ab25db76d0d07b90afb49fc1ca04f42275a8b3c (patch) | |
tree | e5fe6212b90d3d2cc78c1210027ba62f150c3a7e /bundle-plugin/src | |
parent | fa0ec3fac94720c5ecf7dfbd4207a1ee8c2d7422 (diff) |
Warn when provided artifacts are included in compile scope.
- Replaces the broken "unnecessary packages" logic.
Diffstat (limited to 'bundle-plugin/src')
-rw-r--r-- | bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java | 38 |
1 files changed, 22 insertions, 16 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 b6f6d00b4d1..a5392f08e4b 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 @@ -19,6 +19,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import java.io.File; import java.nio.file.Paths; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -28,6 +29,7 @@ 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.classanalysis.Packages.disallowedImports; import static com.yahoo.container.plugin.osgi.ExportPackages.exportsByPackageName; import static com.yahoo.container.plugin.osgi.ImportPackages.calculateImports; @@ -90,8 +92,11 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { Artifacts.ArtifactSet artifactSet = Artifacts.getArtifacts(project); warnOnUnsupportedArtifacts(artifactSet.getNonJarArtifacts()); + + List<Artifact> artifactsToInclude = artifactSet.getJarArtifactsToInclude(); + if (! isContainerDiscArtifact(project.getArtifact())) - throwIfInternalContainerArtifactsAreIncluded(artifactSet.getJarArtifactsToInclude()); + throwIfInternalContainerArtifactsAreIncluded(artifactsToInclude); List<Artifact> providedJarArtifacts = artifactSet.getJarArtifactsProvided(); List<File> providedJarFiles = providedJarArtifacts.stream().map(Artifact::getFile).toList(); @@ -105,7 +110,7 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { PackageTally projectPackages = getProjectClassesTally(); // Packages defined in compile scoped jars - PackageTally compileJarsPackages = definedPackages(artifactSet.getJarArtifactsToInclude()); + PackageTally compileJarsPackages = definedPackages(artifactsToInclude); // The union of packages in the project and compile scoped jars PackageTally includedPackages = projectPackages.combine(compileJarsPackages); @@ -124,7 +129,7 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { "OSGi header may be missing important packages.").formatted(wantedProvidedDependency())); } logOverlappingPackages(projectPackages, exportedPackagesFromProvidedDeps); - logUnnecessaryPackages(compileJarsPackages, exportedPackagesFromProvidedDeps); + logProvidedArtifactsIncluded(artifactsToInclude, providedArtifactsAggregated(providedJarFiles)); Map<String, Import> calculatedImports = calculateImports(includedPackages.referencedPackages(), includedPackages.definedPackages(), @@ -133,7 +138,7 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { List<String> nonPublicApiUsed = disallowedImports(calculatedImports, nonPublicApiPackagesFromProvidedJars); logNonPublicApiUsage(nonPublicApiUsed); - Map<String, String> manifestContent = generateManifestContent(artifactSet.getJarArtifactsToInclude(), calculatedImports, includedPackages); + Map<String, String> manifestContent = generateManifestContent(artifactsToInclude, calculatedImports, includedPackages); addAdditionalManifestProperties(manifestContent); addManifestPropertiesForInternalAndCoreBundles(manifestContent, includedPackages, providedJarArtifacts); addManifestPropertiesForUserBundles(manifestContent, jdiscCore, nonPublicApiUsed); @@ -242,18 +247,19 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { } } - /* - * This mostly detects packages re-exported via composite bundles like jdisc_core and container-disc. - * An artifact can only be represented once, either in compile or provided scope. So if the project - * adds an artifact in compile scope that we deploy as a pre-installed bundle, we won't see the same - * artifact as provided via container-dev and hence can't detect the duplicate packages. - */ - private void logUnnecessaryPackages(PackageTally compileJarsPackages, - Set<String> exportedPackagesFromProvidedDeps) { - Set<String> unnecessaryPackages = Sets.intersection(compileJarsPackages.definedPackages(), exportedPackagesFromProvidedDeps); - if (! unnecessaryPackages.isEmpty()) { - getLog().info("Compile scoped jars contain the following packages that are most likely " + - "available from jdisc runtime: " + unnecessaryPackages); + private void logProvidedArtifactsIncluded(List<Artifact> includedArtifacts, List<ProvidedArtifact> providedArtifacts) { + // TODO: add suppress switch + + Set<ProvidedArtifact> included = includedArtifacts.stream().map(ProvidedArtifact::new).collect(Collectors.toSet()); + Set<ProvidedArtifact> providedIncluded = Sets.intersection(included, new HashSet<>(providedArtifacts)); + + if (! providedIncluded.isEmpty()) { + List<String> sorted = providedIncluded.stream() + .map(ProvidedArtifact::stringValue) + .sorted().toList(); + + // TODO: improve error message + warnOrThrow("Artifacts provided from Jdisc runtime are included in compile scope: " + sorted); } } |