Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2015-09-21 20:13:06 +0000
committerThomas Watson2015-09-21 20:13:57 +0000
commitadd698eab637cb1844590c8151ef1bf787598707 (patch)
tree948e1ff5142e9f86d2054f3ec5f7fda751119b9b /bundles
parentbf37749bff9941ec20833ebaa8c4f77260df2b3e (diff)
downloadrt.equinox.bundles-add698eab637cb1844590c8151ef1bf787598707.tar.gz
rt.equinox.bundles-add698eab637cb1844590c8151ef1bf787598707.tar.xz
rt.equinox.bundles-add698eab637cb1844590c8151ef1bf787598707.zip
Bug 477961 - [region] add ability to replace a connection in the digraph
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java24
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java52
-rw-r--r--bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF4
-rw-r--r--bundles/org.eclipse.equinox.region/pom.xml2
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java22
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java23
6 files changed, 122 insertions, 5 deletions
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java
index 3398b6b3..46cef9dd 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/internal/tests/StandardRegionDigraphTests.java
@@ -129,6 +129,15 @@ public class StandardRegionDigraphTests {
}
@Test
+ public void testReConnection() throws BundleException {
+ setDefaultFilters();
+ replayMocks();
+
+ this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
+ this.digraph.reconnect(this.mockRegion1, this.regionFilter2, this.mockRegion2);
+ }
+
+ @Test
public void testGetEdges() throws BundleException {
setDefaultFilters();
replayMocks();
@@ -150,6 +159,21 @@ public class StandardRegionDigraphTests {
fail("unexpected edge");
}
}
+
+ this.digraph.reconnect(this.mockRegion1, this.regionFilter2, this.mockRegion2);
+
+ edges = this.digraph.getEdges(this.mockRegion1);
+ assertEquals(2, edges.size());
+
+ for (FilteredRegion edge : edges) {
+ if (edge.getRegion().equals(this.mockRegion2)) {
+ assertEquals(this.regionFilter2, edge.getFilter());
+ } else if (edge.getRegion().equals(this.mockRegion3)) {
+ assertEquals(this.regionFilter2, edge.getFilter());
+ } else {
+ fail("unexpected edge");
+ }
+ }
}
@Test
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 faf25d46..70f07b46 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
@@ -18,6 +18,7 @@ import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.management.*;
import org.eclipse.equinox.region.*;
+import org.eclipse.equinox.region.RegionDigraph.FilteredRegion;
import org.osgi.framework.*;
import org.osgi.framework.hooks.bundle.CollisionHook;
import org.osgi.framework.hooks.bundle.EventHook;
@@ -807,4 +808,55 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertNull("Found region for uninstalled bundle.", digraph.getRegion(b));
}
+ public void testReconnect() throws BundleException, InvalidSyntaxException {
+ // get the system region
+ Region systemRegion = digraph.getRegion(0);
+ Map<String, Bundle> bundles = new HashMap<String, Bundle>();
+ // create a disconnected test region for each test bundle
+ for (String location : new String[] {PP1, SP1}) {
+ Region testRegion = digraph.createRegion(location);
+ bundles.put(location, bundleInstaller.installBundle(location, testRegion));
+ // Import the system bundle from the systemRegion
+ digraph.connect(testRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, "(id=0)").build(), systemRegion);
+ // must import Boolean services into systemRegion to test
+ digraph.connect(systemRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, "(objectClass=java.lang.Boolean)").build(), testRegion);
+ }
+
+ bundleInstaller.resolveBundles(bundles.values().toArray(new Bundle[bundles.size()]));
+ assertEquals(PP1, Bundle.RESOLVED, bundles.get(PP1).getState());
+ assertEquals(SP1, Bundle.INSTALLED, bundles.get(SP1).getState());
+
+ // now make a connection that does not let the necessary package through
+ RegionFilter badRegionFilter = digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, "(" + RegionFilter.VISIBLE_PACKAGE_NAMESPACE + "=bad)").build();
+
+ Set<FilteredRegion> edges = digraph.getRegion(SP1).getEdges();
+ assertEquals("Wrong number of edges.", 1, edges.size());
+
+ // use reconnnect and verify a new edge is added if the connection did not exist already
+ assertNull("Found existing connection.", digraph.reconnect(digraph.getRegion(SP1), badRegionFilter, digraph.getRegion(PP1)));
+ edges = digraph.getRegion(SP1).getEdges();
+ assertEquals("Wrong number of edges.", 2, edges.size());
+
+ // still should not resolve
+ bundleInstaller.resolveBundles(bundles.values().toArray(new Bundle[bundles.size()]));
+ assertEquals(PP1, Bundle.RESOLVED, bundles.get(PP1).getState());
+ assertEquals(SP1, Bundle.INSTALLED, bundles.get(SP1).getState());
+
+ // reconnect to let the package though
+ RegionFilter goodRegionFilter = digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_PACKAGE_NAMESPACE, "(" + RegionFilter.VISIBLE_PACKAGE_NAMESPACE + "=pkg1.*)").build();
+ RegionFilter existingFilter = digraph.reconnect(digraph.getRegion(SP1), goodRegionFilter, digraph.getRegion(PP1));
+ assertEquals("Wrong existing filter found.", badRegionFilter, existingFilter);
+
+ // number of edges must remain 2 since we use reconnect
+ edges = digraph.getRegion(SP1).getEdges();
+ assertEquals("Wrong number of edges.", 2, edges.size());
+ // should resolve now
+
+ bundleInstaller.resolveBundles(bundles.values().toArray(new Bundle[bundles.size()]));
+ for (Bundle bundle : bundles.values()) {
+ assertEquals("Bundle did not resolve: " + bundle.getSymbolicName(), Bundle.RESOLVED, bundle.getState());
+ bundle.start();
+ }
+
+ }
}
diff --git a/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF
index c1cbf460..2166381e 100644
--- a/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.region/META-INF/MANIFEST.MF
@@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.equinox.region
-Bundle-Version: 1.2.200.qualifier
+Bundle-Version: 1.3.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Fragment-Host: system.bundle
ExtensionBundle-Activator: org.eclipse.equinox.internal.region.RegionManager
-Export-Package: org.eclipse.equinox.region;version="1.1.0"
+Export-Package: org.eclipse.equinox.region;version="1.2.0"
Bundle-Vendor: %Bundle-Vendor
diff --git a/bundles/org.eclipse.equinox.region/pom.xml b/bundles/org.eclipse.equinox.region/pom.xml
index 48c6b61a..64a70193 100644
--- a/bundles/org.eclipse.equinox.region/pom.xml
+++ b/bundles/org.eclipse.equinox.region/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.region</artifactId>
- <version>1.2.200-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
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 2e4c8d38..fe615be6 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
@@ -130,6 +130,17 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
* {@inheritDoc}
*/
public void connect(Region tailRegion, RegionFilter filter, Region headRegion) throws BundleException {
+ createConnection(tailRegion, filter, headRegion, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RegionFilter reconnect(Region tailRegion, RegionFilter filter, Region headRegion) throws BundleException {
+ return createConnection(tailRegion, filter, headRegion, true);
+ }
+
+ private RegionFilter createConnection(Region tailRegion, RegionFilter filter, Region headRegion, boolean replace) throws BundleException {
if (tailRegion == null)
throw new IllegalArgumentException("The tailRegion must not be null."); //$NON-NLS-1$
if (filter == null)
@@ -144,6 +155,7 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
if (headRegion.getRegionDigraph() != this)
throw new IllegalArgumentException("The headRegion does not belong to this digraph."); //$NON-NLS-1$
+ FilteredRegion existing = null;
boolean tailAdded = false;
boolean headAdded = false;
synchronized (this.monitor) {
@@ -154,7 +166,11 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
connections = new HashSet<FilteredRegion>(connections);
for (FilteredRegion edge : connections) {
if (headRegion.equals(edge.getRegion())) {
- throw new BundleException("Region '" + tailRegion + "' is already connected to region '" + headRegion, BundleException.UNSUPPORTED_OPERATION); //$NON-NLS-1$ //$NON-NLS-2$
+ if (replace) {
+ existing = edge;
+ } else {
+ throw new BundleException("Region '" + tailRegion + "' is already connected to region '" + headRegion, BundleException.UNSUPPORTED_OPERATION); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
}
}
@@ -162,6 +178,9 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
checkFilterDoesNotAllowExistingBundle(tailRegion, filter);
tailAdded = this.regions.put(tailRegion.getName(), tailRegion) == null;
headAdded = this.regions.put(headRegion.getName(), headRegion) == null;
+ if (existing != null) {
+ connections.remove(existing);
+ }
connections.add(new StandardFilteredRegion(headRegion, filter));
this.edges.put(tailRegion, Collections.unmodifiableSet(connections));
incrementUpdateCount();
@@ -172,6 +191,7 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
if (headAdded) {
notifyAdded(headRegion);
}
+ return existing == null ? null : existing.getFilter();
}
private void checkFilterDoesNotAllowExistingBundle(Region tailRegion, RegionFilter filter) {
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java
index b6459428..92f7a8f6 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java
@@ -134,7 +134,7 @@ public interface RegionDigraph extends Iterable<Region> {
Region getRegion(long bundleId);
/**
- * Connects a given tail region to a given head region via an edge labelled with the given {@link RegionFilter}. The
+ * Connects a given tail region to a given head region via an edge labeled with the given {@link RegionFilter}. The
* tail region may then, subject to the region filter, see bundles, packages, and services visible in the head
* region.
* <p>
@@ -154,6 +154,27 @@ public interface RegionDigraph extends Iterable<Region> {
void connect(Region tailRegion, RegionFilter filter, Region headRegion) throws BundleException;
/**
+ * Connects a given tail region to a given head region via an edge labeled with the given {@link RegionFilter}. The
+ * tail region may then, subject to the region filter, see bundles, packages, and services visible in the head
+ * region.
+ * <p>
+ * The given head and tail regions are added to the digraph if they are not already present.
+ * <p>
+ * If the given tail region is already connected to the given head region, then the existing
+ * {@link RegionFilter filter} is replaced by the given {@link RegionFilter}.
+ * <p>
+ * If the given head and the given tail are identical, then BundleException with exception type
+ * UNSUPPORTED_OPERATION is thrown.
+ *
+ * @param tailRegion the region at the tail of the new edge
+ * @param filter a {@link RegionFilter} which labels the new edge
+ * @param headRegion the region at the head of the new edge
+ * @return the existing region filter that was replaced or <code>null</code>.
+ * @throws BundleException if the edge was not created
+ */
+ RegionFilter reconnect(Region tailRegion, RegionFilter filter, Region headRegion) throws BundleException;
+
+ /**
* Gets a {@link Set} containing a snapshot of the {@link FilteredRegion FilteredRegions} attached to the given tail
* region.
*

Back to the top