You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2008/10/09 17:54:32 UTC

svn commit: r703190 - in /felix/trunk: framework/src/main/java/org/apache/felix/framework/cache/ main/ main/src/main/java/org/apache/felix/main/ main/src/main/resources/

Author: rickhall
Date: Thu Oct  9 08:54:32 2008
New Revision: 703190

URL: http://svn.apache.org/viewvc?rev=703190&view=rev
Log:
Modified the bundle cache to no longer have profiles. Instead, it defaults
to creating a directory called "felix-cache" in the current working directory.
Added a config property to specify the precise location of the cache directory,
as well as a property to control the root directory for creating cache
directories if a relative cache directory is specified. Modified main to
deal with the changes; main is no longer interactive. However, it now accepts
a single argument, which is the bundle cache directory to use. (FELIX-754)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
    felix/trunk/main/pom.xml
    felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
    felix/trunk/main/src/main/resources/config.properties
    felix/trunk/main/src/main/resources/default.properties

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java?rev=703190&r1=703189&r2=703190&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/BundleCache.java Thu Oct  9 08:54:32 2008
@@ -73,17 +73,16 @@
 public class BundleCache
 {
     public static final String CACHE_BUFSIZE_PROP = "felix.cache.bufsize";
-    public static final String CACHE_DIR_PROP = "felix.cache.dir";
-    public static final String CACHE_PROFILE_DIR_PROP = "felix.cache.profiledir";
-    public static final String CACHE_PROFILE_PROP = "felix.cache.profile";
+    public static final String CACHE_ROOTDIR_PROP = "felix.cache.rootdir";
 
     protected static transient int BUFSIZE = 4096;
-    protected static transient final String CACHE_DIR_NAME = ".felix";
+    protected static transient final String CACHE_DIR_NAME = "felix-cache";
+    protected static transient final String CACHE_ROOTDIR_DEFAULT = ".";
     protected static transient final String BUNDLE_DIR_PREFIX = "bundle";
 
     private Map m_configMap = null;
     private Logger m_logger = null;
-    private File m_profileDir = null;
+    private File m_cacheDir = null;
     private BundleArchive[] m_archives = null;
 
     private static SecureAction m_secureAction = new SecureAction();
@@ -138,7 +137,7 @@
     {
         // Construct archive root directory.
         File archiveRootDir =
-            new File(m_profileDir, BUNDLE_DIR_PREFIX + Long.toString(id));
+            new File(m_cacheDir, BUNDLE_DIR_PREFIX + Long.toString(id));
 
         try
         {
@@ -203,7 +202,7 @@
     public synchronized File getSystemBundleDataFile(String fileName) throws Exception
     {
         // Make sure system bundle directory exists.
-        File sbDir = new File(m_profileDir, BUNDLE_DIR_PREFIX + Long.toString(0));
+        File sbDir = new File(m_cacheDir, BUNDLE_DIR_PREFIX + Long.toString(0));
 
         // If the system bundle directory exists, then we don't
         // need to initialize since it has already been done.
@@ -300,68 +299,46 @@
             // Use the default value.
         }
 
-        // See if the profile directory is specified.
-        String profileDirStr = (String) m_configMap.get(CACHE_PROFILE_DIR_PROP);
-        profileDirStr = (profileDirStr == null)
-            ? (String) m_configMap.get(SystemBundle.FRAMEWORK_STORAGE_PROP)
-            : profileDirStr;
-        if (profileDirStr != null)
-        {
-            m_profileDir = new File(profileDirStr);
+        // Check to see if the cache directory is specified in the storage
+        // configuration property.
+        String cacheDirStr = (String) m_configMap.get(SystemBundle.FRAMEWORK_STORAGE_PROP);
+        // Get the cache root directory for relative paths; the default is ".".
+        String rootDirStr = (String) m_configMap.get(CACHE_ROOTDIR_PROP);
+        rootDirStr = (rootDirStr == null) ? CACHE_ROOTDIR_DEFAULT : rootDirStr;
+        if (cacheDirStr != null)
+        {
+            // If the specified cache directory is relative, then use the
+            // root directory to calculate the absolute path.
+            m_cacheDir = new File(cacheDirStr);
+            if (!m_cacheDir.isAbsolute())
+            {
+                m_cacheDir = new File(rootDirStr, cacheDirStr);
+            }
         }
         else
         {
-            // Since no profile directory was specified, then the profile
-            // directory will be a directory in the cache directory named
-            // after the profile.
-
-            // First, determine the location of the cache directory; it
-            // can either be specified or in the default location.
-            String cacheDirStr = (String) m_configMap.get(CACHE_DIR_PROP);
-            if (cacheDirStr == null)
-            {
-                // Since no cache directory was specified, put it
-                // ".felix" in the user's home by default.
-                cacheDirStr = System.getProperty("user.home");
-                cacheDirStr = cacheDirStr.endsWith(File.separator)
-                    ? cacheDirStr : cacheDirStr + File.separator;
-                cacheDirStr = cacheDirStr + CACHE_DIR_NAME;
-            }
-
-            // Now, get the profile name.
-            String profileName = (String) m_configMap.get(CACHE_PROFILE_PROP);
-            if (profileName == null)
-            {
-                throw new IllegalArgumentException(
-                    "No profile name or directory has been specified.");
-            }
-            // Profile name cannot contain the File.separator char.
-            else if (profileName.indexOf(File.separator) >= 0)
-            {
-                throw new IllegalArgumentException(
-                    "The profile name cannot contain the file separator character.");
-            }
-
-            m_profileDir = new File(cacheDirStr, profileName);
+            // If no cache directory was specified, then use the default name
+            // in the root directory.
+            m_cacheDir = new File(rootDirStr, CACHE_DIR_NAME);
         }
 
-        // Create profile directory, if it does not exist.
-        if (!getSecureAction().fileExists(m_profileDir))
+        // Create the cache directory, if it does not exist.
+        if (!getSecureAction().fileExists(m_cacheDir))
         {
-            if (!getSecureAction().mkdirs(m_profileDir))
+            if (!getSecureAction().mkdirs(m_cacheDir))
             {
                 m_logger.log(
                     Logger.LOG_ERROR,
-                    getClass().getName() + ": Unable to create directory: "
-                        + m_profileDir);
-                throw new RuntimeException("Unable to create profile directory.");
+                    getClass().getName() + ": Unable to create cache directory: "
+                        + m_cacheDir);
+                throw new RuntimeException("Unable to create cache directory.");
             }
         }
 
         // Create the existing bundle archives in the profile directory,
         // if any exist.
         List archiveList = new ArrayList();
-        File[] children = getSecureAction().listDirectory(m_profileDir);
+        File[] children = getSecureAction().listDirectory(m_cacheDir);
         for (int i = 0; (children != null) && (i < children.length); i++)
         {
             // Ignore directories that aren't bundle directories or

Modified: felix/trunk/main/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/main/pom.xml?rev=703190&r1=703189&r2=703190&view=diff
==============================================================================
--- felix/trunk/main/pom.xml (original)
+++ felix/trunk/main/pom.xml Thu Oct  9 08:54:32 2008
@@ -88,6 +88,7 @@
   </dependencies>
   <properties>
     <property name="install.home" value="${basedir.absolutePath}" />
+    <dollar>$</dollar>
   </properties>
   <build>
     <plugins>
@@ -112,7 +113,6 @@
                  so that we only have to maintain one set of properties
                  and only for that reason. -->
             <_include>src/main/resources/config.properties</_include>
-            <dollar>$</dollar>
           </instructions>
         </configuration>
       </plugin>

Modified: felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/java/org/apache/felix/main/Main.java?rev=703190&r1=703189&r2=703190&view=diff
==============================================================================
--- felix/trunk/main/src/main/java/org/apache/felix/main/Main.java (original)
+++ felix/trunk/main/src/main/java/org/apache/felix/main/Main.java Thu Oct  9 08:54:32 2008
@@ -166,8 +166,16 @@
      * @throws Exception If an error occurs.
     **/
 
-    public static void main(String[] argv) throws Exception
+    public static void main(String[] args) throws Exception
     {
+        // We support at most one argument, which is the bundle
+        // cache directory.
+        if (args.length > 1)
+        {
+            System.out.println("Usage: [<bundle-cache-dir>]");
+            System.exit(0);
+        }
+
         // Load system properties.
         Main.loadSystemProperties();
 
@@ -177,55 +185,17 @@
         // Copy framework properties from the system properties.
         Main.copySystemProperties(configProps);
 
-        // See if the profile name property was specified.
-        String profileName = configProps.getProperty(BundleCache.CACHE_PROFILE_PROP);
-
-        // See if the profile directory property was specified.
-        String profileDirName = configProps.getProperty(BundleCache.CACHE_PROFILE_DIR_PROP);
-        profileDirName = (profileDirName == null)
-            ? configProps.getProperty(SystemBundle.FRAMEWORK_STORAGE_PROP)
-            : profileDirName;
+        // If there is a passed in bundle cache directory, then
+        // that overwrites anything in the config file.
+        if (args.length > 0)
+        {
+            configProps.setProperty(SystemBundle.FRAMEWORK_STORAGE_PROP, args[0]);
+        }
 
         // Print welcome banner.
         System.out.println("\nWelcome to Felix.");
         System.out.println("=================\n");
 
-        // If no profile or profile directory is specified in the
-        // properties, then ask for a profile name.
-        if ((profileName == null) && (profileDirName == null))
-        {
-            System.out.print("Enter profile name: ");
-            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
-            try
-            {
-                profileName = in.readLine();
-            }
-            catch (IOException ex)
-            {
-                System.err.println("Could not read input.");
-                System.exit(-1);
-            }
-            System.out.println("");
-
-            // On some platforms readLine() can return null, such as when
-            // control-C is pressed, so check for that case.
-            if (profileName == null)
-            {
-                profileName = "";
-            }
-            else if (profileName.length() != 0)
-            {
-                configProps.setProperty(BundleCache.CACHE_PROFILE_PROP, profileName);
-            }
-        }
-
-        // A profile directory or name must be specified.
-        if ((profileDirName == null) && (profileName.length() == 0))
-        {
-            System.err.println("You must specify a profile name or directory.");
-            System.exit(-1);
-        }
-
         try
         {
             // Create a list for custom framework activators and

Modified: felix/trunk/main/src/main/resources/config.properties
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/resources/config.properties?rev=703190&r1=703189&r2=703190&view=diff
==============================================================================
--- felix/trunk/main/src/main/resources/config.properties (original)
+++ felix/trunk/main/src/main/resources/config.properties Thu Oct  9 08:54:32 2008
@@ -25,8 +25,22 @@
  org.osgi.util.tracker; version=1.3.3 \
  ${jre-${java.specification.version}}
 
+# The following property makes specified packages from the class path
+# available to all bundles. You should avoid using this property.
 #org.osgi.framework.bootdelegation=sun.*,com.sun.*
-#felix.cache.profile=foo
+
+# The following property explicitly specifies the location of the bundle
+# cache, which defaults to "felix-cache" in the current working directory.
+# If this value is not absolute, then the felix.cache.rootdir controls
+# how the absolute location is calculated. (See next property)
+#org.osgi.framework.storage=${felix.cache.rootdir}/felix-cache
+
+# The following property is used to convert a relative bundle cache
+# location into an absolute one by specifying the root to prepend to
+# the relative cache path. The default for this property is the
+# current working directory.
+#felix.cache.rootdir=${dollar}{user.dir}
+
 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 \

Modified: felix/trunk/main/src/main/resources/default.properties
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/resources/default.properties?rev=703190&r1=703189&r2=703190&view=diff
==============================================================================
--- felix/trunk/main/src/main/resources/default.properties (original)
+++ felix/trunk/main/src/main/resources/default.properties Thu Oct  9 08:54:32 2008
@@ -25,12 +25,33 @@
  org.osgi.util.tracker; version=1.3.3 \
  ${dollar}{jre-${dollar}{java.specification.version}}
 
+# The following property makes specified packages from the class path
+# available to all bundles. You should avoid using this property.
 #org.osgi.framework.bootdelegation=sun.*,com.sun.*
-#felix.cache.profile=foo
+
+# The following property explicitly specifies the location of the bundle
+# cache, which defaults to "felix-cache" in the current working directory.
+# If this value is not absolute, then the felix.cache.rootdir controls
+# how the absolute location is calculated. (See next property)
+#org.osgi.framework.storage=${felix.cache.rootdir}/felix-cache
+
+# The following property is used to convert a relative bundle cache
+# location into an absolute one by specifying the root to prepend to
+# the relative cache path. The default for this property is the
+# current working directory.
+#felix.cache.rootdir=${dollar}{user.dir}
+
 felix.log.level=4
 felix.startlevel.framework=1
 felix.startlevel.bundle=1
-#framework.service.urlhandlers=false
+
+# Invalid fragment bundles throw an 'exception' by default, but
+# uncomment the follow line to have them log a 'warning' instead.
+#felix.fragment.validation=warning
+
+# Felix installs a stream and content handler factories by default,
+# uncomment the following line to not install them.
+#felix.service.urlhandlers=false
 
 #
 # Java platform package export properties.