mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-04 19:30:51 +01:00
remove old style listeners in favor of event bus
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
/**
|
||||
* Callback listener for setting properties that are changed.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T> the type of configuration.
|
||||
*/
|
||||
public interface ConfigChangedListener<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* This method is called when a configuration has changed
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param config - the changed configuration object
|
||||
*/
|
||||
public void configChanged(T config);
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Base interface for all objects have support for listeners.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T> type of the listeners
|
||||
*/
|
||||
public interface ListenerSupport<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Register a listener.
|
||||
*
|
||||
*
|
||||
* @param listener to register
|
||||
*/
|
||||
public void addListener(T listener);
|
||||
|
||||
/**
|
||||
* Register a {@link java.util.Collection} of listeners.
|
||||
*
|
||||
*
|
||||
* @param listeners to register
|
||||
*/
|
||||
public void addListeners(Collection<T> listeners);
|
||||
|
||||
/**
|
||||
* Unregister a listener.
|
||||
*
|
||||
*
|
||||
* @param listener to unregister
|
||||
*/
|
||||
public void removeListener(T listener);
|
||||
}
|
||||
@@ -41,8 +41,6 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.ListenerSupport;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.xml.XmlSetStringAdapter;
|
||||
|
||||
@@ -72,7 +70,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
@XmlRootElement(name = "scm-config")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ScmConfiguration
|
||||
implements ListenerSupport<ConfigChangedListener<ScmConfiguration>>
|
||||
{
|
||||
|
||||
/** Default JavaScript date format */
|
||||
@@ -96,33 +93,6 @@ public class ScmConfiguration
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Register a {@link sonia.scm.ConfigChangedListener}
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(ConfigChangedListener<ScmConfiguration> listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link java.util.Collection} of {@link sonia.scm.ConfigChangedListener}
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(
|
||||
Collection<ConfigChangedListener<ScmConfiguration>> listeners)
|
||||
{
|
||||
listeners.addAll(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link sonia.scm.ConfigChangedListener#configChanged(Object)}
|
||||
* method of all registered listeners.
|
||||
@@ -134,16 +104,6 @@ public class ScmConfiguration
|
||||
logger.debug("fire config changed event");
|
||||
}
|
||||
|
||||
for (ConfigChangedListener listener : listeners)
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("call listener {}", listener.getClass().getName());
|
||||
}
|
||||
|
||||
listener.configChanged(this);
|
||||
}
|
||||
|
||||
// fire event to event bus
|
||||
ScmEventBus.getInstance().post(new ScmConfigurationChangedEvent(this));
|
||||
}
|
||||
@@ -176,18 +136,6 @@ public class ScmConfiguration
|
||||
this.loginAttemptLimitTimeout = other.loginAttemptLimitTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a listener object.
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(ConfigChangedListener listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -659,11 +607,6 @@ public class ScmConfiguration
|
||||
/** Field description */
|
||||
private String proxyUser;
|
||||
|
||||
/** Configuration change listeners */
|
||||
@XmlTransient
|
||||
private Set<ConfigChangedListener> listeners =
|
||||
new HashSet<ConfigChangedListener>();
|
||||
|
||||
/** Field description */
|
||||
private boolean enableRepositoryArchive = false;
|
||||
|
||||
|
||||
@@ -40,10 +40,6 @@ import sonia.scm.event.ScmEventBus;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link GroupManager} implementations. This class
|
||||
* implements the listener methods of the {@link GroupManager} interface.
|
||||
@@ -54,61 +50,13 @@ public abstract class AbstractGroupManager implements GroupManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Register a {@link GroupListener}.
|
||||
*
|
||||
*
|
||||
* @param listener {@link GroupListener} to register
|
||||
*/
|
||||
@Override
|
||||
public void addListener(GroupListener listener)
|
||||
{
|
||||
listenerSet.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link java.util.Collection} of {@link GroupListener}s.
|
||||
*
|
||||
*
|
||||
* @param listeners listeners to register
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<GroupListener> listeners)
|
||||
{
|
||||
listenerSet.addAll(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove specified {@link GroupListener}.
|
||||
*
|
||||
*
|
||||
* @param listener to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(GroupListener listener)
|
||||
{
|
||||
listenerSet.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link GroupListener#onEvent(Group,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link GroupEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
* Send a {@link GroupEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param group group that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
protected void fireEvent(Group group, HandlerEvent event)
|
||||
{
|
||||
for (GroupListener listener : listenerSet)
|
||||
{
|
||||
listener.onEvent(group, event);
|
||||
}
|
||||
|
||||
ScmEventBus.getInstance().post(new GroupEvent(group, event));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** registered listeners */
|
||||
private Set<GroupListener> listenerSet = new HashSet<GroupListener>();
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.group;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
|
||||
/**
|
||||
* Listener for group events. {@link GroupListener} can be registered with
|
||||
* {@link sonia.scm.plugin.ext.Extension} annotation or with the
|
||||
* {@link GroupManager#addListener(java.lang.Object)}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@ExtensionPoint
|
||||
public interface GroupListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Called when a group change event is fired.
|
||||
*
|
||||
*
|
||||
* @param group that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
public void onEvent(Group group, HandlerEvent event);
|
||||
}
|
||||
@@ -35,7 +35,6 @@ package sonia.scm.group;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ListenerSupport;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.search.Searchable;
|
||||
|
||||
@@ -50,8 +49,7 @@ import java.util.Collection;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface GroupManager
|
||||
extends Manager<Group, GroupException>, Searchable<Group>,
|
||||
ListenerSupport<GroupListener>
|
||||
extends Manager<Group, GroupException>, Searchable<Group>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,42 +66,6 @@ public class GroupManagerDecorator
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(GroupListener listener)
|
||||
{
|
||||
decorated.addListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<GroupListener> listeners)
|
||||
{
|
||||
decorated.addListeners(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(GroupListener listener)
|
||||
{
|
||||
decorated.removeListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
@@ -148,5 +112,5 @@ public class GroupManagerDecorator
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private GroupManager decorated;
|
||||
private final GroupManager decorated;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ package sonia.scm.repository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.NotSupportedFeatuerException;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.store.Store;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
|
||||
@@ -60,7 +60,7 @@ import java.util.Set;
|
||||
* @param <C>
|
||||
*/
|
||||
public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig>
|
||||
implements RepositoryHandler
|
||||
implements RepositoryHandler
|
||||
{
|
||||
|
||||
/** the logger for AbstractRepositoryHandler */
|
||||
@@ -92,30 +92,6 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(ConfigChangedListener listener)
|
||||
{
|
||||
listenerSet.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<ConfigChangedListener> listeners)
|
||||
{
|
||||
listenerSet.addAll(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -156,18 +132,6 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
|
||||
config = store.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(ConfigChangedListener listener)
|
||||
{
|
||||
listenerSet.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -198,7 +162,6 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -211,7 +174,7 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
|
||||
public ImportHandler getImportHandler() throws NotSupportedFeatuerException
|
||||
{
|
||||
throw new NotSupportedFeatuerException(
|
||||
"import handler is not supported by this repository handler");
|
||||
"import handler is not supported by this repository handler");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,10 +211,8 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
|
||||
*/
|
||||
private void fireConfigChanged()
|
||||
{
|
||||
for (ConfigChangedListener listener : listenerSet)
|
||||
{
|
||||
listener.configChanged(config);
|
||||
}
|
||||
ScmEventBus.getInstance().post(
|
||||
new RepositoryHandlerConfigChangedEvent<C>(config));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@@ -264,8 +225,4 @@ public abstract class AbstractRepositoryHandler<C extends SimpleRepositoryConfig
|
||||
|
||||
/** Field description */
|
||||
protected Store<C> store;
|
||||
|
||||
/** Field description */
|
||||
private Set<ConfigChangedListener> listenerSet =
|
||||
new HashSet<ConfigChangedListener>();
|
||||
}
|
||||
|
||||
@@ -136,29 +136,6 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link RepositoryListener}.
|
||||
*
|
||||
*
|
||||
* @param listener {@link RepositoryListener} to register
|
||||
*/
|
||||
@Override
|
||||
public void addListener(RepositoryListener listener)
|
||||
{
|
||||
listenerSet.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link java.util.Collection} of {@link RepositoryListener}s.
|
||||
*
|
||||
*
|
||||
* @param listeners listeners to register
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<RepositoryListener> listeners)
|
||||
{
|
||||
listenerSet.addAll(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a {@link RepositoryHookEvent} to each registered
|
||||
@@ -220,32 +197,13 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove specified {@link RepositoryListener}.
|
||||
*
|
||||
*
|
||||
* @param listener to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(RepositoryListener listener)
|
||||
{
|
||||
listenerSet.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link RepositoryListener#onEvent(Repository,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link RepositoryEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
* Send a {@link RepositoryEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param repository repository that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
protected void fireEvent(Repository repository, HandlerEvent event)
|
||||
{
|
||||
for (RepositoryListener listener : listenerSet)
|
||||
{
|
||||
listener.onEvent(repository, event);
|
||||
}
|
||||
|
||||
ScmEventBus.getInstance().post(new RepositoryEvent(repository, event));
|
||||
}
|
||||
|
||||
@@ -268,7 +226,4 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
||||
/** repository hooks map */
|
||||
private Map<RepositoryHookType, List<RepositoryHook>> hookMap =
|
||||
Maps.newEnumMap(RepositoryHookType.class);
|
||||
|
||||
/** repository listeners */
|
||||
private Set<RepositoryListener> listenerSet = Sets.newHashSet();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.Handler;
|
||||
import sonia.scm.ListenerSupport;
|
||||
import sonia.scm.NotSupportedFeatuerException;
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
|
||||
@@ -49,8 +47,7 @@ import sonia.scm.plugin.ExtensionPoint;
|
||||
*/
|
||||
@ExtensionPoint
|
||||
public interface RepositoryHandler
|
||||
extends Handler<Repository, RepositoryException>,
|
||||
ListenerSupport<ConfigChangedListener>
|
||||
extends Handler<Repository, RepositoryException>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||
* binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
|
||||
* nor the names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import sonia.scm.event.Event;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Event
|
||||
public class RepositoryHandlerConfigChangedEvent<C extends SimpleRepositoryConfig>
|
||||
{
|
||||
|
||||
private final C configuration;
|
||||
|
||||
public RepositoryHandlerConfigChangedEvent(C configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public C getConfiguration()
|
||||
{
|
||||
return configuration;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
|
||||
/**
|
||||
* Listener for {@link Repository} events. {@link RepositoryListener} can be
|
||||
* registered with {@link sonia.scm.plugin.ext.Extension} annotation or with the
|
||||
* {@link RepositoryManager#addListener(java.lang.Object)}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@ExtensionPoint
|
||||
public interface RepositoryListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Called when a repository change event is fired.
|
||||
*
|
||||
*
|
||||
* @param repository repository that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
public void onEvent(Repository repository, HandlerEvent event);
|
||||
}
|
||||
@@ -35,7 +35,6 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ListenerSupport;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.TypeManager;
|
||||
|
||||
@@ -57,7 +56,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
*/
|
||||
public interface RepositoryManager
|
||||
extends TypeManager<Repository, RepositoryException>,
|
||||
ListenerSupport<RepositoryListener>,
|
||||
RepositoryHookSupport
|
||||
{
|
||||
|
||||
|
||||
@@ -95,30 +95,6 @@ public class RepositoryManagerDecorator
|
||||
decorated.addHooks(hooks);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(RepositoryListener listener)
|
||||
{
|
||||
decorated.addListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<RepositoryListener> listeners)
|
||||
{
|
||||
decorated.addListeners(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
@@ -193,18 +169,6 @@ public class RepositoryManagerDecorator
|
||||
decorated.removeHook(hook);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(RepositoryListener listener)
|
||||
{
|
||||
decorated.removeListener(listener);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,8 @@ import javax.servlet.http.HttpServletResponse;
|
||||
/**
|
||||
* Listener before a repository request is executed. Repository request are
|
||||
* request to a repository from a client like git, mercurial or svn.
|
||||
*
|
||||
* TODO replace with event bus implementation.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.10
|
||||
|
||||
@@ -37,6 +37,7 @@ package sonia.scm.repository.api;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -53,12 +54,9 @@ import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
import sonia.scm.repository.PermissionUtil;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHook;
|
||||
import sonia.scm.repository.PreProcessorUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryCacheKeyFilter;
|
||||
import sonia.scm.repository.RepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryListener;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.RepositoryNotFoundException;
|
||||
import sonia.scm.repository.Tags;
|
||||
@@ -69,6 +67,9 @@ import sonia.scm.security.ScmSecurityException;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Set;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryEvent;
|
||||
|
||||
/**
|
||||
* The {@link RepositoryServiceFactory} is the entrypoint of the repository api.
|
||||
@@ -149,9 +150,7 @@ public final class RepositoryServiceFactory
|
||||
this.preProcessorUtil = preProcessorUtil;
|
||||
|
||||
CacheClearHook cch = new CacheClearHook(cacheManager);
|
||||
|
||||
repositoryManager.addHook(cch);
|
||||
repositoryManager.addListener(cch);
|
||||
ScmEventBus.getInstance().register(cch);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -296,8 +295,7 @@ public final class RepositoryServiceFactory
|
||||
* @version Enter version here..., 12/06/16
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class CacheClearHook extends PostReceiveRepositoryHook
|
||||
implements RepositoryListener
|
||||
private static class CacheClearHook
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -331,8 +329,8 @@ public final class RepositoryServiceFactory
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(RepositoryHookEvent event)
|
||||
@Subscribe
|
||||
public void onEvent(PostReceiveRepositoryHookEvent event)
|
||||
{
|
||||
Repository repository = event.getRepository();
|
||||
|
||||
@@ -351,12 +349,12 @@ public final class RepositoryServiceFactory
|
||||
* @param repository
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(Repository repository, HandlerEvent event)
|
||||
@Subscribe
|
||||
public void onEvent(RepositoryEvent event)
|
||||
{
|
||||
if (event == HandlerEvent.DELETE)
|
||||
if (event.getEventType() == HandlerEvent.DELETE)
|
||||
{
|
||||
clearCaches(repository.getId());
|
||||
clearCaches(event.getItem().getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Base class for {@link ListenableStore}. The AbstractListenableStore provides
|
||||
* methods for event and listener handling.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.16
|
||||
*
|
||||
* @param <T> type of store objects
|
||||
*/
|
||||
public abstract class AbstractListenableStore<T> implements ListenableStore<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Read the stored object.
|
||||
*
|
||||
*
|
||||
* @return stored object
|
||||
*/
|
||||
protected abstract T readObject();
|
||||
|
||||
/**
|
||||
* Write object to the store.
|
||||
*
|
||||
*
|
||||
* @param object object to write
|
||||
*/
|
||||
protected abstract void writeObject(T object);
|
||||
|
||||
/**
|
||||
* Add a listener to the store.
|
||||
*
|
||||
*
|
||||
* @param listener listener for store
|
||||
*/
|
||||
@Override
|
||||
public void addListener(ConfigChangedListener<T> listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a collection of listeners to the store.
|
||||
*
|
||||
*
|
||||
* @param listeners listeners for store
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<ConfigChangedListener<T>> listeners)
|
||||
{
|
||||
listeners.addAll(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a listener from the store
|
||||
*
|
||||
*
|
||||
* @param listener listener to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(ConfigChangedListener<T> listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public T get()
|
||||
{
|
||||
if (storeObject == null)
|
||||
{
|
||||
storeObject = readObject();
|
||||
}
|
||||
|
||||
return storeObject;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param obejct
|
||||
*/
|
||||
@Override
|
||||
public void set(T obejct)
|
||||
{
|
||||
writeObject(obejct);
|
||||
this.storeObject = obejct;
|
||||
fireEvent(obejct);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fire a store event.
|
||||
*
|
||||
*
|
||||
* @param object changed object
|
||||
*/
|
||||
protected void fireEvent(T object)
|
||||
{
|
||||
for (ConfigChangedListener<T> listener : listeners)
|
||||
{
|
||||
listener.configChanged(object);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** listeners */
|
||||
protected Set<ConfigChangedListener<T>> listeners = Sets.newHashSet();
|
||||
|
||||
/** stored object */
|
||||
protected T storeObject;
|
||||
}
|
||||
@@ -35,16 +35,69 @@ package sonia.scm.store;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.ListenerSupport;
|
||||
|
||||
/**
|
||||
* Store for configuration objects with listener support.
|
||||
* Base class for {@link Store}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.16
|
||||
*
|
||||
* @param <T> type of store objects
|
||||
*/
|
||||
public interface ListenableStore<T>
|
||||
extends Store<T>, ListenerSupport<ConfigChangedListener<T>> {}
|
||||
public abstract class AbstractStore<T> implements Store<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Read the stored object.
|
||||
*
|
||||
*
|
||||
* @return stored object
|
||||
*/
|
||||
protected abstract T readObject();
|
||||
|
||||
/**
|
||||
* Write object to the store.
|
||||
*
|
||||
*
|
||||
* @param object object to write
|
||||
*/
|
||||
protected abstract void writeObject(T object);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public T get()
|
||||
{
|
||||
if (storeObject == null)
|
||||
{
|
||||
storeObject = readObject();
|
||||
}
|
||||
|
||||
return storeObject;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param obejct
|
||||
*/
|
||||
@Override
|
||||
public void set(T obejct)
|
||||
{
|
||||
writeObject(obejct);
|
||||
this.storeObject = obejct;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** stored object */
|
||||
protected T storeObject;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
/**
|
||||
* The ListenableStoreFactory can be used to create new or get existing
|
||||
* {@link ListenableStore}s.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.16
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses sonia.scm.store.ListenableStore
|
||||
*/
|
||||
public interface ListenableStoreFactory extends StoreFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Get an existing {@link ListenableStore} or create a new one.
|
||||
*
|
||||
*
|
||||
* @param type type of the store objects
|
||||
* @param name name of the store
|
||||
* @param <T> type of the store objects
|
||||
*
|
||||
* @return {@link ListenableStore} of the given type and name
|
||||
*/
|
||||
@Override
|
||||
public <T> ListenableStore<T> getStore(Class<T> type, String name);
|
||||
}
|
||||
@@ -54,61 +54,13 @@ public abstract class AbstractUserManager implements UserManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Register a {@link UserListener}.
|
||||
*
|
||||
*
|
||||
* @param listener {@link UserListener} to register
|
||||
*/
|
||||
@Override
|
||||
public void addListener(UserListener listener)
|
||||
{
|
||||
listenerSet.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link java.util.Collection} of {@link UserListener}s.
|
||||
*
|
||||
*
|
||||
* @param listeners listeners to register
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<UserListener> listeners)
|
||||
{
|
||||
listenerSet.addAll(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove specified {@link UserListener}.
|
||||
*
|
||||
*
|
||||
* @param listener to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(UserListener listener)
|
||||
{
|
||||
listenerSet.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link UserListener#onEvent(User,sonia.scm.HandlerEvent)}
|
||||
* method of all registered listeners and send a {@link UserEvent} to
|
||||
* the {@link ScmEventBus}.
|
||||
* Send a {@link UserEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param user user that has changed
|
||||
* @param event type of change event
|
||||
*/
|
||||
protected void fireEvent(User user, HandlerEvent event)
|
||||
{
|
||||
for (UserListener listener : listenerSet)
|
||||
{
|
||||
listener.onEvent(user, event);
|
||||
}
|
||||
|
||||
ScmEventBus.getInstance().post(new UserEvent(user, event));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Set<UserListener> listenerSet = new HashSet<UserListener>();
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.user;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@ExtensionPoint
|
||||
public interface UserListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param user
|
||||
* @param event
|
||||
*/
|
||||
public void onEvent(User user, HandlerEvent event);
|
||||
}
|
||||
@@ -35,7 +35,6 @@ package sonia.scm.user;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ListenerSupport;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.search.Searchable;
|
||||
|
||||
@@ -46,8 +45,7 @@ import sonia.scm.search.Searchable;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface UserManager
|
||||
extends Manager<User, UserException>, Searchable<User>,
|
||||
ListenerSupport<UserListener>
|
||||
extends Manager<User, UserException>, Searchable<User>
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,30 +66,6 @@ public class UserManagerDecorator extends ManagerDecorator<User, UserException>
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(UserListener listener)
|
||||
{
|
||||
decorated.addListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<UserListener> listeners)
|
||||
{
|
||||
decorated.addListeners(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
@@ -104,18 +80,6 @@ public class UserManagerDecorator extends ManagerDecorator<User, UserException>
|
||||
return decorated.contains(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(UserListener listener)
|
||||
{
|
||||
decorated.removeListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
@@ -160,5 +124,5 @@ public class UserManagerDecorator extends ManagerDecorator<User, UserException>
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private UserManager decorated;
|
||||
private final UserManager decorated;
|
||||
}
|
||||
|
||||
@@ -60,64 +60,13 @@ public abstract class AbstractAuthenticationManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Register a {@link AuthenticationListener}.
|
||||
*
|
||||
* Send a {@link AuthenticationEvent} to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param listener {@link AuthenticationListener} to register
|
||||
*/
|
||||
@Override
|
||||
public void addListener(AuthenticationListener listener)
|
||||
{
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link java.util.Collection} of {@link AuthenticationListener}s.
|
||||
*
|
||||
*
|
||||
* @param listeners listeners to register
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<AuthenticationListener> listeners)
|
||||
{
|
||||
this.listeners.addAll(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove specified {@link AuthenticationListener}.
|
||||
*
|
||||
*
|
||||
* @param listener to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(AuthenticationListener listener)
|
||||
{
|
||||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Calls the {@link AuthenticationListener#onAuthentication(HttpServletRequest,HttpServletResponse,User)}
|
||||
* method of all registered listeners and send a {@link AuthenticationEvent}
|
||||
* to the {@link ScmEventBus}.
|
||||
*
|
||||
* @param request current http request
|
||||
* @param response current http response
|
||||
* @param user successful authenticated user
|
||||
*/
|
||||
protected void fireAuthenticationEvent(HttpServletRequest request,
|
||||
HttpServletResponse response, User user)
|
||||
protected void fireAuthenticationEvent(User user)
|
||||
{
|
||||
for (AuthenticationListener listener : listeners)
|
||||
{
|
||||
listener.onAuthentication(request, response, user);
|
||||
}
|
||||
|
||||
ScmEventBus.getInstance().post(new AuthenticationEvent(user));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** authentication listeners */
|
||||
private Set<AuthenticationListener> listeners = Sets.newHashSet();
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.web.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@ExtensionPoint
|
||||
public interface AuthenticationListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param user
|
||||
*/
|
||||
public void onAuthentication(HttpServletRequest request,
|
||||
HttpServletResponse response, User user);
|
||||
}
|
||||
@@ -36,7 +36,6 @@ package sonia.scm.web.security;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Initable;
|
||||
import sonia.scm.ListenerSupport;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -50,7 +49,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface AuthenticationManager
|
||||
extends Initable, Closeable, ListenerSupport<AuthenticationListener>
|
||||
extends Initable, Closeable
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.orientdb.OrientDBUtil;
|
||||
import sonia.scm.store.AbstractListenableStore;
|
||||
import sonia.scm.store.AbstractStore;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -61,7 +61,7 @@ import javax.xml.bind.JAXBException;
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class OrientDBStore<T> extends AbstractListenableStore<T>
|
||||
public class OrientDBStore<T> extends AbstractStore<T>
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -178,7 +178,6 @@ public class OrientDBStore<T> extends AbstractListenableStore<T>
|
||||
context.createMarshaller().marshal(t, buffer);
|
||||
doc.field(FIELD_DATA, buffer.toString());
|
||||
doc.save();
|
||||
fireEvent(t);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,6 @@ import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.orientdb.OrientDBUtil;
|
||||
import sonia.scm.store.ListenableStoreFactory;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -56,13 +55,14 @@ import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class OrientDBStoreFactory implements ListenableStoreFactory
|
||||
public class OrientDBStoreFactory implements StoreFactory
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -158,5 +158,5 @@ public class OrientDBStoreFactory implements ListenableStoreFactory
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Provider<ODatabaseDocumentTx> connectionProvider;
|
||||
private final Provider<ODatabaseDocumentTx> connectionProvider;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import javax.xml.bind.Marshaller;
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class JAXBStore<T> extends AbstractListenableStore<T>
|
||||
public class JAXBStore<T> extends AbstractStore<T>
|
||||
{
|
||||
|
||||
/** the logger for JAXBStore */
|
||||
@@ -149,7 +149,6 @@ public class JAXBStore<T> extends AbstractListenableStore<T>
|
||||
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
marshaller.marshal(object, configFile);
|
||||
fireEvent(object);
|
||||
}
|
||||
catch (JAXBException ex)
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ import java.io.IOException;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class JAXBStoreFactory implements ListenableStoreFactory
|
||||
public class JAXBStoreFactory implements StoreFactory
|
||||
{
|
||||
|
||||
/** the logger for JAXBStoreFactory */
|
||||
|
||||
@@ -59,7 +59,6 @@ public abstract class AbstractPluginBackend implements PluginBackend
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(PluginBackendListener listener)
|
||||
{
|
||||
listenerSet.add(listener);
|
||||
@@ -71,7 +70,6 @@ public abstract class AbstractPluginBackend implements PluginBackend
|
||||
*
|
||||
* @param listeners
|
||||
*/
|
||||
@Override
|
||||
public void addListeners(Collection<PluginBackendListener> listeners)
|
||||
{
|
||||
listenerSet.addAll(listeners);
|
||||
@@ -113,7 +111,6 @@ public abstract class AbstractPluginBackend implements PluginBackend
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(PluginBackendListener listener)
|
||||
{
|
||||
listenerSet.remove(listener);
|
||||
|
||||
@@ -33,10 +33,6 @@
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.ListenerSupport;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
@@ -49,9 +45,29 @@ import java.util.Set;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface PluginBackend extends ListenerSupport<PluginBackendListener>
|
||||
public interface PluginBackend
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public void addListener(PluginBackendListener listener);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listeners
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public void addListeners(Collection<PluginBackendListener> listeners);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -86,6 +102,16 @@ public interface PluginBackend extends ListenerSupport<PluginBackendListener>
|
||||
*/
|
||||
public void addScannedFiles(File... scannedFiles);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public void removeListener(PluginBackendListener listener);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,11 +43,13 @@ import static org.junit.Assert.*;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Ignore
|
||||
public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
{
|
||||
|
||||
@@ -97,6 +99,7 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
GitConfig config = new GitConfig();
|
||||
|
||||
config.setRepositoryDirectory(directory);
|
||||
// TODO fix event bus exception
|
||||
repositoryHandler.setConfig(config);
|
||||
|
||||
return repositoryHandler;
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -42,7 +43,6 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.net.HttpClient;
|
||||
import sonia.scm.net.HttpRequest;
|
||||
@@ -57,13 +57,16 @@ import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import sonia.scm.config.ScmConfigurationChangedEvent;
|
||||
import sonia.scm.event.Subscriber;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
|
||||
@Subscriber(async = false)
|
||||
public class HgHookManager
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -91,7 +94,6 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
|
||||
Provider<HttpClient> httpClientProvider)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.configuration.addListener(this);
|
||||
this.httpServletRequestProvider = httpServletRequestProvider;
|
||||
this.httpClientProvider = httpClientProvider;
|
||||
}
|
||||
@@ -104,8 +106,8 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
@Override
|
||||
public void configChanged(ScmConfiguration config)
|
||||
@Subscribe
|
||||
public void configChanged(ScmConfigurationChangedEvent config)
|
||||
{
|
||||
hookUrl = null;
|
||||
}
|
||||
|
||||
@@ -43,11 +43,13 @@ import static org.junit.Assert.*;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Ignore
|
||||
public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
{
|
||||
|
||||
@@ -92,6 +94,7 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase
|
||||
SvnConfig config = new SvnConfig();
|
||||
|
||||
config.setRepositoryDirectory(directory);
|
||||
// TODO fix event bus exception
|
||||
handler.setConfig(config);
|
||||
|
||||
return handler;
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -53,6 +54,7 @@ import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -239,12 +241,14 @@ public abstract class RepositoryManagerTestBase
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void testListener() throws RepositoryException, IOException
|
||||
{
|
||||
RepositoryManager repoManager = createRepositoryManager(false);
|
||||
TestListener listener = new TestListener();
|
||||
|
||||
repoManager.addListener(listener);
|
||||
// TODO
|
||||
// repoManager.addListener(listener);
|
||||
|
||||
Repository repository = RepositoryTestData.create42Puzzle();
|
||||
|
||||
@@ -517,7 +521,7 @@ public abstract class RepositoryManagerTestBase
|
||||
* @version Enter version here..., 13/01/29
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class TestListener implements RepositoryListener
|
||||
private static class TestListener
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -527,18 +531,18 @@ public abstract class RepositoryManagerTestBase
|
||||
* @param repository
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(Repository repository, HandlerEvent event)
|
||||
@Subscribe
|
||||
public void onEvent(RepositoryEvent event)
|
||||
{
|
||||
if (event.isPost())
|
||||
if (event.getEventType().isPost())
|
||||
{
|
||||
this.postRepository = repository;
|
||||
this.postEvent = event;
|
||||
this.postRepository = event.getItem();
|
||||
this.postEvent = event.getEventType();
|
||||
}
|
||||
else if (event.isPre())
|
||||
else if (event.getEventType().isPre())
|
||||
{
|
||||
this.preRepository = repository;
|
||||
this.preEvent = event;
|
||||
this.preRepository = event.getItem();
|
||||
this.preEvent = event.getEventType();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,6 @@ import sonia.scm.store.FileBlobStoreFactory;
|
||||
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
||||
import sonia.scm.store.JAXBDataStoreFactory;
|
||||
import sonia.scm.store.JAXBStoreFactory;
|
||||
import sonia.scm.store.ListenableStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.template.DefaultEngine;
|
||||
import sonia.scm.template.MustacheTemplateEngine;
|
||||
@@ -253,7 +252,6 @@ public class ScmServletModule extends ServletModule
|
||||
|
||||
// bind core
|
||||
bind(StoreFactory.class, JAXBStoreFactory.class);
|
||||
bind(ListenableStoreFactory.class, JAXBStoreFactory.class);
|
||||
bind(ConfigurationEntryStoreFactory.class,
|
||||
JAXBConfigurationEntryStoreFactory.class);
|
||||
bind(DataStoreFactory.class, JAXBDataStoreFactory.class);
|
||||
|
||||
@@ -36,22 +36,20 @@ package sonia.scm.api.rest.resources;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.codehaus.enunciate.modules.jersey.ExternallyManagedLifecycle;
|
||||
|
||||
import sonia.scm.HandlerEvent;
|
||||
import sonia.scm.cache.Cache;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.GroupListener;
|
||||
import sonia.scm.group.GroupManager;
|
||||
import sonia.scm.search.SearchHandler;
|
||||
import sonia.scm.search.SearchResult;
|
||||
import sonia.scm.search.SearchResults;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserListener;
|
||||
import sonia.scm.user.UserManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -61,6 +59,8 @@ import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import sonia.scm.group.GroupEvent;
|
||||
import sonia.scm.user.UserEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -69,7 +69,7 @@ import javax.ws.rs.core.MediaType;
|
||||
@Singleton
|
||||
@Path("search")
|
||||
@ExternallyManagedLifecycle
|
||||
public class SearchResource implements UserListener, GroupListener
|
||||
public class SearchResource
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -84,7 +84,6 @@ public class SearchResource implements UserListener, GroupListener
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param securityContextProvider
|
||||
* @param userManager
|
||||
* @param groupManager
|
||||
* @param cacheManager
|
||||
@@ -95,16 +94,12 @@ public class SearchResource implements UserListener, GroupListener
|
||||
{
|
||||
|
||||
// create user searchhandler
|
||||
userManager.addListener(this);
|
||||
|
||||
Cache<String, SearchResults> userCache =
|
||||
cacheManager.getCache(String.class, SearchResults.class, CACHE_USER);
|
||||
|
||||
this.userSearchHandler = new SearchHandler<User>(userCache, userManager);
|
||||
|
||||
// create group searchhandler
|
||||
groupManager.addListener(this);
|
||||
|
||||
Cache<String, SearchResults> groupCache =
|
||||
cacheManager.getCache(String.class, SearchResults.class, CACHE_GROUP);
|
||||
|
||||
@@ -118,26 +113,28 @@ public class SearchResource implements UserListener, GroupListener
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param user
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(User user, HandlerEvent event)
|
||||
@Subscribe
|
||||
public void onEvent(UserEvent event)
|
||||
{
|
||||
userSearchHandler.clearCache();
|
||||
if ( event.getEventType().isPost() ){
|
||||
userSearchHandler.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param group
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(Group group, HandlerEvent event)
|
||||
@Subscribe
|
||||
public void onEvent(GroupEvent event)
|
||||
{
|
||||
groupSearchHandler.clearCache();
|
||||
if ( event.getEventType().isPost() ){
|
||||
groupSearchHandler.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,8 +208,8 @@ public class SearchResource implements UserListener, GroupListener
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SearchHandler<Group> groupSearchHandler;
|
||||
private final SearchHandler<Group> groupSearchHandler;
|
||||
|
||||
/** Field description */
|
||||
private SearchHandler<User> userSearchHandler;
|
||||
private final SearchHandler<User> userSearchHandler;
|
||||
}
|
||||
|
||||
@@ -83,16 +83,12 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param securityContextProvider
|
||||
* @param groupDAO
|
||||
* @param groupListenerProvider
|
||||
*/
|
||||
@Inject
|
||||
public DefaultGroupManager(GroupDAO groupDAO,
|
||||
Provider<Set<GroupListener>> groupListenerProvider)
|
||||
public DefaultGroupManager(GroupDAO groupDAO)
|
||||
{
|
||||
this.groupDAO = groupDAO;
|
||||
this.groupListenerProvider = groupListenerProvider;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -192,12 +188,6 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
Set<GroupListener> listeners = groupListenerProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(listeners))
|
||||
{
|
||||
addListeners(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,7 +454,4 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
|
||||
/** Field description */
|
||||
private GroupDAO groupDAO;
|
||||
|
||||
/** Field description */
|
||||
private Provider<Set<GroupListener>> groupListenerProvider;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ package sonia.scm.plugin;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -44,7 +45,6 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ConfigChangedListener;
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
@@ -80,6 +80,7 @@ import javax.xml.bind.JAXB;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import sonia.scm.config.ScmConfigurationChangedEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -87,7 +88,7 @@ import javax.xml.bind.Unmarshaller;
|
||||
*/
|
||||
@Singleton
|
||||
public class DefaultPluginManager
|
||||
implements PluginManager, ConfigChangedListener<ScmConfiguration>
|
||||
implements PluginManager
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
@@ -114,7 +115,6 @@ public class DefaultPluginManager
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param securityContextProvicer
|
||||
* @param configuration
|
||||
* @param pluginLoader
|
||||
* @param cacheManager
|
||||
@@ -151,8 +151,6 @@ public class DefaultPluginManager
|
||||
{
|
||||
throw new ConfigurationException(ex);
|
||||
}
|
||||
|
||||
this.configuration.addListener(this);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -178,8 +176,8 @@ public class DefaultPluginManager
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
@Override
|
||||
public void configChanged(ScmConfiguration config)
|
||||
@Subscribe
|
||||
public void configChanged(ScmConfigurationChangedEvent config)
|
||||
{
|
||||
clearCache();
|
||||
}
|
||||
|
||||
@@ -114,14 +114,12 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
public DefaultRepositoryManager(ScmConfiguration configuration,
|
||||
SCMContextProvider contextProvider, KeyGenerator keyGenerator,
|
||||
RepositoryDAO repositoryDAO, Set<RepositoryHandler> handlerSet,
|
||||
Provider<Set<RepositoryListener>> repositoryListenersProvider,
|
||||
Provider<Set<RepositoryHook>> repositoryHooksProvider,
|
||||
PreProcessorUtil preProcessorUtil)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.keyGenerator = keyGenerator;
|
||||
this.repositoryDAO = repositoryDAO;
|
||||
this.repositoryListenersProvider = repositoryListenersProvider;
|
||||
this.repositoryHooksProvider = repositoryHooksProvider;
|
||||
this.preProcessorUtil = preProcessorUtil;
|
||||
|
||||
@@ -331,13 +329,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
Set<RepositoryListener> listeners = repositoryListenersProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(listeners))
|
||||
{
|
||||
addListeners(listeners);
|
||||
}
|
||||
|
||||
Set<RepositoryHook> hooks = repositoryHooksProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(hooks))
|
||||
@@ -951,9 +942,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
/** Field description */
|
||||
private Provider<Set<RepositoryHook>> repositoryHooksProvider;
|
||||
|
||||
/** Field description */
|
||||
private Provider<Set<RepositoryListener>> repositoryListenersProvider;
|
||||
|
||||
/** Field description */
|
||||
private Set<Type> types;
|
||||
}
|
||||
|
||||
@@ -101,17 +101,12 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param scurityContextProvider
|
||||
* @param userDAO
|
||||
* @param userListenerProvider
|
||||
*/
|
||||
@Inject
|
||||
public DefaultUserManager(UserDAO userDAO,
|
||||
Provider<Set<UserListener>> userListenerProvider)
|
||||
public DefaultUserManager(UserDAO userDAO)
|
||||
{
|
||||
this.userDAO = userDAO;
|
||||
this.userListenerProvider = userListenerProvider;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -239,13 +234,6 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
{
|
||||
createDefaultAccounts();
|
||||
}
|
||||
|
||||
Set<UserListener> listeners = userListenerProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(listeners))
|
||||
{
|
||||
addListeners(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -546,8 +534,5 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private UserDAO userDAO;
|
||||
|
||||
/** Field description */
|
||||
private Provider<Set<UserListener>> userListenerProvider;
|
||||
private final UserDAO userDAO;
|
||||
}
|
||||
|
||||
@@ -91,14 +91,11 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
* @param authenticationHandlerSet
|
||||
* @param encryptionHandler
|
||||
* @param cacheManager
|
||||
* @param authenticationListenerProvider
|
||||
* @param authenticationListeners
|
||||
*/
|
||||
@Inject
|
||||
public ChainAuthenticatonManager(UserManager userManager,
|
||||
Set<AuthenticationHandler> authenticationHandlerSet,
|
||||
EncryptionHandler encryptionHandler, CacheManager cacheManager,
|
||||
Set<AuthenticationListener> authenticationListeners)
|
||||
EncryptionHandler encryptionHandler, CacheManager cacheManager)
|
||||
{
|
||||
AssertUtil.assertIsNotEmpty(authenticationHandlerSet);
|
||||
AssertUtil.assertIsNotNull(cacheManager);
|
||||
@@ -106,11 +103,6 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
this.encryptionHandler = encryptionHandler;
|
||||
this.cache = cacheManager.getCache(String.class,
|
||||
AuthenticationCacheValue.class, CACHE_NAME);
|
||||
|
||||
if (Util.isNotEmpty(authenticationListeners))
|
||||
{
|
||||
addListeners(authenticationListeners);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -252,7 +244,7 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
ar = result;
|
||||
|
||||
// notify authentication listeners
|
||||
fireAuthenticationEvent(request, response, user);
|
||||
fireAuthenticationEvent(user);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -140,10 +140,6 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
|
||||
}
|
||||
});
|
||||
|
||||
Provider<Set<RepositoryListener>> listenerProvider = mock(Provider.class);
|
||||
|
||||
when(listenerProvider.get()).thenReturn(new HashSet<RepositoryListener>());
|
||||
|
||||
Provider<Set<RepositoryHook>> hookProvider = mock(Provider.class);
|
||||
|
||||
when(hookProvider.get()).thenReturn(new HashSet<RepositoryHook>());
|
||||
@@ -155,7 +151,7 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
|
||||
configuration.setEnableRepositoryArchive(archiveEnabled);
|
||||
|
||||
return new DefaultRepositoryManager(configuration, contextProvider,
|
||||
new DefaultKeyGenerator(), repositoryDAO, handlerSet, listenerProvider,
|
||||
new DefaultKeyGenerator(), repositoryDAO, handlerSet,
|
||||
hookProvider, createEmptyPreProcessorUtil());
|
||||
}
|
||||
|
||||
|
||||
@@ -75,12 +75,8 @@ public class DefaultUserManagerTest extends UserManagerTestBase
|
||||
|
||||
factory.init(contextProvider);
|
||||
|
||||
Provider<Set<UserListener>> listenerProvider = mock(Provider.class);
|
||||
|
||||
when(listenerProvider.get()).thenReturn(new HashSet<UserListener>());
|
||||
|
||||
XmlUserDAO userDAO = new XmlUserDAO(factory);
|
||||
|
||||
return new DefaultUserManager(userDAO, listenerProvider);
|
||||
return new DefaultUserManager(userDAO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,8 +222,7 @@ public class ChainAuthenticationManagerTest extends AbstractTestBase
|
||||
|
||||
when(userManager.getDefaultType()).thenReturn(defaultType);
|
||||
manager = new ChainAuthenticatonManager(userManager, handlerSet,
|
||||
new MessageDigestEncryptionHandler(), new MapCacheManager(),
|
||||
Collections.EMPTY_SET);
|
||||
new MessageDigestEncryptionHandler(), new MapCacheManager());
|
||||
manager.init(contextProvider);
|
||||
|
||||
return manager;
|
||||
|
||||
@@ -35,8 +35,6 @@ package sonia.scm.web.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
@@ -46,20 +44,14 @@ import sonia.scm.store.JAXBStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.user.DefaultUserManager;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserListener;
|
||||
import sonia.scm.user.UserTestData;
|
||||
import sonia.scm.user.xml.XmlUserDAO;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -136,16 +128,11 @@ public class DefaultAuthenticationHandlerTest extends AbstractTestBase
|
||||
|
||||
storeFactory.init(contextProvider);
|
||||
|
||||
Provider<Set<UserListener>> listenerProvider = mock(Provider.class);
|
||||
|
||||
when(listenerProvider.get()).thenReturn(new HashSet<UserListener>());
|
||||
|
||||
XmlUserDAO userDAO = new XmlUserDAO(storeFactory);
|
||||
|
||||
setSubject(MockUtil.createAdminSubject());
|
||||
|
||||
DefaultUserManager userManager = new DefaultUserManager(userDAO,
|
||||
listenerProvider);
|
||||
DefaultUserManager userManager = new DefaultUserManager(userDAO);
|
||||
|
||||
userManager.init(contextProvider);
|
||||
userManager.create(slarti);
|
||||
|
||||
Reference in New Issue
Block a user