diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java index 93dfd14bad..4feb6ebbf6 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java @@ -44,7 +44,7 @@ private Bundles() { private static final Logger log = LoggerFactory.getLogger(Bundles.class); - public static List getClasspathEntries(Bundle bundle) { + public static List getClasspathEntries(Bundle bundle, boolean extractRoot) { log.debug("getClasspathEntries(Bundle={})", bundle); Set cp = new LinkedHashSet<>(); if(inDevelopmentMode()) { @@ -53,13 +53,7 @@ public static List getClasspathEntries(Bundle bundle) { cp.addAll(parseBundleClasspath(bundle)); List entries = new ArrayList<>(); for(String cpe : cp) { - String entry; - if(".".equals(cpe)) { - entry = FileLocator.getBundleFileLocation(bundle) - .orElseThrow(() -> new NoSuchElementException("Unable to locate bundle:" + bundle)).toString(); - } else { - entry = getClasspathEntryPath(bundle, cpe); - } + String entry = getClasspathEntryPath(bundle, cpe, extractRoot); if(entry != null) { log.debug("\tEntry:{}", entry); entries.add(entry); @@ -81,16 +75,23 @@ private static List parseBundleClasspath(Bundle bundle) { return List.of("."); } - public static String getClasspathEntryPath(Bundle bundle, String cp) { + public static String getClasspathEntryPath(Bundle bundle, String cp, boolean extractRoot) { // try embedded entries first - URL url = bundle.getEntry(cp); - if(url != null) { - try { + try { + if(".".equals(cp)) { + if(!extractRoot) { + return FileLocator.getBundleFileLocation(bundle) + .orElseThrow(() -> new NoSuchElementException("Unable to locate bundle:" + bundle)).getCanonicalPath(); + } + cp = "/"; // get bundle's root entry below, which extracts the bundle's jar, if it not of shape 'dir' already + } + URL url = bundle.getEntry(cp); + if(url != null) { String path = FileLocator.toFileURL(url).getFile(); return new Path(path).toOSString(); - } catch(IOException ex) { - log.warn("Could not get entry {} for bundle {}", cp, bundle, ex); } + } catch(IOException ex) { + log.warn("Could not get entry {} for bundle {}", cp, bundle, ex); } // in development mode entries can be absolute paths outside of bundle basedir diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java index 28556de6a0..c23ed8f8cd 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java @@ -112,6 +112,8 @@ public void createLauncherConfiguration(IMavenLauncherConfiguration collector, I } } + public static final Set SLF4J_BUNDLE_NAMES = Set.of("org.slf4j.api", "slf4j.api"); + private synchronized void initClasspath() { if(CLASSPATH == null) { Bundle mavenRuntimeBundle = findMavenEmbedderBundle(); @@ -120,9 +122,8 @@ private synchronized void initClasspath() { addBundleClasspathEntries(allEntries, mavenRuntimeBundle, true); allEntries.add(getEmbeddedSLF4JBinding(mavenRuntimeBundle)); - Set noDependencyBundles = Set.of("org.slf4j.api", "slf4j.api"); // Don't include dependencies of slf4j bundle to ensure no other than the slf4j-binding embedded into m2e.maven.runtime is available. - Set bundles = getRequiredBundles(mavenRuntimeBundle, noDependencyBundles); + Set bundles = getRequiredBundles(mavenRuntimeBundle, SLF4J_BUNDLE_NAMES); for(Bundle bundle : bundles) { addBundleClasspathEntries(allEntries, bundle, false); @@ -141,11 +142,13 @@ private synchronized void initClasspath() { } private void addBundleClasspathEntries(Set entries, Bundle bundle, boolean addFragments) { - entries.addAll(Bundles.getClasspathEntries(bundle)); + boolean extractRoot = SLF4J_BUNDLE_NAMES.contains(bundle.getSymbolicName()); + // Use extracted/directory form of slf4j bundles so that their jar-signing signature by the Maven-runtime classloader + entries.addAll(Bundles.getClasspathEntries(bundle, extractRoot)); Bundle[] fragments; if(addFragments && (fragments = Platform.getFragments(bundle)) != null) { for(Bundle fragment : fragments) { - entries.addAll(Bundles.getClasspathEntries(fragment)); + entries.addAll(Bundles.getClasspathEntries(fragment, SLF4J_BUNDLE_NAMES.contains(fragment.getSymbolicName()))); } } } @@ -154,7 +157,7 @@ private static String getEmbeddedSLF4JBinding(Bundle mavenBundle) { String bindingPath = mavenBundle.getHeaders().get(M2E_SL4J_BINDING_HEADER); Objects.requireNonNull(bindingPath, () -> "Missing '" + M2E_SL4J_BINDING_HEADER + "' header in embedded Maven-runtime bundle"); - String bindingJarPath = Bundles.getClasspathEntryPath(mavenBundle, bindingPath); + String bindingJarPath = Bundles.getClasspathEntryPath(mavenBundle, bindingPath, false); return Objects.requireNonNull(bindingJarPath, () -> M2E_SL4J_BINDING_HEADER + " '" + bindingPath + "' not found"); }