Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-03-08 05:44:28 -0500
committerGlyn Normington2011-03-08 05:44:28 -0500
commit8103f908737da184aacd87f9ddcef2dfaab9f18f (patch)
tree71768dce2e2b9a5101426f19505693633876efb7 /org.eclipse.virgo.kernel.model
parent8528d16dbf883c86019cbdb98cc95ff96492ec8a (diff)
downloadorg.eclipse.virgo.kernel-8103f908737da184aacd87f9ddcef2dfaab9f18f.tar.gz
org.eclipse.virgo.kernel-8103f908737da184aacd87f9ddcef2dfaab9f18f.tar.xz
org.eclipse.virgo.kernel-8103f908737da184aacd87f9ddcef2dfaab9f18f.zip
bug 337211: enable RAM to cope with dependencies in the kernel region
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/NotifyingRuntimeArtifactRepository.java8
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java2
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminer.java12
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifact.java175
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml2
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java14
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleDependencyDeterminerTests.java14
7 files changed, 202 insertions, 25 deletions
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 f9b917ab..eacd17b8 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,7 +18,6 @@ import java.util.Set;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,11 +44,8 @@ public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifact
private final List<ArtifactRepositoryListener> listeners;
- private final KernelRegionBundle kernelRegionBundle;
-
- public NotifyingRuntimeArtifactRepository(BundleContext bundleContext, ArtifactRepositoryListener... listeners) {
+ public NotifyingRuntimeArtifactRepository(ArtifactRepositoryListener... listeners) {
this.listeners = Arrays.asList(listeners);
- this.kernelRegionBundle = new KernelRegionBundle(bundleContext.getBundle().getVersion());
}
/**
@@ -110,7 +106,7 @@ public final class NotifyingRuntimeArtifactRepository implements RuntimeArtifact
return artifact;
}
}
- return this.kernelRegionBundle;
+ 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 82951797..a3cff3cf 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
@@ -109,7 +109,7 @@ final class BundleArtifact extends AbstractArtifact {
}
}
- private ArtifactState mapBundleState(int state) {
+ static ArtifactState mapBundleState(int state) {
if (Bundle.UNINSTALLED == state) {
return ArtifactState.UNINSTALLED;
} else if (Bundle.INSTALLED == 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 74bc65e1..c64c8647 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
@@ -20,6 +20,7 @@ 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;
@@ -42,9 +43,12 @@ public final class BundleDependencyDeterminer implements DependencyDeterminer {
private final RuntimeArtifactRepository artifactRepository;
- public BundleDependencyDeterminer(@NonNull QuasiFrameworkFactory quasiFrameworkFactory, @NonNull RuntimeArtifactRepository artifactRepository) {
+ private final PackageAdminUtil packageAdminUtil;
+
+ public BundleDependencyDeterminer(@NonNull QuasiFrameworkFactory quasiFrameworkFactory, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil) {
this.quasiFrameworkFactory = quasiFrameworkFactory;
this.artifactRepository = artifactRepository;
+ this.packageAdminUtil = packageAdminUtil;
}
/**
@@ -62,7 +66,11 @@ public final class BundleDependencyDeterminer implements DependencyDeterminer {
QuasiExportPackage provider = importPackage.getProvider();
if (provider != null) {
QuasiBundle bundle = provider.getExportingBundle();
- artifacts.add(artifactRepository.getArtifact(BundleArtifact.TYPE, bundle.getSymbolicName(), bundle.getVersion()));
+ Artifact artifact = artifactRepository.getArtifact(BundleArtifact.TYPE, bundle.getSymbolicName(), bundle.getVersion());
+ if (artifact == null) {
+ artifact = new QuasiBundleArtifact(bundle, this.packageAdminUtil);
+ }
+ artifacts.add(artifact);
}
}
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
new file mode 100644
index 00000000..6b227845
--- /dev/null
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/QuasiBundleArtifact.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * 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();
+ }
+
+}
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 7ca61dc8..274663d9 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
@@ -27,6 +27,7 @@
<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"
@@ -35,7 +36,6 @@
</bean>
<bean id="artifactRepository" class="org.eclipse.virgo.kernel.model.internal.NotifyingRuntimeArtifactRepository">
- <constructor-arg ref="bundleContext"/>
<constructor-arg ref="artifactRepositoryListener"/>
</bean>
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java
index 818578cf..fd2e0208 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/NotifyingArtifactRepositoryTests.java
@@ -18,24 +18,14 @@ import static org.junit.Assert.assertTrue;
import java.util.Set;
-import org.osgi.framework.Version;
-
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.StubCompositeArtifact;
-import org.eclipse.virgo.kernel.model.internal.ArtifactRepositoryListener;
-import org.eclipse.virgo.kernel.model.internal.NotifyingRuntimeArtifactRepository;
-import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
-import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.junit.Test;
public class NotifyingArtifactRepositoryTests {
- private StubBundle stubBundle = new StubBundle("org.eclipse.virgo.kernel", new Version("3.0.0"));
-
- private StubBundleContext stubBundleContext = new StubBundleContext(stubBundle);
-
- private final NotifyingRuntimeArtifactRepository artifactRepository = new NotifyingRuntimeArtifactRepository(stubBundleContext);
+ private final NotifyingRuntimeArtifactRepository artifactRepository = new NotifyingRuntimeArtifactRepository();
@Test
public void add() {
@@ -56,7 +46,7 @@ public class NotifyingArtifactRepositoryTests {
public void listeners() {
StubArtifactRepositoryListener listener1 = new StubArtifactRepositoryListener(true);
StubArtifactRepositoryListener listener2 = new StubArtifactRepositoryListener(false);
- NotifyingRuntimeArtifactRepository artifactRepository = new NotifyingRuntimeArtifactRepository(stubBundleContext, listener1, listener2);
+ NotifyingRuntimeArtifactRepository artifactRepository = new NotifyingRuntimeArtifactRepository(listener1, listener2);
StubCompositeArtifact artifact = new StubCompositeArtifact();
artifactRepository.add(artifact);
artifactRepository.remove(artifact.getType(), artifact.getName(), artifact.getVersion());
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 457ec64d..8d4c10fe 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
@@ -28,6 +28,7 @@ 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;
@@ -37,17 +38,24 @@ public class BundleDependencyDeterminerTests {
private final QuasiFrameworkFactory quasiFrameworkFactory = createMock(QuasiFrameworkFactory.class);
private final RuntimeArtifactRepository artifactRepository = new StubArtifactRepository();
+
+ private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
- private final BundleDependencyDeterminer determiner = new BundleDependencyDeterminer(quasiFrameworkFactory, artifactRepository);
+ private final BundleDependencyDeterminer determiner = new BundleDependencyDeterminer(quasiFrameworkFactory, artifactRepository, packageAdminUtil);
@Test(expected = FatalAssertionException.class)
public void nullFactory() {
- new BundleDependencyDeterminer(null, artifactRepository);
+ new BundleDependencyDeterminer(null, artifactRepository, packageAdminUtil);
}
@Test(expected = FatalAssertionException.class)
public void nullRepository() {
- new BundleDependencyDeterminer(quasiFrameworkFactory, null);
+ new BundleDependencyDeterminer(quasiFrameworkFactory, null, packageAdminUtil);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullPackageAdminUtil() {
+ new BundleDependencyDeterminer(quasiFrameworkFactory, artifactRepository, null);
}
@Test

Back to the top