From cff6df20a475658f0853e3db6781d200fb337b78 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 31 Mar 2008 05:52:18 +0000 Subject: [PATCH] [MRM-758] cron expressions with a comma are not being scheduled after configuration save git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@642886 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultArchivaConfiguration.java | 43 ++++++++----------- .../src/test/conf/escape-cron-expressions.xml | 2 +- .../ArchivaConfigurationTest.java | 22 +++++++++- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java index d7aac8691..6fd182987 100644 --- a/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java @@ -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 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) 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 i = config.getManagedRepositories().iterator(); i.hasNext(); ) diff --git a/archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml b/archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml index 48de2878d..547e8c0b5 100644 --- a/archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml +++ b/archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/escape-cron-expressions.xml @@ -26,7 +26,7 @@ file://${appserver.base}/repositories/internal false true - 0 0\,30 * * ? + 0 0\,30 * * * ? diff --git a/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java index 623e3e44b..fd71f4792 100644 --- a/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java +++ b/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java @@ -608,7 +608,7 @@ public class ArchivaConfigurationTest userFile.getParentFile().mkdirs(); FileUtils.fileWrite( userFile.getAbsolutePath(), "" ); - 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(); -- 2.39.5