From 21d11e8d89a86322744dea5791e6ff6c53ca0c60 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Thu, 22 Sep 2022 22:50:27 +0200 Subject: [PATCH] Don't extract referenced bundles for Maven runtime classpath Fixes https://github.com/eclipse-m2e/m2e-core/issues/923 OSGi bundles that are referenced by the m2e.maven.runtime bundle don't have to be extracted when added to classpath of an about to be launched Maven build. This significantly speeds up opening the first time the Launch-Config dialog for Maven builds or the Maven Installation settings. Additionally ensure that slf4j from Maven-Central instead of the Orbit version to prevent errors like the following when launching a Maven-build with the embedded runtime from the IDE: class "org.slf4j.MavenSlf4jFriend"'s signer information does not match signer information of other classes in the same package The reason is that the slf4j variant from Orbit is jar-signed by Eclipse, while 'slf4j' and 'maven-slf4j-provider' from Maven-Central is only PGP-signed (and not jarsigned). But because 'slf4j' and 'maven-slf4j-provider' provide classes for the package org.slf4j they must provide the same signer information. --- .../org.eclipse.m2e.maven.runtime/pom.xml | 6 +++--- .../org/eclipse/m2e/core/internal/Bundles.java | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/m2e-maven-runtime/org.eclipse.m2e.maven.runtime/pom.xml b/m2e-maven-runtime/org.eclipse.m2e.maven.runtime/pom.xml index 61efebdad4..d8d1a5d412 100644 --- a/m2e-maven-runtime/org.eclipse.m2e.maven.runtime/pom.xml +++ b/m2e-maven-runtime/org.eclipse.m2e.maven.runtime/pom.xml @@ -169,9 +169,9 @@ com.google.inject.*;provider=m2e;mandatory:=provider,\ io.takari.*;provider=m2e;mandatory:=provider Import-Package: \ - org.slf4j;resolution:=optional;version="[1.7.0,3.0.0)",\ - org.slf4j.spi;resolution:=optional;version="[1.7.0,3.0.0)",\ - org.slf4j.helpers;resolution:=optional;version="[1.7.0,3.0.0)",\ + org.slf4j;resolution:=optional;version="[1.7.31,3.0.0)",\ + org.slf4j.spi;resolution:=optional;version="[1.7.31,3.0.0)",\ + org.slf4j.helpers;resolution:=optional;version="[1.7.31,3.0.0)",\ javax.inject;version="1.0.0",\ javax.annotation;version="[1.2.0,2.0.0)",\ javax.annotation.sql;version="[1.2.0,2.0.0)",\ 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 dde23173e3..a09c056fbc 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 @@ -20,8 +20,8 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; +import java.util.NoSuchElementException; import java.util.Set; -import java.util.stream.Collectors; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -38,6 +38,8 @@ * @since 1.5 */ public class Bundles { + private Bundles() { + } private static final Logger log = LoggerFactory.getLogger(Bundles.class); @@ -50,7 +52,13 @@ public static List getClasspathEntries(Bundle bundle) { cp.addAll(parseBundleClasspath(bundle)); List entries = new ArrayList<>(); for(String cpe : cp) { - String entry = getClasspathEntryPath(bundle, ".".equals(cpe) ? "/" : cpe); + String entry; + if(".".equals(cpe)) { + entry = FileLocator.getBundleFileLocation(bundle) + .orElseThrow(() -> new NoSuchElementException("Unable to locate bundle:" + bundle)).toString(); + } else { + entry = getClasspathEntryPath(bundle, cpe); + } if(entry != null) { log.debug("\tEntry:{}", entry); entries.add(entry); @@ -64,7 +72,7 @@ private static List parseBundleClasspath(Bundle bundle) { try { ManifestElement[] cpEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, header); if(cpEntries != null) { - return Arrays.stream(cpEntries).map(ManifestElement::getValue).collect(Collectors.toList()); + return Arrays.stream(cpEntries).map(ManifestElement::getValue).toList(); } } catch(BundleException ex) { log.warn("Could not parse bundle classpath of {}", bundle, ex); @@ -97,12 +105,12 @@ public static String getClasspathEntryPath(Bundle bundle, String cp) { } @SuppressWarnings("restriction") - public static List getDevClassPath(String bundleSymbolicName) { + private static List getDevClassPath(String bundleSymbolicName) { return Arrays.asList(org.eclipse.core.internal.runtime.DevClassPathHelper.getDevClassPath(bundleSymbolicName)); } @SuppressWarnings("restriction") - public static boolean inDevelopmentMode() { + private static boolean inDevelopmentMode() { return org.eclipse.core.internal.runtime.DevClassPathHelper.inDevelopmentMode(); } }