]> source.dussan.org Git - archiva.git/commitdiff
[MRM-758] cron expressions with a comma are not being scheduled after configuration...
authorBrett Porter <brett@apache.org>
Mon, 31 Mar 2008 05:52:18 +0000 (05:52 +0000)
committerBrett Porter <brett@apache.org>
Mon, 31 Mar 2008 05:52:18 +0000 (05:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@642886 13f79535-47bb-0310-9956-ffa450edef68

archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml
archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java

index d7aac869145a3f0e2d9e487f074086a5a98a5397..6fd182987005a4ae6c53dec29bef4740899f79ea 100644 (file)
@@ -141,7 +141,7 @@ public class DefaultArchivaConfiguration
         if ( configuration == null )
         {
             configuration = load();
-            configuration = processExpressions( configuration );
+            configuration = unescapeExpressions( configuration );
         }
 
         return configuration;
@@ -428,19 +428,7 @@ public class DefaultArchivaConfiguration
         }
 
         // escape all cron expressions to handle ','
-        for ( Iterator<ManagedRepositoryConfiguration> i = configuration.getManagedRepositories().iterator(); i
-            .hasNext(); )
-        {
-            ManagedRepositoryConfiguration c = i.next();
-            c.setRefreshCronExpression( escapeCronExpression( c.getRefreshCronExpression() ) );
-        }
-
-        if ( configuration.getDatabaseScanning() != null )
-        {
-            configuration.getDatabaseScanning().setCronExpression(
-                                                                   escapeCronExpression( configuration
-                                                                       .getDatabaseScanning().getCronExpression() ) );
-        }
+        escapeCronExpressions( configuration );
 
         // [MRM-661] Due to a bug in the modello registry writer, we need to take these out by hand. They'll be put back by the writer.
         if ( configuration.getManagedRepositories().isEmpty() )
@@ -489,9 +477,23 @@ public class DefaultArchivaConfiguration
         new ConfigurationRegistryWriter().write( configuration, section );
         section.save();
 
+        this.configuration = unescapeExpressions( configuration );
+
         triggerEvent( ConfigurationEvent.SAVED );
+    }
 
-        this.configuration = processExpressions( configuration );
+    private void escapeCronExpressions( Configuration configuration )
+    {
+        for ( ManagedRepositoryConfiguration c : (List<ManagedRepositoryConfiguration>) configuration.getManagedRepositories() )
+        {
+            c.setRefreshCronExpression( escapeCronExpression( c.getRefreshCronExpression() ) );
+        }
+
+        DatabaseScanningConfiguration scanning = configuration.getDatabaseScanning();
+        if ( scanning != null )
+        {
+            scanning.setCronExpression( escapeCronExpression( scanning.getCronExpression() ) );
+        }
     }
 
     private Registry createDefaultConfigurationFile()
@@ -559,14 +561,7 @@ public class DefaultArchivaConfiguration
         ConfigurationEvent evt = new ConfigurationEvent( type );
         for ( ConfigurationListener listener : listeners )
         {
-            try
-            {
-                listener.configurationEvent( evt );
-            }
-            catch ( Throwable t )
-            {
-                getLogger().warn( "Unable to notify of saved configuration event.", t );
-            }
+            listener.configurationEvent( evt );
         }
     }
 
@@ -661,7 +656,7 @@ public class DefaultArchivaConfiguration
         return StringUtils.replace( cronExpression, ",", "\\," );
     }
 
-    private Configuration processExpressions( Configuration config )
+    private Configuration unescapeExpressions( Configuration config )
     {
         // TODO: for commons-configuration 1.3 only
         for ( Iterator<ManagedRepositoryConfiguration> i = config.getManagedRepositories().iterator(); i.hasNext(); )
index 48de2878df9cb4c3f1eb2c4c2fb0b28ada895a81..547e8c0b5324d91fe607a5251525fa7eec421237 100644 (file)
@@ -26,7 +26,7 @@
       <location>file://${appserver.base}/repositories/internal</location>
       <releases>false</releases>
       <snapshots>true</snapshots>
-      <refreshCronExpression>0 0\,30 * * ?</refreshCronExpression>
+      <refreshCronExpression>0 0\,30 * * ?</refreshCronExpression>
     </managedRepository>
   </managedRepositories>
   <databaseScanning>
index 623e3e44b4b06a5e16f8761ea1ddcbf6c9ffa6bd..fd71f4792813e36682ba3b2f0099f49b324bd838 100644 (file)
@@ -608,7 +608,7 @@ public class ArchivaConfigurationTest
         userFile.getParentFile().mkdirs();
         FileUtils.fileWrite( userFile.getAbsolutePath(), "<configuration/>" );
 
-        ArchivaConfiguration archivaConfiguration =
+        final ArchivaConfiguration archivaConfiguration =
             (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-cron-expressions" );
 
         Configuration configuration = archivaConfiguration.getConfiguration();
@@ -616,10 +616,28 @@ public class ArchivaConfigurationTest
         ManagedRepositoryConfiguration repository =
             (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
 
-        assertEquals( "check cron expression", "0 0,30 * * ?", repository.getRefreshCronExpression().trim() );
+        assertEquals( "check cron expression", "0 0,30 * * ?", repository.getRefreshCronExpression().trim() );
 
         configuration.getDatabaseScanning().setCronExpression( "0 0,15 0 * * ?" );
 
+        // add a test listener to confirm it doesn't see the escaped format. We don't need to test the number of calls,
+        // etc. as it's done in other tests
+        archivaConfiguration.addListener( new ConfigurationListener()
+        {
+            public void configurationEvent( ConfigurationEvent event )
+            {
+                assertEquals( ConfigurationEvent.SAVED, event.getType() );
+
+                Configuration configuration = archivaConfiguration.getConfiguration();
+
+                ManagedRepositoryConfiguration repository =
+                    (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 );
+
+                assertEquals( "check cron expression", "0 0,15 0 * * ?",
+                              configuration.getDatabaseScanning().getCronExpression() );
+            }
+        } );
+
         archivaConfiguration.save( configuration );
 
         configuration = archivaConfiguration.getConfiguration();