Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorislav Kapukaranov2011-02-03 19:02:43 -0500
committerBorislav Kapukaranov2011-02-03 19:02:43 -0500
commit7952b693f5694bacb0cfb382d123f6738b701612 (patch)
treead2b33e1892986b3365baeaecaaf3ffd75dbed6f /org.eclipse.virgo.kernel.model
parent517a5b8b81f20b0ddd74674301eb51f1fe69c69a (diff)
parent1f610333e7a414e248a19675248a7df45eb9bfb8 (diff)
downloadorg.eclipse.virgo.kernel-7952b693f5694bacb0cfb382d123f6738b701612.tar.gz
org.eclipse.virgo.kernel-7952b693f5694bacb0cfb382d123f6738b701612.tar.xz
org.eclipse.virgo.kernel-7952b693f5694bacb0cfb382d123f6738b701612.zip
Merge with origin/bug330776-framework-hooks
Diffstat (limited to 'org.eclipse.virgo.kernel.model')
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java20
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java21
2 files changed, 26 insertions, 15 deletions
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java
index 7805fbba..813d0fe0 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java
@@ -15,6 +15,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -22,8 +23,6 @@ import org.osgi.framework.BundleListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
-
/**
* An intializer responsible for registering a {@link ModelBundleListener} and enumerating any existing {@link Bundle}
* objects from the OSGi Framework.
@@ -44,17 +43,20 @@ public final class ModelBundleListenerInitializer {
private final PackageAdminUtil packageAdminUtil;
private final BundleContext kernelBundleContext;
-
+
private final BundleContext userRegionBundleContext;
private final BundleListener bundleListener;
+ private final BundleContext systemBundleContext;
+
public ModelBundleListenerInitializer(@NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil,
@NonNull BundleContext kernelBundleContext, @NonNull BundleContext userRegionBundleContext) {
this.artifactRepository = artifactRepository;
this.packageAdminUtil = packageAdminUtil;
this.kernelBundleContext = kernelBundleContext;
this.userRegionBundleContext = userRegionBundleContext;
+ this.systemBundleContext = kernelBundleContext.getBundle(0L).getBundleContext();
this.bundleListener = new ModelBundleListener(kernelBundleContext, artifactRepository, packageAdminUtil);
}
@@ -64,12 +66,14 @@ public final class ModelBundleListenerInitializer {
*/
@PostConstruct
public void initialize() {
- this.userRegionBundleContext.addBundleListener(bundleListener);
- for (Bundle bundle : userRegionBundleContext.getBundles()) {
+ // Register the listener with the system bundle to see all bundles.
+ this.systemBundleContext.addBundleListener(this.bundleListener);
+ // Find bundles using the user region context as application bundles are added to the user region.
+ for (Bundle bundle : this.userRegionBundleContext.getBundles()) {
try {
- this.artifactRepository.add(new BundleArtifact(kernelBundleContext, packageAdminUtil, bundle));
+ this.artifactRepository.add(new BundleArtifact(this.kernelBundleContext, this.packageAdminUtil, bundle));
} catch (Exception e) {
- logger.error(String.format("Exception adding bundle '%s:%s' to the repository", bundle.getSymbolicName(),
+ this.logger.error(String.format("Exception adding bundle '%s:%s' to the repository", bundle.getSymbolicName(),
bundle.getVersion().toString()), e);
}
}
@@ -80,6 +84,6 @@ public final class ModelBundleListenerInitializer {
*/
@PreDestroy
public void destroy() {
- this.userRegionBundleContext.removeBundleListener(bundleListener);
+ this.systemBundleContext.removeBundleListener(this.bundleListener);
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java
index 760a6e4b..3d6811dc 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java
@@ -18,6 +18,7 @@ import java.io.IOException;
import org.junit.Test;
import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
@@ -36,12 +37,18 @@ public class ModelBundleListenerInitializerTests {
private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
private final StubBundleContext bundleContext;
+
+ private final StubBundleContext systemBundleContext;
{
StubBundle bundle = new StubBundle();
this.bundleContext = (StubBundleContext) bundle.getBundleContext();
+ StubBundle stubSystemBundle = new StubBundle(0L, "org.osgi.framework", new Version("0"), "loc");
+ this.systemBundleContext = (StubBundleContext)stubSystemBundle.getBundleContext();
+ this.bundleContext.addInstalledBundle(stubSystemBundle);
+ this.systemBundleContext.addInstalledBundle(bundle);
String filterString = String.format("(&(objectClass=%s)(artifactType=bundle))", DependencyDeterminer.class.getCanonicalName());
this.bundleContext.addFilter(filterString, new TrueFilter(filterString));
- this.bundleContext.addInstalledBundle(bundle);
+ //this.bundleContext.addInstalledBundle(bundle);
}
private final ModelBundleListenerInitializer initializer = new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, bundleContext);
@@ -62,23 +69,23 @@ public class ModelBundleListenerInitializerTests {
}
@Test(expected = FatalAssertionException.class)
- public void nullUserBundleContext() {
+ public void nullUserRegionBundleContext() {
new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, null);
}
-
+
@Test
public void initialize() throws IOException, InvalidSyntaxException {
- assertEquals(0, this.bundleContext.getBundleListeners().size());
+ assertEquals(0, this.systemBundleContext.getBundleListeners().size());
this.initializer.initialize();
- assertEquals(1, this.bundleContext.getBundleListeners().size());
+ assertEquals(1, this.systemBundleContext.getBundleListeners().size());
assertEquals(1, this.artifactRepository.getArtifacts().size());
}
@Test
public void destroy() throws IOException, InvalidSyntaxException {
this.initializer.initialize();
- assertEquals(1, this.bundleContext.getBundleListeners().size());
+ assertEquals(1, this.systemBundleContext.getBundleListeners().size());
this.initializer.destroy();
- assertEquals(0, this.bundleContext.getBundleListeners().size());
+ assertEquals(0, this.systemBundleContext.getBundleListeners().size());
}
}

Back to the top