felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r553090 - in /felix/trunk/configadmin/src: main/java/org/apache/felix/cm/file/FilePersistenceManager.java test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java
Date Wed, 04 Jul 2007 06:14:43 GMT
Author: fmeschbe
Date: Tue Jul  3 23:14:42 2007
New Revision: 553090

URL: http://svn.apache.org/viewvc?view=rev&rev=553090
Log:
FELIX-316 Configuration Admin should use the bundle data storage area by default.
   Cope with BundleContext.getDataFile() returning a relative File

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java?view=diff&rev=553090&r1=553089&r2=553090
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
Tue Jul  3 23:14:42 2007
@@ -254,13 +254,11 @@
      */
     public FilePersistenceManager( BundleContext bundleContext, String location )
     {
-        File locationFile = null;
-
         // no configured location, use the config dir in the bundle persistent
         // area
         if ( location == null && bundleContext != null )
         {
-            locationFile = bundleContext.getDataFile( DEFAULT_CONFIG_DIR );
+            File locationFile = bundleContext.getDataFile( DEFAULT_CONFIG_DIR );
             if ( locationFile != null )
             {
                 location = locationFile.getAbsolutePath();
@@ -274,13 +272,8 @@
             location = System.getProperty( "user.dir" ) + "/config";
         }
 
-        // ensure the File object for the location (may have been set already)
-        if ( locationFile == null )
-        {
-            locationFile = new File( location );
-        }
-
         // ensure the file is absolute
+        File locationFile = new File( location );
         if ( !locationFile.isAbsolute() )
         {
             if ( bundleContext != null )

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java?view=diff&rev=553090&r1=553089&r2=553090
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java
(original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/FilePersistenceManagerConstructorTest.java
Tue Jul  3 23:14:42 2007
@@ -51,17 +51,17 @@
         
         // with null
         fpm = new FilePersistenceManager(null);
-        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile()
);
+        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR) );
         
         // with a relative path
         relPath = "test";
         fpm = new FilePersistenceManager(relPath);
-        assertFpm(fpm, new File(relPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(relPath) );
         
         // with an absolute path
         absPath = new File("test").getAbsolutePath();
         fpm = new FilePersistenceManager(absPath);
-        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(absPath) );
     }
 
 
@@ -75,22 +75,23 @@
         FilePersistenceManager fpm;
         String relPath;
         String absPath;
+        File dataArea;
         
         // first suite: no BundleContext at all
         
         // with null
         fpm = new FilePersistenceManager(null);
-        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile()
);
+        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR) );
         
         // with a relative path
         relPath = "test";
         fpm = new FilePersistenceManager(relPath);
-        assertFpm(fpm, new File(relPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(relPath) );
         
         // with an absolute path
         absPath = new File("test").getAbsolutePath();
         fpm = new FilePersistenceManager(absPath);
-        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(absPath) );
         
         
         // second suite: BundleContext without data file
@@ -98,41 +99,59 @@
         
         // with null
         fpm = new FilePersistenceManager(bundleContext, null);
-        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile()
);
+        assertFpm(fpm, new File(FilePersistenceManager.DEFAULT_CONFIG_DIR) );
         
         // with a relative path
         relPath = "test";
         fpm = new FilePersistenceManager(bundleContext, relPath);
-        assertFpm(fpm, new File(relPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(relPath) );
         
         // with an absolute path
         absPath = new File("test").getAbsolutePath();
         fpm = new FilePersistenceManager(bundleContext, absPath);
-        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(absPath) );
 
         
-        // third suite: BundleContext with data file
-        File dataArea = new File("bundleData");
+        // third suite: BundleContext with relative data file
+        dataArea = new File("bundleData");
         bundleContext = new FilePersistenceManagerBundleContext(dataArea);
         
         // with null
         fpm = new FilePersistenceManager(bundleContext, null);
-        assertFpm(fpm, new File(dataArea, FilePersistenceManager.DEFAULT_CONFIG_DIR).getAbsoluteFile()
);
+        assertFpm(fpm, new File(dataArea, FilePersistenceManager.DEFAULT_CONFIG_DIR) );
         
         // with a relative path
         relPath = "test";
         fpm = new FilePersistenceManager(bundleContext, relPath);
-        assertFpm(fpm, new File(dataArea, relPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(dataArea, relPath) );
         
         // with an absolute path
         absPath = new File("test").getAbsolutePath();
         fpm = new FilePersistenceManager(bundleContext, absPath);
-        assertFpm(fpm, new File(absPath).getAbsoluteFile() );
+        assertFpm(fpm, new File(absPath) );
+
+        // fourth suite: BundleContext with absolute data file
+        dataArea = new File("bundleData").getAbsoluteFile();
+        bundleContext = new FilePersistenceManagerBundleContext(dataArea);
+        
+        // with null
+        fpm = new FilePersistenceManager(bundleContext, null);
+        assertFpm(fpm, new File(dataArea, FilePersistenceManager.DEFAULT_CONFIG_DIR) );
+        
+        // with a relative path
+        relPath = "test";
+        fpm = new FilePersistenceManager(bundleContext, relPath);
+        assertFpm(fpm, new File(dataArea, relPath) );
+        
+        // with an absolute path
+        absPath = new File("test").getAbsolutePath();
+        fpm = new FilePersistenceManager(bundleContext, absPath);
+        assertFpm(fpm, new File(absPath) );
     }
 
     
     private void assertFpm(FilePersistenceManager fpm, File expected) {
-        assertEquals( expected, fpm.getLocation() );
+        assertEquals( expected.getAbsoluteFile(), fpm.getLocation() );
     }
     
     private static final class FilePersistenceManagerBundleContext extends MockBundleContext
{
@@ -141,7 +160,7 @@
         
         private FilePersistenceManagerBundleContext( File dataArea )
         {
-            this.dataArea = (dataArea != null) ? dataArea.getAbsoluteFile() : null;
+            this.dataArea = dataArea;
         }
         
         public File getDataFile( String path )



Mime
View raw message