Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2013-08-29 17:54:44 -0400
committerIgor Fedorenko2013-08-29 17:54:49 -0400
commit128ea00de69608683c7ba2cc69cabbf8e10e4506 (patch)
tree0885ea46b253b60f6d469aebfc36d1d516a302d3
parent8f9c872a2bad58eecdf08b00d5051b48aff8ce70 (diff)
downloadm2e-core-128ea00de69608683c7ba2cc69cabbf8e10e4506.tar.gz
m2e-core-128ea00de69608683c7ba2cc69cabbf8e10e4506.tar.xz
m2e-core-128ea00de69608683c7ba2cc69cabbf8e10e4506.zip
416037 use standard OSGi API to collect embedded maven classpath
Based on the code by Thomas Watson <tjwatson@us.ibm.com> attached to the bugzilla. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java48
2 files changed, 20 insertions, 30 deletions
diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
index 62bd25be..4ded3855 100644
--- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
@@ -7,7 +7,7 @@ Bundle-Activator: org.eclipse.m2e.core.internal.MavenPluginActivator
Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Require-Bundle:
- org.eclipse.core.runtime,
+ org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.core.resources;bundle-version="3.6.0",
org.eclipse.m2e.maven.runtime;bundle-version="[1.5.0,1.6.0)",
org.eclipse.m2e.archetype.common;bundle-version="[1.5.0,1.6.0)",
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java
index 9f7609b0..7b080d46 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java
@@ -31,6 +31,10 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,11 +42,6 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.osgi.service.resolver.BaseDescription;
-import org.eclipse.osgi.service.resolver.BundleDescription;
-import org.eclipse.osgi.service.resolver.ExportPackageDescription;
-import org.eclipse.osgi.service.resolver.State;
-import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.util.ManifestElement;
import org.codehaus.plexus.util.IOUtil;
@@ -127,10 +126,8 @@ public class MavenEmbeddedRuntime implements MavenRuntime {
addBundleClasspathEntries(allentries, mavenRuntimeBundle);
// find and add more bundles
- State state = Platform.getPlatformAdmin().getState(false);
- BundleDescription description = state.getBundle(mavenRuntimeBundle.getBundleId());
for(String sname : new String[] {"com.ning.async-http-client", "org.jboss.netty", "org.slf4j.api"}) {
- Bundle dependency = findDependencyBundle(description, sname, new HashSet<BundleDescription>());
+ Bundle dependency = findDependencyBundle(mavenRuntimeBundle, sname, new HashSet<Bundle>());
if(dependency != null) {
addBundleClasspathEntries(allentries, dependency);
} else {
@@ -156,18 +153,21 @@ public class MavenEmbeddedRuntime implements MavenRuntime {
}
}
- private Bundle findDependencyBundle(BundleDescription bundleDescription, String dependencyName,
- Set<BundleDescription> visited) {
- ArrayList<VersionConstraint> dependencies = new ArrayList<VersionConstraint>();
- dependencies.addAll(Arrays.asList(bundleDescription.getRequiredBundles()));
- dependencies.addAll(Arrays.asList(bundleDescription.getImportPackages()));
- for(VersionConstraint requiredSpecification : dependencies) {
- BundleDescription requiredDescription = getDependencyBundleDescription(requiredSpecification);
- if(requiredDescription != null && visited.add(requiredDescription)) {
- if(dependencyName.equals(requiredDescription.getName())) {
- return bundleContext.getBundle(requiredDescription.getBundleId());
+ private Bundle findDependencyBundle(Bundle bundle, String dependencyName, Set<Bundle> visited) {
+ BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
+ if(bundleWiring == null) {
+ return null;
+ }
+ ArrayList<BundleWire> dependencies = new ArrayList<BundleWire>();
+ dependencies.addAll(bundleWiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE));
+ dependencies.addAll(bundleWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE));
+ for(BundleWire wire : dependencies) {
+ Bundle requiredBundle = wire.getProviderWiring().getBundle();
+ if(requiredBundle != null && visited.add(requiredBundle)) {
+ if(dependencyName.equals(requiredBundle.getSymbolicName())) {
+ return requiredBundle;
}
- Bundle required = findDependencyBundle(requiredDescription, dependencyName, visited);
+ Bundle required = findDependencyBundle(requiredBundle, dependencyName, visited);
if(required != null) {
return required;
}
@@ -176,16 +176,6 @@ public class MavenEmbeddedRuntime implements MavenRuntime {
return null;
}
- private BundleDescription getDependencyBundleDescription(VersionConstraint requiredSpecification) {
- BaseDescription supplier = requiredSpecification.getSupplier();
- if(supplier instanceof BundleDescription) {
- return (BundleDescription) supplier;
- } else if(supplier instanceof ExportPackageDescription) {
- return ((ExportPackageDescription) supplier).getExporter();
- }
- return null;
- }
-
private void addBundleClasspathEntries(Set<String> entries, Bundle bundle) {
log.debug("addBundleClasspathEntries(Bundle={})", bundle.toString());

Back to the top