Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2015-09-10 15:47:34 +0000
committerThomas Watson2015-09-10 15:47:34 +0000
commit1d05e4be57a0f783d612e9a643198bfeab2d38ba (patch)
treeada3e3adcbeef61ecf1d11a691183c5d34808642 /bundles
parent5e5bc32ca0b7903b947cf577314798101cba751b (diff)
downloadrt.equinox.bundles-1d05e4be57a0f783d612e9a643198bfeab2d38ba.tar.gz
rt.equinox.bundles-1d05e4be57a0f783d612e9a643198bfeab2d38ba.tar.xz
rt.equinox.bundles-1d05e4be57a0f783d612e9a643198bfeab2d38ba.zip
Bug 477073 - [region] must use max ranking for hook implementations
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java31
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/RegionManager.java55
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java15
3 files changed, 46 insertions, 55 deletions
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
index e8abd8a0..faf25d46 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
@@ -741,7 +741,7 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
- public void testHigherRankedEventHook() throws BundleException {
+ public void testHigherRankedEventHookResolve() throws BundleException {
final List<BundleEvent> events = new CopyOnWriteArrayList<BundleEvent>();
SynchronousBundleListener listener = new SynchronousBundleListener() {
@Override
@@ -770,7 +770,8 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
bundleEventHook.unregister();
}
- for (int eventType : new int[] {BundleEvent.INSTALLED, BundleEvent.RESOLVED, BundleEvent.STARTING, BundleEvent.STARTED}) {
+ // Had to change the expected order to be out of order now since region hooks are always first
+ for (int eventType : new int[] {BundleEvent.RESOLVED, BundleEvent.INSTALLED, BundleEvent.STARTING, BundleEvent.STARTED}) {
if (events.isEmpty()) {
fail("No events left, expecting event: " + eventType);
}
@@ -780,4 +781,30 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
}
}
+ public void testHigherRankedEventHookUninstall() throws BundleException {
+ // register a higher ranked bundle EventHook that causes a bundle to resolve while processing INSTALLED events
+ ServiceRegistration<EventHook> bundleEventHook = getContext().registerService(EventHook.class, new EventHook() {
+ @Override
+ public void event(BundleEvent event, Collection<BundleContext> contexts) {
+ // force uninstall if event is INSTALLED (evil)
+ if (event.getType() == BundleEvent.INSTALLED) {
+ try {
+ event.getBundle().uninstall();
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }, new Hashtable<String, Object>(Collections.singletonMap(Constants.SERVICE_RANKING, Integer.MAX_VALUE)));
+ Bundle b = null;
+ try {
+ // install a bundle with no dependencies
+ b = bundleInstaller.installBundle(CP1);
+ } finally {
+ bundleEventHook.unregister();
+ }
+
+ assertNull("Found region for uninstalled bundle.", digraph.getRegion(b));
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/RegionManager.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/RegionManager.java
index 77b372ed..0b2f74f6 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/RegionManager.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/RegionManager.java
@@ -12,14 +12,12 @@
package org.eclipse.equinox.internal.region;
import java.io.*;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.*;
import org.eclipse.equinox.internal.region.management.StandardManageableRegionDigraph;
import org.eclipse.equinox.region.Region;
import org.eclipse.equinox.region.RegionDigraph;
import org.osgi.framework.*;
-import org.osgi.framework.hooks.bundle.EventHook;
-import org.osgi.framework.hooks.bundle.FindHook;
+import org.osgi.framework.hooks.bundle.*;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
/**
@@ -38,6 +36,7 @@ public final class RegionManager implements BundleActivator {
private static final String REGION_DOMAIN_PROP = "org.eclipse.equinox.region.domain"; //$NON-NLS-1$
private static final String DIGRAPH_FILE = "digraph"; //$NON-NLS-1$
private static final String REGION_REGISTER_MBEANS = "org.eclipse.equinox.region.register.mbeans"; //$NON-NLS-1$
+ private static final Dictionary<String, Object> MAX_RANKING = new Hashtable<String, Object>(Collections.singletonMap(Constants.SERVICE_RANKING, Integer.MAX_VALUE));
Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
@@ -62,7 +61,7 @@ public final class RegionManager implements BundleActivator {
// if they do then we assume the need to be in the kernel region
checkForOrphans(digraph);
digraphMBean = registerDigraphMbean(digraph);
- registerRegionDigraph(digraph);
+ registerService(RegionDigraph.class, digraph);
}
private void checkForOrphans(StandardRegionDigraph regionDigraph) {
@@ -144,47 +143,19 @@ public final class RegionManager implements BundleActivator {
return standardManageableRegionDigraph;
}
- private void registerRegionHooks(StandardRegionDigraph regionDigraph) {
- registerResolverHookFactory(regionDigraph.getResolverHookFactory());
-
- registerBundleCollisionHook(regionDigraph.getBundleCollisionHook());
- registerBundleFindHook(regionDigraph.getBundleFindHook());
- registerBundleEventHook(regionDigraph.getBundleEventHook());
-
- registerServiceFindHook(regionDigraph.getServiceFindHook());
- registerServiceEventHook(regionDigraph.getServiceEventHook());
- }
-
- private void registerRegionDigraph(RegionDigraph regionDigraph) {
- this.registrations.add(this.bundleContext.registerService(RegionDigraph.class, regionDigraph, null));
- }
-
- private void registerServiceFindHook(org.osgi.framework.hooks.service.FindHook serviceFindHook) {
- this.registrations.add(this.bundleContext.registerService(org.osgi.framework.hooks.service.FindHook.class, serviceFindHook, null));
- }
-
@SuppressWarnings("deprecation")
- private void registerServiceEventHook(org.osgi.framework.hooks.service.EventHook serviceEventHook) {
- this.registrations.add(this.bundleContext.registerService(org.osgi.framework.hooks.service.EventHook.class, serviceEventHook, null));
- }
-
- private void registerBundleFindHook(FindHook findHook) {
- this.registrations.add(this.bundleContext.registerService(FindHook.class, findHook, null));
- }
-
- private void registerBundleEventHook(EventHook eventHook) {
- this.registrations.add(this.bundleContext.registerService(EventHook.class, eventHook, null));
+ private void registerRegionHooks(StandardRegionDigraph regionDigraph) {
+ registerService(ResolverHookFactory.class, regionDigraph.getResolverHookFactory());
- }
+ registerService(CollisionHook.class, regionDigraph.getBundleCollisionHook());
+ registerService(FindHook.class, regionDigraph.getBundleFindHook());
+ registerService(EventHook.class, regionDigraph.getBundleEventHook());
- private void registerBundleCollisionHook(Object collisionHook) {
- if (collisionHook != null) {
- this.registrations.add(this.bundleContext.registerService("org.osgi.framework.hooks.bundle.CollisionHook", collisionHook, null)); //$NON-NLS-1$
- }
+ registerService(org.osgi.framework.hooks.service.FindHook.class, regionDigraph.getServiceFindHook());
+ registerService(org.osgi.framework.hooks.service.EventHook.class, regionDigraph.getServiceEventHook());
}
- private void registerResolverHookFactory(ResolverHookFactory resolverHookFactory) {
- this.registrations.add(this.bundleContext.registerService(ResolverHookFactory.class, resolverHookFactory, null));
+ private <S> void registerService(Class<S> clazz, S service) {
+ this.registrations.add(this.bundleContext.registerService(clazz, service, MAX_RANKING));
}
-
}
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
index fedb941e..c70ddcf1 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
@@ -16,8 +16,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.equinox.internal.region.hook.*;
import org.eclipse.equinox.region.*;
import org.osgi.framework.*;
-import org.osgi.framework.hooks.bundle.EventHook;
-import org.osgi.framework.hooks.bundle.FindHook;
+import org.osgi.framework.hooks.bundle.*;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
/**
@@ -53,7 +52,7 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
private final SubgraphTraverser subgraphTraverser;
- private final Object bundleCollisionHook;
+ private final org.osgi.framework.hooks.bundle.CollisionHook bundleCollisionHook;
private final org.osgi.framework.hooks.bundle.EventHook bundleEventHook;
private final org.osgi.framework.hooks.bundle.FindHook bundleFindHook;
@SuppressWarnings("deprecation")
@@ -88,13 +87,7 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
this.bundleFindHook = new RegionBundleFindHook(this, bundleContext == null ? 0 : bundleContext.getBundle().getBundleId());
this.bundleEventHook = new RegionBundleEventHook(this, this.threadLocal, bundleContext == null ? 0 : bundleContext.getBundle().getBundleId());
- Object hook;
- try {
- hook = new RegionBundleCollisionHook(this, this.threadLocal);
- } catch (Throwable t) {
- hook = null;
- }
- this.bundleCollisionHook = hook;
+ this.bundleCollisionHook = new RegionBundleCollisionHook(this, this.threadLocal);
this.serviceFindHook = new RegionServiceFindHook(this);
this.serviceEventHook = new RegionServiceEventHook(this);
@@ -477,7 +470,7 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
return resolverHookFactory;
}
- Object getBundleCollisionHook() {
+ CollisionHook getBundleCollisionHook() {
return bundleCollisionHook;
}

Back to the top