From 66d1390fd188baaeb3aaf02eef1abe77c5a73a0b Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 17 Jul 2011 18:02:01 +0200 Subject: [PATCH] improve post receive hook api --- .../repository/PostReceiveHookSupport.java | 32 +++++++++++- .../RepositoryNotFoundException.java | 46 +++++++++++++++++ .../repository/xml/XmlRepositoryManager.java | 49 +++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 scm-core/src/main/java/sonia/scm/repository/RepositoryNotFoundException.java diff --git a/scm-core/src/main/java/sonia/scm/repository/PostReceiveHookSupport.java b/scm-core/src/main/java/sonia/scm/repository/PostReceiveHookSupport.java index c0782f4e29..ad1318019b 100644 --- a/scm-core/src/main/java/sonia/scm/repository/PostReceiveHookSupport.java +++ b/scm-core/src/main/java/sonia/scm/repository/PostReceiveHookSupport.java @@ -64,7 +64,37 @@ public interface PostReceiveHookSupport * @param changesets which modified the repository */ public void firePostReceiveEvent(Repository repository, - List changesets); + List changesets); + + /** + * Fires a post receive hook event. This methods calls the + * {@link PostReceiveHook#onPostReceive(Repository, List)} of each registered + * {@link PostReceiveHook}. + * + * + * @param type of the repository + * @param name of the repository + * @param changesets which modified the repository + * + * @throws RepositoryNotFoundException if the repository could not be found. + */ + public void firePostReceiveEvent(String type, String name, + List changesets) + throws RepositoryNotFoundException; + + /** + * Fires a post receive hook event. This methods calls the + * {@link PostReceiveHook#onPostReceive(Repository, List)} of each registered + * {@link PostReceiveHook}. + * + * + * @param id of the repository + * @param changesets which modified the repository + * + * @throws RepositoryNotFoundException if the repository could not be found + */ + public void firePostReceiveEvent(String id, List changesets) + throws RepositoryNotFoundException; /** * Unregisters the given {@link PostReceiveHook}. diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryNotFoundException.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryNotFoundException.java new file mode 100644 index 0000000000..d1ed0501e5 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryNotFoundException.java @@ -0,0 +1,46 @@ +/** + * 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 class RepositoryNotFoundException extends RepositoryException +{ + + /** Field description */ + private static final long serialVersionUID = -6583078808900520166L; +} 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 cba913106d..ef71497644 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 @@ -58,6 +58,7 @@ import sonia.scm.repository.RepositoryBrowser; import sonia.scm.repository.RepositoryException; import sonia.scm.repository.RepositoryHandler; import sonia.scm.repository.RepositoryHandlerNotFoundException; +import sonia.scm.repository.RepositoryNotFoundException; import sonia.scm.security.ScmSecurityException; import sonia.scm.store.Store; import sonia.scm.store.StoreFactory; @@ -225,6 +226,54 @@ public class XmlRepositoryManager extends AbstractRepositoryManager fireEvent(repository, HandlerEvent.DELETE); } + /** + * TODO protect + * + * + * @param type + * @param name + * @param changesets + * + * @throws RepositoryNotFoundException + */ + @Override + public void firePostReceiveEvent(String type, String name, + List changesets) + throws RepositoryNotFoundException + { + Repository repository = repositoryDB.get(type, name); + + if (repository != null) + { + throw new RepositoryNotFoundException(); + } + + firePostReceiveEvent(repository, changesets); + } + + /** + * TODO protect + * + * + * @param id + * @param changesets + * + * @throws RepositoryNotFoundException + */ + @Override + public void firePostReceiveEvent(String id, List changesets) + throws RepositoryNotFoundException + { + Repository repository = repositoryDB.get(id); + + if (repository != null) + { + throw new RepositoryNotFoundException(); + } + + firePostReceiveEvent(repository, changesets); + } + /** * Method description *