Skip to content

Commit

Permalink
Don't extract referenced bundles for Maven runtime classpath
Browse files Browse the repository at this point in the history
Fixes #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.
  • Loading branch information
HannesWell committed Oct 1, 2022
1 parent 2a214b2 commit 21d11e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions m2e-maven-runtime/org.eclipse.m2e.maven.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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)",\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +38,8 @@
* @since 1.5
*/
public class Bundles {
private Bundles() {
}

private static final Logger log = LoggerFactory.getLogger(Bundles.class);

Expand All @@ -50,7 +52,13 @@ public static List<String> getClasspathEntries(Bundle bundle) {
cp.addAll(parseBundleClasspath(bundle));
List<String> 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);
Expand All @@ -64,7 +72,7 @@ private static List<String> 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);
Expand Down Expand Up @@ -97,12 +105,12 @@ public static String getClasspathEntryPath(Bundle bundle, String cp) {
}

@SuppressWarnings("restriction")
public static List<String> getDevClassPath(String bundleSymbolicName) {
private static List<String> 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();
}
}

0 comments on commit 21d11e8

Please sign in to comment.