aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2011-10-31 13:50:59 (EDT)
committerOleg Besedin2011-10-31 13:56:50 (EDT)
commitdee2acec3c876b69c1522aa925f9ee85a3809f92 (patch)
tree3630da9c529675914794fcf88a78e813c070df83
parent5ac37d109d815c15a42bf8b626b87870570533e1 (diff)
downloadeclipse.platform.runtime-dee2acec3c876b69c1522aa925f9ee85a3809f92.zip
eclipse.platform.runtime-dee2acec3c876b69c1522aa925f9ee85a3809f92.tar.gz
eclipse.platform.runtime-dee2acec3c876b69c1522aa925f9ee85a3809f92.tar.bz2
Bug 317706 - [DI] OSGi services aren't injected if they weren'tv20111031-1756
registered when the context is created
-rw-r--r--bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/osgi/EclipseContextOSGi.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/osgi/EclipseContextOSGi.java b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/osgi/EclipseContextOSGi.java
index 4d1e7ec..de1a1b9 100644
--- a/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/osgi/EclipseContextOSGi.java
+++ b/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/osgi/EclipseContextOSGi.java
@@ -17,13 +17,15 @@ import java.util.Map;
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.internal.contexts.EclipseContext;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.SynchronousBundleListener;
-public class EclipseContextOSGi extends EclipseContext implements ServiceListener {
+public class EclipseContextOSGi extends EclipseContext implements ServiceListener, SynchronousBundleListener {
final private BundleContext bundleContext;
@@ -46,6 +48,7 @@ public class EclipseContextOSGi extends EclipseContext implements ServiceListene
// should never happen
}
this.bundleContext.addServiceListener(this);
+ this.bundleContext.addBundleListener(this);
}
public boolean containsKey(String name, boolean localOnly) {
@@ -93,6 +96,7 @@ public class EclipseContextOSGi extends EclipseContext implements ServiceListene
}
refs.clear();
bundleContext.removeServiceListener(this);
+ bundleContext.removeBundleListener(this);
super.dispose();
}
@@ -116,4 +120,14 @@ public class EclipseContextOSGi extends EclipseContext implements ServiceListene
}
}
}
+
+ public void bundleChanged(BundleEvent event) {
+ // In case OSGi context has not being properly disposed by the application,
+ // OSGi framework shutdown will trigged uninjection of all consumed OSGi
+ // service. To avoid this, we detect framework shutdown and release services.
+ if (event.getType() != BundleEvent.STOPPING)
+ return;
+ if (event.getBundle().getBundleId() == 0)
+ dispose();
+ }
}