Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2016-11-04 14:02:41 -0400
committerFred Bricon2016-11-04 14:02:41 -0400
commita084af349d44c4d9a9f1fe1d34b1dc61c4cd6c19 (patch)
tree4e83295ecd1840bfc7d13b88181c72e6c3f9e283 /org.eclipse.m2e.core
parent11490f15c5ee8e4d6a82439cad23ead2bfda09fb (diff)
downloadm2e-core-a084af349d44c4d9a9f1fe1d34b1dc61c4cd6c19.tar.gz
m2e-core-a084af349d44c4d9a9f1fe1d34b1dc61c4cd6c19.tar.xz
m2e-core-a084af349d44c4d9a9f1fe1d34b1dc61c4cd6c19.zip
506473 ensure slf4j is added to the embedded Maven runtime
Change-Id: Ib58f592696abc92454ab421b79b3d24d67e8b330 Signed-off-by: Fred Bricon <fbricon@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java32
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java21
2 files changed, 51 insertions, 2 deletions
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 cc101bae..b43433cc 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
@@ -26,6 +26,7 @@ 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.BundleCapability;
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
import org.slf4j.Logger;
@@ -144,4 +145,35 @@ public class Bundles {
return null;
}
+ private static Bundle findDependencyBundleByPackage(Bundle bundle, String packageName, 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) {
+ BundleCapability cap = wire.getCapability();
+ String pkg = (String) cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+ Bundle requiredBundle = wire.getProviderWiring().getBundle();
+ if(requiredBundle != null) {
+ if(packageName.equals(pkg)) {
+ return requiredBundle;
+ }
+ if(visited.add(requiredBundle)) {
+ Bundle required = findDependencyBundleByPackage(requiredBundle, packageName, visited);
+ if(required != null) {
+ return required;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public static Bundle findDependencyBundleByPackage(Bundle bundle, String packageName) {
+ return findDependencyBundleByPackage(bundle, packageName, new HashSet<Bundle>());
+ }
+
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java
index 4dcdbbd6..de1ecf04 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java
@@ -109,11 +109,12 @@ public class MavenEmbeddedRuntime extends AbstractMavenRuntime {
addBundleClasspathEntries(allentries, mavenRuntimeBundle);
+ Set<Bundle> bundles = new LinkedHashSet<>();
// find and add more bundles
- for(String sname : new String[] {"org.slf4j.api", "org.eclipse.m2e.maven.runtime.slf4j.simple", "javax.inject"}) {
+ for(String sname : new String[] {"org.eclipse.m2e.maven.runtime.slf4j.simple", "javax.inject"}) {
Bundle dependency = Bundles.findDependencyBundle(mavenRuntimeBundle, sname);
if(dependency != null) {
- addBundleClasspathEntries(allentries, dependency);
+ bundles.add(dependency);
} else {
log.warn(
"Could not find OSGi bundle with symbolic name ''{}'' required to launch embedded maven runtime in external process",
@@ -121,6 +122,22 @@ public class MavenEmbeddedRuntime extends AbstractMavenRuntime {
}
}
+ // find bundles by exported packages
+ for(String pname : new String[] {"org.slf4j", "org.slf4j.helpers", "org.slf4j.spi"}) {
+ Bundle dependency = Bundles.findDependencyBundleByPackage(mavenRuntimeBundle, pname);
+ if(dependency != null) {
+ bundles.add(dependency);
+ } else {
+ log.warn(
+ "Could not find OSGi bundle exporting package ''{}'' required to launch embedded maven runtime in external process",
+ pname);
+ }
+ }
+
+ for(Bundle bundle : bundles) {
+ addBundleClasspathEntries(allentries, bundle);
+ }
+
List<String> cp = new ArrayList<String>();
List<String> lcp = new ArrayList<String>();

Back to the top