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 the classpath of an about to be
launched Maven build. Not extracting them significantly speeds up the
launch of the first build after IDE start or opening the first time the
Launch-Config dialog for Maven builds or the Maven Installation
settings.

Additionally ensure that slf4j from Maven-Central is used instead of the
one from Orbit 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 for that error 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. This check is
not performed if a jar is extracted and added to the classpath as
directory, but we don't want to do that anymore.
  • Loading branch information
HannesWell committed Oct 1, 2022
1 parent 2a214b2 commit e6f8afc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "m2e-core-tests"]
path = m2e-core-tests
url = https://github.com/tesla/m2e-core-tests.git
branch = master
url = https://github.com/HannesWell/m2e-core-tests.git
branch = slf4jInTests
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;version="[1.7.31,3.0.0)",\
org.slf4j.spi;version="[1.7.31,3.0.0)",\
org.slf4j.helpers;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 @@ -18,10 +18,11 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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,19 +39,27 @@
* @since 1.5
*/
public class Bundles {
private Bundles() {
}

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

public static List<String> getClasspathEntries(Bundle bundle) {
log.debug("getClasspathEntries(Bundle={})", bundle);
Set<String> cp = new LinkedHashSet<>();
if(inDevelopmentMode()) {
cp.addAll(getDevClassPath(bundle.getSymbolicName()));
Collections.addAll(cp, getDevClassPath(bundle.getSymbolicName()));
}
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 +73,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 +106,12 @@ public static String getClasspathEntryPath(Bundle bundle, String cp) {
}

@SuppressWarnings("restriction")
public static List<String> getDevClassPath(String bundleSymbolicName) {
return Arrays.asList(org.eclipse.core.internal.runtime.DevClassPathHelper.getDevClassPath(bundleSymbolicName));
private static String[] getDevClassPath(String bundleSymbolicName) {
return 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 e6f8afc

Please sign in to comment.