mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
rebuild repository hook api
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
@@ -35,14 +35,21 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.HandlerEvent;
|
import sonia.scm.HandlerEvent;
|
||||||
import sonia.scm.util.AssertUtil;
|
import sonia.scm.util.AssertUtil;
|
||||||
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,16 +59,76 @@ import java.util.Set;
|
|||||||
public abstract class AbstractRepositoryManager implements RepositoryManager
|
public abstract class AbstractRepositoryManager implements RepositoryManager
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** the logger for AbstractRepositoryManager */
|
||||||
|
private static final Logger logger =
|
||||||
|
LoggerFactory.getLogger(AbstractRepositoryManager.class);
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param hook
|
* @param hook
|
||||||
* @param repository
|
* @param event
|
||||||
* @param changesets
|
|
||||||
*/
|
*/
|
||||||
protected abstract void firePostReceiveEvent(PostReceiveHook hook,
|
protected abstract void fireHookEvent(RepositoryHook hook,
|
||||||
Repository repository, List<Changeset> changesets);
|
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
|
* Method description
|
||||||
@@ -87,6 +154,32 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
|||||||
listenerSet.addAll(listeners);
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -94,40 +187,21 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
|||||||
* @param hook
|
* @param hook
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addPostReceiveHook(PostReceiveHook hook)
|
public void removeHook(RepositoryHook hook)
|
||||||
{
|
{
|
||||||
postReceiveHookSet.add(hook);
|
Collection<RepositoryHookType> types = hook.getTypes();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (types != null)
|
||||||
* 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)
|
|
||||||
{
|
{
|
||||||
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);
|
listenerSet.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param hook
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void removePostReceiveHook(PostReceiveHook hook)
|
|
||||||
{
|
|
||||||
removePostReceiveHook(hook);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -173,8 +235,9 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<PostReceiveHook> postReceiveHookSet =
|
private Map<RepositoryHookType, List<RepositoryHook>> hookMap =
|
||||||
new HashSet<PostReceiveHook>();
|
new EnumMap<RepositoryHookType,
|
||||||
|
List<RepositoryHook>>(RepositoryHookType.class);
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<RepositoryListener> listenerSet =
|
private Set<RepositoryListener> listenerSet =
|
||||||
|
|||||||
@@ -33,40 +33,43 @@
|
|||||||
|
|
||||||
package sonia.scm.repository;
|
package sonia.scm.repository;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import sonia.scm.plugin.ExtensionPoint;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Collection;
|
||||||
|
import sonia.scm.plugin.ExtensionPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for post receive events.
|
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
@ExtensionPoint
|
@ExtensionPoint
|
||||||
public interface PostReceiveHook
|
public interface RepositoryHook
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is invoked after a repository has changed.
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param repository that has changed
|
* @param event
|
||||||
* @param changesets which modified the repository
|
|
||||||
*/
|
*/
|
||||||
public void onPostReceive(Repository repository, List<Changeset> changesets);
|
public void onEvent(RepositoryHookEvent event);
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- 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();
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -36,31 +36,29 @@ package sonia.scm.repository;
|
|||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support for post receive hooks.
|
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
public interface PostReceiveHookSupport
|
public interface RepositoryHookSupport
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a new {@link PostReceiveHook}.
|
* Registers a new {@link RepositoryHook}.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param hook to register
|
* @param hook to register
|
||||||
*/
|
*/
|
||||||
public void addPostReceiveHook(PostReceiveHook hook);
|
public void addHook(RepositoryHook hook);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a {@link java.util.Collection} of hooks.
|
* Register a {@link java.util.Collection} of hooks.
|
||||||
*
|
*
|
||||||
* @param hooks to register
|
* @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
|
* Fires a post receive hook event. This methods calls the
|
||||||
@@ -69,10 +67,9 @@ public interface PostReceiveHookSupport
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param repository that has changed
|
* @param repository that has changed
|
||||||
* @param changesets which modified the repository
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void firePostReceiveEvent(Repository repository,
|
public void fireHookEvent(Repository repository, RepositoryHookEvent event);
|
||||||
List<Changeset> changesets);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires a post receive hook event. This methods calls the
|
* Fires a post receive hook event. This methods calls the
|
||||||
@@ -82,33 +79,32 @@ public interface PostReceiveHookSupport
|
|||||||
*
|
*
|
||||||
* @param type of the repository
|
* @param type of the repository
|
||||||
* @param name 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.
|
* @throws RepositoryNotFoundException if the repository could not be found.
|
||||||
*/
|
*/
|
||||||
public void firePostReceiveEvent(String type, String name,
|
public void fireHookEvent(String type, String name, RepositoryHookEvent event)
|
||||||
List<Changeset> changesets)
|
|
||||||
throws RepositoryNotFoundException;
|
throws RepositoryNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires a post receive hook event. This methods calls the
|
* Fires a hook event. This methods calls the
|
||||||
* {@link PostReceiveHook#onPostReceive(Repository, List)} of each registered
|
* {@link RepositoryHook#onEvent(RepositoryHookEvent} of each registered
|
||||||
* {@link PostReceiveHook}.
|
* {@link RepositoryHook}.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param id of the repository
|
* @param id of the repository
|
||||||
* @param changesets which modified the repository
|
* @param event
|
||||||
*
|
*
|
||||||
* @throws RepositoryNotFoundException if the repository could not be found
|
* @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;
|
throws RepositoryNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters the given {@link PostReceiveHook}.
|
* Unregisters the given {@link RepositoryHook}.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param hook to unregister
|
* @param hook to unregister
|
||||||
*/
|
*/
|
||||||
public void removePostReceiveHook(PostReceiveHook hook);
|
public void removeHook(RepositoryHook hook);
|
||||||
}
|
}
|
||||||
@@ -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 }
|
||||||
@@ -50,7 +50,7 @@ import java.util.Collection;
|
|||||||
public interface RepositoryManager
|
public interface RepositoryManager
|
||||||
extends TypeManager<Repository, RepositoryException>,
|
extends TypeManager<Repository, RepositoryException>,
|
||||||
ListenerSupport<RepositoryListener>, RepositoryBrowserProvider,
|
ListenerSupport<RepositoryListener>, RepositoryBrowserProvider,
|
||||||
PostReceiveHookSupport
|
RepositoryHookSupport
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,10 +45,12 @@ import org.eclipse.jgit.transport.ReceivePack;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import sonia.scm.repository.AbstractRepositoryHookEvent;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.GitChangesetConverter;
|
import sonia.scm.repository.GitChangesetConverter;
|
||||||
import sonia.scm.repository.GitRepositoryHandler;
|
import sonia.scm.repository.GitRepositoryHandler;
|
||||||
import sonia.scm.repository.GitUtil;
|
import sonia.scm.repository.GitUtil;
|
||||||
|
import sonia.scm.repository.RepositoryHookType;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.repository.RepositoryNotFoundException;
|
import sonia.scm.repository.RepositoryNotFoundException;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
@@ -133,8 +135,9 @@ public class GitPostReceiveHook implements PostReceiveHook
|
|||||||
|
|
||||||
String repositoryName = rpack.getRepository().getDirectory().getName();
|
String repositoryName = rpack.getRepository().getDirectory().getName();
|
||||||
|
|
||||||
repositoryManager.firePostReceiveEvent(GitRepositoryHandler.TYPE_NAME,
|
repositoryManager.fireHookEvent(GitRepositoryHandler.TYPE_NAME,
|
||||||
repositoryName, changesets);
|
repositoryName,
|
||||||
|
new GitRepositoryHook(changesets));
|
||||||
}
|
}
|
||||||
catch (RepositoryNotFoundException ex)
|
catch (RepositoryNotFoundException ex)
|
||||||
{
|
{
|
||||||
@@ -167,6 +170,62 @@ public class GitPostReceiveHook implements PostReceiveHook
|
|||||||
|| (rc.getType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD);
|
|| (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 ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ import sonia.scm.io.FileSystem;
|
|||||||
import sonia.scm.plugin.ext.Extension;
|
import sonia.scm.plugin.ext.Extension;
|
||||||
import sonia.scm.plugin.ext.ExtensionProcessor;
|
import sonia.scm.plugin.ext.ExtensionProcessor;
|
||||||
import sonia.scm.repository.ChangesetPreProcessor;
|
import sonia.scm.repository.ChangesetPreProcessor;
|
||||||
import sonia.scm.repository.PostReceiveHook;
|
|
||||||
import sonia.scm.repository.RepositoryHandler;
|
import sonia.scm.repository.RepositoryHandler;
|
||||||
|
import sonia.scm.repository.RepositoryHook;
|
||||||
import sonia.scm.repository.RepositoryListener;
|
import sonia.scm.repository.RepositoryListener;
|
||||||
import sonia.scm.resources.ResourceHandler;
|
import sonia.scm.resources.ResourceHandler;
|
||||||
import sonia.scm.security.EncryptionHandler;
|
import sonia.scm.security.EncryptionHandler;
|
||||||
@@ -212,16 +212,16 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
|||||||
|
|
||||||
changesetPreProcessorBinder.addBinding().to(extensionClass);
|
changesetPreProcessorBinder.addBinding().to(extensionClass);
|
||||||
}
|
}
|
||||||
else if (PostReceiveHook.class.isAssignableFrom(extensionClass))
|
else if (RepositoryHook.class.isAssignableFrom(extensionClass))
|
||||||
{
|
{
|
||||||
if (logger.isInfoEnabled())
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -310,9 +310,9 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Module> getModuleSet()
|
public Set<RepositoryHook> getHooks()
|
||||||
{
|
{
|
||||||
return moduleSet;
|
return hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -321,9 +321,9 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
|||||||
*
|
*
|
||||||
* @return
|
* @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;
|
private Class<? extends FileSystem> fileSystemClass;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<Module> moduleSet;
|
private Set<RepositoryHook> hooks = new HashSet<RepositoryHook>();
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<PostReceiveHook> postReceiveHooks =
|
private Set<Module> moduleSet;
|
||||||
new HashSet<PostReceiveHook>();
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Set<RepositoryListener> repositoryListeners =
|
private Set<RepositoryListener> repositoryListeners =
|
||||||
|
|||||||
@@ -148,8 +148,7 @@ public class ScmContextListener extends GuiceServletContextListener
|
|||||||
injector.getInstance(RepositoryManager.class);
|
injector.getInstance(RepositoryManager.class);
|
||||||
|
|
||||||
repositoryManager.addListeners(bindExtProcessor.getRepositoryListeners());
|
repositoryManager.addListeners(bindExtProcessor.getRepositoryListeners());
|
||||||
repositoryManager.addPostReceiveHooks(
|
repositoryManager.addHooks(bindExtProcessor.getHooks());
|
||||||
bindExtProcessor.getPostReceiveHooks());
|
|
||||||
repositoryManager.init(context);
|
repositoryManager.init(context);
|
||||||
|
|
||||||
// init UserManager
|
// init UserManager
|
||||||
|
|||||||
@@ -38,24 +38,19 @@ package sonia.scm.repository.xml;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.RepositoryHook;
|
||||||
import sonia.scm.repository.PostReceiveHook;
|
import sonia.scm.repository.RepositoryHookEvent;
|
||||||
import sonia.scm.repository.Repository;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @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 =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(PostReceiveHookTask.class);
|
LoggerFactory.getLogger(RepositoryHookTask.class);
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
@@ -64,15 +59,12 @@ public class PostReceiveHookTask implements Runnable
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param hook
|
* @param hook
|
||||||
* @param repository
|
* @param event
|
||||||
* @param changesets
|
|
||||||
*/
|
*/
|
||||||
public PostReceiveHookTask(PostReceiveHook hook, Repository repository,
|
public RepositoryHookTask(RepositoryHook hook, RepositoryHookEvent event)
|
||||||
List<Changeset> changesets)
|
|
||||||
{
|
{
|
||||||
this.hook = hook;
|
this.hook = hook;
|
||||||
this.repository = repository;
|
this.event = event;
|
||||||
this.changesets = changesets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -86,21 +78,20 @@ public class PostReceiveHookTask implements Runnable
|
|||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("execute async PostReceiveHook {} for repository {}",
|
Object[] args = new Object[] { event.getType(), hook.getClass().getName(),
|
||||||
hook.getClass().getName(), repository.getName());
|
event.getRepository().getName() };
|
||||||
|
|
||||||
|
logger.debug("execute async {} hook {} for repository {}", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook.onPostReceive(repository, changesets);
|
hook.onEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private List<Changeset> changesets;
|
private RepositoryHookEvent event;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private PostReceiveHook hook;
|
private RepositoryHook hook;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Repository repository;
|
|
||||||
}
|
}
|
||||||
@@ -47,17 +47,17 @@ import sonia.scm.HandlerEvent;
|
|||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.Type;
|
import sonia.scm.Type;
|
||||||
import sonia.scm.repository.AbstractRepositoryManager;
|
import sonia.scm.repository.AbstractRepositoryManager;
|
||||||
import sonia.scm.repository.Changeset;
|
|
||||||
import sonia.scm.repository.ChangesetViewer;
|
import sonia.scm.repository.ChangesetViewer;
|
||||||
import sonia.scm.repository.PermissionType;
|
import sonia.scm.repository.PermissionType;
|
||||||
import sonia.scm.repository.PermissionUtil;
|
import sonia.scm.repository.PermissionUtil;
|
||||||
import sonia.scm.repository.PostReceiveHook;
|
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.RepositoryAllreadyExistExeption;
|
import sonia.scm.repository.RepositoryAllreadyExistExeption;
|
||||||
import sonia.scm.repository.RepositoryBrowser;
|
import sonia.scm.repository.RepositoryBrowser;
|
||||||
import sonia.scm.repository.RepositoryException;
|
import sonia.scm.repository.RepositoryException;
|
||||||
import sonia.scm.repository.RepositoryHandler;
|
import sonia.scm.repository.RepositoryHandler;
|
||||||
import sonia.scm.repository.RepositoryHandlerNotFoundException;
|
import sonia.scm.repository.RepositoryHandlerNotFoundException;
|
||||||
|
import sonia.scm.repository.RepositoryHook;
|
||||||
|
import sonia.scm.repository.RepositoryHookEvent;
|
||||||
import sonia.scm.repository.RepositoryNotFoundException;
|
import sonia.scm.repository.RepositoryNotFoundException;
|
||||||
import sonia.scm.security.ScmSecurityException;
|
import sonia.scm.security.ScmSecurityException;
|
||||||
import sonia.scm.store.Store;
|
import sonia.scm.store.Store;
|
||||||
@@ -227,18 +227,17 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO protect
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* @param name
|
* @param name
|
||||||
* @param changesets
|
* @param event
|
||||||
*
|
*
|
||||||
* @throws RepositoryNotFoundException
|
* @throws RepositoryNotFoundException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void firePostReceiveEvent(String type, String name,
|
public void fireHookEvent(String type, String name, RepositoryHookEvent event)
|
||||||
List<Changeset> changesets)
|
|
||||||
throws RepositoryNotFoundException
|
throws RepositoryNotFoundException
|
||||||
{
|
{
|
||||||
Repository repository = repositoryDB.get(type, name);
|
Repository repository = repositoryDB.get(type, name);
|
||||||
@@ -248,20 +247,20 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
|||||||
throw new RepositoryNotFoundException();
|
throw new RepositoryNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
firePostReceiveEvent(repository, changesets);
|
fireHookEvent(repository, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO protect
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param changesets
|
* @param event
|
||||||
*
|
*
|
||||||
* @throws RepositoryNotFoundException
|
* @throws RepositoryNotFoundException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void firePostReceiveEvent(String id, List<Changeset> changesets)
|
public void fireHookEvent(String id, RepositoryHookEvent event)
|
||||||
throws RepositoryNotFoundException
|
throws RepositoryNotFoundException
|
||||||
{
|
{
|
||||||
Repository repository = repositoryDB.get(id);
|
Repository repository = repositoryDB.get(id);
|
||||||
@@ -271,7 +270,7 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
|||||||
throw new RepositoryNotFoundException();
|
throw new RepositoryNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
firePostReceiveEvent(repository, changesets);
|
fireHookEvent(repository, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -616,28 +615,27 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param hook
|
* @param hook
|
||||||
* @param repository
|
* @param event
|
||||||
* @param changesets
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void firePostReceiveEvent(PostReceiveHook hook,
|
protected void fireHookEvent(RepositoryHook hook, RepositoryHookEvent event)
|
||||||
Repository repository, List<Changeset> changesets)
|
|
||||||
{
|
{
|
||||||
if (hook.isAsynchronous())
|
if (hook.isAsync())
|
||||||
{
|
{
|
||||||
|
new Thread(new RepositoryHookTask(hook, event)).start();
|
||||||
// TODO add queue
|
|
||||||
new Thread(new PostReceiveHookTask(hook, repository, changesets)).start();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("execute PostReceiveHook {} for repository {}",
|
Object[] args = new Object[] { event.getType(),
|
||||||
hook.getClass().getName(), repository.getName());
|
hook.getClass().getName(),
|
||||||
|
event.getRepository().getName() };
|
||||||
|
|
||||||
|
logger.debug("execute {} hook {} for repository {}", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook.onPostReceive(repository, changesets);
|
hook.onEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user