mirror of https://github.com/apache/archiva.git
Reducing chattiness by adding ConfigurationListener to give option of event on configuration save as a whole, not each field.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@582993 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8af86cd884
commit
25bc854985
|
@ -49,10 +49,25 @@ public interface ArchivaConfiguration
|
||||||
throws RegistryException, IndeterminateConfigurationException;
|
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
|
* @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 );
|
void addChangeListener( RegistryListener listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public interface ConfigurationListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generic event point to notify components that something has happend in the configuration.
|
||||||
|
*/
|
||||||
|
public void configurationEvent(ConfigurationEvent event);
|
||||||
|
}
|
|
@ -35,10 +35,11 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of configuration holder that retrieves it from the registry.
|
* Implementation of configuration holder that retrieves it from the registry.
|
||||||
|
@ -84,9 +85,14 @@ public class DefaultArchivaConfiguration
|
||||||
private String userConfigFilename;
|
private String userConfigFilename;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listeners we've registered.
|
* Configuration Listeners we've registered.
|
||||||
*/
|
*/
|
||||||
private List<RegistryListener> listeners = new LinkedList<RegistryListener>();
|
private Set<ConfigurationListener> listeners = new HashSet<ConfigurationListener>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registry Listeners we've registered.
|
||||||
|
*/
|
||||||
|
private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
|
||||||
|
|
||||||
public String getFilteredUserConfigFilename()
|
public String getFilteredUserConfigFilename()
|
||||||
{
|
{
|
||||||
|
@ -250,6 +256,8 @@ public class DefaultArchivaConfiguration
|
||||||
new ConfigurationRegistryWriter().write( configuration, section );
|
new ConfigurationRegistryWriter().write( configuration, section );
|
||||||
section.save();
|
section.save();
|
||||||
|
|
||||||
|
triggerEvent( ConfigurationEvent.SAVED );
|
||||||
|
|
||||||
this.configuration = processExpressions( configuration );
|
this.configuration = processExpressions( configuration );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,11 +279,9 @@ public class DefaultArchivaConfiguration
|
||||||
{
|
{
|
||||||
( (Initializable) registry ).initialize();
|
( (Initializable) registry ).initialize();
|
||||||
|
|
||||||
for ( Iterator<RegistryListener> i = listeners.iterator(); i.hasNext(); )
|
for ( RegistryListener regListener: registryListeners )
|
||||||
{
|
{
|
||||||
RegistryListener l = i.next();
|
addRegistryChangeListener( regListener );
|
||||||
|
|
||||||
addRegistryChangeListener( l );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( InitializationException e )
|
catch ( InitializationException e )
|
||||||
|
@ -283,15 +289,53 @@ public class DefaultArchivaConfiguration
|
||||||
throw new RegistryException( "Unable to reinitialize configuration: " + e.getMessage(), e );
|
throw new RegistryException( "Unable to reinitialize configuration: " + e.getMessage(), e );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
triggerEvent( ConfigurationEvent.SAVED );
|
||||||
|
|
||||||
return registry.getSection( KEY + ".user" );
|
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 )
|
public void addChangeListener( RegistryListener listener )
|
||||||
{
|
{
|
||||||
addRegistryChangeListener( listener );
|
addRegistryChangeListener( listener );
|
||||||
|
|
||||||
// keep track for later
|
// keep track for later
|
||||||
listeners.add( listener );
|
registryListeners.add( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRegistryChangeListener( RegistryListener listener )
|
private void addRegistryChangeListener( RegistryListener listener )
|
||||||
|
@ -308,6 +352,7 @@ public class DefaultArchivaConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
throws InitializationException
|
throws InitializationException
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,9 +21,7 @@ package org.apache.maven.archiva.configuration;
|
||||||
|
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.registry.Registry;
|
import org.codehaus.plexus.registry.Registry;
|
||||||
import org.codehaus.plexus.registry.RegistryListener;
|
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
import org.easymock.AbstractMatcher;
|
|
||||||
import org.easymock.MockControl;
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -38,6 +36,7 @@ import java.util.Map;
|
||||||
public class ArchivaConfigurationTest
|
public class ArchivaConfigurationTest
|
||||||
extends PlexusTestCase
|
extends PlexusTestCase
|
||||||
{
|
{
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private Registry registry;
|
private Registry registry;
|
||||||
|
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
|
@ -108,7 +107,7 @@ public class ArchivaConfigurationTest
|
||||||
assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
|
assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
|
||||||
assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
|
assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
|
||||||
|
|
||||||
List patterns = filetypes.getFileTypePatterns( "artifacts" );
|
List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
|
||||||
assertNotNull( "check 'artifacts' file type", patterns );
|
assertNotNull( "check 'artifacts' file type", patterns );
|
||||||
assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
|
assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
|
||||||
|
|
||||||
|
@ -192,15 +191,12 @@ public class ArchivaConfigurationTest
|
||||||
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
||||||
|
|
||||||
// add a change listener
|
// add a change listener
|
||||||
MockControl control = createRegistryListenerMockControl();
|
MockControl control = createConfigurationListenerMockControl();
|
||||||
RegistryListener listener = (RegistryListener) control.getMock();
|
ConfigurationListener listener = (ConfigurationListener) control.getMock();
|
||||||
archivaConfiguration.addChangeListener( listener );
|
archivaConfiguration.addListener( listener );
|
||||||
|
|
||||||
listener.beforeConfigurationChange( registry, "version", "1" );
|
listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
|
||||||
listener.beforeConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
control.setVoidCallable();
|
||||||
|
|
||||||
listener.afterConfigurationChange( registry, "version", "1" );
|
|
||||||
listener.afterConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
|
||||||
|
|
||||||
control.replay();
|
control.replay();
|
||||||
|
|
||||||
|
@ -221,21 +217,9 @@ public class ArchivaConfigurationTest
|
||||||
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MockControl createRegistryListenerMockControl()
|
private static MockControl createConfigurationListenerMockControl()
|
||||||
{
|
{
|
||||||
MockControl control = MockControl.createControl( RegistryListener.class );
|
MockControl control = MockControl.createControl( ConfigurationListener.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 ? "<any>" : super.argumentToString( object );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,12 +275,13 @@ public class ArchivaConfigurationTest
|
||||||
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
||||||
|
|
||||||
// add a change listener
|
// add a change listener
|
||||||
MockControl control = createRegistryListenerMockControl();
|
MockControl control = createConfigurationListenerMockControl();
|
||||||
RegistryListener listener = (RegistryListener) control.getMock();
|
ConfigurationListener listener = (ConfigurationListener) control.getMock();
|
||||||
archivaConfiguration.addChangeListener( listener );
|
archivaConfiguration.addListener( listener );
|
||||||
|
|
||||||
listener.beforeConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
|
||||||
listener.afterConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
// once from default creation, and again from manual call to save
|
||||||
|
control.setVoidCallable( 2 );
|
||||||
|
|
||||||
control.replay();
|
control.replay();
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,14 @@ package org.apache.maven.archiva.indexer;
|
||||||
|
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
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.Registry;
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
import org.codehaus.plexus.registry.RegistryException;
|
||||||
import org.codehaus.plexus.registry.RegistryListener;
|
import org.codehaus.plexus.registry.RegistryListener;
|
||||||
import org.easymock.MockControl;
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Set;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MockConfiguration
|
* MockConfiguration
|
||||||
|
@ -43,7 +43,8 @@ public class MockConfiguration implements ArchivaConfiguration
|
||||||
{
|
{
|
||||||
private Configuration configuration = new Configuration();
|
private Configuration configuration = new Configuration();
|
||||||
|
|
||||||
private List listeners = new ArrayList();
|
private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
|
||||||
|
private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
|
||||||
|
|
||||||
private MockControl registryControl;
|
private MockControl registryControl;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ public class MockConfiguration implements ArchivaConfiguration
|
||||||
|
|
||||||
public void addChangeListener( RegistryListener listener )
|
public void addChangeListener( RegistryListener listener )
|
||||||
{
|
{
|
||||||
listeners.add( listener );
|
registryListeners.add( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration getConfiguration()
|
public Configuration getConfiguration()
|
||||||
|
@ -73,10 +74,8 @@ public class MockConfiguration implements ArchivaConfiguration
|
||||||
|
|
||||||
public void triggerChange( String name, String value )
|
public void triggerChange( String name, String value )
|
||||||
{
|
{
|
||||||
Iterator it = listeners.iterator();
|
for(RegistryListener listener: registryListeners)
|
||||||
while ( it.hasNext() )
|
|
||||||
{
|
{
|
||||||
RegistryListener listener = (RegistryListener) it.next();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
listener.afterConfigurationChange( registryMock, name, value );
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,14 @@ package org.apache.maven.archiva.proxy;
|
||||||
|
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
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.Registry;
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
import org.codehaus.plexus.registry.RegistryException;
|
||||||
import org.codehaus.plexus.registry.RegistryListener;
|
import org.codehaus.plexus.registry.RegistryListener;
|
||||||
import org.easymock.MockControl;
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MockConfiguration
|
* MockConfiguration
|
||||||
|
@ -43,7 +44,8 @@ public class MockConfiguration
|
||||||
{
|
{
|
||||||
private Configuration configuration = new Configuration();
|
private Configuration configuration = new Configuration();
|
||||||
|
|
||||||
private List<RegistryListener> listeners = new ArrayList<RegistryListener>();
|
private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
|
||||||
|
private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
|
||||||
|
|
||||||
private MockControl registryControl;
|
private MockControl registryControl;
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ public class MockConfiguration
|
||||||
|
|
||||||
public void addChangeListener( RegistryListener listener )
|
public void addChangeListener( RegistryListener listener )
|
||||||
{
|
{
|
||||||
listeners.add( listener );
|
registryListeners.add( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration getConfiguration()
|
public Configuration getConfiguration()
|
||||||
|
@ -73,7 +75,7 @@ public class MockConfiguration
|
||||||
|
|
||||||
public void triggerChange( String name, String value )
|
public void triggerChange( String name, String value )
|
||||||
{
|
{
|
||||||
for( RegistryListener listener: listeners )
|
for(RegistryListener listener: registryListeners)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -85,4 +87,14 @@ public class MockConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addListener( ConfigurationListener listener )
|
||||||
|
{
|
||||||
|
configListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeListener( ConfigurationListener listener )
|
||||||
|
{
|
||||||
|
configListeners.remove( listener );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,17 @@ package org.apache.maven.archiva.repository;
|
||||||
|
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
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.Registry;
|
||||||
import org.codehaus.plexus.registry.RegistryException;
|
import org.codehaus.plexus.registry.RegistryException;
|
||||||
import org.codehaus.plexus.registry.RegistryListener;
|
import org.codehaus.plexus.registry.RegistryListener;
|
||||||
import org.easymock.MockControl;
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MockConfiguration
|
* MockConfiguration
|
||||||
|
@ -44,7 +47,8 @@ public class MockConfiguration
|
||||||
{
|
{
|
||||||
private Configuration configuration = new Configuration();
|
private Configuration configuration = new Configuration();
|
||||||
|
|
||||||
private List<RegistryListener> listeners = new ArrayList<RegistryListener>();
|
private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
|
||||||
|
private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
|
||||||
|
|
||||||
private MockControl registryControl;
|
private MockControl registryControl;
|
||||||
|
|
||||||
|
@ -58,7 +62,7 @@ public class MockConfiguration
|
||||||
|
|
||||||
public void addChangeListener( RegistryListener listener )
|
public void addChangeListener( RegistryListener listener )
|
||||||
{
|
{
|
||||||
listeners.add( listener );
|
registryListeners.add( listener );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration getConfiguration()
|
public Configuration getConfiguration()
|
||||||
|
@ -74,10 +78,8 @@ public class MockConfiguration
|
||||||
|
|
||||||
public void triggerChange( String name, String value )
|
public void triggerChange( String name, String value )
|
||||||
{
|
{
|
||||||
Iterator<RegistryListener> it = listeners.iterator();
|
for(RegistryListener listener: registryListeners)
|
||||||
while ( it.hasNext() )
|
|
||||||
{
|
{
|
||||||
RegistryListener listener = (RegistryListener) it.next();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
listener.afterConfigurationChange( registryMock, name, value );
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue