commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r764689 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java test/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
Date Tue, 14 Apr 2009 07:09:17 GMT
Author: rgoers
Date: Tue Apr 14 07:09:16 2009
New Revision: 764689

URL: http://svn.apache.org/viewvc?rev=764689&view=rev
Log:
Fix NPE when no ReloadingStrategy and enable detection of newly created files.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestVFSConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java?rev=764689&r1=764688&r2=764689&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
Tue Apr 14 07:09:16 2009
@@ -92,6 +92,9 @@
     /** The Logger name to use */
     private String loggerName = "";
 
+    /** The Reloading strategy to use on created configurations */
+    private ReloadingStrategy fileStrategy;
+
     /**
      * Default Constructor.
      */
@@ -156,6 +159,16 @@
         this.attributeSplittingDisabled = attributeSplittingDisabled;
     }
 
+    public ReloadingStrategy getReloadingStrategy()
+    {
+        return fileStrategy;
+    }
+
+    public void setReloadingStrategy(ReloadingStrategy strategy)
+    {
+        this.fileStrategy = strategy;
+    }
+
     /**
      * Set to true if an empty Configuration should be returned when loading fails. If
      * false an exception will be thrown.
@@ -669,36 +682,35 @@
         }
 
         XMLConfiguration configuration = new XMLConfiguration();
-        try
+
+        if (loggerName != null)
         {
-            if (loggerName != null)
+            Log log = LogFactory.getLog(loggerName);
+            if (log != null)
             {
-                Log log = LogFactory.getLog(loggerName);
-                if (log != null)
-                {
-                    configuration.setLogger(log);
-                }
+                configuration.setLogger(log);
             }
-            configuration.setBasePath(getBasePath());
-            configuration.setFileName(path);
-            configuration.setFileSystem(getFileSystem());
-            configuration.setExpressionEngine(getExpressionEngine());
-            configuration.setReloadingStrategy(createReloadingStrategy());
-            configuration.setDelimiterParsingDisabled(isDelimiterParsingDisabled());
-            configuration.setValidating(validating);
-            configuration.setSchemaValidation(schemaValidation);
-            configuration.setAttributeSplittingDisabled(attributeSplittingDisabled);
-            configuration.setListDelimiter(getListDelimiter());
-            configuration.addConfigurationListener(this);
-            configuration.addErrorListener(this);
+        }
+        configuration.setBasePath(getBasePath());
+        configuration.setFileName(path);
+        configuration.setFileSystem(getFileSystem());
+        configuration.setExpressionEngine(getExpressionEngine());
+        ReloadingStrategy strategy = createReloadingStrategy();
+        if (strategy != null)
+        {
+            configuration.setReloadingStrategy(strategy);
+        }
+        configuration.setDelimiterParsingDisabled(isDelimiterParsingDisabled());
+        configuration.setValidating(validating);
+        configuration.setSchemaValidation(schemaValidation);
+        configuration.setAttributeSplittingDisabled(attributeSplittingDisabled);
+        configuration.setListDelimiter(getListDelimiter());
+        configuration.addConfigurationListener(this);
+        configuration.addErrorListener(this);
+
+        try
+        {
             configuration.load();
-            synchronized (configurationsMap)
-            {
-                if (!configurationsMap.containsKey(path))
-                {
-                    configurationsMap.put(path, configuration);
-                }
-            }
         }
         catch (ConfigurationException ce)
         {
@@ -707,6 +719,13 @@
                 throw new ConfigurationRuntimeException(ce);
             }
         }
+        synchronized (configurationsMap)
+        {
+            if (!configurationsMap.containsKey(path))
+            {
+                configurationsMap.put(path, configuration);
+            }
+        }
 
         return configuration;
     }
@@ -717,13 +736,13 @@
      */
     private ReloadingStrategy createReloadingStrategy()
     {
-        if (getReloadingStrategy() == null)
+        if (fileStrategy == null)
         {
             return null;
         }
         try
         {
-            ReloadingStrategy strategy = (ReloadingStrategy) BeanUtils.cloneBean(getReloadingStrategy());
+            ReloadingStrategy strategy = (ReloadingStrategy) BeanUtils.cloneBean(fileStrategy);
             strategy.setConfiguration(null);
             return strategy;
         }
@@ -733,4 +752,5 @@
         }
 
     }
+
 }

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestVFSConfigurationBuilder.java?rev=764689&r1=764688&r2=764689&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
Tue Apr 14 07:09:16 2009
@@ -929,7 +929,7 @@
                     if (conf instanceof FileSystemBased)
                     {
                         assertTrue("Incorrect file system for Configuration " + conf,
-                            ((FileSystemBased)conf).getFileSystem() == fs); 
+                            ((FileSystemBased)conf).getFileSystem() == fs);
                     }
                 }
             }
@@ -973,12 +973,12 @@
         }
     }
 
-    public void testFileMonitor() throws Exception
+    public void testFileMonitor1() throws Exception
     {
-
         // create a new configuration
         File input = new File("target/test-classes/testMultiConfiguration_1001.xml");
         File output = new File("target/test-classes/testwrite/testMultiConfiguration_1001.xml");
+        output.delete();
         output.getParentFile().mkdir();
         copyFile(input, output);
 
@@ -998,8 +998,37 @@
         // Let FileMonitor detect the change.
         Thread.sleep(2000);
         verify("1001", config, 50);
+        output.delete();
+    }
+
+    public void testFileMonitor2() throws Exception
+    {
+        // create a new configuration
+        File input = new File("target/test-classes/testMultiConfiguration_1002.xml");
+        File output = new File("target/test-classes/testwrite/testMultiConfiguration_1002.xml");
+        output.delete();
+
+        factory.setFile(FILEMONITOR_FILE);
+        FileSystem.resetDefaultFileSystem();
+        System.getProperties().remove("Id");
+
+        CombinedConfiguration config = factory.getConfiguration(true);
+        assertNotNull(config);
+
+        verify("1002", config, 50);
+        Thread.sleep(1000);
+
+        output.getParentFile().mkdir();
+        copyFile(input, output);
+
+        // Allow time for the monitor to notice the change.
+        Thread.sleep(2000);
+        verify("1002", config, 25);
+        output.delete();
     }
 
+
+
     private void copyFile(File input, File output) throws IOException
     {
         Reader reader = new FileReader(input);



Mime
View raw message