From 8d3ffdcadbfe063441f04a69d17bb90df9146bb9 Mon Sep 17 00:00:00 2001 From: gjoranv Date: Fri, 12 Jun 2020 17:21:02 +0200 Subject: Warn when the 'component' artifact is embedded in the bundle. - Embedding it may cause resource leaks in the container runtime because the framework will not be able to identify user components that extend AbstractComponent. --- .../plugin/mojo/GenerateOsgiManifestMojo.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'bundle-plugin') 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 3020184fd35..864c8d6fe9c 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 @@ -59,6 +59,7 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { try { Artifacts.ArtifactSet artifactSet = Artifacts.getArtifacts(project); warnOnUnsupportedArtifacts(artifactSet.getNonJarArtifacts()); + warnIfInternalContainerArtifactsAreIncluded(artifactSet.getJarArtifactsToInclude()); List exportedPackagesFromProvidedJars = exportedPackagesAggregated( artifactSet.getJarArtifactsProvided().stream().map(Artifact::getFile).collect(Collectors.toList())); @@ -180,6 +181,23 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { artifact.getId(), artifact.getType()))); } + // TODO: fail the build by throwing a MojoExecutionException + private void warnIfInternalContainerArtifactsAreIncluded(Collection includedArtifacts) throws MojoExecutionException { + /* In most cases it's sufficient to test for 'component', as it's the lowest level container artifact, + * Embedding container artifacts will cause class loading issues at runtime, because the classes will + * not be equal to those seen by the framework (e.g. AbstractComponent). + */ + if (includedArtifacts.stream().anyMatch(this::isJdiscComponentArtifact)) { + getLog().warn("This project includes the 'com.yahoo.vespa:component' artifact in compile scope." + + " It must be set to scope 'provided' to avoid resource leaks in your application at runtime." + + " The build will fail on a future Vespa version unless this is fixed."); + } + } + + private boolean isJdiscComponentArtifact(Artifact a) { + return a.getArtifactId().equals("component") && a.getGroupId().equals("com.yahoo.vespa"); + } + private PackageTally getProjectClassesTally() { File outputDirectory = new File(project.getBuild().getOutputDirectory()); -- cgit v1.2.3