Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-03-29 12:04:08 -0400
committerGlyn Normington2011-03-29 12:04:08 -0400
commit0d25116ac552e19442cfc0bdc89951788c5fbc00 (patch)
tree7596028649f9d6b8fd6bdaef78fb4686b3a9bfce
parent5fc7144956b3c515c6556032ed63aa6e2dc675bc (diff)
downloadorg.eclipse.virgo.kernel-0d25116ac552e19442cfc0bdc89951788c5fbc00.tar.gz
org.eclipse.virgo.kernel-0d25116ac552e19442cfc0bdc89951788c5fbc00.tar.xz
org.eclipse.virgo.kernel-0d25116ac552e19442cfc0bdc89951788c5fbc00.zip
bug 336941: state dumping and analysis with region digraph
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/quasi/QuasiFrameworkFactory.java10
-rw-r--r--org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/StateService.java75
-rw-r--r--org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java44
-rw-r--r--org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubQuasiFrameworkFactory.java10
-rw-r--r--org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubStateService.java32
-rw-r--r--org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/QuasiFrameworkStateDumpIntegrationTests.java49
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java25
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/DumpExtractor.java49
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/dump/StandardDumpExtractor.java83
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/equinox/RegionDigraphDumpContributor.java72
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java64
-rw-r--r--org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java21
12 files changed, 391 insertions, 143 deletions
diff --git a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/quasi/QuasiFrameworkFactory.java b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/quasi/QuasiFrameworkFactory.java
index 5bea9b9e..ad5033e4 100644
--- a/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/quasi/QuasiFrameworkFactory.java
+++ b/org.eclipse.virgo.kernel.osgi/src/main/java/org/eclipse/virgo/kernel/osgi/quasi/QuasiFrameworkFactory.java
@@ -12,6 +12,8 @@
package org.eclipse.virgo.kernel.osgi.quasi;
import java.io.File;
+import java.io.IOException;
+import java.util.zip.ZipException;
/**
* {@link QuasiFrameworkFactory} is used to create {@link QuasiFramework QuasiFrameworks}.
@@ -32,11 +34,13 @@ public interface QuasiFrameworkFactory {
QuasiFramework create();
/**
- * Creates a {@link QuasiFramework} from a state dump in the given directory.
+ * Creates a {@link QuasiFramework} from a dump in the given directory.
*
- * @param stateDump a {@link File} containing the state dump directory
+ * @param stateDump a {@link File} containing the dump directory
* @return the <code>QuasiFramework</code>, which is never <code>null</code>
+ * @throws ZipException when unzipping
+ * @throws IOException when reading
*/
- QuasiFramework create(File stateDump);
+ QuasiFramework create(File stateDump) throws ZipException, IOException ;
}
diff --git a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/StateService.java b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/StateService.java
index 64d21ae2..87bf8e60 100644
--- a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/StateService.java
+++ b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/StateService.java
@@ -15,95 +15,84 @@ import java.io.File;
import java.util.List;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
-import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiResolutionFailure;
/**
* <p>
- * <code>StateService</code>
+ * <code>StateService</code>
* </p>
*
* <strong>Concurrent Semantics</strong><br />
*
- * Implementations should be thread-safe.
+ * Implementations must be thread-safe.
*
*/
public interface StateService {
- /**
- * Obtains {@link QuasiBundle} representations of all the bundles present
- * in the underlying state.
- *
- * @param source can be null to request the live state
- * @return all the bundles or the empty list if the source can't be found
- */
+ /**
+ * Obtains {@link QuasiBundle} representations of all the bundles present in the live state or the given dump
+ * directory.
+ *
+ * @param source can be <code>null</code> to request the live state
+ * @return all the bundles or the empty list if the source can't be found
+ */
public List<QuasiBundle> getAllBundles(File source);
/**
- * Obtains {@link QuasiLiveService} representations of all the services present
- * in the underlying osgi instance.
+ * Obtains {@link QuasiLiveService} representations of all the services present in the live state or the given dump
+ * directory.
*
- * @param source can be null to request the live state
+ * @param source can be <code>null</code> to request the live state
* @return all the services or the empty list if the source can't be found
*/
public List<QuasiLiveService> getAllServices(File source);
/**
- * Looks at all the bundles in the underlying state and return the one with
- * the given id, if no such bundle exists then null is returned.
+ * Looks at all the bundles in the live state or the given dump directory and return the one with the given id, if
+ * no such bundle exists then <code>null</code> is returned.
*
- * @param source can be null to request the live state
+ * @param source can be <code>null</code> to request the live state
* @param bundleId of required bundle
- * @return the requested bundle or null
+ * @return the requested bundle or <code>null</code>
*/
public QuasiBundle getBundle(File source, long bundleId);
-
+
/**
- * Returns the {@link QuasiLiveService} that represents the service with
- * the requested service Id. If no such service exists then null is
- * returned.
+ * Returns the {@link QuasiLiveService} that represents the service with the requested service Id in the live state
+ * or the given dump directory. If no such service exists then <code>null</code> is returned.
*
- * @param source can be null to request the live state
+ * @param source can be <code>null</code> to request the live state
* @param serviceId
* @return the service with id serviceId
*/
- public QuasiLiveService getService(File source, long serviceId) ;
-
+ public QuasiLiveService getService(File source, long serviceId);
+
/**
- * Will return {@link QuasiResolutionFailure} for the requested bundle.
- * If there are no resolution failures then null will be returned.
+ * Returns {@link QuasiResolutionFailure} for the requested bundle in the live state or the given dump
+ * directory. If there are no resolution failures then <code>null</code> will be returned.
*
- * @param source can be null to request the live state
+ * @param source can be <code>null</code> to request the live state
* @param bundleId of the fail bundle
* @return <code>QuasiResolutionFailure</code>
*/
public List<QuasiResolutionFailure> getResolverReport(File source, long bundleId);
-
- /**
- * Installs a bundle into the requested {@link QuasiFramework} using the given
- * {@link String} location and returns a {@link QuasiBundle}.
- *
- * @param source can be null to request the live state
- * @param location
- * @return the bundle installed
- */
- public QuasiBundle installBundle(File source, String location);
-
+
/**
+ * Returns the {@link QuasiPackage QuasiPackages} with the given name in the live state or the given dump directory.
*
- * @param source can be null to request the live state
+ * @param source can be <code>null</code> to request the live state
* @param packageName to find
* @return the package found
*/
public QuasiPackage getPackages(File source, String packageName);
-
+
/**
- * Search the requested state for bundles matching the given string
+ * Searches the live state or the given dump directory for bundles matching the given string.
*
- * @param source can be null to request the live state
+ * @param source can be <code>null</code> to request the live state
* @param term to search for
* @return a list of matched bundles
*/
public List<QuasiBundle> search(File source, String term);
-
+
}
diff --git a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java
index 0fc2da6d..1d4d5cef 100644
--- a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java
+++ b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/state/internal/StandardStateService.java
@@ -29,15 +29,17 @@ import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.shell.state.QuasiLiveService;
import org.eclipse.virgo.kernel.shell.state.QuasiPackage;
import org.eclipse.virgo.kernel.shell.state.StateService;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.springframework.util.AntPathMatcher;
/**
- *
+ * {@link StandardStateService} is the default implementation of {@link StateService}.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * Thread safe.
*/
final public class StandardStateService implements StateService {
@@ -65,6 +67,7 @@ final public class StandardStateService implements StateService {
/**
* {@inheritDoc}
*/
+ @Override
public List<QuasiBundle> getAllBundles(File source) {
List<QuasiBundle> bundles = this.getQuasiFramework(source).getBundles();
if (source == null) {
@@ -88,6 +91,7 @@ final public class StandardStateService implements StateService {
/**
* {@inheritDoc}
*/
+ @Override
public QuasiBundle getBundle(File source, long bundleId) {
return this.getQuasiFramework(source).getBundle(bundleId);
}
@@ -95,6 +99,7 @@ final public class StandardStateService implements StateService {
/**
* {@inheritDoc}
*/
+ @Override
public List<QuasiLiveService> getAllServices(File source) {
List<QuasiLiveService> quasiLiveServices = new ArrayList<QuasiLiveService>();
if (source == null) {
@@ -131,6 +136,7 @@ final public class StandardStateService implements StateService {
/**
* {@inheritDoc}
*/
+ @Override
public QuasiLiveService getService(File source, long serviceId) {
if (source == null) {
SortedMap<Long, QuasiLiveService> services = getServicesSortedMap(this.getQuasiFramework(source));
@@ -142,6 +148,7 @@ final public class StandardStateService implements StateService {
/**
* {@inheritDoc}
*/
+ @Override
public List<QuasiResolutionFailure> getResolverReport(File source, long bundleId) {
QuasiFramework framework = this.getQuasiFramework(source);
return framework.diagnose(bundleId);
@@ -150,29 +157,7 @@ final public class StandardStateService implements StateService {
/**
* {@inheritDoc}
*/
- public QuasiBundle installBundle(File source, String location) {
- if (source != null) {
- throw new IllegalStateException("Unable to install a bundle in to a non-live state.");
- }
- Bundle installBundle = null;
- try {
- installBundle = this.bundleContext.installBundle(location);
- } catch (BundleException e) {
- throw new IllegalStateException(String.format("Unable to install the bundle '%s'.", e.getMessage()), e);
- }
- if (installBundle == null) {
- return null;
- }
- QuasiFramework framework = this.getQuasiFramework(null);
- if (framework == null) {
- return null;
- }
- return framework.getBundle(installBundle.getBundleId());
- }
-
- /**
- * {@inheritDoc}
- */
+ @Override
public QuasiPackage getPackages(File source, String packageName) {
QuasiFramework framework = this.getQuasiFramework(source);
if (packageName != null) {
@@ -197,6 +182,7 @@ final public class StandardStateService implements StateService {
/**
* {@inheritDoc}
*/
+ @Override
public List<QuasiBundle> search(File source, String term) {
QuasiFramework framework = this.getQuasiFramework(source);
List<QuasiBundle> matchingBundles = new ArrayList<QuasiBundle>();
@@ -218,7 +204,11 @@ final public class StandardStateService implements StateService {
if (source == null) {
return new StandardQuasiLiveFramework(this.quasiFrameworkFactory.create(), this.bundleContext);
} else {
- return this.quasiFrameworkFactory.create(source);
+ try {
+ return this.quasiFrameworkFactory.create(source);
+ } catch (Exception e) {
+ throw new RuntimeException("Error creating quasi-framework", e);
+ }
}
}
diff --git a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubQuasiFrameworkFactory.java b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubQuasiFrameworkFactory.java
index ef3c6b3a..4eab1d96 100644
--- a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubQuasiFrameworkFactory.java
+++ b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubQuasiFrameworkFactory.java
@@ -20,12 +20,20 @@ import org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory;
*/
public class StubQuasiFrameworkFactory implements QuasiFrameworkFactory {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public QuasiFramework create() {
return new StubQuasiFramework();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public QuasiFramework create(File arg0) {
return new StubQuasiFramework();
}
-
+
}
diff --git a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubStateService.java b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubStateService.java
index 458f44be..5c32c4cc 100644
--- a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubStateService.java
+++ b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/stubs/StubStateService.java
@@ -30,14 +30,26 @@ public class StubStateService implements StateService {
private StubQuasiLiveBundle stubQuasiBundle = new StubQuasiLiveBundle(STUB_STATE_BUNDLE_ID, new StubBundle());
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public List<QuasiBundle> getAllBundles(File source) {
return new ArrayList<QuasiBundle>();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public List<QuasiLiveService> getAllServices(File source) {
return new ArrayList<QuasiLiveService>();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public QuasiBundle getBundle(File source, long bundleId) {
if (bundleId == stubQuasiBundle.getBundleId()) {
return this.stubQuasiBundle;
@@ -46,22 +58,34 @@ public class StubStateService implements StateService {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public List<QuasiResolutionFailure> getResolverReport(File source, long bundleId) {
return new ArrayList<QuasiResolutionFailure>();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public QuasiLiveService getService(File source, long serviceId) {
return new StubQuasiLiveService(STUB_STATE_SERVICE_ID, this.stubQuasiBundle);
}
- public QuasiBundle installBundle(File source, String location) {
- return this.stubQuasiBundle;
- }
-
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public QuasiPackage getPackages(File source, String packageName) {
return new StubQuasiPackage(packageName);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public List<QuasiBundle> search(File source, String term) {
ArrayList<QuasiBundle> arrayList = new ArrayList<QuasiBundle>();
if (term.contains("*")) {
diff --git a/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/QuasiFrameworkStateDumpIntegrationTests.java b/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/QuasiFrameworkStateDumpIntegrationTests.java
index c238c264..cc9bb3f4 100644
--- a/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/QuasiFrameworkStateDumpIntegrationTests.java
+++ b/org.eclipse.virgo.kernel.test/src/test/java/org/eclipse/virgo/kernel/osgi/test/QuasiFrameworkStateDumpIntegrationTests.java
@@ -12,21 +12,11 @@
package org.eclipse.virgo.kernel.osgi.test;
import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.zip.ZipException;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Version;
import org.eclipse.virgo.kernel.osgi.framework.OsgiFrameworkUtils;
import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
@@ -34,10 +24,14 @@ 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.test.AbstractKernelIntegrationTest;
-import org.eclipse.virgo.util.io.PathReference;
-import org.eclipse.virgo.util.io.ZipUtils;
import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Version;
/**
*/
@@ -82,7 +76,7 @@ public class QuasiFrameworkStateDumpIntegrationTests extends AbstractKernelInteg
File dump = newFileSet.iterator().next();
- QuasiFramework stateDump = this.quasiFrameworkFactory.create(getStateDump(dump));
+ QuasiFramework stateDump = this.quasiFrameworkFactory.create(dump);
List<QuasiBundle> bundles = stateDump.getBundles();
boolean found = false;
for (QuasiBundle quasiBundle : bundles) {
@@ -94,35 +88,6 @@ public class QuasiFrameworkStateDumpIntegrationTests extends AbstractKernelInteg
}
- private File getStateDump(File dump) throws ZipException, IOException {
- File stateDump;
- Assert.assertFalse(dump == null);
- File[] stateDumpZipFiles = dump.listFiles(new FilenameFilter() {
-
- public boolean accept(File dir, String name) {
- return name.equals("osgi.zip");
- }
- });
- Assert.assertEquals(1, stateDumpZipFiles.length);
- File stateDumpZipFile = stateDumpZipFiles[0];
-
- stateDump = unzip(stateDumpZipFile);
- return stateDump;
- }
-
- private File unzip(File stateDumpZipFile) throws IOException {
- PathReference zipFile = new PathReference(stateDumpZipFile);
- String stateDumpFileName = getTmpDir();
- PathReference dest = new PathReference(stateDumpFileName);
- ZipUtils.unzipTo(zipFile, dest);
- return dest.newChild("state").toFile();
- }
-
- private static String getTmpDir() {
- return System.getProperty("java.io.tmpdir") + File.separator + QuasiFrameworkStateDumpIntegrationTests.class.getSimpleName()
- + System.currentTimeMillis();
- }
-
private Set<File> getDumpFiles() {
Set<File> oldFileSet = null;
{
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java
index e82de778..14ede535 100644
--- a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/Activator.java
@@ -32,9 +32,12 @@ import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.services.work.WorkArea;
import org.eclipse.virgo.kernel.shim.scope.ScopeFactory;
+import org.eclipse.virgo.kernel.userregion.internal.dump.StandardDumpExtractor;
import org.eclipse.virgo.kernel.userregion.internal.equinox.EquinoxHookRegistrar;
import org.eclipse.virgo.kernel.userregion.internal.equinox.EquinoxOsgiFramework;
+import org.eclipse.virgo.kernel.userregion.internal.equinox.RegionDigraphDumpContributor;
import org.eclipse.virgo.kernel.userregion.internal.equinox.ResolutionDumpContributor;
import org.eclipse.virgo.kernel.userregion.internal.equinox.StandardPackageAdminUtil;
import org.eclipse.virgo.kernel.userregion.internal.equinox.TransformedManifestProvidingBundleFileWrapper;
@@ -96,7 +99,9 @@ public class Activator implements BundleActivator {
EventLogger eventLogger = OsgiFrameworkUtils.getService(context, EventLoggerFactory.class).getService().createEventLogger(context.getBundle());
RegionDigraph regionDigraph = OsgiFrameworkUtils.getService(context, RegionDigraph.class).getService();
-
+
+ WorkArea workArea = OsgiFrameworkUtils.getService(context, WorkArea.class).getService();
+
ImportExpansionHandler importExpansionHandler = createImportExpansionHandler(context, packageAdmin, repository, eventLogger);
this.registrationTracker.track(context.registerService(ImportExpander.class.getName(), importExpansionHandler, null));
@@ -105,10 +110,14 @@ public class Activator implements BundleActivator {
OsgiFramework osgiFramework = createOsgiFramework(context, packageAdmin, bundleTransformerHandler);
this.registrationTracker.track(context.registerService(OsgiFramework.class.getName(), osgiFramework, null));
- DumpContributor dumpContributor = createResolutionDumpContributor(context);
- this.registrationTracker.track(context.registerService(DumpContributor.class.getName(), dumpContributor, null));
+ DumpContributor resolutionDumpContributor = createResolutionDumpContributor(context);
+ this.registrationTracker.track(context.registerService(DumpContributor.class.getName(), resolutionDumpContributor, null));
+
+ DumpContributor regionDigraphDumpContributor = createRegionDigraphDumpContributor(context);
+ this.registrationTracker.track(context.registerService(DumpContributor.class.getName(), regionDigraphDumpContributor, null));
- QuasiFrameworkFactory quasiFrameworkFactory = createQuasiFrameworkFactory(context, rfd, repository, bundleTransformerHandler, regionDigraph);
+ DumpExtractor dumpExtractor = new StandardDumpExtractor(workArea);
+ QuasiFrameworkFactory quasiFrameworkFactory = createQuasiFrameworkFactory(context, rfd, repository, bundleTransformerHandler, regionDigraph, dumpExtractor);
this.registrationTracker.track(context.registerService(QuasiFrameworkFactory.class.getName(), quasiFrameworkFactory, null));
EquinoxHookRegistrar hookRegistrar = createHookRegistrar(context, packageAdmin, bundleTransformerHandler);
@@ -141,9 +150,13 @@ public class Activator implements BundleActivator {
return new ResolutionDumpContributor(bundleContext);
}
+ private DumpContributor createRegionDigraphDumpContributor(BundleContext bundleContext) {
+ return new RegionDigraphDumpContributor(bundleContext);
+ }
+
private QuasiFrameworkFactory createQuasiFrameworkFactory(BundleContext bundleContext, ResolutionFailureDetective detective,
- Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformerHandler, RegionDigraph regionDigraph) {
- return new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleTransformerHandler, regionDigraph);
+ Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformerHandler, RegionDigraph regionDigraph, DumpExtractor dumpExtractor) {
+ return new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleTransformerHandler, regionDigraph, dumpExtractor);
}
private TransformedManifestProvidingBundleFileWrapper createBundleTransformationHandler(ImportExpansionHandler importExpander) {
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/DumpExtractor.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/DumpExtractor.java
new file mode 100644
index 00000000..71c9652c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/DumpExtractor.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 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.userregion.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.zip.ZipException;
+
+/**
+ * <p>
+ * DumpExtractor provides an interface for clients to obtain state dumps and region digraph dumps.
+ * </p>
+ *
+ * <strong>Concurrent Semantics</strong><br/>
+ *
+ * Implementations of this interface must be thread safe.
+ *
+ */
+public interface DumpExtractor {
+
+ /**
+ * Returns an unzipped version of the state dump zip file from the given dump directory.
+ *
+ * @param dumpDir dump directory
+ * @return the unzipped state dump file
+ * @throws ZipException when unzipping
+ * @throws IOException when reading
+ */
+ public File getStateDump(File dumpDir) throws ZipException, IOException;
+
+ /**
+ * Returns a region digraph dump file from the given dump directory.
+ *
+ * @param dumpDir dump directory
+ * @return the region digraph dump file
+ * @throws IOException when reading
+ */
+ public File getRegionDigraphDump(File dumpDir) throws IOException;
+
+}
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/dump/StandardDumpExtractor.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/dump/StandardDumpExtractor.java
new file mode 100644
index 00000000..9fd4f22e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/dump/StandardDumpExtractor.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 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.userregion.internal.dump;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.zip.ZipException;
+
+import org.eclipse.virgo.kernel.services.work.WorkArea;
+import org.eclipse.virgo.kernel.userregion.internal.DumpExtractor;
+import org.eclipse.virgo.util.io.FileSystemUtils;
+import org.eclipse.virgo.util.io.PathReference;
+import org.eclipse.virgo.util.io.ZipUtils;
+
+/**
+ * <p>
+ * DumpStateExtractor can extract the OSGi state from a dump directory and place it in a staging location for use by
+ * clients of this class. It can also locate the region digraph dump in a dump directory.
+ * </p>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Thread safe.
+ *
+ */
+public final class StandardDumpExtractor implements DumpExtractor {
+
+ private final File stagingDir;
+
+ /**
+ * @param workArea to extract dumps to
+ */
+ public StandardDumpExtractor(WorkArea workArea) {
+ this.stagingDir = workArea.getWorkDirectory().newChild("extracted-state-dumps").createDirectory().toFile();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public File getStateDump(File dump) throws ZipException, IOException {
+ File stateDumpZipFile = getDumpFile(dump, "osgi.zip");
+
+ return unzip(stateDumpZipFile);
+ }
+
+ private File getDumpFile(File dumpDirectory, final String fileName) throws IOException {
+ if (dumpDirectory == null) {
+ throw new IllegalArgumentException("Requested dump cannot be null");
+ }
+
+ File[] dumpFiles = FileSystemUtils.listFiles(dumpDirectory, new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ return name.equals(fileName);
+ }
+ });
+ if (dumpFiles.length != 1) {
+ throw new IOException(String.format("Exactly one dump file with name '%s' expected, found '%s'", fileName, dumpFiles.length));
+ }
+ return dumpFiles[0];
+ }
+
+ private File unzip(File stateDumpZipFile) throws IOException {
+ PathReference zipFile = new PathReference(stateDumpZipFile);
+ PathReference dest = new PathReference(this.stagingDir);
+ return new File(ZipUtils.unzipTo(zipFile, dest).toFile(), "state");
+ }
+
+ public File getRegionDigraphDump(File dump) throws IOException {
+ return getDumpFile(dump, "region.digraph");
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/equinox/RegionDigraphDumpContributor.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/equinox/RegionDigraphDumpContributor.java
new file mode 100644
index 00000000..7a320c9b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/equinox/RegionDigraphDumpContributor.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.userregion.internal.equinox;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.serviceability.NonNull;
+import org.eclipse.virgo.medic.dump.Dump;
+import org.eclipse.virgo.medic.dump.DumpContributionFailedException;
+import org.eclipse.virgo.medic.dump.DumpContributor;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * {@link RegionDigraphDumpContributor} dumps the {@link RegionDigraph} to a file.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * Thread safe.
+ */
+public final class RegionDigraphDumpContributor implements DumpContributor {
+
+ private final BundleContext bundleContext;
+
+ public RegionDigraphDumpContributor(@NonNull BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void contribute(Dump dump) throws DumpContributionFailedException {
+ File outputFile = dump.createFile("region.digraph");
+ ServiceReference<RegionDigraph> serviceReference = this.bundleContext.getServiceReference(RegionDigraph.class);
+ RegionDigraph regionDigraph = this.bundleContext.getService(serviceReference);
+ try {
+ OutputStream output = new FileOutputStream(outputFile);
+ try {
+ regionDigraph.getRegionDigraphPersistence().save(regionDigraph, output);
+ } finally {
+ output.close();
+ }
+ } catch (Exception e) {
+ throw new DumpContributionFailedException("Failed to dump region digraph", e);
+ } finally {
+ this.bundleContext.ungetService(serviceReference);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getName() {
+ return "region digraph";
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java
index 78297c9f..ddc732cb 100644
--- a/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java
+++ b/org.eclipse.virgo.kernel.userregion/src/main/java/org/eclipse/virgo/kernel/userregion/internal/quasi/StandardQuasiFrameworkFactory.java
@@ -14,7 +14,10 @@ package org.eclipse.virgo.kernel.userregion.internal.quasi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipException;
import org.eclipse.osgi.internal.baseadaptor.StateManager;
import org.eclipse.osgi.service.resolver.PlatformAdmin;
@@ -25,6 +28,8 @@ import org.eclipse.virgo.kernel.osgi.framework.OsgiServiceHolder;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
import org.eclipse.virgo.kernel.osgi.quasi.QuasiFrameworkFactory;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
+import org.eclipse.virgo.kernel.osgi.region.RegionDigraphPersistence;
+import org.eclipse.virgo.kernel.userregion.internal.DumpExtractor;
import org.eclipse.virgo.kernel.userregion.internal.equinox.TransformedManifestProvidingBundleFileWrapper;
import org.eclipse.virgo.repository.Repository;
import org.eclipse.virgo.util.io.FileSystemUtils;
@@ -52,15 +57,18 @@ public final class StandardQuasiFrameworkFactory implements QuasiFrameworkFactor
private final StateManager stateManager;
- private ResolutionFailureDetective detective;
+ private final ResolutionFailureDetective detective;
private final Repository repository;
-
+
private final TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler;
- private final RegionDigraph userRegion;
+ private final RegionDigraph regionDigraph;
+
+ private final DumpExtractor dumpExtractor;
- public StandardQuasiFrameworkFactory(BundleContext bundleContext, ResolutionFailureDetective detective, Repository repository, TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler, RegionDigraph regionDigraph) {
+ public StandardQuasiFrameworkFactory(BundleContext bundleContext, ResolutionFailureDetective detective, Repository repository,
+ TransformedManifestProvidingBundleFileWrapper bundleTransformationHandler, RegionDigraph regionDigraph, DumpExtractor dumpExtractor) {
this.bundleContext = bundleContext;
this.platformAdmin = getPlatformAdminService(bundleContext);
this.detective = detective;
@@ -68,44 +76,68 @@ public final class StandardQuasiFrameworkFactory implements QuasiFrameworkFactor
ServiceReference<PlatformAdmin> platformAdminServiceReference = bundleContext.getServiceReference(PlatformAdmin.class);
this.stateManager = (StateManager) bundleContext.getService(platformAdminServiceReference);
this.bundleTransformationHandler = bundleTransformationHandler;
- this.userRegion = regionDigraph;
+ this.regionDigraph = regionDigraph;
+ this.dumpExtractor = dumpExtractor;
}
/**
* {@inheritDoc}
*/
public QuasiFramework create() {
- return new StandardQuasiFramework(this.bundleContext, createState(), this.platformAdmin, this.detective, this.repository, this.bundleTransformationHandler, this.userRegion);
+ return new StandardQuasiFramework(this.bundleContext, createState(), this.platformAdmin, this.detective, this.repository,
+ this.bundleTransformationHandler, this.regionDigraph);
}
/**
* {@inheritDoc}
*/
- public QuasiFramework create(File stateDump) {
- return new StandardQuasiFramework(this.bundleContext, readStateDump(stateDump), this.platformAdmin, this.detective, this.repository, this.bundleTransformationHandler, this.userRegion);
+ @Override
+ public QuasiFramework create(File dumpDirName) throws ZipException, IOException {
+ return create(this.dumpExtractor.getStateDump(dumpDirName), this.dumpExtractor.getRegionDigraphDump(dumpDirName));
+ }
+
+ private QuasiFramework create(File stateDump, File regionDigraphDump) {
+ return new StandardQuasiFramework(this.bundleContext, readStateDump(stateDump), this.platformAdmin, this.detective, this.repository,
+ this.bundleTransformationHandler, readRegionDigraphDump(regionDigraphDump));
+ }
+
+ private RegionDigraph readRegionDigraphDump(File regionDigraphDump) {
+ RegionDigraphPersistence regionDigraphPersistence = this.regionDigraph.getRegionDigraphPersistence();
+ RegionDigraph digraph;
+ try {
+ InputStream input = new FileInputStream(regionDigraphDump);
+ try {
+ digraph = regionDigraphPersistence.load(input);
+ } finally {
+ input.close();
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to read region digraph dump", e);
+ }
+ return digraph;
}
@SuppressWarnings("deprecation")
- private State createState() {
+ private State createState() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
+
State state;
-
+
try {
this.platformAdmin.getFactory().writeState(this.stateManager.getSystemState(), baos);
state = this.platformAdmin.getFactory().readState(new ByteArrayInputStream(baos.toByteArray()));
} catch (IOException ioe) {
throw new RuntimeException("Failed to create a copy of the OSGi state", ioe);
}
-
+
if (state.getResolver() == null) {
state.setResolver(this.platformAdmin.createResolver());
}
-
+
if (!state.isResolved()) {
state.resolve(true);
}
-
+
return state;
}
@@ -133,7 +165,7 @@ public final class StandardQuasiFrameworkFactory implements QuasiFrameworkFactor
}
}
}
-
+
if (state.getResolver() == null) {
state.setResolver(this.platformAdmin.createResolver());
}
@@ -141,7 +173,7 @@ public final class StandardQuasiFrameworkFactory implements QuasiFrameworkFactor
if (!state.isResolved()) {
state.resolve(true);
}
-
+
return state;
}
diff --git a/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java b/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
index 4106ed06..d34b9796 100644
--- a/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
+++ b/org.eclipse.virgo.kernel.userregion/src/test/java/org/eclipse/virgo/kernel/userregion/internal/equinox/AbstractOsgiFrameworkLaunchingTests.java
@@ -31,6 +31,9 @@ import org.eclipse.virgo.kernel.osgi.region.Region;
import org.eclipse.virgo.kernel.osgi.region.RegionDigraph;
import org.eclipse.virgo.kernel.osgi.region.internal.StandardRegionDigraph;
import org.eclipse.virgo.kernel.services.repository.internal.RepositoryFactoryBean;
+import org.eclipse.virgo.kernel.services.work.WorkArea;
+import org.eclipse.virgo.kernel.userregion.internal.DumpExtractor;
+import org.eclipse.virgo.kernel.userregion.internal.dump.StandardDumpExtractor;
import org.eclipse.virgo.kernel.userregion.internal.importexpansion.ImportExpansionHandler;
import org.eclipse.virgo.kernel.userregion.internal.quasi.StandardQuasiFrameworkFactory;
import org.eclipse.virgo.kernel.userregion.internal.quasi.StandardResolutionFailureDetective;
@@ -45,8 +48,10 @@ import org.eclipse.virgo.repository.Repository;
import org.eclipse.virgo.repository.RepositoryFactory;
import org.eclipse.virgo.repository.internal.RepositoryBundleActivator;
import org.eclipse.virgo.util.io.FileSystemUtils;
+import org.eclipse.virgo.util.io.PathReference;
import org.junit.After;
import org.junit.Before;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -157,7 +162,21 @@ public abstract class AbstractOsgiFrameworkLaunchingTests {
PluggableClassLoadingHook.getInstance().setClassLoaderCreator(new KernelClassLoaderCreator());
StandardResolutionFailureDetective detective = new StandardResolutionFailureDetective(platformAdmin);
- this.quasiFramework = new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleFileWrapper, regionDigraph).create();
+
+ WorkArea workArea = new WorkArea() {
+
+ @Override
+ public Bundle getOwner() {
+ return bundleContext.getBundle();
+ }
+
+ @Override
+ public PathReference getWorkDirectory() {
+ return new PathReference(new File("target/work"));
+ }
+ };
+ DumpExtractor dumpExtractor = new StandardDumpExtractor(workArea);
+ this.quasiFramework = new StandardQuasiFrameworkFactory(bundleContext, detective, repository, bundleFileWrapper, regionDigraph, dumpExtractor).create();
}
private ImportExpander createImportExpander(PackageAdmin packageAdmin) {

Back to the top