added api for PostReceiveHooks

This commit is contained in:
Sebastian Sdorra
2011-07-17 17:06:11 +02:00
parent bbfad810df
commit c51704f2ee
4 changed files with 164 additions and 1 deletions

View File

@@ -36,11 +36,13 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.HandlerEvent;
import sonia.scm.util.AssertUtil;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
@@ -50,6 +52,17 @@ import java.util.Set;
public abstract class AbstractRepositoryManager implements RepositoryManager
{
/**
* Method description
*
*
* @param hook
* @param repository
* @param changesets
*/
protected abstract void firePostReceiveEvent(PostReceiveHook hook,
Repository repository, List<Changeset> changesets);
/**
* Method description
*
@@ -74,6 +87,38 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
listenerSet.addAll(listeners);
}
/**
* Method description
*
*
* @param hook
*/
@Override
public void addPostReceiveHook(PostReceiveHook hook)
{
postReceiveHookSet.add(hook);
}
/**
* Method description
*
*
* @param repository
* @param changesets
*/
@Override
public void firePostReceiveEvent(Repository repository,
List<Changeset> changesets)
{
AssertUtil.assertIsNotNull(repository);
AssertUtil.assertIsNotEmpty(changesets);
for (PostReceiveHook hook : postReceiveHookSet)
{
firePostReceiveEvent(hook, repository, changesets);
}
}
/**
* Method description
*
@@ -86,6 +131,18 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
listenerSet.remove(listener);
}
/**
* Method description
*
*
* @param hook
*/
@Override
public void removePostReceiveHook(PostReceiveHook hook)
{
removePostReceiveHook(hook);
}
/**
* Method description
*
@@ -103,6 +160,10 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<PostReceiveHook> postReceiveHookSet =
new HashSet<PostReceiveHook>();
/** Field description */
private Set<RepositoryListener> listenerSet =
new HashSet<RepositoryListener>();

View File

@@ -0,0 +1,76 @@
/**
* 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;
//~--- JDK imports ------------------------------------------------------------
import java.util.List;
/**
* Support for post receive hooks.
*
* @author Sebastian Sdorra
* @since 1.6
*/
public interface PostReceiveHookSupport
{
/**
* Registers a new {@link PostReceiveHook}.
*
*
* @param hook to register
*/
public void addPostReceiveHook(PostReceiveHook hook);
/**
* Fires a post receive hook event. This methods calls the
* {@link PostReceiveHook#onPostReceive(Repository, List)} of each registered
* {@link PostReceiveHook}.
*
*
* @param repository that has changed
* @param changesets which modified the repository
*/
public void firePostReceiveEvent(Repository repository,
List<Changeset> changesets);
/**
* Unregisters the given {@link PostReceiveHook}.
*
*
* @param hook to unregister
*/
public void removePostReceiveHook(PostReceiveHook hook);
}

View File

@@ -49,7 +49,8 @@ import java.util.Collection;
*/
public interface RepositoryManager
extends TypeManager<Repository, RepositoryException>,
ListenerSupport<RepositoryListener>, RepositoryBrowserProvider
ListenerSupport<RepositoryListener>, RepositoryBrowserProvider,
PostReceiveHookSupport
{
/**

View File

@@ -47,9 +47,11 @@ import sonia.scm.HandlerEvent;
import sonia.scm.SCMContextProvider;
import sonia.scm.Type;
import sonia.scm.repository.AbstractRepositoryManager;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetViewer;
import sonia.scm.repository.PermissionType;
import sonia.scm.repository.PermissionUtil;
import sonia.scm.repository.PostReceiveHook;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryAllreadyExistExeption;
import sonia.scm.repository.RepositoryBrowser;
@@ -560,6 +562,29 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param hook
* @param repository
* @param changesets
*/
@Override
protected void firePostReceiveEvent(PostReceiveHook hook,
Repository repository, List<Changeset> changesets)
{
if (hook.isAsynchronous())
{
// todo
}
else
{
hook.onPostReceive(repository, changesets);
}
}
/**
* Method description
*