diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java
index b6340af8f..1be1daa15 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ArchivaConfiguration.java
@@ -49,10 +49,25 @@ public interface ArchivaConfiguration
throws RegistryException, IndeterminateConfigurationException;
/**
- * Add a change listener so that registry changes are propogated.
+ * Add a configuration listener to notify of changes to the configuration.
*
* @param listener the listener
*/
+ void addListener( ConfigurationListener listener );
+
+ /**
+ * Remove a configuration listener to stop notifications of changes to the configuration.
+ *
+ * @param listener the listener
+ */
+ void removeListener( ConfigurationListener listener );
+
+ /**
+ * Add a registry listener to notify of events in plexus-registry.
+ *
+ * @param listener the listener
+ * TODO: Remove in future.
+ */
void addChangeListener( RegistryListener listener );
}
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationEvent.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationEvent.java
new file mode 100644
index 000000000..6e9201b00
--- /dev/null
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationEvent.java
@@ -0,0 +1,77 @@
+package org.apache.maven.archiva.configuration;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * ConfigurationEvent
+ *
+ * @author Joakim Erdfelt
+ * @version $Id$
+ */
+public class ConfigurationEvent
+{
+ public static final int SAVED = 1;
+
+ public static final int CHANGED = 2;
+
+ private int type;
+
+ public ConfigurationEvent( int type )
+ {
+ this.type = type;
+ }
+
+ public int getType()
+ {
+ return type;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + type;
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ {
+ return true;
+ }
+ if ( obj == null )
+ {
+ return false;
+ }
+ if ( getClass() != obj.getClass() )
+ {
+ return false;
+ }
+ final ConfigurationEvent other = (ConfigurationEvent) obj;
+ if ( type != other.type )
+ {
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationListener.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationListener.java
new file mode 100644
index 000000000..69945a2fb
--- /dev/null
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationListener.java
@@ -0,0 +1,34 @@
+package org.apache.maven.archiva.configuration;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * ConfigurationListener
+ *
+ * @author Joakim Erdfelt
+ * @version $Id$
+ */
+public interface ConfigurationListener
+{
+ /**
+ * Generic event point to notify components that something has happend in the configuration.
+ */
+ public void configurationEvent(ConfigurationEvent event);
+}
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
index 72d5b6734..95d85ad1d 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
@@ -35,10 +35,11 @@ import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Implementation of configuration holder that retrieves it from the registry.
@@ -84,9 +85,14 @@ public class DefaultArchivaConfiguration
private String userConfigFilename;
/**
- * Listeners we've registered.
+ * Configuration Listeners we've registered.
*/
- private List listeners = new LinkedList();
+ private Set listeners = new HashSet();
+
+ /**
+ * Registry Listeners we've registered.
+ */
+ private Set registryListeners = new HashSet();
public String getFilteredUserConfigFilename()
{
@@ -249,6 +255,8 @@ public class DefaultArchivaConfiguration
new ConfigurationRegistryWriter().write( configuration, section );
section.save();
+
+ triggerEvent( ConfigurationEvent.SAVED );
this.configuration = processExpressions( configuration );
}
@@ -270,28 +278,64 @@ public class DefaultArchivaConfiguration
try
{
( (Initializable) registry ).initialize();
-
- for ( Iterator i = listeners.iterator(); i.hasNext(); )
+
+ for ( RegistryListener regListener: registryListeners )
{
- RegistryListener l = i.next();
-
- addRegistryChangeListener( l );
+ addRegistryChangeListener( regListener );
}
}
catch ( InitializationException e )
{
throw new RegistryException( "Unable to reinitialize configuration: " + e.getMessage(), e );
}
+
+ triggerEvent( ConfigurationEvent.SAVED );
return registry.getSection( KEY + ".user" );
}
+ private void triggerEvent( int type )
+ {
+ 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 );
+ }
+ }
+ }
+
+ public void addListener( ConfigurationListener listener )
+ {
+ if ( listener == null )
+ {
+ return;
+ }
+
+ listeners.add( listener );
+ }
+
+ public void removeListener( ConfigurationListener listener )
+ {
+ if ( listener == null )
+ {
+ return;
+ }
+
+ listeners.remove( listener );
+ }
+
public void addChangeListener( RegistryListener listener )
{
addRegistryChangeListener( listener );
// keep track for later
- listeners.add( listener );
+ registryListeners.add( listener );
}
private void addRegistryChangeListener( RegistryListener listener )
@@ -308,6 +352,7 @@ public class DefaultArchivaConfiguration
}
}
+
public void initialize()
throws InitializationException
{
diff --git a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
index fd4f88b8e..81108ddb9 100644
--- a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
+++ b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
@@ -21,9 +21,7 @@ package org.apache.maven.archiva.configuration;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.registry.Registry;
-import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.plexus.util.FileUtils;
-import org.easymock.AbstractMatcher;
import org.easymock.MockControl;
import java.io.File;
@@ -38,6 +36,7 @@ import java.util.Map;
public class ArchivaConfigurationTest
extends PlexusTestCase
{
+ @SuppressWarnings("unused")
private Registry registry;
protected void setUp()
@@ -108,7 +107,7 @@ public class ArchivaConfigurationTest
assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
- List patterns = filetypes.getFileTypePatterns( "artifacts" );
+ List patterns = filetypes.getFileTypePatterns( "artifacts" );
assertNotNull( "check 'artifacts' file type", patterns );
assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
@@ -192,15 +191,12 @@ public class ArchivaConfigurationTest
configuration.getWebapp().getUi().setAppletFindEnabled( false );
// add a change listener
- MockControl control = createRegistryListenerMockControl();
- RegistryListener listener = (RegistryListener) control.getMock();
- archivaConfiguration.addChangeListener( listener );
-
- listener.beforeConfigurationChange( registry, "version", "1" );
- listener.beforeConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
-
- listener.afterConfigurationChange( registry, "version", "1" );
- listener.afterConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
+ MockControl control = createConfigurationListenerMockControl();
+ ConfigurationListener listener = (ConfigurationListener) control.getMock();
+ archivaConfiguration.addListener( listener );
+
+ listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
+ control.setVoidCallable();
control.replay();
@@ -221,21 +217,9 @@ public class ArchivaConfigurationTest
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
}
- private static MockControl createRegistryListenerMockControl()
+ private static MockControl createConfigurationListenerMockControl()
{
- MockControl control = MockControl.createControl( RegistryListener.class );
- control.setDefaultMatcher( new AbstractMatcher()
- {
- protected boolean argumentMatches( Object object, Object object1 )
- {
- return object instanceof Registry || super.argumentMatches( object, object1 );
- }
-
- protected String argumentToString( Object object )
- {
- return object instanceof Registry ? "" : super.argumentToString( object );
- }
- } );
+ MockControl control = MockControl.createControl( ConfigurationListener.class );
return control;
}
@@ -291,12 +275,13 @@ public class ArchivaConfigurationTest
configuration.getWebapp().getUi().setAppletFindEnabled( false );
// add a change listener
- MockControl control = createRegistryListenerMockControl();
- RegistryListener listener = (RegistryListener) control.getMock();
- archivaConfiguration.addChangeListener( listener );
+ MockControl control = createConfigurationListenerMockControl();
+ ConfigurationListener listener = (ConfigurationListener) control.getMock();
+ archivaConfiguration.addListener( listener );
- listener.beforeConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
- listener.afterConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
+ listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
+ // once from default creation, and again from manual call to save
+ control.setVoidCallable( 2 );
control.replay();
diff --git a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java
index f3d56ae25..d4a123a62 100644
--- a/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java
+++ b/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/MockConfiguration.java
@@ -21,14 +21,14 @@ package org.apache.maven.archiva.indexer;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ConfigurationListener;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.easymock.MockControl;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
/**
* MockConfiguration
@@ -43,7 +43,8 @@ public class MockConfiguration implements ArchivaConfiguration
{
private Configuration configuration = new Configuration();
- private List listeners = new ArrayList();
+ private Set registryListeners = new HashSet();
+ private Set configListeners = new HashSet();
private MockControl registryControl;
@@ -57,7 +58,7 @@ public class MockConfiguration implements ArchivaConfiguration
public void addChangeListener( RegistryListener listener )
{
- listeners.add( listener );
+ registryListeners.add( listener );
}
public Configuration getConfiguration()
@@ -73,10 +74,8 @@ public class MockConfiguration implements ArchivaConfiguration
public void triggerChange( String name, String value )
{
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
+ for(RegistryListener listener: registryListeners)
{
- RegistryListener listener = (RegistryListener) it.next();
try
{
listener.afterConfigurationChange( registryMock, name, value );
@@ -87,4 +86,14 @@ public class MockConfiguration implements ArchivaConfiguration
}
}
}
+
+ public void addListener( ConfigurationListener listener )
+ {
+ configListeners.add(listener);
+ }
+
+ public void removeListener( ConfigurationListener listener )
+ {
+ configListeners.remove( listener );
+ }
}
diff --git a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java
index 69f3ce3f4..08e4d2740 100644
--- a/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java
+++ b/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java
@@ -21,13 +21,14 @@ package org.apache.maven.archiva.proxy;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ConfigurationListener;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.easymock.MockControl;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
/**
* MockConfiguration
@@ -43,7 +44,8 @@ public class MockConfiguration
{
private Configuration configuration = new Configuration();
- private List listeners = new ArrayList();
+ private Set registryListeners = new HashSet();
+ private Set configListeners = new HashSet();
private MockControl registryControl;
@@ -57,7 +59,7 @@ public class MockConfiguration
public void addChangeListener( RegistryListener listener )
{
- listeners.add( listener );
+ registryListeners.add( listener );
}
public Configuration getConfiguration()
@@ -73,7 +75,7 @@ public class MockConfiguration
public void triggerChange( String name, String value )
{
- for( RegistryListener listener: listeners )
+ for(RegistryListener listener: registryListeners)
{
try
{
@@ -85,4 +87,14 @@ public class MockConfiguration
}
}
}
+
+ public void addListener( ConfigurationListener listener )
+ {
+ configListeners.add(listener);
+ }
+
+ public void removeListener( ConfigurationListener listener )
+ {
+ configListeners.remove( listener );
+ }
}
diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java
index 7a58f3bfc..393eb743b 100755
--- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java
+++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/MockConfiguration.java
@@ -21,14 +21,17 @@ package org.apache.maven.archiva.repository;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ConfigurationListener;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.easymock.MockControl;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
/**
* MockConfiguration
@@ -44,7 +47,8 @@ public class MockConfiguration
{
private Configuration configuration = new Configuration();
- private List listeners = new ArrayList();
+ private Set registryListeners = new HashSet();
+ private Set configListeners = new HashSet();
private MockControl registryControl;
@@ -58,7 +62,7 @@ public class MockConfiguration
public void addChangeListener( RegistryListener listener )
{
- listeners.add( listener );
+ registryListeners.add( listener );
}
public Configuration getConfiguration()
@@ -74,10 +78,8 @@ public class MockConfiguration
public void triggerChange( String name, String value )
{
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
+ for(RegistryListener listener: registryListeners)
{
- RegistryListener listener = (RegistryListener) it.next();
try
{
listener.afterConfigurationChange( registryMock, name, value );
@@ -88,4 +90,14 @@ public class MockConfiguration
}
}
}
+
+ public void addListener( ConfigurationListener listener )
+ {
+ configListeners.add(listener);
+ }
+
+ public void removeListener( ConfigurationListener listener )
+ {
+ configListeners.remove( listener );
+ }
}