Implements support for flushing the cache on framework initialization.
(FELIX-755)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@703502 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 6a79f4e..79375f5 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -685,6 +685,25 @@
throw new BundleException("Error creating bundle cache.", ex);
}
+ // If this is the first time init is called, check to see if
+ // we need to flush the bundle cache.
+ if (state == Bundle.INSTALLED)
+ {
+ String flush = (String) m_configMap.get(Constants.FRAMEWORK_STORAGE_CLEAN);
+ if ((flush != null)
+ && flush.equalsIgnoreCase(Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT))
+ {
+ try
+ {
+ m_cache.flush();
+ }
+ catch (Exception ex)
+ {
+ throw new BundleException("Unable to flush bundle cache.", ex);
+ }
+ }
+ }
+
// Initialize installed bundle data structures.
m_installedBundleMap = new HashMap();
m_installedBundleIndex = new TreeMap();
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java b/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
index e8da6ae..d9cc7db 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
@@ -100,6 +100,19 @@
return m_secureAction;
}
+ public synchronized void flush() throws Exception
+ {
+ // Dispose of all existing archives.
+ for (int i = 0; (m_archives != null) && (i < m_archives.length); i++)
+ {
+ m_archives[i].dispose();
+ }
+ // Delete the cache directory.
+ deleteDirectoryTree(m_cacheDir);
+ // Reinitialize the cache.
+ initialize();
+ }
+
public synchronized BundleArchive[] getArchives()
throws Exception
{
diff --git a/main/src/main/java/org/apache/felix/main/Main.java b/main/src/main/java/org/apache/felix/main/Main.java
index ce007da..8540813 100644
--- a/main/src/main/java/org/apache/felix/main/Main.java
+++ b/main/src/main/java/org/apache/felix/main/Main.java
@@ -465,10 +465,7 @@
e.hasMoreElements(); )
{
String key = (String) e.nextElement();
- if (key.startsWith("felix.") ||
- key.equals("org.osgi.framework.system.packages") ||
- key.equals("org.osgi.framework.storage") ||
- key.equals("org.osgi.framework.bootdelegation"))
+ if (key.startsWith("felix.") || key.startsWith("org.osgi.framework."))
{
configProps.setProperty(key, System.getProperty(key));
}
diff --git a/main/src/main/resources/config.properties b/main/src/main/resources/config.properties
index 9b2d9cc..6857aae 100644
--- a/main/src/main/resources/config.properties
+++ b/main/src/main/resources/config.properties
@@ -41,6 +41,11 @@
# current working directory.
#felix.cache.rootdir=${dollar}{user.dir}
+# The following property controls whether the bundle cache is flushed
+# the first time the framework is initialized. Possible values are
+# "none" and "onFirstInit"; the default is "none".
+#org.osgi.framework.storage.clean=onFirstInit
+
felix.auto.start.1= \
file:bundle/org.apache.felix.shell-1.1.0-SNAPSHOT.jar \
file:bundle/org.apache.felix.shell.tui-1.1.0-SNAPSHOT.jar \