From 3bb0de4eaed391efdf225f6bd6b9c3bdfda56548 Mon Sep 17 00:00:00 2001 From: laeubi Date: Thu, 19 Oct 2023 17:15:07 +0200 Subject: [PATCH] Fix using the outputfolder as a classpath jar The ProjectBuilder currently uses the output folder of a project as an additional classpath jar, this then can even confuse BND as it thinks we have a split package and try to copy that class into the jar itself. This extends the default ProjectBuilder, check if the jar is sourced at the output location and then skip adding the jar. --- .../pde/internal/core/bnd/BndBuilder.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java index d62d816b271..225116ec2dc 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/BndBuilder.java @@ -14,6 +14,7 @@ package org.eclipse.pde.internal.core.bnd; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -131,7 +132,25 @@ private static void buildProjectJar(IProject project, IProgressMonitor monitor) if (monitor.isCanceled()) { return; } - try (Project bnd = bndProject.get(); ProjectBuilder builder = new ProjectBuilder(bnd)) { + try (Project bnd = bndProject.get(); ProjectBuilder builder = new ProjectBuilder(bnd) { + @Override + public void addClasspath(aQute.bnd.osgi.Jar jar) { + try { + // If the output exits, the ProjectBuilder adds the + // output as a classpath jar, this on the other hand + // later confuses BND because it thinks there is a + // splitpackage and tries to copy the class into the jar + // again... + if (Objects.equals(jar.getSource(), bnd.getOutput())) { + jar.close(); + return; + } + } catch (Exception e) { + // can't do anything useful... + } + super.addClasspath(jar); + } + }) { builder.setBase(bnd.getBase()); ProjectJar jar = new ProjectJar(project, CLASS_FILTER); builder.setJar(jar);