rebuild repository hook api

This commit is contained in:
Sebastian Sdorra
2011-07-19 15:32:53 +02:00
parent 292d143761
commit 96400d164b
12 changed files with 451 additions and 147 deletions

View File

@@ -0,0 +1,74 @@
/**
* 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;
/**
*
* @author Sebastian Sdorra
* @since 1.6
*/
public abstract class AbstractRepositoryHookEvent implements RepositoryHookEvent
{
/**
* Method description
*
*
* @return
*/
@Override
public Repository getRepository()
{
return repository;
}
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repository
*/
@Override
public void setRepository(Repository repository)
{
this.repository = repository;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Repository repository;
}

View File

@@ -35,14 +35,21 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.HandlerEvent;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -52,16 +59,76 @@ import java.util.Set;
public abstract class AbstractRepositoryManager implements RepositoryManager
{
/** the logger for AbstractRepositoryManager */
private static final Logger logger =
LoggerFactory.getLogger(AbstractRepositoryManager.class);
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param hook
* @param repository
* @param changesets
* @param event
*/
protected abstract void firePostReceiveEvent(PostReceiveHook hook,
Repository repository, List<Changeset> changesets);
protected abstract void fireHookEvent(RepositoryHook hook,
RepositoryHookEvent event);
/**
* Method description
*
*
* @param hook
*/
@Override
public void addHook(RepositoryHook hook)
{
Collection<RepositoryHookType> types = hook.getTypes();
if (types != null)
{
for (RepositoryHookType type : types)
{
if (logger.isDebugEnabled())
{
logger.debug("register {} hook {}", type, hook.getClass());
}
synchronized (AbstractRepositoryManager.class)
{
List<RepositoryHook> hooks = hookMap.get(type);
if (hooks == null)
{
hooks = new ArrayList<RepositoryHook>();
hookMap.put(type, hooks);
}
hooks.add(hook);
}
}
}
else if (logger.isWarnEnabled())
{
logger.warn("could not find any repository type");
}
}
/**
* Method description
*
*
* @param hooks
*/
@Override
public void addHooks(Collection<RepositoryHook> hooks)
{
for (RepositoryHook hook : hooks)
{
addHook(hook);
}
}
/**
* Method description
@@ -87,6 +154,32 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
listenerSet.addAll(listeners);
}
/**
* Method description
*
*
* @param repository
* @param event
*/
@Override
public void fireHookEvent(Repository repository, RepositoryHookEvent event)
{
AssertUtil.assertIsNotNull(repository);
AssertUtil.assertIsNotNull(event);
AssertUtil.assertIsNotNull(event.getType());
event.setRepository(repository);
List<RepositoryHook> hooks = hookMap.get(event.getType());
if (Util.isNotEmpty(hooks))
{
for (RepositoryHook hook : hooks)
{
fireHookEvent(hook, event);
}
}
}
/**
* Method description
*
@@ -94,40 +187,21 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
* @param hook
*/
@Override
public void addPostReceiveHook(PostReceiveHook hook)
public void removeHook(RepositoryHook hook)
{
postReceiveHookSet.add(hook);
}
Collection<RepositoryHookType> types = hook.getTypes();
/**
* Method description
*
*
* @param hooks
*/
@Override
public void addPostReceiveHooks(Collection<PostReceiveHook> hooks)
{
postReceiveHookSet.addAll(hooks);
}
/**
* 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)
if (types != null)
{
firePostReceiveEvent(hook, repository, changesets);
for (RepositoryHookType type : types)
{
List<RepositoryHook> hooks = hookMap.get(type);
if (hooks != null)
{
hooks.remove(hook);
}
}
}
}
@@ -143,18 +217,6 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
listenerSet.remove(listener);
}
/**
* Method description
*
*
* @param hook
*/
@Override
public void removePostReceiveHook(PostReceiveHook hook)
{
removePostReceiveHook(hook);
}
/**
* Method description
*
@@ -173,8 +235,9 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<PostReceiveHook> postReceiveHookSet =
new HashSet<PostReceiveHook>();
private Map<RepositoryHookType, List<RepositoryHook>> hookMap =
new EnumMap<RepositoryHookType,
List<RepositoryHook>>(RepositoryHookType.class);
/** Field description */
private Set<RepositoryListener> listenerSet =

View File

@@ -33,40 +33,43 @@
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.plugin.ExtensionPoint;
//~--- JDK imports ------------------------------------------------------------
import java.util.List;
import java.util.Collection;
import sonia.scm.plugin.ExtensionPoint;
/**
* Hook for post receive events.
*
* @author Sebastian Sdorra
* @since 1.6
*/
@ExtensionPoint
public interface PostReceiveHook
public interface RepositoryHook
{
/**
* This method is invoked after a repository has changed.
* Method description
*
*
* @param repository that has changed
* @param changesets which modified the repository
* @param event
*/
public void onPostReceive(Repository repository, List<Changeset> changesets);
public void onEvent(RepositoryHookEvent event);
//~--- get methods ----------------------------------------------------------
/**
* Returns true if the hook is executed asynchronous.
* Method description
*
*
* @return true if the hook is executed asynchronous
* @return
*/
public boolean isAsynchronous();
public Collection<RepositoryHookType> getTypes();
/**
* Method description
*
*
* @return
*/
public boolean isAsync();
}

View File

@@ -0,0 +1,81 @@
/**
* 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.Collection;
/**
*
* @author Sebastian Sdorra
* @since 1.6
*/
public interface RepositoryHookEvent
{
/**
* Method description
*
*
* @return
*/
public Collection<Changeset> getChangesets();
/**
* Method description
*
*
* @return
*/
public Repository getRepository();
/**
* Method description
*
*
* @return
*/
public RepositoryHookType getType();
//~--- set methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repository
*/
void setRepository(Repository repository);
}

View File

@@ -36,31 +36,29 @@ package sonia.scm.repository;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import java.util.List;
/**
* Support for post receive hooks.
*
* @author Sebastian Sdorra
* @since 1.6
*/
public interface PostReceiveHookSupport
public interface RepositoryHookSupport
{
/**
* Registers a new {@link PostReceiveHook}.
* Registers a new {@link RepositoryHook}.
*
*
* @param hook to register
*/
public void addPostReceiveHook(PostReceiveHook hook);
public void addHook(RepositoryHook hook);
/**
* Register a {@link java.util.Collection} of hooks.
*
* @param hooks to register
*/
public void addPostReceiveHooks(Collection<PostReceiveHook> hooks);
public void addHooks(Collection<RepositoryHook> hooks);
/**
* Fires a post receive hook event. This methods calls the
@@ -69,10 +67,9 @@ public interface PostReceiveHookSupport
*
*
* @param repository that has changed
* @param changesets which modified the repository
* @param event
*/
public void firePostReceiveEvent(Repository repository,
List<Changeset> changesets);
public void fireHookEvent(Repository repository, RepositoryHookEvent event);
/**
* Fires a post receive hook event. This methods calls the
@@ -82,33 +79,32 @@ public interface PostReceiveHookSupport
*
* @param type of the repository
* @param name of the repository
* @param changesets which modified the repository
* @param event
*
* @throws RepositoryNotFoundException if the repository could not be found.
*/
public void firePostReceiveEvent(String type, String name,
List<Changeset> changesets)
public void fireHookEvent(String type, String name, RepositoryHookEvent event)
throws RepositoryNotFoundException;
/**
* Fires a post receive hook event. This methods calls the
* {@link PostReceiveHook#onPostReceive(Repository, List)} of each registered
* {@link PostReceiveHook}.
* Fires a hook event. This methods calls the
* {@link RepositoryHook#onEvent(RepositoryHookEvent} of each registered
* {@link RepositoryHook}.
*
*
* @param id of the repository
* @param changesets which modified the repository
* @param event
*
* @throws RepositoryNotFoundException if the repository could not be found
*/
public void firePostReceiveEvent(String id, List<Changeset> changesets)
public void fireHookEvent(String id, RepositoryHookEvent event)
throws RepositoryNotFoundException;
/**
* Unregisters the given {@link PostReceiveHook}.
* Unregisters the given {@link RepositoryHook}.
*
*
* @param hook to unregister
*/
public void removePostReceiveHook(PostReceiveHook hook);
public void removeHook(RepositoryHook hook);
}

View File

@@ -0,0 +1,41 @@
/**
* 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;
/**
*
* @author Sebastian Sdorra
* @since 1.6
*/
public enum RepositoryHookType { POST_RECEIVE }

View File

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

View File

@@ -45,10 +45,12 @@ import org.eclipse.jgit.transport.ReceivePack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.AbstractRepositoryHookEvent;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.GitChangesetConverter;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.RepositoryHookType;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryNotFoundException;
import sonia.scm.util.IOUtil;
@@ -133,8 +135,9 @@ public class GitPostReceiveHook implements PostReceiveHook
String repositoryName = rpack.getRepository().getDirectory().getName();
repositoryManager.firePostReceiveEvent(GitRepositoryHandler.TYPE_NAME,
repositoryName, changesets);
repositoryManager.fireHookEvent(GitRepositoryHandler.TYPE_NAME,
repositoryName,
new GitRepositoryHook(changesets));
}
catch (RepositoryNotFoundException ex)
{
@@ -167,6 +170,62 @@ public class GitPostReceiveHook implements PostReceiveHook
|| (rc.getType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD);
}
//~--- inner classes --------------------------------------------------------
/**
* Class description
*
*
* @version Enter version here..., 11/07/19
* @author Enter your name here...
*/
private static class GitRepositoryHook extends AbstractRepositoryHookEvent
{
/**
* Constructs ...
*
*
* @param changesets
*/
public GitRepositoryHook(Collection<Changeset> changesets)
{
this.changesets = changesets;
}
//~--- get methods --------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Collection<Changeset> getChangesets()
{
return changesets;
}
/**
* Method description
*
*
* @return
*/
@Override
public RepositoryHookType getType()
{
return RepositoryHookType.POST_RECEIVE;
}
//~--- fields -------------------------------------------------------------
/** Field description */
private Collection<Changeset> changesets;
}
//~--- fields ---------------------------------------------------------------
/** Field description */

View File

@@ -47,8 +47,8 @@ import sonia.scm.io.FileSystem;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.plugin.ext.ExtensionProcessor;
import sonia.scm.repository.ChangesetPreProcessor;
import sonia.scm.repository.PostReceiveHook;
import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryHook;
import sonia.scm.repository.RepositoryListener;
import sonia.scm.resources.ResourceHandler;
import sonia.scm.security.EncryptionHandler;
@@ -212,16 +212,16 @@ public class BindingExtensionProcessor implements ExtensionProcessor
changesetPreProcessorBinder.addBinding().to(extensionClass);
}
else if (PostReceiveHook.class.isAssignableFrom(extensionClass))
else if (RepositoryHook.class.isAssignableFrom(extensionClass))
{
if (logger.isInfoEnabled())
{
logger.info("bind PostReceiveHook {}", extensionClass.getName());
logger.info("bind RepositoryHook {}", extensionClass.getName());
}
PostReceiveHook hook = (PostReceiveHook) extensionClass.newInstance();
RepositoryHook hook = (RepositoryHook) extensionClass.newInstance();
postReceiveHooks.add(hook);
hooks.add(hook);
}
else
{
@@ -310,9 +310,9 @@ public class BindingExtensionProcessor implements ExtensionProcessor
*
* @return
*/
public Set<Module> getModuleSet()
public Set<RepositoryHook> getHooks()
{
return moduleSet;
return hooks;
}
/**
@@ -321,9 +321,9 @@ public class BindingExtensionProcessor implements ExtensionProcessor
*
* @return
*/
public Set<PostReceiveHook> getPostReceiveHooks()
public Set<Module> getModuleSet()
{
return postReceiveHooks;
return moduleSet;
}
/**
@@ -402,11 +402,10 @@ public class BindingExtensionProcessor implements ExtensionProcessor
private Class<? extends FileSystem> fileSystemClass;
/** Field description */
private Set<Module> moduleSet;
private Set<RepositoryHook> hooks = new HashSet<RepositoryHook>();
/** Field description */
private Set<PostReceiveHook> postReceiveHooks =
new HashSet<PostReceiveHook>();
private Set<Module> moduleSet;
/** Field description */
private Set<RepositoryListener> repositoryListeners =

View File

@@ -148,8 +148,7 @@ public class ScmContextListener extends GuiceServletContextListener
injector.getInstance(RepositoryManager.class);
repositoryManager.addListeners(bindExtProcessor.getRepositoryListeners());
repositoryManager.addPostReceiveHooks(
bindExtProcessor.getPostReceiveHooks());
repositoryManager.addHooks(bindExtProcessor.getHooks());
repositoryManager.init(context);
// init UserManager

View File

@@ -38,24 +38,19 @@ package sonia.scm.repository.xml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.PostReceiveHook;
import sonia.scm.repository.Repository;
//~--- JDK imports ------------------------------------------------------------
import java.util.List;
import sonia.scm.repository.RepositoryHook;
import sonia.scm.repository.RepositoryHookEvent;
/**
*
* @author Sebastian Sdorra
*/
public class PostReceiveHookTask implements Runnable
public class RepositoryHookTask implements Runnable
{
/** the logger for PostReceiveHookTask */
/** the logger for RepositoryHookTask */
private static final Logger logger =
LoggerFactory.getLogger(PostReceiveHookTask.class);
LoggerFactory.getLogger(RepositoryHookTask.class);
//~--- constructors ---------------------------------------------------------
@@ -64,15 +59,12 @@ public class PostReceiveHookTask implements Runnable
*
*
* @param hook
* @param repository
* @param changesets
* @param event
*/
public PostReceiveHookTask(PostReceiveHook hook, Repository repository,
List<Changeset> changesets)
public RepositoryHookTask(RepositoryHook hook, RepositoryHookEvent event)
{
this.hook = hook;
this.repository = repository;
this.changesets = changesets;
this.event = event;
}
//~--- methods --------------------------------------------------------------
@@ -86,21 +78,20 @@ public class PostReceiveHookTask implements Runnable
{
if (logger.isDebugEnabled())
{
logger.debug("execute async PostReceiveHook {} for repository {}",
hook.getClass().getName(), repository.getName());
Object[] args = new Object[] { event.getType(), hook.getClass().getName(),
event.getRepository().getName() };
logger.debug("execute async {} hook {} for repository {}", args);
}
hook.onPostReceive(repository, changesets);
hook.onEvent(event);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private List<Changeset> changesets;
private RepositoryHookEvent event;
/** Field description */
private PostReceiveHook hook;
/** Field description */
private Repository repository;
private RepositoryHook hook;
}

View File

@@ -47,17 +47,17 @@ 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;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RepositoryHandler;
import sonia.scm.repository.RepositoryHandlerNotFoundException;
import sonia.scm.repository.RepositoryHook;
import sonia.scm.repository.RepositoryHookEvent;
import sonia.scm.repository.RepositoryNotFoundException;
import sonia.scm.security.ScmSecurityException;
import sonia.scm.store.Store;
@@ -227,18 +227,17 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
}
/**
* TODO protect
* Method description
*
*
* @param type
* @param name
* @param changesets
* @param event
*
* @throws RepositoryNotFoundException
*/
@Override
public void firePostReceiveEvent(String type, String name,
List<Changeset> changesets)
public void fireHookEvent(String type, String name, RepositoryHookEvent event)
throws RepositoryNotFoundException
{
Repository repository = repositoryDB.get(type, name);
@@ -248,20 +247,20 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
throw new RepositoryNotFoundException();
}
firePostReceiveEvent(repository, changesets);
fireHookEvent(repository, event);
}
/**
* TODO protect
* Method description
*
*
* @param id
* @param changesets
* @param event
*
* @throws RepositoryNotFoundException
*/
@Override
public void firePostReceiveEvent(String id, List<Changeset> changesets)
public void fireHookEvent(String id, RepositoryHookEvent event)
throws RepositoryNotFoundException
{
Repository repository = repositoryDB.get(id);
@@ -271,7 +270,7 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
throw new RepositoryNotFoundException();
}
firePostReceiveEvent(repository, changesets);
fireHookEvent(repository, event);
}
/**
@@ -616,28 +615,27 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
*
*
* @param hook
* @param repository
* @param changesets
* @param event
*/
@Override
protected void firePostReceiveEvent(PostReceiveHook hook,
Repository repository, List<Changeset> changesets)
protected void fireHookEvent(RepositoryHook hook, RepositoryHookEvent event)
{
if (hook.isAsynchronous())
if (hook.isAsync())
{
// TODO add queue
new Thread(new PostReceiveHookTask(hook, repository, changesets)).start();
new Thread(new RepositoryHookTask(hook, event)).start();
}
else
{
if (logger.isDebugEnabled())
{
logger.debug("execute PostReceiveHook {} for repository {}",
hook.getClass().getName(), repository.getName());
Object[] args = new Object[] { event.getType(),
hook.getClass().getName(),
event.getRepository().getName() };
logger.debug("execute {} hook {} for repository {}", args);
}
hook.onPostReceive(repository, changesets);
hook.onEvent(event);
}
}