Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-04-01 15:59:47 -0400
committerGlyn Normington2011-04-01 15:59:47 -0400
commita3bc4a553bb9935ea9d1cfacdd6675e464396db3 (patch)
treec6788c88269220479045c45ab0cbc2297aac0bcc /org.eclipse.virgo.kernel.model
parent816cc7a9a7790a667cbe36abbcef6e208744ec0e (diff)
downloadorg.eclipse.virgo.kernel-a3bc4a553bb9935ea9d1cfacdd6675e464396db3.tar.gz
org.eclipse.virgo.kernel-a3bc4a553bb9935ea9d1cfacdd6675e464396db3.tar.xz
org.eclipse.virgo.kernel-a3bc4a553bb9935ea9d1cfacdd6675e464396db3.zip
add regions to RAM
Diffstat (limited to 'org.eclipse.virgo.kernel.model')
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/Artifact.java8
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java1
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java9
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/AbstractArtifact.java61
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java10
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java9
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminer.java17
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java13
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java30
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifact.java211
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/configurationadmin/ConfigurationArtifact.java2
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifact.java8
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java5
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java16
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java15
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java16
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java21
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml3
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/osgi-context.xml2
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubCompositeArtifact.java6
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/AbztractArtifactTests.java4
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java13
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminerTests.java20
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java43
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java25
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifactTests.java170
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java14
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java15
28 files changed, 269 insertions, 498 deletions
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/Artifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/Artifact.java
index 9f2d202f..22a5c46b 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/Artifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/Artifact.java
@@ -14,6 +14,7 @@ package org.eclipse.virgo.kernel.model;
import java.util.Map;
import java.util.Set;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.osgi.framework.Version;
/**
@@ -70,6 +71,13 @@ public interface Artifact {
* @return The {@link Version} of this {@link Artifact}
*/
Version getVersion();
+
+ /**
+ * Get the {@link Region} of this {@link Artifact} or <code>null</code> if this artifact does not belong in a region
+ *
+ * @return the {@link Region} of this {@link Artifact} or <code>null</code> if this artifact does not belong in a region
+ */
+ Region getRegion();
/**
* Get the state of this {@link Artifact}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java
index c32f3f34..f1adde24 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java
@@ -39,4 +39,5 @@ public interface BundleArtifact extends Artifact {
* @param targetPath The bundle relative path to delete
*/
void deleteEntry(String targetPath);
+
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java
index bb45d094..0f68bd44 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/RuntimeArtifactRepository.java
@@ -19,6 +19,9 @@ import org.osgi.framework.Version;
* A single in-memory repository with representations of all artifacts in the running system. Operations are generally
* executed against the artifacts themselves rather than the repository.
* <p />
+ * Bundle artifacts may reside in a number of {@link Region Regions}, but certain repository operations such as remove
+ * and get operate only on bundle artifacts in the user region. This is to preserve backward compatibility with Virgo
+ * 2.1.0 for the RuntimeArtifactRepository interface (and for JMX).
*
* <strong>Concurrent Semantics</strong><br />
*
@@ -37,7 +40,8 @@ public interface RuntimeArtifactRepository {
boolean add(Artifact artifact);
/**
- * Remove an {@link Artifact} from this repository
+ * Remove an {@link Artifact} from this repository. If the artifact is a bundle, it is only removed if the bundle is
+ * in the user region.
*
* @param type The type of the {@link Artifact} to remove
* @param name The name of the {@link Artifact} to remove
@@ -56,7 +60,8 @@ public interface RuntimeArtifactRepository {
Set<Artifact> getArtifacts();
/**
- * Gets a specific {@link Artifact} from this repository
+ * Gets a specific {@link Artifact} from this repository. If the artifact is a bundle, it is only returned if the
+ * bundle is in the user region.
*
* @param type The type of the {@link Artifact} to get
* @param name The name of the {@link Artifact} to get
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/AbstractArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/AbstractArtifact.java
index f6532c82..1e0f12f8 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/AbstractArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/AbstractArtifact.java
@@ -17,6 +17,7 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.virgo.kernel.model.Artifact;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
@@ -24,7 +25,6 @@ import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
import org.osgi.util.tracker.ServiceTracker;
-
/**
* An abstract implementation of {@link Artifact} that all implementations should extend.
* <p/>
@@ -54,10 +54,13 @@ public abstract class AbstractArtifact implements Artifact {
private final ServiceTracker dependencyDeterminerTracker;
- public AbstractArtifact(@NonNull BundleContext bundleContext, @NonNull String type, @NonNull String name, @NonNull Version version) {
+ private final Region region;
+
+ public AbstractArtifact(@NonNull BundleContext bundleContext, @NonNull String type, @NonNull String name, @NonNull Version version, Region region) {
this.type = type;
this.name = name;
this.version = version;
+ this.region = region;
Filter filter;
try {
@@ -93,6 +96,14 @@ public abstract class AbstractArtifact implements Artifact {
/**
* {@inheritDoc}
*/
+ @Override
+ public Region getRegion() {
+ return this.region;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public final Set<Artifact> getDependents() {
Set<Artifact> dependents = new HashSet<Artifact>();
@@ -116,43 +127,55 @@ public abstract class AbstractArtifact implements Artifact {
/**
* {@inheritDoc}
*/
+ @Override
public final int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + name.hashCode();
- result = prime * result + type.hashCode();
- result = prime * result + version.hashCode();
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((region == null) ? 0 : region.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
}
/**
* {@inheritDoc}
*/
+ @Override
public final boolean equals(Object obj) {
- if (this == obj) {
+ if (this == obj)
return true;
- }
- if (obj == null) {
+ if (obj == null)
return false;
- }
- if (!(obj instanceof Artifact)) {
+ if (!(obj instanceof AbstractArtifact))
return false;
- }
- Artifact other = (Artifact) obj;
- if (!name.equals(other.getName())) {
+ AbstractArtifact other = (AbstractArtifact) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
return false;
- }
- if (!type.equals(other.getType())) {
+ if (region == null) {
+ if (other.region != null)
+ return false;
+ } else if (!region.equals(other.region))
return false;
- }
- if (!version.equals(other.getVersion())) {
+ if (type == null) {
+ if (other.type != null)
+ return false;
+ } else if (!type.equals(other.type))
+ return false;
+ if (version == null) {
+ if (other.version != null)
+ return false;
+ } else if (!version.equals(other.version))
return false;
- }
return true;
}
@Override
public String toString() {
- return String.format("type: %s, name: %s, version: %s", this.type, this.name, this.version.toString());
+ return String.format("type: %s, name: %s, version: %s, region: " + (this.region == null ? "?" : this.region.getName()), this.type, this.name,
+ this.version.toString());
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java
index eacd17b8..63665a2c 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/NotifyingRuntimeArtifactRepository.java
@@ -18,11 +18,11 @@ import java.util.Set;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.osgi.framework.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Implementation of {@link RuntimeArtifactRepository} that notifies a collection of listeners that a change has
* happened to this repository.
@@ -102,8 +102,12 @@ public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifact
public Artifact getArtifact(String type, String name, Version version) {
synchronized (this.monitor) {
for (Artifact artifact : this.artifacts) {
- if (artifact.getType().equals(type) && artifact.getName().equals(name) && artifact.getVersion().equals(version)) {
- return artifact;
+ // Skip kernel artifacts.
+ Region region = artifact.getRegion();
+ if (region == null || !region.contains(0L)) {
+ if (artifact.getType().equals(type) && artifact.getName().equals(name) && artifact.getVersion().equals(version)) {
+ return artifact;
+ }
}
}
return null;
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java
index a3cff3cf..0bbecaac 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java
@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
+import org.eclipse.virgo.kernel.osgi.region.Region;
/**
* Implementation of {@link Artifact} that delegates to an OSGi native bundle
@@ -41,9 +42,9 @@ final class BundleArtifact extends AbstractArtifact {
private final PackageAdminUtil packageAdminUtil;
private final Bundle bundle;
-
- public BundleArtifact(@NonNull BundleContext bundleContext, @NonNull PackageAdminUtil packageAdminUtil, @NonNull Bundle bundle) {
- super(bundleContext, TYPE, bundle.getSymbolicName(), bundle.getVersion());
+
+ public BundleArtifact(@NonNull BundleContext bundleContext, @NonNull PackageAdminUtil packageAdminUtil, @NonNull Bundle bundle, Region region) {
+ super(bundleContext, TYPE, bundle.getSymbolicName(), bundle.getVersion(), region);
this.packageAdminUtil = packageAdminUtil;
this.bundle = bundle;
}
@@ -126,5 +127,5 @@ final class BundleArtifact extends AbstractArtifact {
throw new IllegalArgumentException(String.format("Unknown bundle state '%d'", state));
}
}
-
+
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminer.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminer.java
index c64c8647..be497ca1 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminer.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminer.java
@@ -18,14 +18,12 @@ import java.util.Set;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
-import org.eclipse.virgo.kernel.serviceability.NonNull;
-
-import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiExportPackage;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiImportPackage;
+import org.eclipse.virgo.kernel.serviceability.NonNull;
/**
* Implementation of {@link DependencyDeterminer} that returns the dependents of a {@link org.osgi.framework.Bundle
@@ -43,12 +41,9 @@ public final class BundleDependencyDeterminer implements DependencyDeterminer {
private final RuntimeArtifactRepository artifactRepository;
- private final PackageAdminUtil packageAdminUtil;
-
- public BundleDependencyDeterminer(@NonNull QuasiFrameworkFactory quasiFrameworkFactory, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil) {
+ public BundleDependencyDeterminer(@NonNull QuasiFrameworkFactory quasiFrameworkFactory, @NonNull RuntimeArtifactRepository artifactRepository) {
this.quasiFrameworkFactory = quasiFrameworkFactory;
this.artifactRepository = artifactRepository;
- this.packageAdminUtil = packageAdminUtil;
}
/**
@@ -68,7 +63,13 @@ public final class BundleDependencyDeterminer implements DependencyDeterminer {
QuasiBundle bundle = provider.getExportingBundle();
Artifact artifact = artifactRepository.getArtifact(BundleArtifact.TYPE, bundle.getSymbolicName(), bundle.getVersion());
if (artifact == null) {
- artifact = new QuasiBundleArtifact(bundle, this.packageAdminUtil);
+ // If there is no matching artifact in the user region, try the kernel region.
+ for (Artifact a : this.artifactRepository.getArtifacts()) {
+ if (BundleArtifact.TYPE.equals(a.getType()) && bundle.getSymbolicName().equals(a.getName()) && bundle.getVersion().equals(a.getVersion())) {
+ artifact = a;
+ break;
+ }
+ }
}
artifacts.add(artifact);
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
index 58e7de1c..38acc1f4 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
@@ -22,6 +22,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
+import org.eclipse.virgo.kernel.osgi.region.Region;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
/**
* Implementation of {@link BundleListener} that notices {@link BundleEvent#INSTALLED} and
@@ -44,11 +46,14 @@ final class ModelBundleListener implements SynchronousBundleListener {
private final PackageAdminUtil packageAdminUtil;
+ private final RegionDigraph regionDigraph;
+
public ModelBundleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository,
- @NonNull PackageAdminUtil packageAdminUtil) {
+ @NonNull PackageAdminUtil packageAdminUtil, @NonNull RegionDigraph regionDigraph) {
this.bundleContext = bundleContext;
this.artifactRepository = artifactRepository;
this.packageAdminUtil = packageAdminUtil;
+ this.regionDigraph = regionDigraph;
}
/**
@@ -64,8 +69,10 @@ final class ModelBundleListener implements SynchronousBundleListener {
private void processInstalled(BundleEvent event) {
Bundle bundle = event.getBundle();
- logger.info("Processing installed event for '{}:{}'", bundle.getSymbolicName(), bundle.getVersion().toString());
- this.artifactRepository.add(new BundleArtifact(bundleContext, packageAdminUtil, bundle));
+ Region region = this.regionDigraph.getRegion(bundle);
+ String regionName = region == null ? "?" : region.getName();
+ logger.info("Processing installed event for '{}:{}' in region '" + regionName + "'", bundle.getSymbolicName(), bundle.getVersion().toString());
+ this.artifactRepository.add(new BundleArtifact(bundleContext, packageAdminUtil, bundle, region));
}
private void processUninstalled(BundleEvent event) {
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 d9869fbf..ca8a0929 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
@@ -16,6 +16,7 @@ import javax.annotation.PreDestroy;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -44,17 +45,17 @@ public final class ModelBundleListenerInitializer {
private final BundleContext kernelBundleContext;
- private final BundleContext userRegionBundleContext;
-
private final BundleListener bundleListener;
+ private final RegionDigraph regionDigraph;
+
public ModelBundleListenerInitializer(@NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil,
- @NonNull BundleContext kernelBundleContext, @NonNull BundleContext userRegionBundleContext) {
+ @NonNull BundleContext kernelBundleContext, @NonNull BundleContext userRegionBundleContext, @NonNull RegionDigraph regionDigraph) {
this.artifactRepository = artifactRepository;
this.packageAdminUtil = packageAdminUtil;
this.kernelBundleContext = kernelBundleContext;
- this.userRegionBundleContext = userRegionBundleContext;
- this.bundleListener = new ModelBundleListener(kernelBundleContext, artifactRepository, packageAdminUtil);
+ this.bundleListener = new ModelBundleListener(kernelBundleContext, artifactRepository, packageAdminUtil, regionDigraph);
+ this.regionDigraph = regionDigraph;
}
/**
@@ -63,12 +64,14 @@ public final class ModelBundleListenerInitializer {
*/
@PostConstruct
public void initialize() {
- // Register the listener with the user region bundle context to see all bundles in the user region.
- this.userRegionBundleContext.addBundleListener(this.bundleListener);
- // Find bundles in the user region as the listener has almost certainly missed their installation.
- for (Bundle bundle : this.userRegionBundleContext.getBundles()) {
+ BundleContext systemBundleContext = getSystemBundleContext();
+ // Register the listener with the system bundle context to see all bundles in all regions.
+ systemBundleContext.addBundleListener(this.bundleListener);
+ // Find bundles that the listener has almost certainly missed.
+ for (Bundle bundle : systemBundleContext.getBundles()) {
try {
- this.artifactRepository.add(new BundleArtifact(this.kernelBundleContext, this.packageAdminUtil, bundle));
+ this.artifactRepository.add(new BundleArtifact(this.kernelBundleContext, this.packageAdminUtil, bundle,
+ this.regionDigraph.getRegion(bundle)));
} catch (Exception e) {
this.logger.error(String.format("Exception adding bundle '%s:%s' to the repository", bundle.getSymbolicName(),
bundle.getVersion().toString()), e);
@@ -76,11 +79,16 @@ public final class ModelBundleListenerInitializer {
}
}
+ private BundleContext getSystemBundleContext() {
+ BundleContext systemBundleContext = this.kernelBundleContext.getBundle(0L).getBundleContext();
+ return systemBundleContext;
+ }
+
/**
* Unregisters the listener from the OSGi framework
*/
@PreDestroy
public void destroy() {
- this.userRegionBundleContext.removeBundleListener(this.bundleListener);
+ getSystemBundleContext().removeBundleListener(this.bundleListener);
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifact.java
deleted file mode 100644
index a32e9c3c..00000000
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifact.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VMware Inc. - initial contribution
- *******************************************************************************/
-
-package org.eclipse.virgo.kernel.model.internal.bundle;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.virgo.kernel.model.Artifact;
-import org.eclipse.virgo.kernel.model.ArtifactState;
-import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
-import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
-import org.eclipse.virgo.kernel.serviceability.NonNull;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Version;
-
-/**
- * {@link QuasiBundleArtifact} is an {@link Artifact} that wraps a {@link QuasiBundle}.
- * <p />
- *
- * <strong>Concurrent Semantics</strong><br />
- * Thread safe.
- */
-final class QuasiBundleArtifact implements Artifact {
-
- private final QuasiBundle quasiBundle;
-
- private final PackageAdminUtil packageAdminUtil;
-
- QuasiBundleArtifact(@NonNull QuasiBundle quasiBundle, @NonNull PackageAdminUtil packageAdminUtil) {
- this.quasiBundle = quasiBundle;
- this.packageAdminUtil = packageAdminUtil;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void start() {
- Bundle bundle = getBundle();
- try {
- bundle.start();
- } catch (BundleException e) {
- throw new RuntimeException("Failed to start", e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void stop() {
- Bundle bundle = getBundle();
- if (bundle != null) {
- BundleContext bundleContext = bundle.getBundleContext();
- if (bundleContext != null) {
- new BundleArtifact(bundleContext, this.packageAdminUtil, bundle).stop();
- }
- }
- }
-
- private Bundle getBundle() {
- return quasiBundle.getBundle();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean refresh() {
- Bundle bundle = getBundle();
- if (bundle != null) {
- BundleContext bundleContext = bundle.getBundleContext();
- if (bundleContext != null) {
- return new BundleArtifact(bundleContext, this.packageAdminUtil, bundle).refresh();
- } else {
- try {
- bundle.update();
- return true;
- } catch (BundleException _) {
- return false;
- }
- }
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void uninstall() {
- Bundle bundle = getBundle();
- if (bundle != null) {
- try {
- bundle.uninstall();
- } catch (BundleException e) {
- throw new RuntimeException("Failed to uninstall", e);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getType() {
- return BundleArtifact.TYPE;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getName() {
- return this.quasiBundle.getSymbolicName();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Version getVersion() {
- return this.quasiBundle.getVersion();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ArtifactState getState() {
- Bundle bundle = getBundle();
- if (bundle != null) {
- return BundleArtifact.mapBundleState(bundle.getState());
- }
- return ArtifactState.UNINSTALLED;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<Artifact> getDependents() {
- Set<Artifact> dependents = new HashSet<Artifact>();
- for (QuasiBundle quasiBundle : this.quasiBundle.getDependents()) {
- /*
- * Since QuasiBundleArtifact is used to represent dependencies in the kernel, the dependents should also be in
- * the kernel and so can be represented by further QuasiBundleArtifacts.
- */
- dependents.add(new QuasiBundleArtifact(quasiBundle, this.packageAdminUtil));
- }
- return dependents;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Map<String, String> getProperties() {
- return Collections.<String, String> emptyMap();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((quasiBundle == null) ? 0 : quasiBundle.hashCode());
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof QuasiBundleArtifact)) {
- return false;
- }
- QuasiBundleArtifact other = (QuasiBundleArtifact) obj;
- if (quasiBundle == null) {
- if (other.quasiBundle != null) {
- return false;
- }
- } else if (!quasiBundle.equals(other.quasiBundle)) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/configurationadmin/ConfigurationArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/configurationadmin/ConfigurationArtifact.java
index f7149d5a..cc52980e 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/configurationadmin/ConfigurationArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/configurationadmin/ConfigurationArtifact.java
@@ -43,7 +43,7 @@ final class ConfigurationArtifact extends AbstractArtifact {
private final String pid;
public ConfigurationArtifact(@NonNull BundleContext bundleContext, @NonNull ConfigurationAdmin configurationAdmin, @NonNull String pid) {
- super(bundleContext, TYPE, pid, Version.emptyVersion);
+ super(bundleContext, TYPE, pid, Version.emptyVersion, null);
this.configurationAdmin = configurationAdmin;
this.pid = pid;
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifact.java
index b107b529..ccc4bc87 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerArtifact.java
@@ -25,6 +25,7 @@ import org.eclipse.virgo.kernel.install.artifact.InstallArtifact.State;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.ArtifactState;
import org.eclipse.virgo.kernel.model.internal.AbstractArtifact;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.BundleContext;
@@ -42,7 +43,12 @@ class DeployerArtifact extends AbstractArtifact {
private final InstallArtifact installArtifact;
public DeployerArtifact(@NonNull BundleContext bundleContext, @NonNull InstallArtifact installArtifact) {
- super(bundleContext, installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion());
+ super(bundleContext, installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), null);
+ this.installArtifact = installArtifact;
+ }
+
+ public DeployerArtifact(@NonNull BundleContext bundleContext, @NonNull InstallArtifact installArtifact, Region region) {
+ super(bundleContext, installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), region);
this.installArtifact = installArtifact;
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
index 3b99f6ea..4bf25494 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
@@ -18,13 +18,14 @@ import org.osgi.framework.BundleContext;
import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
import org.eclipse.virgo.kernel.model.BundleArtifact;
+import org.eclipse.virgo.kernel.osgi.region.Region;
final class DeployerBundleArtifact extends DeployerArtifact implements BundleArtifact {
private final BundleInstallArtifact installArtifact;
- public DeployerBundleArtifact(@NonNull BundleContext bundleContext, @NonNull BundleInstallArtifact installArtifact) {
- super(bundleContext, installArtifact);
+ public DeployerBundleArtifact(@NonNull BundleContext bundleContext, @NonNull BundleInstallArtifact installArtifact, Region region) {
+ super(bundleContext, installArtifact, region);
this.installArtifact = installArtifact;
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java
index af480931..193faf2d 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java
@@ -24,6 +24,7 @@ import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListene
import org.eclipse.virgo.kernel.install.artifact.PlanInstallArtifact;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
/**
* Implementation of {@link InstallArtifactLifecycleListener} that notices
@@ -44,15 +45,21 @@ import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
*/
class ModelInstallArtifactLifecycleListener extends InstallArtifactLifecycleListenerSupport {
+ private static final String USER_REGION_NAME = "org.eclipse.virgo.region.user";
+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final RuntimeArtifactRepository artifactRepository;
private final BundleContext bundleContext;
- public ModelInstallArtifactLifecycleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository) {
+ private final RegionDigraph regionDigraph;
+
+ public ModelInstallArtifactLifecycleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository,
+ @NonNull RegionDigraph regionDigraph) {
this.bundleContext = bundleContext;
this.artifactRepository = artifactRepository;
+ this.regionDigraph = regionDigraph;
}
/**
@@ -79,7 +86,8 @@ class ModelInstallArtifactLifecycleListener extends InstallArtifactLifecycleList
bundleInstallArtifact.getVersion());
if (!(existingBundleArtifact instanceof DeployerBundleArtifact)) {
remove(bundleInstallArtifact);
- this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, bundleInstallArtifact));
+ this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, bundleInstallArtifact,
+ this.regionDigraph.getRegion(USER_REGION_NAME)));
}
}
@@ -106,8 +114,8 @@ class ModelInstallArtifactLifecycleListener extends InstallArtifactLifecycleList
}
private void logEvent(String event, InstallArtifact installArtifact) {
- this.logger.info("Processing " + event + " event for {} '{}' version '{}'", new String[] { installArtifact.getType(),
- installArtifact.getName(), installArtifact.getVersion().toString() });
+ this.logger.info("Processing " + event + " event for {} '{}' version '{}'",
+ new String[] { installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion().toString() });
}
private void remove(InstallArtifact installArtifact) {
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java
index 493a380d..7c69d455 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java
@@ -22,6 +22,7 @@ import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
import org.eclipse.virgo.kernel.install.artifact.PlanInstallArtifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
import org.eclipse.virgo.kernel.deployer.model.RuntimeArtifactModel;
@@ -35,7 +36,7 @@ import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
*
* <strong>Concurrent Semantics</strong><br />
*
- * TODO Document concurrent semantics of ModelInstallArtifactLifecycleListenerInitializer
+ * Thread safe.
*
* @see ModelInstallArtifactLifecycleListener
*/
@@ -51,11 +52,14 @@ public final class ModelInstallArtifactLifecycleListenerInitializer {
private final ServiceRegistrationTracker registrationTracker = new ServiceRegistrationTracker();
+ private final RegionDigraph regionDigraph;
+
public ModelInstallArtifactLifecycleListenerInitializer(@NonNull RuntimeArtifactRepository artifactRepository,
- @NonNull BundleContext bundleContext, @NonNull RuntimeArtifactModel runtimeArtifactModel) {
+ @NonNull BundleContext bundleContext, @NonNull RuntimeArtifactModel runtimeArtifactModel, @NonNull RegionDigraph regionDigraph) {
this.artifactRepository = artifactRepository;
this.bundleContext = bundleContext;
this.runtimeArtifactModel = runtimeArtifactModel;
+ this.regionDigraph = regionDigraph;
}
/**
@@ -64,7 +68,8 @@ public final class ModelInstallArtifactLifecycleListenerInitializer {
*/
@PostConstruct
public void initialize() {
- ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(this.bundleContext, this.artifactRepository);
+ ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(this.bundleContext, this.artifactRepository,
+ this.regionDigraph);
this.registrationTracker.track(this.bundleContext.registerService(InstallArtifactLifecycleListener.class.getCanonicalName(), listener, null));
for (DeploymentIdentity deploymentIdentity : this.runtimeArtifactModel.getDeploymentIdentities()) {
InstallArtifact installArtifact = this.runtimeArtifactModel.get(deploymentIdentity);
@@ -73,7 +78,9 @@ public final class ModelInstallArtifactLifecycleListenerInitializer {
this.artifactRepository.add(new DeployerCompositeArtifact(this.bundleContext, (PlanInstallArtifact) installArtifact));
} else if (installArtifact instanceof BundleInstallArtifact) {
this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion());
- this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, (BundleInstallArtifact) installArtifact));
+ BundleInstallArtifact bundleInstallArtifact = (BundleInstallArtifact) installArtifact;
+ this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, bundleInstallArtifact,
+ this.regionDigraph.getRegion(bundleInstallArtifact.getBundle())));
} else {
this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion());
this.artifactRepository.add(new DeployerArtifact(this.bundleContext, installArtifact));
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java
index 7c70a376..e7772fcd 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java
@@ -14,10 +14,9 @@ package org.eclipse.virgo.kernel.model.management;
import javax.management.ObjectName;
import org.eclipse.virgo.kernel.model.Artifact;
-import org.eclipse.virgo.kernel.model.internal.AbstractArtifact;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.osgi.framework.Version;
-
/**
* An strategy interface for creating object names based on an input {@link Artifact}
* <p />
@@ -44,11 +43,22 @@ public interface RuntimeArtifactModelObjectNameCreator {
* @param type The type of the object to create an @{link ObjectName} for
* @param name The name of the object to create an @{link ObjectName} for
* @param version The version of the object to create an @{link ObjectName} for
- * @return An {@link ObjectName} for the runtime artifact represented by this type name and version
+ * @return An {@link ObjectName} for the runtime artifact represented by this type, name, and version
*/
ObjectName create(String type, String name, Version version);
/**
+ * Creates an {@link ObjectName} based on an input type, name, version, and region.
+ *
+ * @param type The type of the object to create an @{link ObjectName} for
+ * @param name The name of the object to create an @{link ObjectName} for
+ * @param version The version of the object to create an @{link ObjectName} for
+ * @param region The {@link Region} of the object to create an @{link ObjectName} for
+ * @return An {@link ObjectName} for the runtime artifact represented by this type, name, version, and region
+ */
+ ObjectName create(String type, String name, Version version, Region region);
+
+ /**
* Creates a query {@link ObjectName} that can be used to enumerate all of the artifacts in the runtime artifact
* model
*
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java
index 0ab5ee66..296550f7 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java
@@ -16,10 +16,10 @@ import javax.management.ObjectName;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.management.RuntimeArtifactModelObjectNameCreator;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Version;
-
/**
* The default implementation of {@link RuntimeArtifactModelObjectNameCreator}. This implementation creates names based
* on the following pattern:
@@ -33,6 +33,8 @@ import org.osgi.framework.Version;
*/
public final class DefaultRuntimeArtifactModelObjectNameCreator implements RuntimeArtifactModelObjectNameCreator {
+ private static final String USER_REGION_NAME = "org.eclipse.virgo.region.user";
+
private static final String ARTIFACTS_FORMAT = "%s:type=Model,*";
private static final String ARTIFACTS_OF_TYPE_FORMAT = "%s:type=Model,artifact-type=%s,*";
@@ -40,6 +42,8 @@ public final class DefaultRuntimeArtifactModelObjectNameCreator implements Runti
private static final String ARTIFACTS_OF_TYPE_AND_NAME_FORMAT = "%s:type=Model,artifact-type=%s,name=%s,*";
private static final String ARTIFACT_FORMAT = "%s:type=Model,artifact-type=%s,name=%s,version=%s";
+
+ private static final String EXTENDED_ARTIFACT_FORMAT = "%s:type=RegionModel,artifact-type=%s,name=%s,version=%s,region=%s";
private static final String KEY_TYPE = "artifact-type";
@@ -57,7 +61,20 @@ public final class DefaultRuntimeArtifactModelObjectNameCreator implements Runti
* {@inheritDoc}
*/
public ObjectName create(@NonNull Artifact artifact) {
- return create(artifact.getType(), artifact.getName(), artifact.getVersion());
+ Region region = artifact.getRegion();
+ // Treat user region artifacts specially to preserve JMX compatibility with Virgo 2.1.0.
+ if (region == null || USER_REGION_NAME.equals(region.getName())) {
+ return create(artifact.getType(), artifact.getName(), artifact.getVersion());
+ }
+ return create(artifact.getType(), artifact.getName(), artifact.getVersion(), region);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ObjectName create(String type, String name, Version version, Region region) {
+ String regionName = region == null ? "?" : region.getName();
+ return createObjectName(String.format(EXTENDED_ARTIFACT_FORMAT, this.domain, type, name, version, regionName));
}
/**
diff --git a/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml b/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml
index 274663d9..52d5dcdc 100644
--- a/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml
+++ b/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml
@@ -10,6 +10,7 @@
<constructor-arg ref="packageAdminUtil"/>
<constructor-arg ref="bundleContext"/>
<constructor-arg ref="userBundleContext"/>
+ <constructor-arg ref="regionDigraph"/>
</bean>
<bean class="org.eclipse.virgo.kernel.model.internal.configurationadmin.ModelConfigurationListenerInitializer">
@@ -22,12 +23,12 @@
<constructor-arg ref="artifactRepository"/>
<constructor-arg ref="bundleContext"/>
<constructor-arg ref="runtimeArtifactModel"/>
+ <constructor-arg ref="regionDigraph"/>
</bean>
<bean id="bundleDependencyDeterminer" class="org.eclipse.virgo.kernel.model.internal.bundle.BundleDependencyDeterminer">
<constructor-arg ref="quasiFrameworkFactory"/>
<constructor-arg ref="artifactRepository"/>
- <constructor-arg ref="packageAdminUtil"/>
</bean>
<bean id="deployerCompositeArtifactDependencyDeterminer"
diff --git a/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/osgi-context.xml b/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/osgi-context.xml
index 62a60c80..b9c99de4 100644
--- a/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/osgi-context.xml
+++ b/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/osgi-context.xml
@@ -42,5 +42,7 @@
<reference id="userBundleContext" interface="org.osgi.framework.BundleContext" filter="(org.eclipse.virgo.kernel.regionContext=true)"/>
<reference id="applicationDeployer" interface="org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer"/>
+
+ <reference id="regionDigraph" interface="org.eclipse.virgo.kernel.osgi.region.RegionDigraph" />
</beans:beans>
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubCompositeArtifact.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubCompositeArtifact.java
index 7d2508ed..0434e39a 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubCompositeArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubCompositeArtifact.java
@@ -17,6 +17,7 @@ import java.util.Set;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.ArtifactState;
import org.eclipse.virgo.kernel.model.CompositeArtifact;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.osgi.framework.Version;
public class StubCompositeArtifact implements CompositeArtifact {
@@ -69,4 +70,9 @@ public class StubCompositeArtifact implements CompositeArtifact {
throw new UnsupportedOperationException();
}
+ @Override
+ public Region getRegion() {
+ return null;
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/AbztractArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/AbztractArtifactTests.java
index 0d312f5e..e9c6c9cf 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/AbztractArtifactTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/AbztractArtifactTests.java
@@ -121,11 +121,11 @@ public class AbztractArtifactTests {
private static class StubArtifact extends AbstractArtifact {
public StubArtifact(BundleContext bundleContext) {
- super(bundleContext, "test-type", "test-name", Version.emptyVersion);
+ super(bundleContext, "test-type", "test-name", Version.emptyVersion, null);
}
public StubArtifact(BundleContext bundleContext, String type, String name, Version version) {
- super(bundleContext, type, name, version);
+ super(bundleContext, type, name, version, null);
}
public ArtifactState getState() {
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java
index b27975af..4abf5703 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java
@@ -13,6 +13,7 @@ package org.eclipse.virgo.kernel.model.internal.bundle;
import static org.easymock.EasyMock.aryEq;
import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
@@ -22,6 +23,7 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
+import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.model.ArtifactState;
import org.eclipse.virgo.kernel.model.internal.AbstractArtifact;
@@ -39,28 +41,31 @@ public class BundleArtifactTests {
private final StubBundle bundle = new StubBundle();
private final StubBundleContext bundleContext;
+
+ private final Region region = createMock(Region.class);
{
this.bundleContext = (StubBundleContext) bundle.getBundleContext();
String filterString = String.format("(&(objectClass=%s)(artifactType=bundle))", DependencyDeterminer.class.getCanonicalName());
bundleContext.addFilter(filterString, new TrueFilter(filterString));
+ expect(this.region.getName()).andReturn("test.region").anyTimes();
}
- private final AbstractArtifact artifact = new BundleArtifact(bundleContext, packageAdminUtil, bundle);
+ private final AbstractArtifact artifact = new BundleArtifact(bundleContext, packageAdminUtil, bundle, this.region);
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new BundleArtifact(null, packageAdminUtil, bundle);
+ new BundleArtifact(null, packageAdminUtil, bundle, this.region);
}
@Test(expected = FatalAssertionException.class)
public void nullPackageAdminUtil() {
- new BundleArtifact(bundleContext, null, bundle);
+ new BundleArtifact(bundleContext, null, bundle, this.region);
}
@Test(expected = FatalAssertionException.class)
public void nullBundle() {
- new BundleArtifact(bundleContext, packageAdminUtil, null);
+ new BundleArtifact(bundleContext, packageAdminUtil, null, this.region);
}
@Test
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminerTests.java
index 8d4c10fe..164097b9 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminerTests.java
@@ -24,14 +24,11 @@ import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.StubCompositeArtifact;
-import org.eclipse.virgo.kernel.model.internal.bundle.BundleDependencyDeterminer;
-import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
-import org.junit.Test;
-
-import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory;
+import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
+import org.junit.Test;
public class BundleDependencyDeterminerTests {
@@ -39,25 +36,18 @@ public class BundleDependencyDeterminerTests {
private final RuntimeArtifactRepository artifactRepository = new StubArtifactRepository();
- private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
-
- private final BundleDependencyDeterminer determiner = new BundleDependencyDeterminer(quasiFrameworkFactory, artifactRepository, packageAdminUtil);
+ private final BundleDependencyDeterminer determiner = new BundleDependencyDeterminer(quasiFrameworkFactory, artifactRepository);
@Test(expected = FatalAssertionException.class)
public void nullFactory() {
- new BundleDependencyDeterminer(null, artifactRepository, packageAdminUtil);
+ new BundleDependencyDeterminer(null, artifactRepository);
}
@Test(expected = FatalAssertionException.class)
public void nullRepository() {
- new BundleDependencyDeterminer(quasiFrameworkFactory, null, packageAdminUtil);
+ new BundleDependencyDeterminer(quasiFrameworkFactory, null);
}
- @Test(expected = FatalAssertionException.class)
- public void nullPackageAdminUtil() {
- new BundleDependencyDeterminer(quasiFrameworkFactory, artifactRepository, null);
- }
-
@Test
public void unknownBundle() {
QuasiFramework framework = createMock(QuasiFramework.class);
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 9abb68d5..bae26f85 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
@@ -16,19 +16,17 @@ import static org.junit.Assert.assertEquals;
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;
-
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
-import org.eclipse.virgo.kernel.model.internal.bundle.ModelBundleListenerInitializer;
+import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.eclipse.virgo.teststubs.osgi.support.TrueFilter;
+import org.junit.Test;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
public class ModelBundleListenerInitializerTests {
@@ -37,54 +35,63 @@ public class ModelBundleListenerInitializerTests {
private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
private final StubBundleContext bundleContext;
-
+
private final StubBundleContext systemBundleContext;
+
+ private final RegionDigraph regionDigraph = createMock(RegionDigraph.class);
+
{
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.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));
}
- private final ModelBundleListenerInitializer initializer = new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, bundleContext);
+ private final ModelBundleListenerInitializer initializer = new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil,
+ bundleContext, bundleContext, regionDigraph);
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelBundleListenerInitializer(null, packageAdminUtil, bundleContext, bundleContext);
+ new ModelBundleListenerInitializer(null, packageAdminUtil, bundleContext, bundleContext, regionDigraph);
}
@Test(expected = FatalAssertionException.class)
public void nullPackageAdminUtil() {
- new ModelBundleListenerInitializer(artifactRepository, null, bundleContext, bundleContext);
+ new ModelBundleListenerInitializer(artifactRepository, null, bundleContext, bundleContext, regionDigraph);
}
@Test(expected = FatalAssertionException.class)
public void nullKernelBundleContext() {
- new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, null, bundleContext);
+ new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, null, bundleContext, regionDigraph);
}
@Test(expected = FatalAssertionException.class)
public void nullUserRegionBundleContext() {
- new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, null);
+ new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, null, regionDigraph);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullRegionDigraph() {
+ new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, 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());
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
index 98fda81e..b77d1b7f 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
@@ -12,12 +12,17 @@
package org.eclipse.virgo.kernel.model.internal.bundle;
import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
@@ -34,31 +39,41 @@ public class ModelBundleListenerTests {
private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
private final StubBundleContext bundleContext;
+
+ private final RegionDigraph regionDigraph = createMock(RegionDigraph.class);
+
{
this.bundleContext = new StubBundleContext();
String filterString = String.format("(&(objectClass=%s)(artifactType=bundle))", DependencyDeterminer.class.getCanonicalName());
this.bundleContext.addFilter(filterString, new TrueFilter(filterString));
+ expect(regionDigraph.getRegion(isA(Bundle.class))).andReturn(null).anyTimes();
}
- private final ModelBundleListener listener = new ModelBundleListener(bundleContext, artifactRepository, packageAdminUtil);
+ private final ModelBundleListener listener = new ModelBundleListener(bundleContext, artifactRepository, packageAdminUtil, regionDigraph);
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new ModelBundleListener(null, artifactRepository, packageAdminUtil);
+ new ModelBundleListener(null, artifactRepository, packageAdminUtil, regionDigraph);
}
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelBundleListener(bundleContext, null, packageAdminUtil);
+ new ModelBundleListener(bundleContext, null, packageAdminUtil, regionDigraph);
}
@Test(expected = FatalAssertionException.class)
public void nullPackageAdminUtil() {
- new ModelBundleListener(bundleContext, artifactRepository, null);
+ new ModelBundleListener(bundleContext, artifactRepository, null, regionDigraph);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullRegionDigraph() {
+ new ModelBundleListener(bundleContext, artifactRepository, packageAdminUtil, null);
}
@Test
public void installed() {
+ replay(regionDigraph);
assertEquals(0, this.artifactRepository.getArtifacts().size());
BundleEvent event1 = new BundleEvent(BundleEvent.INSTALLED, new StubBundle().setBundleContext(this.bundleContext));
this.listener.bundleChanged(event1);
@@ -70,6 +85,7 @@ public class ModelBundleListenerTests {
@Test
public void uninstalled() {
+ replay(regionDigraph);
BundleEvent event1 = new BundleEvent(BundleEvent.INSTALLED, new StubBundle().setBundleContext(this.bundleContext));
this.listener.bundleChanged(event1);
assertEquals(1, this.artifactRepository.getArtifacts().size());
@@ -83,6 +99,7 @@ public class ModelBundleListenerTests {
@Test
public void unknownEventType() {
+ replay(regionDigraph);
BundleEvent event = new BundleEvent(-1, new StubBundle().setBundleContext(this.bundleContext));
this.listener.bundleChanged(event);
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifactTests.java
deleted file mode 100644
index 4f063308..00000000
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifactTests.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VMware Inc. - initial contribution
- *******************************************************************************/
-
-package org.eclipse.virgo.kernel.model.internal.bundle;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.Assert;
-
-import org.easymock.EasyMock;
-import org.eclipse.virgo.kernel.model.Artifact;
-import org.eclipse.virgo.kernel.model.ArtifactState;
-import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
-import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Filter;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
-
-public class QuasiBundleArtifactTests {
-
- private static final Version TEST_BUNDLE_VERSION = new Version("4345.234.56.sfghz");
-
- private static final String TEST_BUNDLE_SYMBOLIC_NAME = "test.bundle";
-
- private QuasiBundle mockQuasiBundle;
-
- private Bundle mockBundle;
-
- private PackageAdminUtil mockPackageAdminUtil;
-
- private Artifact quasiBundleArtifact;
-
- private BundleContext mockBundleContext;
-
- private Filter mockFilter;
-
- @Before
- public void setUp() throws Exception {
- this.mockQuasiBundle = EasyMock.createMock(QuasiBundle.class);
- EasyMock.expect(this.mockQuasiBundle.getSymbolicName()).andReturn(TEST_BUNDLE_SYMBOLIC_NAME).anyTimes();
- EasyMock.expect(this.mockQuasiBundle.getVersion()).andReturn(TEST_BUNDLE_VERSION).anyTimes();
-
- this.mockBundle = EasyMock.createMock(Bundle.class);
- this.mockBundleContext = EasyMock.createMock(BundleContext.class);
- this.mockFilter = EasyMock.createMock(Filter.class);
- EasyMock.expect(this.mockBundle.getSymbolicName()).andReturn(TEST_BUNDLE_SYMBOLIC_NAME).anyTimes();
- EasyMock.expect(this.mockBundle.getVersion()).andReturn(TEST_BUNDLE_VERSION).anyTimes();
- EasyMock.expect(this.mockBundle.getBundleContext()).andReturn(this.mockBundleContext).anyTimes();
- EasyMock.expect(this.mockBundle.getState()).andReturn(Bundle.ACTIVE).anyTimes();
- EasyMock.expect(this.mockBundleContext.createFilter(EasyMock.isA(String.class))).andReturn(this.mockFilter).anyTimes();
- this.mockBundleContext.addServiceListener(EasyMock.isA(ServiceListener.class), EasyMock.isA(String.class));
- EasyMock.expectLastCall().anyTimes();
- ServiceReference<?>[] refs = {};
- EasyMock.expect(this.mockBundleContext.getServiceReferences((String) EasyMock.eq(null), EasyMock.isA(String.class))).andReturn(refs).anyTimes();
-
- EasyMock.expect(this.mockQuasiBundle.getBundle()).andReturn(this.mockBundle).anyTimes();
-
- this.mockPackageAdminUtil = EasyMock.createMock(PackageAdminUtil.class);
- this.quasiBundleArtifact = new QuasiBundleArtifact(this.mockQuasiBundle, this.mockPackageAdminUtil);
- }
-
- private void replay() {
- EasyMock.replay(this.mockQuasiBundle, this.mockPackageAdminUtil, this.mockBundle, this.mockBundleContext, this.mockFilter);
- }
-
- @After
- public void tearDown() throws Exception {
- EasyMock.verify(this.mockQuasiBundle, this.mockPackageAdminUtil, this.mockBundle, this.mockBundleContext, this.mockFilter);
- }
-
- @Test
- public void testStart() throws BundleException {
- this.mockBundle.start();
- EasyMock.expectLastCall();
- replay();
- this.quasiBundleArtifact.start();
- }
-
- @Test
- public void testStop() throws BundleException {
- this.mockBundle.stop();
- EasyMock.expectLastCall();
- replay();
- this.quasiBundleArtifact.stop();
- }
-
- @Test
- public void testRefresh() throws BundleException {
- this.mockBundle.update();
- Bundle[] bundles = { this.mockBundle };
- this.mockPackageAdminUtil.synchronouslyRefreshPackages(EasyMock.aryEq(bundles));
- EasyMock.expectLastCall().anyTimes();
- EasyMock.expectLastCall();
- replay();
- this.quasiBundleArtifact.refresh();
- }
-
- @Test
- public void testUninstall() throws BundleException {
- this.mockBundle.uninstall();
- EasyMock.expectLastCall();
- replay();
- this.quasiBundleArtifact.uninstall();
- }
-
- @Test
- public void testGetType() {
- replay();
- Assert.assertEquals("bundle", this.quasiBundleArtifact.getType());
- }
-
- @Test
- public void testGetName() {
- replay();
- Assert.assertEquals(TEST_BUNDLE_SYMBOLIC_NAME, this.quasiBundleArtifact.getName());
- }
-
- @Test
- public void testGetVersion() {
- replay();
- Assert.assertEquals(TEST_BUNDLE_VERSION, this.quasiBundleArtifact.getVersion());
- }
-
- @Test
- public void testGetState() {
- replay();
- Assert.assertEquals(ArtifactState.ACTIVE, this.quasiBundleArtifact.getState());
- }
-
- @Test
- public void testGetDependents() {
- QuasiBundle qb1 = EasyMock.createMock(QuasiBundle.class);
- QuasiBundle qb2 = EasyMock.createMock(QuasiBundle.class);
- List<QuasiBundle> dependents = new ArrayList<QuasiBundle>();
- dependents.add(qb1);
- dependents.add(qb2);
- EasyMock.expect(this.mockQuasiBundle.getDependents()).andReturn(dependents);
- replay();
- Set<Artifact> expected = new HashSet<Artifact>();
- expected.add(new QuasiBundleArtifact(qb1, this.mockPackageAdminUtil));
- expected.add(new QuasiBundleArtifact(qb2, this.mockPackageAdminUtil));
- Assert.assertEquals(expected, this.quasiBundleArtifact.getDependents());
- }
-
- @Test
- public void testGetProperties() {
- replay();
- Assert.assertEquals(new HashMap<String, String>(), this.quasiBundleArtifact.getProperties());
- }
-
-} \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java
index 62f93ad9..eb380dab 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java
@@ -30,6 +30,7 @@ import org.eclipse.virgo.kernel.deployer.model.RuntimeArtifactModel;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.model.internal.deployer.ModelInstallArtifactLifecycleListenerInitializer;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
import org.eclipse.virgo.kernel.stubs.StubInstallArtifact;
import org.eclipse.virgo.kernel.stubs.StubPlanInstallArtifact;
@@ -41,6 +42,8 @@ public class ModelInstallArtifactLifecycleListenerInitializerTests {
private final StubArtifactRepository artifactRepository = new StubArtifactRepository();
private final RuntimeArtifactModel runtimeArtifactModel = createMock(RuntimeArtifactModel.class);
+
+ private final RegionDigraph regionDigraph = createMock(RegionDigraph.class);
private final StubBundleContext bundleContext;
{
@@ -52,16 +55,21 @@ public class ModelInstallArtifactLifecycleListenerInitializerTests {
}
private final ModelInstallArtifactLifecycleListenerInitializer initializer = new ModelInstallArtifactLifecycleListenerInitializer(
- artifactRepository, bundleContext, runtimeArtifactModel);
+ artifactRepository, bundleContext, runtimeArtifactModel, regionDigraph);
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelInstallArtifactLifecycleListenerInitializer(null, bundleContext, runtimeArtifactModel);
+ new ModelInstallArtifactLifecycleListenerInitializer(null, bundleContext, runtimeArtifactModel, regionDigraph);
}
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, null, runtimeArtifactModel);
+ new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, null, runtimeArtifactModel, regionDigraph);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullRegionDigraph() {
+ new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, null);
}
@Test
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java
index 086df7f0..af9edca4 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java
@@ -11,6 +11,7 @@
package org.eclipse.virgo.kernel.model.internal.deployer;
+import static org.easymock.EasyMock.createMock;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
@@ -19,6 +20,7 @@ import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.model.internal.deployer.ModelInstallArtifactLifecycleListener;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
@@ -31,6 +33,8 @@ import org.eclipse.virgo.teststubs.osgi.support.TrueFilter;
public class ModelInstallArtifactLifecycleListenerTests {
private final StubArtifactRepository artifactRepository = new StubArtifactRepository();
+
+ private final RegionDigraph regionDigraph = createMock(RegionDigraph.class);
private final StubBundleContext bundleContext;
{
@@ -41,16 +45,21 @@ public class ModelInstallArtifactLifecycleListenerTests {
this.bundleContext.addFilter(filterString2, new TrueFilter(filterString2));
}
- private final ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository);
+ private final ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, regionDigraph);
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new ModelInstallArtifactLifecycleListener(null, artifactRepository);
+ new ModelInstallArtifactLifecycleListener(null, artifactRepository, regionDigraph);
}
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelInstallArtifactLifecycleListener(bundleContext, null);
+ new ModelInstallArtifactLifecycleListener(bundleContext, null, regionDigraph);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullRegionDigraph() {
+ new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, null);
}
@Test

Back to the top