Skip to content

Commit

Permalink
Add full dependencies-closure to classpath of launched embedded Maven
Browse files Browse the repository at this point in the history
The Eclipse-Platform changed to use Google-Guava jar from
Maven-Central for the 2022-09 release. In contrast to the Guava variant
from Eclipse-Orbit, which was used before, that bundle is not
self-contained and requires classes in other jars like
guava.failureaccess.
Consequently it is not sufficient anymore to only put first-level
requirements on the classpath of the launched embedded Maven runtime. It
has to be the full requirements closure now.
  • Loading branch information
HannesWell committed Sep 4, 2022
1 parent 90c20cb commit e27a860
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.m2e.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.core;singleton:=true
Bundle-Version: 2.0.2.qualifier
Bundle-Version: 2.0.3.qualifier
Bundle-Activator: org.eclipse.m2e.core.internal.MavenPluginActivator
Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.namespace.BundleNamespace;
import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
import org.slf4j.Logger;
Expand Down Expand Up @@ -118,13 +120,7 @@ private synchronized void initClasspath() {
addBundleClasspathEntries(allEntries, mavenRuntimeBundle, true);
allEntries.add(getEmbeddedSLF4JBinding(mavenRuntimeBundle));

Set<Bundle> bundles = new LinkedHashSet<>();
// find and add required bundles and bundles providing imported packages
List<BundleWire> requiredWires = new ArrayList<>();
BundleWiring wiring = mavenRuntimeBundle.adapt(BundleWiring.class);
requiredWires.addAll(wiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE));
requiredWires.addAll(wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE));
requiredWires.stream().map(BundleWire::getProvider).map(BundleRevision::getBundle).forEach(bundles::add);
Set<Bundle> bundles = getRequiredBundles(mavenRuntimeBundle);

for(Bundle bundle : bundles) {
addBundleClasspathEntries(allEntries, bundle, false);
Expand Down Expand Up @@ -160,6 +156,30 @@ private static String getEmbeddedSLF4JBinding(Bundle mavenBundle) {
return Objects.requireNonNull(bindingJarPath, () -> M2E_SL4J_BINDING_HEADER + " '" + bindingPath + "' not found");
}

private static final List<String> CLASSPATH_CONSIDERED_REQUIREMENT_NAMESPACES = List
.of(BundleNamespace.BUNDLE_NAMESPACE, PackageNamespace.PACKAGE_NAMESPACE);

private Set<Bundle> getRequiredBundles(Bundle root) {
// find and add required bundles and bundles providing imported packages
Set<Bundle> bundles = new LinkedHashSet<>();
Queue<Bundle> pending = new ArrayDeque<>();
pending.add(root);
while(!pending.isEmpty()) { // breath-first search to collect all (transitively) required bundles
Bundle bundle = pending.remove();
BundleWiring wiring = bundle.adapt(BundleWiring.class);
for(String namespace : CLASSPATH_CONSIDERED_REQUIREMENT_NAMESPACES) {
for(BundleWire wire : wiring.getRequiredWires(namespace)) {
Bundle requiredBundle = wire.getProvider().getBundle();
if(requiredBundle.getBundleId() != Constants.SYSTEM_BUNDLE_ID && bundles.add(requiredBundle)) {
// Don't add OSGi System-Bundle, which is wired if a bundle imports java.* or sun.* packages
pending.add(requiredBundle);
}
}
}
}
return bundles;
}

private static Bundle findMavenEmbedderBundle() {
return FrameworkUtil.getBundle(Maven.class);
}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.m2e.feature"
label="%featureName"
version="2.0.3.qualifier"
version="2.0.4.qualifier"
provider-name="%providerName"
plugin="org.eclipse.m2e.core"
license-feature="org.eclipse.license"
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.m2e.sdk.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.m2e.sdk.feature"
label="%featureName"
version="2.0.3.qualifier"
version="2.0.4.qualifier"
provider-name="%providerName"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down

0 comments on commit e27a860

Please sign in to comment.