Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-01-28 16:21:23 +0000
committerGlyn Normington2011-01-28 16:21:23 +0000
commitca911ddd68ffeac684a689a9d4cf34f837d42c22 (patch)
treec882a084062323f8216fe51ea52d24fb41e31c90
parent730f6d095f4d33e7155f691cd195e86b44815735 (diff)
downloadorg.eclipse.virgo.kernel-ca911ddd68ffeac684a689a9d4cf34f837d42c22.tar.gz
org.eclipse.virgo.kernel-ca911ddd68ffeac684a689a9d4cf34f837d42c22.tar.xz
org.eclipse.virgo.kernel-ca911ddd68ffeac684a689a9d4cf34f837d42c22.zip
bug 330776: relax restriction that a region and its inbound filters may not both contain a given bundle symbolic name and bundle version
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/AbstractDeployerIntegrationTest.java23
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties16
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml4
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java58
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/Region.java41
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java8
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionFilter.java95
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java67
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/StandardRegionFilter.java20
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java5
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHook.java96
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java119
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/resources/META-INF/spring/osgi-framework-context.xml4
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java33
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java62
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java92
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionFilterTests.java7
-rw-r--r--org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java6
-rw-r--r--org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/module-context.xml2
-rw-r--r--org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/osgi-context.xml2
-rw-r--r--org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/RegionTests.java1
-rw-r--r--org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/test/AbstractKernelIntegrationTest.java22
-rw-r--r--org.eclipse.virgo.kernel.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties6
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java11
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/DependencyCalculator.java129
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java25
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java11
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java52
-rw-r--r--org.eclipse.virgo.kernel.userregion/template.mf1
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java18
-rw-r--r--org.eclipse.virgo.kernel.userregionfactory/template.mf2
31 files changed, 623 insertions, 415 deletions
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/AbstractDeployerIntegrationTest.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/AbstractDeployerIntegrationTest.java
index e2b3cc0a..497bdab5 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/AbstractDeployerIntegrationTest.java
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/AbstractDeployerIntegrationTest.java
@@ -16,7 +16,6 @@ import static org.junit.Assert.assertFalse;
import java.io.IOException;
import java.lang.management.ManagementFactory;
-import java.util.Collection;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -24,9 +23,7 @@ import javax.management.ObjectName;
import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer;
import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
import org.eclipse.virgo.kernel.osgi.framework.OsgiFramework;
-import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.test.framework.dmkernel.DmKernelTestRunner;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
@@ -75,25 +72,7 @@ public abstract class AbstractDeployerIntegrationTest {
}
private BundleContext getKernelContext() {
- try {
- Collection<ServiceReference<Region>> references = this.context.getServiceReferences(Region.class,"(org.eclipse.virgo.kernel.region.name=org.eclipse.virgo.region.kernel)");
- //XXX Assert.assertEquals(1, references.size()); Appear to get two services with the same region bundle context
- ServiceReference<Region> reference = references.iterator().next();
- Region kernelRegion = this.context.getService(reference);
- Assert.assertNotNull("Kernel Region not found", kernelRegion);
- BundleContext kernelContext = kernelRegion.getBundleContext();
-
- //ServiceReference<Region> ref2 = i.next();
- //BundleContext kc2 = this.context.getService(ref2).getBundleContext();
-
- Assert.assertNotNull("Kernel Region bundle context not found", kernelContext);
- this.context.ungetService(reference);
- return kernelContext;
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- Assert.assertTrue(false);
- return null;
- }
+ return this.context.getBundle(0L).getBundleContext();
}
@BeforeClass
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties
index 735fcfea..702be33b 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties
@@ -42,14 +42,20 @@ packageImports =\
org.aspectj.*;version="[1.6.5.RELEASE,2.0.0)",\
org.junit;version="[4.7.0,5.0.0)",\
org.junit.runner;version="[4.7.0,5.0.0)",\
+ org.osgi.*;version="0",\
+ org.ietf.jgss;version="0",\
+ org.omg.*;version="0",\
+ org.w3c.*;version="0",\
+ org.xml.*;version="0",\
+ org.eclipse.osgi.*;version="0",\
+ javax.*;version="0",\
org.osgi.service.cm;version="0",\
org.osgi.service.event;version="0",\
org.slf4j;version="[1.6.1,2)"
serviceImports =\
org.eclipse.virgo.kernel.osgi.region.Region,\
- org.eclipse.virgo.kernel.osgi.region.RegionMembership,\
- org.osgi.framework.hooks.resolver.ResolverHookFactory,\
+ org.eclipse.virgo.kernel.osgi.region.RegionDigraph,\
org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer,\
org.eclipse.virgo.kernel.deployer.core.DeployUriNormaliser,\
org.eclipse.virgo.kernel.install.artifact.ScopeServiceRepository,\
@@ -60,18 +66,22 @@ serviceImports =\
org.eclipse.virgo.medic.eventlog.EventLoggerFactory,\
org.eclipse.virgo.repository.Repository,\
org.eclipse.virgo.kernel.core.Shutdown,\
+ org.osgi.framework.hooks.resolver.ResolverHookFactory,\
org.osgi.service.cm.ConfigurationAdmin,\
org.osgi.service.event.EventAdmin,\
org.eclipse.virgo.medic.eventlog.EventLogger,\
org.eclipse.virgo.medic.dump.DumpGenerator,\
org.eclipse.virgo.kernel.shim.scope.ScopeFactory,\
org.eclipse.virgo.kernel.shim.serviceability.TracingService,\
- org.eclipse.virgo.kernel.model.RuntimeArtifactRepository
+ org.eclipse.virgo.kernel.model.RuntimeArtifactRepository,\
+ org.eclipse.osgi.service.resolver.PlatformAdmin,\
+ org.osgi.service.packageadmin.PackageAdmin
serviceExports =\
org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener,\
org.eclipse.virgo.kernel.install.artifact.ArtifactTypeDeterminer,\
org.eclipse.virgo.kernel.install.pipeline.stage.transform.Transformer,\
+ org.eclipse.virgo.kernel.module.ModuleContextAccessor,\
org.eclipse.virgo.medic.dump.DumpContributor,\
org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory,\
org.eclipse.virgo.kernel.osgi.framework.OsgiFramework,\
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml b/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml
index a5da1843..09e3bca0 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml
+++ b/org.eclipse.virgo.kernel.deployer/src/main/resources/META-INF/spring/deployer-context.xml
@@ -259,10 +259,12 @@
<beans:constructor-arg ref="bundleStarter" />
<beans:constructor-arg ref="tracingService" />
<beans:constructor-arg ref="packageAdminUtil" />
- <beans:constructor-arg value="#{region.getBundleContext()}" />
+ <beans:constructor-arg ref="userBundleContext" />
<beans:constructor-arg ref="eventLogger" />
<beans:constructor-arg ref="artifactIdentityDeterminer" />
</beans:bean>
+
+ <reference id="userBundleContext" interface="org.osgi.framework.BundleContext" filter="(org.eclipse.virgo.kernel.regionContext=true)"/>
<service ref="bundleInstallArtifactTreeFactory"
interface="org.eclipse.virgo.kernel.install.artifact.InstallArtifactTreeFactory" />
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java
index 98946a85..a1a80512 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/BundleIdBasedRegion.java
@@ -18,10 +18,8 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
-import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.eclipse.virgo.util.math.ConcurrentHashSet;
-import org.eclipse.virgo.util.math.OrderedPair;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -82,8 +80,6 @@ public final class BundleIdBasedRegion implements Region {
checkDuplicateBundleInRegion(bundle, symbolicName, version);
- checkDuplicateBundleViaFilter(bundle, symbolicName, version);
-
this.bundleIds.add(bundle.getBundleId());
}
}
@@ -98,20 +94,20 @@ public final class BundleIdBasedRegion implements Region {
private void checkDuplicateBundleInRegion(Bundle bundle, String symbolicName, Version version) throws BundleException {
Bundle existingBundle = getBundle(symbolicName, version);
- if (existingBundle != null) {
+ if (existingBundle != null && !existingBundle.equals(bundle)) {
throw new BundleException("Cannot add bundle '" + bundle + "' to region '" + this
+ "' as its symbolic name and version conflict with those of bundle '" + existingBundle + "' which is already present in the region",
BundleException.DUPLICATE_BUNDLE_ERROR);
}
}
-
- private void checkDuplicateBundleViaFilter(Bundle bundle, String symbolicName, Version version) throws BundleException {
- for (FilteredRegion filteredRegion : this.regionDigraph.getEdges(this)) {
- RegionFilter filter = filteredRegion.getFilter();
- if (filter.getAllowedBundles().contains(new OrderedPair<String, Version>(symbolicName, version))) {
- throw new BundleException("Cannot add bundle '" + bundle + "' to region '" + this + "' as filter '" + filter
- + "' allows it to be seen from region '" + filteredRegion.getRegion() + "'", BundleException.DUPLICATE_BUNDLE_ERROR);
- }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addBundle(long bundleId) {
+ synchronized (this.updateMonitor) {
+ this.bundleIds.add(bundleId);
}
}
@@ -197,15 +193,6 @@ public final class BundleIdBasedRegion implements Region {
* {@inheritDoc}
*/
@Override
- public BundleContext getBundleContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
public boolean contains(Bundle bundle) {
return this.bundleIds.contains(bundle.getBundleId());
}
@@ -241,4 +228,31 @@ public final class BundleIdBasedRegion implements Region {
return this.bundleIds.contains(bundleId);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeBundle(Bundle bundle) {
+ removeBundle(bundle.getBundleId());
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeBundle(long bundleId) {
+ synchronized (this.updateMonitor) {
+ this.bundleIds.remove(bundleId);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return getName();
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/Region.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/Region.java
index 0e90aef4..f2f4d4f7 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/Region.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/Region.java
@@ -62,6 +62,17 @@ public interface Region {
void addBundle(Bundle bundle) throws BundleException;
/**
+ * Associates the given bundle id with this region. If the given bundle id is already associated with this region,
+ * this is not an error and there is no effect.
+ * <p>
+ * This is useful when manipulating offline resolver states and bundle descriptions which do not correspond to
+ * bundles.
+ *
+ * @param bundleId the bundle id to be associated with this region
+ */
+ void addBundle(long bundleId);
+
+ /**
* Installs a bundle and associates the bundle with this region. The bundle's location will have the region name
* prepended to the given location to ensure the location is unique across regions.
* <p>
@@ -92,7 +103,7 @@ public interface Region {
* @see BundleContext#installBundle(String)
*/
Bundle installBundle(String location) throws BundleException;
-
+
/**
* Returns <code>true</code> if and only if the given bundle belongs to this region.
*
@@ -105,10 +116,11 @@ public interface Region {
* Returns <code>true</code> if and only if a bundle with the given bundle id belongs to this region.
*
* @param bundleId a bundle id
- * @return <code>true</code> if a bundle with the given bundle id belongs to this region and <code>false</code> otherwise
+ * @return <code>true</code> if a bundle with the given bundle id belongs to this region and <code>false</code>
+ * otherwise
*/
boolean contains(long bundleId);
-
+
/**
* Get the bundle in this region with the given symbolic name and version.
*
@@ -119,9 +131,9 @@ public interface Region {
Bundle getBundle(String symbolicName, Version version);
/**
- * Connects this region to the given tail region and associates the given {@link RegionFilter} with the
- * connection. This region may then, subject to the region filter, see bundles, packages, and services visible in
- * the tail region.
+ * Connects this region to the given tail region and associates the given {@link RegionFilter} with the connection.
+ * This region may then, subject to the region filter, see bundles, packages, and services visible in the tail
+ * region.
* <p>
* If the filter allows the same bundle symbolic name and version as a bundle already present in this region or a
* filter connecting this region to a region other than the tail region, then BundleException with exception type
@@ -137,12 +149,19 @@ public interface Region {
void connectRegion(Region tailRegion, RegionFilter filter) throws BundleException;
/**
- * Returns a {@link BundleContext} that can be used to access the contents of the region.
+ * Removes the given bundle from this region. If the given bundle does not belong to this region, this is not an
+ * error and there is no effect.
+ *
+ * @param bundle the bundle to be removed
+ */
+ void removeBundle(Bundle bundle);
+
+ /**
+ * Removes the given bundle id from this region. If the given bundle id is not associated with this region, this is
+ * not an error and there is no effect.
*
- * @return a <code>BundleContext</code>
- * @deprecated This method should not appear on the API as it is hard to guarantee the availability of a suitable
- * bundle context
+ * @param bundleId the bundle id to be removed
*/
- BundleContext getBundleContext();
+ void removeBundle(long bundleId);
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java
index d4cfcdad..c62708fc 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionDigraph.java
@@ -63,6 +63,14 @@ public interface RegionDigraph extends Iterable<Region> {
void addRegion(Region region);
/**
+ * Removes the given {@link Region} from the digraph along with any edges which have the given region as head or
+ * tail. If the given region is not present in the digraph, this is not an error and there is no effect.
+ *
+ * @param coregion the {@link Region} to be removed
+ */
+ void removeRegion(Region coregion);
+
+ /**
* Gets the {@link Region} in the digraph with the given name.
*
* @param regionName the name of the region
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionFilter.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionFilter.java
index 43f1f632..05ebc2a4 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionFilter.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionFilter.java
@@ -13,10 +13,11 @@
package org.eclipse.virgo.kernel.osgi.region;
-import java.util.Set;
+import java.util.Dictionary;
+import java.util.Map;
-import org.eclipse.virgo.util.math.OrderedPair;
import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
/**
@@ -31,6 +32,70 @@ import org.osgi.framework.Version;
*/
public interface RegionFilter {
+ public static final RegionPackageImportPolicy ALL_PACKAGES = new RegionPackageImportPolicy() {
+
+ @Override
+ public boolean isImported(String packageName, Map<String, Object> attributes, Map<String, String> directives) {
+ return true;
+ }
+ };
+
+ public static final Filter ALL_SERVICES = new Filter() {
+
+ @Override
+ public boolean match(ServiceReference<?> reference) {
+ return true;
+ }
+
+ @Override
+ public boolean match(Dictionary<String, ?> dictionary) {
+ return true;
+ }
+
+ @Override
+ public boolean matchCase(Dictionary<String, ?> dictionary) {
+ return true;
+ }
+
+ @Override
+ public boolean matches(Map<String, ?> map) {
+ return true;
+ }
+ };
+
+ public static final RegionFilter TOP = new RegionFilter() {
+
+ @Override
+ public RegionFilter allowBundle(String bundleSymbolicName, Version bundleVersion) {
+ return this;
+ }
+
+ @Override
+ public boolean isBundleAllowed(String bundleSymbolicName, Version bundleVersion) {
+ return true;
+ }
+
+ @Override
+ public RegionFilter setPackageImportPolicy(RegionPackageImportPolicy packageImportPolicy) {
+ return this;
+ }
+
+ @Override
+ public RegionPackageImportPolicy getPackageImportPolicy() {
+ return ALL_PACKAGES;
+ }
+
+ @Override
+ public RegionFilter setServiceFilter(Filter serviceFilter) {
+ return this;
+ }
+
+ @Override
+ public Filter getServiceFilter() {
+ return ALL_SERVICES;
+ }
+ };
+
/**
* Allows a bundle with the given bundle symbolic name and version to be imported.
*
@@ -38,35 +103,37 @@ public interface RegionFilter {
*
* @param bundleSymbolicName
* @param bundleVersion
- * @return
+ * @return this {@link RegionFilter} for chaining purposes
*/
RegionFilter allowBundle(String bundleSymbolicName, Version bundleVersion);
/**
- * Gets the bundles allowed by this filter.
+ * Determines whether this filter allows the bundle with the given symbolic name and version
*
- * @return a collection of (bundle symbolic name, bundle version) pairs
+ * @param bundleSymbolicName the symbolic name of the bundle
+ * @param bundleVersion the {@link Version} of the bundle
+ * @return <code>true</code> if the bundle is allowed and <code>false</code>otherwise
*/
- Set<OrderedPair<String, Version>> getAllowedBundles();
+ boolean isBundleAllowed(String bundleSymbolicName, Version bundleVersion);
/**
- * Gets the package import policy of this filter.
+ * Sets the package import policy of this filter.
*
- * @return the package import policy or <code>null</code> if this has not been set
+ * @param packageImportPolicy
+ * @return this {@link RegionFilter} for chaining purposes
*/
- RegionPackageImportPolicy getPackageImportPolicy();
+ RegionFilter setPackageImportPolicy(RegionPackageImportPolicy packageImportPolicy);
/**
- * Sets the package import policy of this filter.
+ * Gets the package import policy of this filter.
*
- * @param packageImportPolicy
- * @return
+ * @return the package import policy or <code>null</code> if this has not been set
*/
- RegionFilter setPackageImportPolicy(RegionPackageImportPolicy packageImportPolicy);
+ RegionPackageImportPolicy getPackageImportPolicy();
/**
* @param serviceFilter
- * @return
+ * @return this {@link RegionFilter} for chaining purposes
* @see org.osgi.framework.Filter more information about service filters
*/
RegionFilter setServiceFilter(Filter serviceFilter);
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
index 75c2d956..54b4430d 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/RegionManager.java
@@ -14,23 +14,21 @@ package org.eclipse.virgo.kernel.osgi.region;
import java.util.Dictionary;
import java.util.Hashtable;
-import org.eclipse.virgo.kernel.core.Shutdown;
import org.eclipse.virgo.kernel.osgi.region.hook.RegionBundleEventHook;
import org.eclipse.virgo.kernel.osgi.region.hook.RegionBundleFindHook;
import org.eclipse.virgo.kernel.osgi.region.hook.RegionResolverHookFactory;
import org.eclipse.virgo.kernel.osgi.region.hook.RegionServiceEventHook;
import org.eclipse.virgo.kernel.osgi.region.hook.RegionServiceFindHook;
import org.eclipse.virgo.kernel.osgi.region.internal.StandardRegionDigraph;
-import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
+import org.osgi.framework.SynchronousBundleListener;
import org.osgi.framework.hooks.bundle.EventHook;
import org.osgi.framework.hooks.bundle.FindHook;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.event.EventAdmin;
/**
* Creates and manages the user {@link Region regions}.
@@ -49,12 +47,10 @@ final class RegionManager {
private final BundleContext bundleContext;
- public RegionManager(BundleContext bundleContext, EventAdmin eventAdmin, ConfigurationAdmin configAdmin, EventLogger eventLogger,
- Shutdown shutdown) {
+ public RegionManager(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
-
public void start() throws BundleException {
RegionDigraph regionDigraph = createRegionDigraph();
registerRegionHooks(regionDigraph);
@@ -62,35 +58,76 @@ final class RegionManager {
private RegionDigraph createRegionDigraph() throws BundleException {
RegionDigraph regionDigraph = new StandardRegionDigraph();
- createKernelRegion(regionDigraph);
+ Region kernelRegion = createKernelRegion(regionDigraph);
registerRegionDigraph(regionDigraph, this.bundleContext);
+ createBundleListener(regionDigraph, kernelRegion);
return regionDigraph;
}
+ private void createBundleListener(final RegionDigraph regionDigraph, final Region kernelRegion) {
+ BundleContext systemBundleContext = getSystemBundleContext();
+ systemBundleContext.addBundleListener(new SynchronousBundleListener() {
+
+ @Override
+ public void bundleChanged(BundleEvent event) {
+ Bundle bundle = event.getBundle();
+ switch (event.getType()) {
+ case BundleEvent.INSTALLED:
+ Bundle originBundle = event.getOrigin();
+ /*
+ * The system bundle is used, by BundleIdBasedRegion, to install bundles into arbitrary regions,
+ * so ignore it as an origin.
+ */
+ if (originBundle.getBundleId() != 0L) {
+ Region originRegion = regionDigraph.getRegion(originBundle);
+ if (originRegion != null) {
+ try {
+ originRegion.addBundle(bundle);
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ break;
+ case BundleEvent.UNINSTALLED:
+ Region region = regionDigraph.getRegion(bundle);
+ if (region != null) {
+ region.removeBundle(bundle);
+ }
+ break;
+ default:
+ break;
+ }
+
+ }
+ });
- private void createKernelRegion(RegionDigraph regionDigraph) throws BundleException {
+ }
+
+ private Region createKernelRegion(RegionDigraph regionDigraph) throws BundleException {
Region kernelRegion = new BundleIdBasedRegion(REGION_KERNEL, regionDigraph, getSystemBundleContext());
regionDigraph.addRegion(kernelRegion);
for (Bundle bundle : this.bundleContext.getBundles()) {
kernelRegion.addBundle(bundle);
}
-
+
registerRegionService(kernelRegion);
- }
+ return kernelRegion;
+ }
private void registerRegionHooks(RegionDigraph regionDigraph) {
registerResolverHookFactory(new RegionResolverHookFactory(regionDigraph));
-
+
RegionBundleFindHook bundleFindHook = new RegionBundleFindHook(regionDigraph);
-
+
registerBundleFindHook(bundleFindHook);
registerBundleEventHook(new RegionBundleEventHook(bundleFindHook));
RegionServiceFindHook serviceFindHook = new RegionServiceFindHook(regionDigraph);
-
+
registerServiceFindHook(serviceFindHook);
registerServiceEventHook(new RegionServiceEventHook(serviceFindHook));
@@ -99,7 +136,7 @@ final class RegionManager {
private BundleContext getSystemBundleContext() {
return this.bundleContext.getBundle(0L).getBundleContext();
}
-
+
private void registerRegionDigraph(RegionDigraph regionDigraph, BundleContext userRegionBundleContext) {
this.tracker.track(this.bundleContext.registerService(RegionDigraph.class, regionDigraph, null));
if (userRegionBundleContext != null) {
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/StandardRegionFilter.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/StandardRegionFilter.java
index 7334499d..28132a07 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/StandardRegionFilter.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/StandardRegionFilter.java
@@ -11,7 +11,6 @@
package org.eclipse.virgo.kernel.osgi.region;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -42,19 +41,13 @@ public final class StandardRegionFilter implements RegionFilter {
@Override
public RegionFilter allowBundle(String bundleSymbolicName, Version bundleVersion) {
synchronized (this.monitor) {
- this.allowedBundles.add(new OrderedPair<String, Version>(bundleSymbolicName, bundleVersion));
+ this.allowedBundles.add(createPair(bundleSymbolicName, bundleVersion));
}
return this;
}
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<OrderedPair<String, Version>> getAllowedBundles() {
- synchronized (this.monitor) {
- return Collections.unmodifiableSet(this.allowedBundles);
- }
+ private OrderedPair<String, Version> createPair(String bundleSymbolicName, Version bundleVersion) {
+ return new OrderedPair<String, Version>(bundleSymbolicName, bundleVersion);
}
/**
@@ -93,4 +86,11 @@ public final class StandardRegionFilter implements RegionFilter {
return this;
}
+ @Override
+ public boolean isBundleAllowed(String bundleSymbolicName, Version bundleVersion) {
+ synchronized (this.monitor) {
+ return this.allowedBundles.contains(createPair(bundleSymbolicName, bundleVersion));
+ }
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
index 72e1d076..f126a577 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionBundleFindHook.java
@@ -20,10 +20,8 @@ import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
-import org.eclipse.virgo.util.math.OrderedPair;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
import org.osgi.framework.hooks.bundle.FindHook;
/**
@@ -95,11 +93,10 @@ public final class RegionBundleFindHook implements FindHook {
}
private void filter(Set<Bundle> bundles, RegionFilter filter) {
- Set<OrderedPair<String, Version>> allowedBundles = filter.getAllowedBundles();
Iterator<Bundle> i = bundles.iterator();
while (i.hasNext()) {
Bundle b = i.next();
- if (!allowedBundles.contains(new OrderedPair<String, Version>(b.getSymbolicName(), b.getVersion()))) {
+ if (!filter.isBundleAllowed(b.getSymbolicName(), b.getVersion())) {
i.remove();
}
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHook.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHook.java
index 0bc21dc2..5c28307d 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHook.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/hook/RegionResolverHook.java
@@ -19,13 +19,11 @@ import java.util.Set;
import org.eclipse.osgi.internal.module.ResolverBundle;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.osgi.region.RegionPackageImportPolicy;
-import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
import org.eclipse.virgo.kernel.serviceability.Assert;
-import org.eclipse.virgo.util.math.OrderedPair;
import org.osgi.framework.Bundle;
-import org.osgi.framework.Version;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.Capability;
@@ -41,6 +39,8 @@ final class RegionResolverHook implements ResolverHook {
private static final long INVALID_BUNDLE_ID = -1L;
+ private static final Boolean DEBUG = true;
+
private final RegionDigraph regionDigraph;
RegionResolverHook(RegionDigraph regionDigraph) {
@@ -49,19 +49,29 @@ final class RegionResolverHook implements ResolverHook {
@Override
public void filterMatches(BundleRevision requirer, Collection<Capability> candidates) {
- if (getBundleId(requirer) == 0L) {
- return;
- }
+ try {
+ if (DEBUG) {
+ debugEntry(requirer, candidates);
+ }
- Region requirerRegion = getRegion(requirer);
- if (requirerRegion == null) {
- candidates.clear();
- return;
- }
+ if (getBundleId(requirer) == 0L) {
+ return;
+ }
+
+ Region requirerRegion = getRegion(requirer);
+ if (requirerRegion == null) {
+ candidates.clear();
+ return;
+ }
- Set<Capability> allowed = getAllowed(requirerRegion, candidates, new HashSet<Region>());
+ Set<Capability> allowed = getAllowed(requirerRegion, candidates, new HashSet<Region>());
- candidates.retainAll(allowed);
+ candidates.retainAll(allowed);
+ } finally {
+ if (DEBUG) {
+ debugExit(requirer, candidates);
+ }
+ }
}
private Region getRegion(BundleRevision bundleRevision) {
@@ -127,7 +137,6 @@ final class RegionResolverHook implements ResolverHook {
private void filter(Set<Capability> capabilities, RegionFilter filter) {
RegionPackageImportPolicy packageImportPolicy = filter.getPackageImportPolicy();
- Set<OrderedPair<String, Version>> allowedBundles = filter.getAllowedBundles();
Iterator<Capability> i = capabilities.iterator();
while (i.hasNext()) {
Capability c = i.next();
@@ -138,22 +147,13 @@ final class RegionResolverHook implements ResolverHook {
i.remove();
}
} else {
- if (!allowedBundle(c.getProviderRevision(), allowedBundles)) {
+ BundleRevision providerRevision = c.getProviderRevision();
+ if (!filter.isBundleAllowed(providerRevision.getSymbolicName(), providerRevision.getVersion())) {
i.remove();
}
- }
- }
- }
- private boolean allowedBundle(BundleRevision bundleRevision, Set<OrderedPair<String, Version>> allowedBundles) {
- String symbolicName = bundleRevision.getSymbolicName();
- Version version = bundleRevision.getVersion();
- for (OrderedPair<String, Version> allowedBundle : allowedBundles) {
- if (symbolicName.equals(allowedBundle.getFirst()) && version.equals(allowedBundle.getSecond())) {
- return true;
}
}
- return false;
}
private Region getRegion(Bundle bundle) {
@@ -167,8 +167,6 @@ final class RegionResolverHook implements ResolverHook {
@Override
public void end() {
- // TODO Auto-generated method stub
-
}
@Override
@@ -179,4 +177,48 @@ final class RegionResolverHook implements ResolverHook {
public void filterSingletonCollisions(Capability singleton, Collection<Capability> collisionCandidates) {
}
+ private void debugEntry(BundleRevision requirer, Collection<Capability> candidates) {
+ System.out.println("Requirer: " + requirer.getSymbolicName() + "_" + requirer.getVersion() + "[" + getBundleId(requirer) + "]");
+ System.out.println(" Candidates: ");
+ Iterator<Capability> i = candidates.iterator();
+ while (i.hasNext()) {
+ Capability c = i.next();
+ String namespace = c.getNamespace();
+ if (Capability.PACKAGE_CAPABILITY.equals(namespace)) {
+ BundleRevision providerRevision = c.getProviderRevision();
+ String pkg = (String) c.getAttributes().get(Capability.PACKAGE_CAPABILITY);
+ System.out.println(" Package " + pkg + " from provider " + providerRevision.getSymbolicName() + "_"
+ + providerRevision.getVersion() + "[" + getBundleId(providerRevision) + "]");
+ if (pkg.equals("javax.portlet")) {
+ System.out.println(">>> put breakpoint here <<<");
+ }
+ } else {
+ BundleRevision providerRevision = c.getProviderRevision();
+ System.out.println(" Bundle from provider " + providerRevision.getSymbolicName() + "_" + providerRevision.getVersion() + "["
+ + getBundleId(providerRevision) + "]");
+ }
+ }
+ }
+
+ private void debugExit(BundleRevision requirer, Collection<Capability> candidates) {
+ System.out.println(" Filtered candidates: ");
+ Iterator<Capability> i = candidates.iterator();
+ while (i.hasNext()) {
+ Capability c = i.next();
+ String namespace = c.getNamespace();
+ if (Capability.PACKAGE_CAPABILITY.equals(namespace)) {
+ BundleRevision providerRevision = c.getProviderRevision();
+ String pkg = (String) c.getAttributes().get(Capability.PACKAGE_CAPABILITY);
+ System.out.println(" Package " + pkg + " from provider " + providerRevision.getSymbolicName() + "_"
+ + providerRevision.getVersion() + "[" + getBundleId(providerRevision) + "]");
+ if (pkg.equals("org.springframework.jdbc")) {
+ System.out.println(">>> put breakpoint here <<<");
+ }
+ } else {
+ BundleRevision providerRevision = c.getProviderRevision();
+ System.out.println(" Bundle from provider " + providerRevision.getSymbolicName() + "_" + providerRevision.getVersion() + "["
+ + getBundleId(providerRevision) + "]");
+ }
+ }
+ }
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java
index 89f469e4..e0a8ab42 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraph.java
@@ -13,7 +13,6 @@
package org.eclipse.virgo.kernel.osgi.region.internal;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -27,7 +26,6 @@ import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.eclipse.virgo.util.math.OrderedPair;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
-import org.osgi.framework.Version;
/**
* {@link StandardRegionDigraph} is the default implementation of {@link RegionDigraph}.
@@ -60,7 +58,7 @@ public final class StandardRegionDigraph implements RegionDigraph {
throw new BundleException("Region '" + tailRegion + "' is already connected to region '" + headRegion,
BundleException.UNSUPPORTED_OPERATION);
} else {
- checkDuplicateBundle(tailRegion, filter);
+ checkFilterDoesNotAllowExistingBundle(tailRegion, filter);
this.regions.add(tailRegion);
this.regions.add(headRegion);
this.filter.put(nodePair, filter);
@@ -69,36 +67,8 @@ public final class StandardRegionDigraph implements RegionDigraph {
}
- private void checkDuplicateBundle(Region tailRegion, RegionFilter filter) throws BundleException {
- checkFilterDoesNotAllowExistingBundle(tailRegion, filter);
- checkFilterDoesNotAllowSameBundleAsExistingFilter(tailRegion, filter);
- }
-
private void checkFilterDoesNotAllowExistingBundle(Region tailRegion, RegionFilter filter) throws BundleException {
- for (OrderedPair<String, Version> filterBundle : filter.getAllowedBundles()) {
- String symbolicName = filterBundle.getFirst();
- Version version = filterBundle.getSecond();
- if (tailRegion.getBundle(symbolicName, version) != null) {
- throw new BundleException("RegionFilter '" + filter + "' allows bundle '" + symbolicName + "_" + version
- + "' which is present in region '" + tailRegion + "'", BundleException.DUPLICATE_BUNDLE_ERROR);
- }
- }
- }
-
- private void checkFilterDoesNotAllowSameBundleAsExistingFilter(Region tailRegion, RegionFilter f) throws BundleException {
- Collection<OrderedPair<String, Version>> fAllowed = f.getAllowedBundles();
- for (FilteredRegion edge : getEdges(tailRegion)) {
- RegionFilter g = edge.getFilter();
- Collection<OrderedPair<String, Version>> gAllowed = g.getAllowedBundles();
- for (OrderedPair<String, Version> bundle : gAllowed) {
- if (fAllowed.contains(bundle)) {
- String symbolicName = bundle.getFirst();
- Version version = bundle.getSecond();
- throw new BundleException("RegionFilter '" + f + "' allows bundle '" + symbolicName + "_" + version
- + "' which is allowed into region '" + tailRegion + "' by filter '" + g + "'", BundleException.DUPLICATE_BUNDLE_ERROR);
- }
- }
- }
+ // TODO: enumerate the bundles in the region and check the filter does not allow any of them
}
/**
@@ -163,40 +133,97 @@ public final class StandardRegionDigraph implements RegionDigraph {
}
- /**
+ /**
* {@inheritDoc}
*/
@Override
public Region getRegion(@NonNull String regionName) {
- for (Region region : this) {
- if (regionName.equals(region.getName())) {
- return region;
+ synchronized (this.monitor) {
+ for (Region region : this) {
+ if (regionName.equals(region.getName())) {
+ return region;
+ }
}
+ return null;
}
- return null;
}
- /**
+ /**
* {@inheritDoc}
*/
@Override
public Region getRegion(Bundle bundle) {
- for (Region region : this) {
- if (region.contains(bundle)) {
- return region;
+ synchronized (this.monitor) {
+ for (Region region : this) {
+ if (region.contains(bundle)) {
+ return region;
+ }
}
+ return null;
}
- return null;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Region getRegion(long bundleId) {
- for (Region region : this) {
- if (region.contains(bundleId)) {
- return region;
+ synchronized (this.monitor) {
+ for (Region region : this) {
+ if (region.contains(bundleId)) {
+ return region;
+ }
+ }
+ return null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeRegion(@NonNull Region coregion) {
+ synchronized (this.monitor) {
+ this.regions.remove(coregion);
+ Iterator<OrderedPair<Region, Region>> i = this.filter.keySet().iterator();
+ while (i.hasNext()) {
+ OrderedPair<Region, Region> regionPair = i.next();
+ if (coregion.equals(regionPair.getFirst()) || coregion.equals(regionPair.getSecond())) {
+ i.remove();
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ synchronized (this.monitor) {
+ StringBuffer s = new StringBuffer();
+ boolean first = true;
+ s.append("RegionDigraph{");
+ for (Region r : this) {
+ if (!first) {
+ s.append(", ");
+ }
+ s.append(r);
+ first = false;
+ }
+ s.append("}");
+ s.append("[");
+ first = true;
+ for (OrderedPair<Region, Region> regionPair : this.filter.keySet()) {
+ if (!first) {
+ s.append(", ");
+ }
+ s.append(regionPair.getFirst() + "->" + regionPair.getSecond());
+ first = false;
}
+ s.append("]");
+ return s.toString();
}
- return null;
}
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/resources/META-INF/spring/osgi-framework-context.xml b/org.eclipse.virgo.kernel.osgi/src/main/resources/META-INF/spring/osgi-framework-context.xml
index d53c124c..1189ba57 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/resources/META-INF/spring/osgi-framework-context.xml
+++ b/org.eclipse.virgo.kernel.osgi/src/main/resources/META-INF/spring/osgi-framework-context.xml
@@ -5,10 +5,6 @@
<bean class="org.eclipse.virgo.kernel.osgi.region.RegionManager" init-method="start" destroy-method="stop">
<constructor-arg ref="bundleContext"/>
- <constructor-arg ref="eventAdmin"/>
- <constructor-arg ref="configAdmin"/>
- <constructor-arg ref="eventLogger"/>
- <constructor-arg ref="shutdown"/>
</bean>
</beans>
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java
index 93b2a0a3..573bf898 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java
@@ -11,28 +11,15 @@
package org.eclipse.virgo.kernel.osgi.region;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.isNull;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
-import java.util.Dictionary;
-import java.util.Hashtable;
import java.util.List;
-import org.eclipse.virgo.kernel.core.Shutdown;
-import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.eclipse.virgo.teststubs.osgi.framework.StubServiceRegistration;
import org.junit.Test;
import org.osgi.framework.Version;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.event.EventAdmin;
public class RegionManagerTests {
@@ -42,28 +29,18 @@ public class RegionManagerTests {
StubBundle stubUserRegionFactoryBundle = new StubBundle("org.eclipse.virgo.kernel.userregionfactory", new Version("2.2.0"));
bundleContext.addInstalledBundle(stubUserRegionFactoryBundle);
-
- EventAdmin eventAdmin = createMock(EventAdmin.class);
-
- Dictionary<String, String> properties = new Hashtable<String, String>();
- Configuration config = createMock(Configuration.class);
- expect(config.getProperties()).andReturn(properties);
-
- ConfigurationAdmin configAdmin = createMock(ConfigurationAdmin.class);
- expect(configAdmin.getConfiguration(isA(String.class), (String) isNull())).andReturn(config);
- EventLogger eventLogger = createMock(EventLogger.class);
- Shutdown shutdown = createMock(Shutdown.class);
-
- replay(eventAdmin, configAdmin, config);
- RegionManager manager = new RegionManager(bundleContext, eventAdmin, configAdmin, eventLogger, shutdown);
+ StubBundle stubSystemBundle = new StubBundle(0L, "org.osgi.framework", new Version("0"), "");
+ bundleContext.addInstalledBundle(stubSystemBundle);
+
+
+ RegionManager manager = new RegionManager(bundleContext);
manager.start();
List<StubServiceRegistration<Object>> serviceRegistrations = bundleContext.getServiceRegistrations();
assertEquals("Region services not registered", 8, serviceRegistrations.size());
manager.stop();
- verify(eventAdmin, configAdmin, config);
}
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java
index c4a43fa5..893744c2 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/BundleIdBasedRegionTests.java
@@ -43,9 +43,13 @@ public class BundleIdBasedRegionTests {
private static final Version BUNDLE_VERSION = new Version("1");
private static final long BUNDLE_ID = 1L;
+
+ private static final long BUNDLE_ID_2 = 2L;
private static final String REGION_NAME = "reg";
+ private static final long TEST_BUNDLE_ID = 99L;
+
private Bundle mockBundle;
private RegionDigraph mockGraph;
@@ -142,14 +146,13 @@ public class BundleIdBasedRegionTests {
EasyMock.expect(this.mockGraph.getEdges(EasyMock.isA(Region.class))).andReturn(edges).anyTimes();
Set<OrderedPair<String, Version>> allowedBundles = new HashSet<OrderedPair<String, Version>>();
allowedBundles.add(new OrderedPair<String, Version>(BUNDLE_SYMBOLIC_NAME_2, BUNDLE_VERSION));
- EasyMock.expect(this.mockRegionFilter.getAllowedBundles()).andReturn(allowedBundles).anyTimes();
replayMocks();
Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
r.addBundle(this.mockBundle);
}
- @Test(expected = BundleException.class)
+ @Test
public void testAddExistingBundle() throws BundleException {
defaultSetUp();
@@ -159,6 +162,22 @@ public class BundleIdBasedRegionTests {
}
@Test(expected = BundleException.class)
+ public void testAddConflictingBundle() throws BundleException {
+ defaultSetUp();
+
+ Bundle mockBundle2 = EasyMock.createMock(Bundle.class);
+ EasyMock.expect(mockBundle2.getSymbolicName()).andReturn(BUNDLE_SYMBOLIC_NAME).anyTimes();
+ EasyMock.expect(mockBundle2.getVersion()).andReturn(BUNDLE_VERSION).anyTimes();
+ EasyMock.expect(mockBundle2.getBundleId()).andReturn(BUNDLE_ID_2).anyTimes();
+ EasyMock.replay(mockBundle2);
+
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ r.addBundle(this.mockBundle);
+ r.addBundle(mockBundle2);
+ }
+
+
+ @Test(expected = BundleException.class)
public void testAddBundlePresentInAnotherRegion() throws BundleException {
this.regionIterator = new Iterator<Region>() {
@@ -194,34 +213,6 @@ public class BundleIdBasedRegionTests {
r.addBundle(this.mockBundle);
}
- @Test(expected = BundleException.class)
- public void testAddImportedBundle() throws BundleException {
- EasyMock.expect(this.mockGraph.iterator()).andReturn(this.regionIterator).anyTimes();
-
- HashSet<FilteredRegion> edges = new HashSet<FilteredRegion>();
- edges.add(new FilteredRegion() {
-
- @Override
- public Region getRegion() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public RegionFilter getFilter() {
- return mockRegionFilter;
- }
- });
- EasyMock.expect(this.mockGraph.getEdges(EasyMock.isA(Region.class))).andReturn(edges).anyTimes();
- Set<OrderedPair<String, Version>> allowedBundles = new HashSet<OrderedPair<String, Version>>();
- allowedBundles.add(new OrderedPair<String, Version>(BUNDLE_SYMBOLIC_NAME, BUNDLE_VERSION));
- EasyMock.expect(this.mockRegionFilter.getAllowedBundles()).andReturn(allowedBundles).anyTimes();
- replayMocks();
-
- Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
- r.addBundle(this.mockBundle);
- }
-
@Test
public void testInstallBundleStringInputStream() {
defaultSetUp();
@@ -299,5 +290,16 @@ public class BundleIdBasedRegionTests {
assertFalse(r.equals(s));
assertFalse(r.equals(null));
}
+
+ @Test
+ public void testAddRemoveBundleId() {
+ defaultSetUp();
+ Region r = new BundleIdBasedRegion(REGION_NAME, this.mockGraph, this.mockBundleContext);
+ r.addBundle(TEST_BUNDLE_ID);
+ assertTrue(r.contains(TEST_BUNDLE_ID));
+ r.removeBundle(TEST_BUNDLE_ID);
+ assertFalse(r.contains(TEST_BUNDLE_ID));
+
+ }
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java
index 7958aead..0eb4bb56 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionDigraphTests.java
@@ -13,18 +13,19 @@
package org.eclipse.virgo.kernel.osgi.region.internal;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import java.util.Arrays;
-import java.util.HashSet;
import java.util.Set;
import org.easymock.EasyMock;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
-import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph.FilteredRegion;
-import org.eclipse.virgo.kernel.osgi.region.internal.StandardRegionDigraph;
+import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.util.math.OrderedPair;
import org.junit.After;
import org.junit.Before;
@@ -52,9 +53,16 @@ public class StandardRegionDigraphTests {
@Before
public void setUp() throws Exception {
this.digraph = new StandardRegionDigraph();
+
this.mockRegion1 = EasyMock.createMock(Region.class);
+ EasyMock.expect(this.mockRegion1.getName()).andReturn("mockRegion1").anyTimes();
+
this.mockRegion2 = EasyMock.createMock(Region.class);
+ EasyMock.expect(this.mockRegion2.getName()).andReturn("mockRegion2").anyTimes();
+
this.mockRegion3 = EasyMock.createMock(Region.class);
+ EasyMock.expect(this.mockRegion3.getName()).andReturn("mockRegion3").anyTimes();
+
this.regionFilter1 = EasyMock.createMock(RegionFilter.class);
this.regionFilter2 = EasyMock.createMock(RegionFilter.class);
this.mockBundle = EasyMock.createMock(Bundle.class);
@@ -65,8 +73,15 @@ public class StandardRegionDigraphTests {
setMockFilterAllowedBundles(this.regionFilter2);
}
- private void setMockFilterAllowedBundles(RegionFilter regionFilter, OrderedPair<String, Version>... bundles) {
- EasyMock.expect(regionFilter.getAllowedBundles()).andReturn(new HashSet<OrderedPair<String, Version>>(Arrays.asList(bundles))).anyTimes();
+ private void setMockFilterAllowedBundles(RegionFilter regionFilter) {
+ EasyMock.expect(regionFilter.isBundleAllowed(EasyMock.isA(String.class), EasyMock.isA(Version.class))).andReturn(false).anyTimes();
+ }
+
+ private void setMockFilterAllowedBundle(RegionFilter regionFilter, OrderedPair<String, Version> bundle) {
+ EasyMock.expect(regionFilter.isBundleAllowed(EasyMock.eq(bundle.getFirst()), EasyMock.eq(bundle.getSecond()))).andReturn(true).anyTimes();
+ EasyMock.expect(regionFilter.isBundleAllowed(EasyMock.not(EasyMock.eq(bundle.getFirst())), EasyMock.eq(bundle.getSecond()))).andReturn(false).anyTimes();
+ EasyMock.expect(regionFilter.isBundleAllowed(EasyMock.eq(bundle.getFirst()), EasyMock.not(EasyMock.eq(bundle.getSecond())))).andReturn(false).anyTimes();
+ EasyMock.expect(regionFilter.isBundleAllowed(EasyMock.not(EasyMock.eq(bundle.getFirst())), EasyMock.not(EasyMock.eq(bundle.getSecond())))).andReturn(false).anyTimes();
}
private void replayMocks() {
@@ -82,33 +97,31 @@ public class StandardRegionDigraphTests {
public void testConnect() throws BundleException {
setDefaultMockFilters();
replayMocks();
-
+
this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
}
- @SuppressWarnings("unchecked")
@Test
public void testConnectWithFilterContents() throws BundleException {
- OrderedPair<String, Version> b1 = new OrderedPair<String,Version>("b1", new Version("0"));
- setMockFilterAllowedBundles(this.regionFilter1, b1);
+ OrderedPair<String, Version> b1 = new OrderedPair<String, Version>("b1", new Version("0"));
+ setMockFilterAllowedBundle(this.regionFilter1, b1);
EasyMock.expect(this.mockRegion1.getBundle(b1.getFirst(), b1.getSecond())).andReturn(null).anyTimes();
-
- OrderedPair<String, Version> b2 = new OrderedPair<String,Version>("b2", new Version("0"));
- setMockFilterAllowedBundles(this.regionFilter2, b2);
+
+ OrderedPair<String, Version> b2 = new OrderedPair<String, Version>("b2", new Version("0"));
+ setMockFilterAllowedBundle(this.regionFilter2, b2);
EasyMock.expect(this.mockRegion1.getBundle(b2.getFirst(), b2.getSecond())).andReturn(null).anyTimes();
replayMocks();
-
+
this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion3);
}
-
@Test(expected = BundleException.class)
public void testConnectLoop() throws BundleException {
setDefaultMockFilters();
replayMocks();
-
+
this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion1);
}
@@ -116,41 +129,16 @@ public class StandardRegionDigraphTests {
public void testDuplicateConnection() throws BundleException {
setDefaultMockFilters();
replayMocks();
-
- this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
- this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion2);
- }
- @SuppressWarnings("unchecked")
- @Test(expected = BundleException.class)
- public void testConnectWithClashingFilters() throws BundleException {
- OrderedPair<String, Version> bundle = new OrderedPair<String,Version>("b", new Version("0"));
- setMockFilterAllowedBundles(this.regionFilter1, bundle);
- setMockFilterAllowedBundles(this.regionFilter2, bundle);
- EasyMock.expect(this.mockRegion1.getBundle(bundle.getFirst(), bundle.getSecond())).andReturn(null).anyTimes();
- replayMocks();
-
- this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
- this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion3);
- }
-
- @SuppressWarnings("unchecked")
- @Test(expected = BundleException.class)
- public void testConnectWithClashingRegion() throws BundleException {
- OrderedPair<String, Version> bundle = new OrderedPair<String,Version>("b", new Version("0"));
- setMockFilterAllowedBundles(this.regionFilter1, bundle);
- EasyMock.expect(this.mockRegion1.getBundle(bundle.getFirst(), bundle.getSecond())).andReturn(this.mockBundle);
- replayMocks();
-
this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
+ this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion2);
}
-
@Test
public void testAddRegion() {
setDefaultMockFilters();
replayMocks();
-
+
this.digraph.addRegion(this.mockRegion1);
boolean found = false;
for (Region region : this.digraph) {
@@ -165,7 +153,7 @@ public class StandardRegionDigraphTests {
public void testGetEdges() throws BundleException {
setDefaultMockFilters();
replayMocks();
-
+
this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
this.digraph.connect(this.mockRegion1, this.regionFilter2, this.mockRegion3);
this.digraph.connect(this.mockRegion2, this.regionFilter2, this.mockRegion1);
@@ -185,4 +173,18 @@ public class StandardRegionDigraphTests {
}
}
+ @Test
+ public void testRemoveRegion() throws BundleException {
+ setDefaultMockFilters();
+ replayMocks();
+
+ this.digraph.connect(this.mockRegion1, this.regionFilter1, this.mockRegion2);
+ this.digraph.connect(this.mockRegion2, this.regionFilter2, this.mockRegion1);
+ assertNotNull(this.digraph.getRegion("mockRegion1"));
+ assertNotNull(this.digraph.getRegion("mockRegion2"));
+ this.digraph.removeRegion(this.mockRegion1);
+ assertNull(this.digraph.getRegion("mockRegion1"));
+ assertNotNull(this.digraph.getRegion("mockRegion2"));
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionFilterTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionFilterTests.java
index 6bec3bb1..b8936829 100644
--- a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionFilterTests.java
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/internal/StandardRegionFilterTests.java
@@ -16,13 +16,10 @@ package org.eclipse.virgo.kernel.osgi.region.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.Set;
-
import org.easymock.EasyMock;
import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.osgi.region.RegionPackageImportPolicy;
import org.eclipse.virgo.kernel.osgi.region.StandardRegionFilter;
-import org.eclipse.virgo.util.math.OrderedPair;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -55,9 +52,7 @@ public class StandardRegionFilterTests {
@Test
public void testAllowBundle() {
this.regionFilter.allowBundle(BUNDLE_SYMBOLIC_NAME, BUNDLE_VERSION);
- Set<OrderedPair<String, Version>> allowedBundles = this.regionFilter.getAllowedBundles();
- assertEquals(1, allowedBundles.size());
- assertTrue(allowedBundles.contains(new OrderedPair<String, Version>(BUNDLE_SYMBOLIC_NAME, BUNDLE_VERSION)));
+ assertTrue(this.regionFilter.isBundleAllowed(BUNDLE_SYMBOLIC_NAME, BUNDLE_VERSION));
}
@Test
diff --git a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java
index c5ab86fc..3e020088 100644
--- a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java
+++ b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java
@@ -50,11 +50,11 @@ final public class StandardStateService implements StateService {
private final Region kernelRegion;
- public StandardStateService(QuasiFrameworkFactory quasiFrameworkFactory, BundleContext bundleContext, RegionDigraph regionMembership) {
+ public StandardStateService(QuasiFrameworkFactory quasiFrameworkFactory, BundleContext bundleContext, RegionDigraph regionDigraph) {
this.quasiFrameworkFactory = quasiFrameworkFactory;
this.bundleContext = bundleContext;
- this.regionDigraph = regionMembership;
- this.kernelRegion = getKernelRegion(regionMembership);
+ this.regionDigraph = regionDigraph;
+ this.kernelRegion = getKernelRegion(regionDigraph);
}
private Region getKernelRegion(RegionDigraph regionDigraph) {
diff --git a/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/module-context.xml b/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/module-context.xml
index 785db471..6835911e 100644
--- a/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/module-context.xml
+++ b/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/module-context.xml
@@ -28,7 +28,7 @@
<bean id="stateService" class="org.eclipse.virgo.kernel.shell.state.internal.StandardStateService">
<constructor-arg ref="quasiFrameworkFactory" />
<constructor-arg ref="userRegionBundleContext" />
- <constructor-arg ref="regionMembership" />
+ <constructor-arg ref="regionDigraph" />
</bean>
<bean id="installCommand" class="org.eclipse.virgo.kernel.shell.internal.commands.InstallCommand"/>
diff --git a/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/osgi-context.xml b/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/osgi-context.xml
index 1d64cf2e..11c74046 100644
--- a/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/osgi-context.xml
+++ b/org.eclipse.virgo.kernel.shell/src/main/resources/META-INF/spring/osgi-context.xml
@@ -29,6 +29,8 @@
<osgi:service ref="modelAccessorHelper" interface="org.eclipse.virgo.kernel.shell.model.helper.RamAccessorHelper" />
+ <osgi:reference id="regionDigraph" interface="org.eclipse.virgo.kernel.osgi.region.RegionDigraph" />
+
<!-- SERVICES FOR THE TYPE CONVERTERS -->
<osgi:service ref="longConverter" interface="org.eclipse.virgo.kernel.shell.Converter">
diff --git a/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/RegionTests.java b/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/RegionTests.java
index eb668b1b..6bf51bc4 100644
--- a/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/RegionTests.java
+++ b/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/RegionTests.java
@@ -36,7 +36,6 @@ public class RegionTests extends AbstractKernelIntegrationTest {
Region userRegion = (Region) this.kernelContext.getService(serviceReferences[0]);
assertNotNull(userRegion);
- assertNotNull(userRegion.getBundleContext());
}
private ServiceReference<?>[] lookupRegionServices(String name) throws InvalidSyntaxException {
diff --git a/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/test/AbstractKernelIntegrationTest.java b/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/test/AbstractKernelIntegrationTest.java
index 283a875f..d52a11f6 100644
--- a/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/test/AbstractKernelIntegrationTest.java
+++ b/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/test/AbstractKernelIntegrationTest.java
@@ -12,22 +12,17 @@
package org.eclipse.virgo.kernel.test;
import java.lang.management.ManagementFactory;
-import java.util.Collection;
-import java.util.Iterator;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.eclipse.virgo.kernel.osgi.framework.OsgiFramework;
-import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.test.framework.dmkernel.DmKernelTestRunner;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@RunWith(DmKernelTestRunner.class)
@@ -50,22 +45,7 @@ public abstract class AbstractKernelIntegrationTest {
}
private BundleContext getKernelContext() {
- try {
- Collection<ServiceReference<Region>> references = this.context.getServiceReferences(Region.class,"(org.eclipse.virgo.kernel.region.name=org.eclipse.virgo.region.kernel)");
- Assert.assertEquals(1, references.size());
- Iterator<ServiceReference<Region>> i = references.iterator();
- ServiceReference<Region> reference = i.next();
- Region kernelRegion = this.context.getService(reference);
- Assert.assertNotNull("Kernel Region not found", kernelRegion);
- BundleContext kernelContext = kernelRegion.getBundleContext();
- Assert.assertNotNull("Kernel Region bundle context not found", kernelContext);
- this.context.ungetService(reference);
- return kernelContext;
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- Assert.assertTrue(false);
- return null;
- }
+ return this.context.getBundle(0L).getBundleContext();
}
@BeforeClass
diff --git a/org.eclipse.virgo.kernel.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties b/org.eclipse.virgo.kernel.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties
index 52ef46c2..4886ea5f 100644
--- a/org.eclipse.virgo.kernel.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties
+++ b/org.eclipse.virgo.kernel.test/src/test/resources/config/org.eclipse.virgo.kernel.userregion.properties
@@ -39,13 +39,14 @@ packageImports =\
org.junit.runner;version="[4.7.0,5.0.0)",\
org.osgi.*;version="0",\
org.eclipse.osgi.*;version="0",\
+ javax.management;version="0",\
+ javax.management.*;version="0",\
org.slf4j;version="[1.6.1,2)",\
org.slf4j.spi;version="[1.6.1,2)"
serviceImports =\
org.eclipse.virgo.kernel.osgi.region.Region,\
- org.eclipse.virgo.kernel.osgi.region.RegionMembership,\
- org.osgi.framework.hooks.resolver.ResolverHookFactory,\
+ org.eclipse.virgo.kernel.osgi.region.RegionDigraph,\
org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer,\
org.eclipse.virgo.kernel.deployer.core.DeployUriNormaliser,\
org.eclipse.virgo.kernel.install.artifact.ScopeServiceRepository,\
@@ -57,6 +58,7 @@ serviceImports =\
org.eclipse.virgo.medic.eventlog.EventLoggerFactory,\
org.eclipse.virgo.repository.Repository,\
org.eclipse.virgo.kernel.core.Shutdown,\
+ org.osgi.framework.hooks.resolver.ResolverHookFactory,\
org.osgi.service.cm.ConfigurationAdmin,\
org.osgi.service.event.EventAdmin,\
org.eclipse.virgo.medic.eventlog.EventLogger,\
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java
index 012ff737..18d1a0c7 100644
--- a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java
@@ -31,6 +31,8 @@ import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkUtils;
import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory;
+import org.eclipse.virgo.kernel.osgi.region.Region;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.shim.scope.ScopeFactory;
import org.eclipse.virgo.kernel.userregion.internal.equinox.EquinoxHookRegistrar;
import org.eclipse.virgo.kernel.userregion.internal.equinox.EquinoxOsgiFramework;
@@ -93,6 +95,9 @@ public class Activator implements BundleActivator {
PackageAdmin packageAdmin = OsgiFrameworkUtils.getService(context, PackageAdmin.class).getService();
EventLogger eventLogger = OsgiFrameworkUtils.getService(context, EventLoggerFactory.class).getService().createEventLogger(context.getBundle());
+
+ RegionDigraph regionDigraph = OsgiFrameworkUtils.getService(context, RegionDigraph.class).getService();
+ Region userRegion = regionDigraph.getRegion("org.eclipse.virgo.region.user");
ImportExpansionHandler importExpansionHandler = createImportExpansionHandler(context, packageAdmin, repository, eventLogger);
this.registrationTracker.track(context.registerService(ImportExpander.class.getName(), importExpansionHandler, null));
@@ -105,7 +110,7 @@ public class Activator implements BundleActivator {
DumpContributor dumpContributor = createResolutionDumpContributor(context);
this.registrationTracker.track(context.registerService(DumpContributor.class.getName(), dumpContributor, null));
- QuasiFrameworkFactory quasiFrameworkFactory = createQuasiFrameworkFactory(context, rfd, repository, bundleTransformerHandler);
+ QuasiFrameworkFactory quasiFrameworkFactory = createQuasiFrameworkFactory(context, rfd, repository, bundleTransformerHandler, userRegion);
this.registrationTracker.track(context.registerService(QuasiFrameworkFactory.class.getName(), quasiFrameworkFactory, null));
EquinoxHookRegistrar hookRegistrar = createHookRegistrar(context, packageAdmin, bundleTransformerHandler);
@@ -139,8 +144,8 @@ public class Activator implements BundleActivator {
}
private QuasiFrameworkFactory createQuasiFrameworkFactory(BundleContext bundleContext, ResolutionFailureDetective detective,
- Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformerHandler) {
- return new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleTransformerHandler);
+ Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformerHandler, Region userRegion) {
+ return new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleTransformerHandler, userRegion);
}
private TransformedManifestProvidingBundleFileWrapper createBundleTransformationHandler(ImportExpansionHandler importExpander) {
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/DependencyCalculator.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/DependencyCalculator.java
index 2cb32f11..fafe134d 100644
--- a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/DependencyCalculator.java
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/DependencyCalculator.java
@@ -37,25 +37,25 @@ import org.eclipse.osgi.service.resolver.StateDelta;
import org.eclipse.osgi.service.resolver.StateObjectFactory;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.service.resolver.VersionRange;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Version;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import org.eclipse.virgo.kernel.artifact.bundle.BundleBridge;
import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException;
import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyDependenciesException;
+import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.osgi.region.RegionFilter;
import org.eclipse.virgo.kernel.userregion.internal.equinox.ResolutionDumpContributor;
import org.eclipse.virgo.kernel.userregion.internal.quasi.ResolutionFailureDetective.ResolverErrorsHolder;
-
-import org.eclipse.virgo.kernel.artifact.bundle.BundleBridge;
import org.eclipse.virgo.medic.dump.DumpGenerator;
import org.eclipse.virgo.repository.ArtifactDescriptor;
import org.eclipse.virgo.repository.Attribute;
import org.eclipse.virgo.repository.Query;
import org.eclipse.virgo.repository.Repository;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Calculates the dependencies of a given set of {@link BundleDescription BundleDescriptions}.
@@ -68,7 +68,9 @@ import org.eclipse.virgo.repository.Repository;
*/
public final class DependencyCalculator {
- private static final String USER_REGION_TAG = "userregion@";
+ private static final String COREGION_SUFFIX = ".coregion";
+
+ private static final String REGION_LOCATION_DELIMITER = "@";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -84,9 +86,13 @@ public final class DependencyCalculator {
private final DumpGenerator dumpGenerator;
- private RegionDigraph regionDigraph;
+ private final RegionDigraph regionDigraph;
+
+ private final Region userRegion;
- private Region userRegion;
+ private Region coregion;
+
+ private final BundleContext systemBundleContext;
public DependencyCalculator(StateObjectFactory stateObjectFactory, ResolutionFailureDetective detective, Repository repository,
BundleContext bundleContext) {
@@ -95,7 +101,8 @@ public final class DependencyCalculator {
this.stateObjectFactory = stateObjectFactory;
this.dumpGenerator = bundleContext.getService(bundleContext.getServiceReference(DumpGenerator.class));
this.regionDigraph = bundleContext.getService(bundleContext.getServiceReference(RegionDigraph.class));
- userRegion = this.regionDigraph.getRegion(bundleContext.getBundle());
+ this.userRegion = this.regionDigraph.getRegion(bundleContext.getBundle());
+ this.systemBundleContext = bundleContext.getBundle(0L).getBundleContext();
}
/**
@@ -127,57 +134,74 @@ public final class DependencyCalculator {
UnableToSatisfyDependenciesException {
this.logger.info("Calculating missing dependencies of bundle(s) '{}'", bundles);
synchronized (this.monitor) {
-
- doSatisfyConstraints(bundles, state);
-
- StateDelta delta = state.resolve(bundles);
-
- for (BundleDescription description : bundles) {
- if (!description.isResolved()) {
- generateDump(state);
-
- ResolverErrorsHolder reh = new ResolverErrorsHolder();
- String failure = this.detective.generateFailureDescription(state, description, reh);
-
- ResolverError[] resolverErrors = reh.getResolverErrors();
- if (resolverErrors != null) {
- for (ResolverError resolverError : resolverErrors) {
- if (resolverError.getType() == ResolverError.IMPORT_PACKAGE_USES_CONFLICT) {
- VersionConstraint unsatisfiedConstraint = resolverError.getUnsatisfiedConstraint();
- if ((unsatisfiedConstraint instanceof ImportPackageSpecification)) {
- ImportPackageSpecification importPackageSpecification = (ImportPackageSpecification) unsatisfiedConstraint;
- this.logger.debug("Uses conflict: package '{}' version '{}' bundle '{}' version '{}'", new Object[] {
- importPackageSpecification.getName(), importPackageSpecification.getVersionRange(),
- importPackageSpecification.getBundleSymbolicName(), importPackageSpecification.getBundleVersionRange() });
+ createCoregion();
+
+ try {
+ doSatisfyConstraints(bundles, state);
+
+ StateDelta delta = state.resolve(bundles);
+
+ for (BundleDescription description : bundles) {
+ if (!description.isResolved()) {
+ generateDump(state);
+
+ ResolverErrorsHolder reh = new ResolverErrorsHolder();
+ String failure = this.detective.generateFailureDescription(state, description, reh);
+
+ ResolverError[] resolverErrors = reh.getResolverErrors();
+ if (resolverErrors != null) {
+ for (ResolverError resolverError : resolverErrors) {
+ if (resolverError.getType() == ResolverError.IMPORT_PACKAGE_USES_CONFLICT) {
+ VersionConstraint unsatisfiedConstraint = resolverError.getUnsatisfiedConstraint();
+ if (unsatisfiedConstraint instanceof ImportPackageSpecification) {
+ ImportPackageSpecification importPackageSpecification = (ImportPackageSpecification) unsatisfiedConstraint;
+ this.logger.debug("Uses conflict: package '{}' version '{}' bundle '{}' version '{}'", new Object[] {
+ importPackageSpecification.getName(), importPackageSpecification.getVersionRange(),
+ importPackageSpecification.getBundleSymbolicName(), importPackageSpecification.getBundleVersionRange() });
+ }
}
}
}
- }
- throw new UnableToSatisfyBundleDependenciesException(description.getSymbolicName(), description.getVersion(), failure, state,
- reh.getResolverErrors());
+ throw new UnableToSatisfyBundleDependenciesException(description.getSymbolicName(), description.getVersion(), failure, state,
+ reh.getResolverErrors());
+ }
}
- }
- BundleDelta[] deltas = delta.getChanges(BundleDelta.ADDED, false);
- Set<BundleDescription> newBundles = new HashSet<BundleDescription>();
+ BundleDelta[] deltas = delta.getChanges(BundleDelta.ADDED, false);
+ Set<BundleDescription> newBundles = new HashSet<BundleDescription>();
- for (BundleDelta bundleDelta : deltas) {
- newBundles.add(bundleDelta.getBundle());
- }
+ for (BundleDelta bundleDelta : deltas) {
+ newBundles.add(bundleDelta.getBundle());
+ }
- Set<BundleDescription> dependenciesSet = getNewTransitiveDependencies(new HashSet<BundleDescription>(Arrays.asList(bundles)), newBundles);
+ Set<BundleDescription> dependenciesSet = getNewTransitiveDependencies(new HashSet<BundleDescription>(Arrays.asList(bundles)),
+ newBundles);
- List<BundleDescription> dependencies = new ArrayList<BundleDescription>(dependenciesSet);
- this.logger.info("The dependencies of '{}' are '{}'", Arrays.toString(bundles), dependencies);
+ List<BundleDescription> dependencies = new ArrayList<BundleDescription>(dependenciesSet);
+ this.logger.info("The dependencies of '{}' are '{}'", Arrays.toString(bundles), dependencies);
- Collections.sort(dependencies, new BundleDescriptionComparator());
+ Collections.sort(dependencies, new BundleDescriptionComparator());
- BundleDescription[] dependencyDescriptions = dependencies.toArray(new BundleDescription[dependencies.size()]);
- return dependencyDescriptions;
+ BundleDescription[] dependencyDescriptions = dependencies.toArray(new BundleDescription[dependencies.size()]);
+ return dependencyDescriptions;
+ } finally {
+ destroyCoregion();
+ }
}
}
+ private void createCoregion() throws BundleException {
+ this.coregion = new BundleIdBasedRegion(this.userRegion.getName() + COREGION_SUFFIX, this.regionDigraph, this.systemBundleContext);
+ this.userRegion.connectRegion(this.coregion, RegionFilter.TOP);
+ this.coregion.connectRegion(this.userRegion, RegionFilter.TOP);
+ }
+
+ private void destroyCoregion() {
+ this.regionDigraph.removeRegion(this.coregion);
+ this.coregion = null;
+ }
+
private Set<BundleDescription> getNewTransitiveDependencies(Set<BundleDescription> dependingBundles, Collection<BundleDescription> newBundles) {
Set<BundleDescription> transitiveDependencies = new HashSet<BundleDescription>();
@@ -259,6 +283,7 @@ public final class DependencyCalculator {
for (BundleDescription constraintSatisfier : constraintsSatisfiers) {
if (!isBundlePresentInState(constraintSatisfier.getName(), constraintSatisfier.getVersion(), state)) {
state.addBundle(constraintSatisfier);
+ this.coregion.addBundle(constraintSatisfier.getBundleId());
doSatisfyConstraints(constraintSatisfier, state);
}
}
@@ -358,9 +383,9 @@ public final class DependencyCalculator {
try {
URI uri = artifact.getUri();
String installLocation = "file".equals(uri.getScheme()) ? new File(uri).getAbsolutePath() : uri.toString();
- BundleDescription bundleDescription = this.stateObjectFactory.createBundleDescription(state, manifest, this.userRegion.getName() + "@" + installLocation,
- this.bundleId.getAndIncrement());
- //TODO: need to add bundle id to user region and then clean it up at the end
+ BundleDescription bundleDescription = this.stateObjectFactory.createBundleDescription(state, manifest, this.coregion.getName()
+ + REGION_LOCATION_DELIMITER + installLocation, this.bundleId.getAndIncrement());
+ this.coregion.addBundle(bundleDescription.getBundleId());
return bundleDescription;
} catch (RuntimeException e) {
throw new BundleException("Unable to read bundle at '" + artifact.getUri() + "'", e);
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java
index f9871add..e5327c9b 100644
--- a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFramework.java
@@ -38,6 +38,7 @@ import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyDependenciesExcept
import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiResolutionFailure;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.userregion.internal.equinox.TransformedManifestProvidingBundleFileWrapper;
import org.eclipse.virgo.kernel.userregion.internal.quasi.ResolutionFailureDetective.ResolverErrorsHolder;
import org.eclipse.virgo.repository.Repository;
@@ -65,14 +66,12 @@ import org.slf4j.LoggerFactory;
*/
final class StandardQuasiFramework implements QuasiFramework {
- private static final String USER_REGION_TAG = "userregion@";
+ private static final String REGION_LOCATION_DELIMITER = "@";
private static final String REFERENCE_SCHEME = "reference:";
private static final String FILE_SCHEME = "file:";
- private static final String USER_REGION_LOCATION_TAG = USER_REGION_TAG;
-
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Object monitor = new Object();
@@ -98,8 +97,10 @@ final class StandardQuasiFramework implements QuasiFramework {
private final TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler;
+ private final Region userRegion;
+
StandardQuasiFramework(BundleContext bundleContext, State state, PlatformAdmin platformAdmin, ResolutionFailureDetective detective,
- Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler) {
+ Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler, Region userRegion) {
this.bundleContext = bundleContext;
this.state = state;
this.stateObjectFactory = platformAdmin.getFactory();
@@ -107,6 +108,7 @@ final class StandardQuasiFramework implements QuasiFramework {
this.dependencyCalculator = new DependencyCalculator(platformAdmin.getFactory(), this.detective, repository, this.bundleContext);
this.stateHelper = platformAdmin.getStateHelper();
this.bundleTransformationHandler = bundleTransformationHandler;
+ this.userRegion = userRegion;
setResolverHookFactory();
}
@@ -141,8 +143,8 @@ final class StandardQuasiFramework implements QuasiFramework {
try {
Dictionary<String, String> manifest = bundleManifest.toDictionary();
String installLocation = "file".equals(location.getScheme()) ? new File(location).getAbsolutePath() : location.toString();
- BundleDescription bundleDescription = this.stateObjectFactory.createBundleDescription(this.state, manifest, USER_REGION_TAG
- + installLocation, nextBundleId());
+ BundleDescription bundleDescription = this.stateObjectFactory.createBundleDescription(this.state, manifest, this.userRegion.getName()
+ + REGION_LOCATION_DELIMITER + installLocation, nextBundleId());
this.state.addBundle(bundleDescription);
return new StandardQuasiBundle(bundleDescription, bundleManifest, this.stateHelper);
} catch (RuntimeException e) {
@@ -284,7 +286,7 @@ final class StandardQuasiFramework implements QuasiFramework {
VersionRange bundleVersionRange = convertVersionRange(importPackageSpecification.getBundleVersionRange());
long bundleId = importPackageSpecification.getBundle().getBundleId();
this.logger.debug("Missing import: package '{}' version '{}' bundle '{}' version '{}' id '{}'", new Object[] { pkgName, pkgVersionRange,
- bundleSymbolicName, bundleVersionRange, bundleId});
+ bundleSymbolicName, bundleVersionRange, bundleId });
return new PackageQuasiResolutionFailure(failureDescription, quasiBundle, pkgName, pkgVersionRange, bundleSymbolicName, bundleVersionRange);
}
@@ -297,7 +299,7 @@ final class StandardQuasiFramework implements QuasiFramework {
VersionRange bundleVersionRange = convertVersionRange(importPackageSpecification.getBundleVersionRange());
long bundleId = importPackageSpecification.getBundle().getBundleId();
this.logger.debug("Uses conflict: package '{}' version '{}' bundle '{}' version '{}' id '{}'", new Object[] { pkgName, pkgVersionRange,
- bundleSymbolicName, bundleVersionRange, bundleId});
+ bundleSymbolicName, bundleVersionRange, bundleId });
return new PackageUsesQuasiResolutionFailure(failureDescription, quasiBundle, pkgName, pkgVersionRange, bundleSymbolicName,
bundleVersionRange);
}
@@ -408,8 +410,9 @@ final class StandardQuasiFramework implements QuasiFramework {
}
private String stripRegionTag(String location) {
- if (location.startsWith(USER_REGION_TAG)) {
- return location.substring(USER_REGION_TAG.length());
+ int atPos = location.indexOf(REGION_LOCATION_DELIMITER);
+ if (atPos != -1) {
+ return location.substring(atPos + 1);
}
return location;
}
@@ -437,7 +440,7 @@ final class StandardQuasiFramework implements QuasiFramework {
}
private Bundle doInstallBundleInternal(String location) throws BundleException {
- return this.bundleContext.installBundle(USER_REGION_LOCATION_TAG + location, openBundleStream(location));
+ return this.userRegion.installBundle(location, openBundleStream(location));
}
private InputStream openBundleStream(String location) throws BundleException {
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java
index ec910884..33d23cce 100644
--- a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java
@@ -29,6 +29,8 @@ import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkUtils;
import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory;
+import org.eclipse.virgo.kernel.osgi.region.Region;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.userregion.internal.equinox.TransformedManifestProvidingBundleFileWrapper;
import org.eclipse.virgo.repository.Repository;
import org.eclipse.virgo.util.io.FileSystemUtils;
@@ -58,7 +60,9 @@ public final class StandardQuasiFrameworkFactory implements QuasiFrameworkFactor
private final TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler;
- public StandardQuasiFrameworkFactory(BundleContext bundleContext, ResolutionFailureDetective detective, Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler) {
+ private final Region userRegion;
+
+ public StandardQuasiFrameworkFactory(BundleContext bundleContext, ResolutionFailureDetective detective, Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler, Region userRegion) {
this.bundleContext = bundleContext;
this.platformAdmin = getPlatformAdminService(bundleContext);
this.detective = detective;
@@ -66,20 +70,21 @@ public final class StandardQuasiFrameworkFactory implements QuasiFrameworkFactor
ServiceReference<PlatformAdmin> platformAdminServiceReference = bundleContext.getServiceReference(PlatformAdmin.class);
this.stateManager = (StateManager) bundleContext.getService(platformAdminServiceReference);
this.bundleTransformationHandler = bundleTransformationHandler;
+ this.userRegion = userRegion;
}
/**
* {@inheritDoc}
*/
public QuasiFramework create() {
- return new StandardQuasiFramework(this.bundleContext, createState(), this.platformAdmin, this.detective, this.repository, this.bundleTransformationHandler);
+ return new StandardQuasiFramework(this.bundleContext, createState(), this.platformAdmin, this.detective, this.repository, this.bundleTransformationHandler, this.userRegion);
}
/**
* {@inheritDoc}
*/
public QuasiFramework create(File stateDump) {
- return new StandardQuasiFramework(this.bundleContext, readStateDump(stateDump), this.platformAdmin, this.detective, this.repository, this.bundleTransformationHandler);
+ return new StandardQuasiFramework(this.bundleContext, readStateDump(stateDump), this.platformAdmin, this.detective, this.repository, this.bundleTransformationHandler, this.userRegion);
}
@SuppressWarnings("deprecation")
diff --git a/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java b/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
index 9f1285ee..66d7e935 100644
--- a/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
+++ b/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
@@ -23,37 +23,36 @@ import java.util.Set;
import org.eclipse.osgi.launch.Equinox;
import org.eclipse.osgi.service.resolver.PlatformAdmin;
-import org.junit.After;
-import org.junit.Before;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.packageadmin.ExportedPackage;
-import org.osgi.service.packageadmin.PackageAdmin;
-
+import org.eclipse.virgo.kernel.artifact.bundle.BundleBridge;
+import org.eclipse.virgo.kernel.artifact.library.LibraryBridge;
import org.eclipse.virgo.kernel.osgi.framework.ImportExpander;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
+import org.eclipse.virgo.kernel.osgi.region.BundleIdBasedRegion;
+import org.eclipse.virgo.kernel.osgi.region.Region;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.osgi.region.internal.StandardRegionDigraph;
import org.eclipse.virgo.kernel.services.repository.internal.RepositoryFactoryBean;
-import org.eclipse.virgo.kernel.userregion.internal.equinox.EquinoxOsgiFramework;
-import org.eclipse.virgo.kernel.userregion.internal.equinox.KernelClassLoaderCreator;
-import org.eclipse.virgo.kernel.userregion.internal.equinox.TransformedManifestProvidingBundleFileWrapper;
import org.eclipse.virgo.kernel.userregion.internal.importexpansion.ImportExpansionHandler;
import org.eclipse.virgo.kernel.userregion.internal.quasi.StandardQuasiFrameworkFactory;
import org.eclipse.virgo.kernel.userregion.internal.quasi.StandardResolutionFailureDetective;
-
-import org.eclipse.virgo.osgi.extensions.equinox.EquinoxLauncherConfiguration;
-import org.eclipse.virgo.osgi.extensions.equinox.ExtendedEquinoxLauncher;
-import org.eclipse.virgo.osgi.extensions.equinox.hooks.PluggableClassLoadingHook;
-import org.eclipse.virgo.kernel.artifact.bundle.BundleBridge;
-import org.eclipse.virgo.kernel.artifact.library.LibraryBridge;
import org.eclipse.virgo.medic.dump.DumpGenerator;
import org.eclipse.virgo.medic.eventlog.EventLogger;
import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.osgi.extensions.equinox.EquinoxLauncherConfiguration;
+import org.eclipse.virgo.osgi.extensions.equinox.ExtendedEquinoxLauncher;
+import org.eclipse.virgo.osgi.extensions.equinox.hooks.PluggableClassLoadingHook;
import org.eclipse.virgo.repository.ArtifactBridge;
import org.eclipse.virgo.repository.Repository;
import org.eclipse.virgo.repository.RepositoryFactory;
import org.eclipse.virgo.repository.internal.RepositoryBundleActivator;
import org.eclipse.virgo.util.io.FileSystemUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
@SuppressWarnings("deprecation")
public abstract class AbstractOsgiFrameworkLaunchingTests {
@@ -74,6 +73,8 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
private ServiceRegistration<DumpGenerator> dumpGeneratorRegistration;
+ private ServiceRegistration<RegionDigraph> regionDigraphRegistration;
+
private Equinox equinox;
protected QuasiFramework quasiFramework;
@@ -89,6 +90,9 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
// Uncomment this line to enable Equinox debugging
// FrameworkProperties.setProperty("osgi.debug", "src/test/resources/debug.options");
+
+ // Uncomment thils line to enable Equinox console
+ // FrameworkProperties.setProperty("osgi.console", "2401");
EquinoxLauncherConfiguration launcherConfiguration = new EquinoxLauncherConfiguration();
launcherConfiguration.setClean(true);
URI targetURI = new File("./target").toURI();
@@ -109,10 +113,17 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
};
+ RegionDigraph regionDigraph = new StandardRegionDigraph();
+
+ Region userRegion = new BundleIdBasedRegion("stubUserRegion", regionDigraph, bundleContext.getBundle(0L).getBundleContext());
+ regionDigraph.addRegion(userRegion);
+ userRegion.addBundle(this.bundleContext.getBundle());
+
final EventLogger mockEventLogger = new MockEventLogger();
eventLoggerRegistration = bundleContext.registerService(EventLogger.class, mockEventLogger, null);
dumpGeneratorRegistration = bundleContext.registerService(DumpGenerator.class, dumpGenerator, null);
+ regionDigraphRegistration = bundleContext.registerService(RegionDigraph.class, regionDigraph, null);
this.repositoryBundleActivator = new RepositoryBundleActivator();
this.repositoryBundleActivator.start(bundleContext);
@@ -145,7 +156,7 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
PluggableClassLoadingHook.getInstance().setClassLoaderCreator(new KernelClassLoaderCreator());
StandardResolutionFailureDetective detective = new StandardResolutionFailureDetective(platformAdmin);
- this.quasiFramework = new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleFileWrapper).create();
+ this.quasiFramework = new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleFileWrapper, userRegion).create();
}
private ImportExpander createImportExpander(PackageAdmin packageAdmin) {
@@ -172,6 +183,11 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
this.dumpGeneratorRegistration = null;
}
+ if (this.regionDigraphRegistration != null) {
+ this.regionDigraphRegistration.unregister();
+ this.regionDigraphRegistration = null;
+ }
+
if (this.eventLoggerRegistration != null) {
this.eventLoggerRegistration.unregister();
this.eventLoggerRegistration = null;
diff --git a/org.eclipse.virgo.kernel.userregion/template.mf b/org.eclipse.virgo.kernel.userregion/template.mf
index 5f77e51d..08736486 100644
--- a/org.eclipse.virgo.kernel.userregion/template.mf
+++ b/org.eclipse.virgo.kernel.userregion/template.mf
@@ -21,3 +21,4 @@ Import-Template:
org.slf4j.*;version="${org.slf4j:[=.=.=, +1)}",
org.springframework.*;version="${org.springframework:[2.5.6, =.+1)}"
Bundle-Activator: org.eclipse.virgo.kernel.userregion.internal.Activator
+Import-Package: org.eclipse.virgo.medic.log;version="0"
diff --git a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
index 50c04f73..d3b35fad 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
+++ b/org.eclipse.virgo.kernel.userregionfactory/src/main/java/org/eclipse/virgo/kernel/userregionfactory/Activator.java
@@ -139,10 +139,14 @@ public final class Activator implements BundleActivator {
private void createUserRegion(BundleContext userRegionBundleContext, RegionDigraph regionDigraph) throws BundleException {
BundleContext systemBundleContext = getSystemBundleContext();
+ Bundle userRegionFactoryBundle = userRegionBundleContext.getBundle();
+
+ Region kernelRegion = getKernelRegion(regionDigraph);
+ kernelRegion.removeBundle(userRegionFactoryBundle);
Region userRegion = new BundleIdBasedRegion(REGION_USER, regionDigraph, systemBundleContext);
-
- Region kernelRegion = getKernelRegion(regionDigraph);
+ regionDigraph.addRegion(userRegion);
+ userRegion.addBundle(userRegionFactoryBundle);
RegionFilter kernelFilter = createKernelFilter(systemBundleContext);
userRegion.connectRegion(kernelRegion, kernelFilter);
@@ -215,21 +219,13 @@ public final class Activator implements BundleActivator {
String expandedUserRegionImportsProperty = null;
if (userRegionImportsProperty != null) {
expandedUserRegionImportsProperty = PackageImportWildcardExpander.expandPackageImportsWildcards(userRegionImportsProperty,
- this.bundleContext);
+ systemBundleContext);
}
- //expandedUserRegionImportsProperty += getSystemBundleExports(systemBundleContext);
-
UserRegionPackageImportPolicy userRegionPackageImportPolicy = new UserRegionPackageImportPolicy(expandedUserRegionImportsProperty);
return userRegionPackageImportPolicy;
}
- private String getSystemBundleExports(BundleContext systemBundleContext) {
- //systemBundleContext.getBundle().get
- // TODO Auto-generated method stub
- return ",org.osgi.framework,org.osgi.service.packageadmin,org.eclipse.osgi.baseadaptor,org.eclipse.osgi.baseadaptor.bundlefile";
- }
-
private BundleContext getSystemBundleContext() {
return this.bundleContext.getBundle(0L).getBundleContext();
}
diff --git a/org.eclipse.virgo.kernel.userregionfactory/template.mf b/org.eclipse.virgo.kernel.userregionfactory/template.mf
index 95c321b5..228ea8cd 100644
--- a/org.eclipse.virgo.kernel.userregionfactory/template.mf
+++ b/org.eclipse.virgo.kernel.userregionfactory/template.mf
@@ -11,7 +11,7 @@ Import-Template:
org.osgi.framework.*;version="0",
org.osgi.service.*;version="0",
org.eclipse.virgo.medic.*;version="${org.eclipse.virgo.medic:[=.=.=, =.+1)}"
-Import-Package: org.aspectj.lang
+Import-Package: org.aspectj.lang;version="0"
Bundle-Activator: org.eclipse.virgo.kernel.userregionfactory.Activator
Excluded-Imports: org.easymock,
org.eclipse.virgo.osgi.launcher.*,

Back to the top