aboutsummaryrefslogtreecommitdiffstats
path: root/bundle-plugin
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-06-12 17:21:02 +0200
committergjoranv <gv@verizonmedia.com>2020-07-01 19:26:30 +0200
commit8d3ffdcadbfe063441f04a69d17bb90df9146bb9 (patch)
tree2dd6369a183c2bb99aab614f303042e56ece737a /bundle-plugin
parent227ebbed0765606f1d03a9f16e0bca82950c94d7 (diff)
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.
Diffstat (limited to 'bundle-plugin')
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java18
1 files changed, 18 insertions, 0 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 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<Export> 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<Artifact> 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());