if ( configuration == null )
{
configuration = load();
- configuration = processExpressions( configuration );
+ configuration = unescapeExpressions( configuration );
}
return configuration;
}
// 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() )
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()
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 );
}
}
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(); )
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();
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();