diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHookEvent.java b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHookEvent.java new file mode 100644 index 0000000000..26c9f5b722 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHookEvent.java @@ -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; +} diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryManager.java b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryManager.java index d3fc2f92ef..98aa27f788 100644 --- a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryManager.java +++ b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryManager.java @@ -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 changesets); + protected abstract void fireHookEvent(RepositoryHook hook, + RepositoryHookEvent event); + + /** + * Method description + * + * + * @param hook + */ + @Override + public void addHook(RepositoryHook hook) + { + Collection types = hook.getTypes(); + + if (types != null) + { + for (RepositoryHookType type : types) + { + if (logger.isDebugEnabled()) + { + logger.debug("register {} hook {}", type, hook.getClass()); + } + + synchronized (AbstractRepositoryManager.class) + { + List hooks = hookMap.get(type); + + if (hooks == null) + { + hooks = new ArrayList(); + 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 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 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 types = hook.getTypes(); - /** - * Method description - * - * - * @param hooks - */ - @Override - public void addPostReceiveHooks(Collection hooks) - { - postReceiveHookSet.addAll(hooks); - } - - /** - * Method description - * - * - * @param repository - * @param changesets - */ - @Override - public void firePostReceiveEvent(Repository repository, - List changesets) - { - AssertUtil.assertIsNotNull(repository); - AssertUtil.assertIsNotEmpty(changesets); - - for (PostReceiveHook hook : postReceiveHookSet) + if (types != null) { - firePostReceiveEvent(hook, repository, changesets); + for (RepositoryHookType type : types) + { + List 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 postReceiveHookSet = - new HashSet(); + private Map> hookMap = + new EnumMap>(RepositoryHookType.class); /** Field description */ private Set listenerSet = diff --git a/scm-core/src/main/java/sonia/scm/repository/PostReceiveHook.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryHook.java similarity index 78% rename from scm-core/src/main/java/sonia/scm/repository/PostReceiveHook.java rename to scm-core/src/main/java/sonia/scm/repository/RepositoryHook.java index ec99558272..6502eb4c8a 100644 --- a/scm-core/src/main/java/sonia/scm/repository/PostReceiveHook.java +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryHook.java @@ -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 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 getTypes(); + + /** + * Method description + * + * + * @return + */ + public boolean isAsync(); } diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryHookEvent.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookEvent.java new file mode 100644 index 0000000000..9065e3568c --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookEvent.java @@ -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 getChangesets(); + + /** + * Method description + * + * + * @return + */ + public Repository getRepository(); + + /** + * Method description + * + * + * @return + */ + public RepositoryHookType getType(); + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param repository + */ + void setRepository(Repository repository); +} diff --git a/scm-core/src/main/java/sonia/scm/repository/PostReceiveHookSupport.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookSupport.java similarity index 73% rename from scm-core/src/main/java/sonia/scm/repository/PostReceiveHookSupport.java rename to scm-core/src/main/java/sonia/scm/repository/RepositoryHookSupport.java index 56769ca72c..63452822ef 100644 --- a/scm-core/src/main/java/sonia/scm/repository/PostReceiveHookSupport.java +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookSupport.java @@ -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 hooks); + public void addHooks(Collection 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 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 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 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); } diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryHookType.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookType.java new file mode 100644 index 0000000000..aab40d4b88 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookType.java @@ -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 } diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryManager.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryManager.java index 5bfc6283e1..d373acd13c 100644 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryManager.java +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryManager.java @@ -50,7 +50,7 @@ import java.util.Collection; public interface RepositoryManager extends TypeManager, ListenerSupport, RepositoryBrowserProvider, - PostReceiveHookSupport + RepositoryHookSupport { /** diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitPostReceiveHook.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitPostReceiveHook.java index 1938de533b..23b0321fbd 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitPostReceiveHook.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitPostReceiveHook.java @@ -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 changesets) + { + this.changesets = changesets; + } + + //~--- get methods -------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + public Collection getChangesets() + { + return changesets; + } + + /** + * Method description + * + * + * @return + */ + @Override + public RepositoryHookType getType() + { + return RepositoryHookType.POST_RECEIVE; + } + + //~--- fields ------------------------------------------------------------- + + /** Field description */ + private Collection changesets; + } + + //~--- fields --------------------------------------------------------------- /** Field description */ diff --git a/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java b/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java index 136ed2be25..be49d54df7 100644 --- a/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java +++ b/scm-webapp/src/main/java/sonia/scm/BindingExtensionProcessor.java @@ -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 getModuleSet() + public Set getHooks() { - return moduleSet; + return hooks; } /** @@ -321,9 +321,9 @@ public class BindingExtensionProcessor implements ExtensionProcessor * * @return */ - public Set getPostReceiveHooks() + public Set getModuleSet() { - return postReceiveHooks; + return moduleSet; } /** @@ -402,11 +402,10 @@ public class BindingExtensionProcessor implements ExtensionProcessor private Class fileSystemClass; /** Field description */ - private Set moduleSet; + private Set hooks = new HashSet(); /** Field description */ - private Set postReceiveHooks = - new HashSet(); + private Set moduleSet; /** Field description */ private Set repositoryListeners = diff --git a/scm-webapp/src/main/java/sonia/scm/ScmContextListener.java b/scm-webapp/src/main/java/sonia/scm/ScmContextListener.java index 4a109ad6ef..6c75c5db86 100644 --- a/scm-webapp/src/main/java/sonia/scm/ScmContextListener.java +++ b/scm-webapp/src/main/java/sonia/scm/ScmContextListener.java @@ -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 diff --git a/scm-webapp/src/main/java/sonia/scm/repository/xml/PostReceiveHookTask.java b/scm-webapp/src/main/java/sonia/scm/repository/xml/RepositoryHookTask.java similarity index 71% rename from scm-webapp/src/main/java/sonia/scm/repository/xml/PostReceiveHookTask.java rename to scm-webapp/src/main/java/sonia/scm/repository/xml/RepositoryHookTask.java index 8d98a3cb8a..bb8a856bd4 100644 --- a/scm-webapp/src/main/java/sonia/scm/repository/xml/PostReceiveHookTask.java +++ b/scm-webapp/src/main/java/sonia/scm/repository/xml/RepositoryHookTask.java @@ -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 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 changesets; + private RepositoryHookEvent event; /** Field description */ - private PostReceiveHook hook; - - /** Field description */ - private Repository repository; + private RepositoryHook hook; } diff --git a/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java b/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java index b3bb8f4a49..6a4bd1416c 100644 --- a/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java +++ b/scm-webapp/src/main/java/sonia/scm/repository/xml/XmlRepositoryManager.java @@ -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 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 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 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); } }