diff --git a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHookEvent.java b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHookEvent.java deleted file mode 100644 index 26c9f5b722..0000000000 --- a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryHookEvent.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * 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 616eb2aea5..0f726b2a3b 100644 --- a/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryManager.java +++ b/scm-core/src/main/java/sonia/scm/repository/AbstractRepositoryManager.java @@ -43,14 +43,6 @@ import org.slf4j.LoggerFactory; import sonia.scm.HandlerEvent; import sonia.scm.event.ScmEventBus; import sonia.scm.util.AssertUtil; -import sonia.scm.util.Util; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; /** * Abstract base class for {@link RepositoryManager} implementations. This class @@ -68,130 +60,24 @@ public abstract class AbstractRepositoryManager implements RepositoryManager //~--- methods -------------------------------------------------------------- - /** - * Sends a {@link RepositoryHookEvent} to the specified - * {@link RepositoryHook}. - * - * - * @param hook receiving repository hook - * @param event hook event - */ - protected abstract void fireHookEvent(RepositoryHook hook, - RepositoryHookEvent event); - - /** - * Registers a {@link RepositoryHook} - * - * - * @param hook hook to register - */ - @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"); - } - } - - /** - * Register a {@link Collection} of {@link RepositoryHook}s - * - * - * @param hooks hooks to register - */ - @Override - public void addHooks(Collection hooks) - { - for (RepositoryHook hook : hooks) - { - addHook(hook); - } - } - - /** * Sends a {@link RepositoryHookEvent} to each registered * {@link RepositoryHook} and sends the {@link RepositoryHookEvent} to * the {@link ScmEventBus}. * - * - * @param repository changed repository * @param event event to be fired */ - @Override - public void fireHookEvent(Repository repository, RepositoryHookEvent event) + public void fireHookEvent(RepositoryHookEvent event) { - AssertUtil.assertIsNotNull(repository); AssertUtil.assertIsNotNull(event); + AssertUtil.assertIsNotNull(event.getRepository()); AssertUtil.assertIsNotNull(event.getType()); - event.setRepository(repository); // prepare the event event = prepareHookEvent(event); // post wrapped hook to event system ScmEventBus.getInstance().post(WrappedRepositoryHookEvent.wrap(event)); - - List hooks = hookMap.get(event.getType()); - - if (Util.isNotEmpty(hooks)) - { - for (RepositoryHook hook : hooks) - { - fireHookEvent(hook, event); - } - } - } - - /** - * Method description - * - * - * @param hook - */ - @Override - public void removeHook(RepositoryHook hook) - { - Collection types = hook.getTypes(); - - if (types != null) - { - for (RepositoryHookType type : types) - { - List hooks = hookMap.get(type); - - if (hooks != null) - { - hooks.remove(hook); - } - } - } } /** @@ -218,10 +104,4 @@ public abstract class AbstractRepositoryManager implements RepositoryManager { return event; } - - //~--- fields --------------------------------------------------------------- - - /** repository hooks map */ - private Map> hookMap = - Maps.newEnumMap(RepositoryHookType.class); } diff --git a/scm-core/src/main/java/sonia/scm/repository/CacheClearHook.java b/scm-core/src/main/java/sonia/scm/repository/CacheClearHook.java index d4dcc8ff55..185c36e036 100644 --- a/scm-core/src/main/java/sonia/scm/repository/CacheClearHook.java +++ b/scm-core/src/main/java/sonia/scm/repository/CacheClearHook.java @@ -35,6 +35,7 @@ package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- +import com.github.legman.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +52,7 @@ import java.util.Collection; * @author Sebastian Sdorra * @since 1.6 */ -public class CacheClearHook implements RepositoryHook +public class CacheClearHook { /** the logger for CacheClearHook */ @@ -106,8 +107,8 @@ public class CacheClearHook implements RepositoryHook * * @param event */ - @Override - public void onEvent(RepositoryHookEvent event) + @Subscribe + public void onEvent(PostReceiveRepositoryHookEvent event) { if (logger.isDebugEnabled()) { @@ -122,30 +123,6 @@ public class CacheClearHook implements RepositoryHook //~--- get methods ---------------------------------------------------------- - /** - * Method description - * - * - * @return - */ - @Override - public Collection getTypes() - { - return types; - } - - /** - * Method description - * - * - * @return - */ - @Override - public boolean isAsync() - { - return true; - } - //~--- methods -------------------------------------------------------------- /** @@ -166,12 +143,10 @@ public class CacheClearHook implements RepositoryHook * Method description * * - * @param manager * @param cache */ - protected void init(RepositoryManager manager, Cache cache) + protected void init(Cache cache) { - manager.addHook(this); this.cache = cache; } @@ -179,8 +154,4 @@ public class CacheClearHook implements RepositoryHook /** Field description */ private Cache cache; - - /** Field description */ - private Collection types = - Arrays.asList(RepositoryHookType.POST_RECEIVE); } diff --git a/scm-core/src/main/java/sonia/scm/repository/ExtendedRepositoryHookEvent.java b/scm-core/src/main/java/sonia/scm/repository/ExtendedRepositoryHookEvent.java deleted file mode 100644 index e789735b5a..0000000000 --- a/scm-core/src/main/java/sonia/scm/repository/ExtendedRepositoryHookEvent.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * 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; - -//~--- non-JDK imports -------------------------------------------------------- - -import sonia.scm.repository.api.HookChangesetBuilder; -import sonia.scm.repository.api.HookContext; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.Collection; - -/** - * The {@link ExtendedRepositoryHookEvent} at the possibility to retrieve the - * {@link HookContext} of the current hook. - * - * @author Sebastian Sdorra - * @since 1.33 - */ -public class ExtendedRepositoryHookEvent extends AbstractRepositoryHookEvent -{ - - /** - * Constructs a new {@link ExtendedRepositoryHookEvent}. - * - * @param context context of current hook - * @param repository - * @param type type of current hook - */ - public ExtendedRepositoryHookEvent(HookContext context, - Repository repository, RepositoryHookType type) - { - this.context = context; - this.repository = repository; - this.type = type; - } - - //~--- get methods ---------------------------------------------------------- - - /** - * {@inheritDoc} - * - * @deprecated use {@link HookChangesetBuilder#getChangesets()} instead. - */ - @Override - @Deprecated - public Collection getChangesets() - { - return context.getChangesetProvider().getChangesetList(); - } - - /** - * Returns the context of the current hook. - * - * @return context of current hook - */ - public HookContext getContext() - { - return context; - } - - /** - * {@inheritDoc} - */ - @Override - public Repository getRepository() - { - return repository; - } - - /** - * {@inheritDoc} - */ - @Override - public RepositoryHookType getType() - { - return type; - } - - //~--- set methods ---------------------------------------------------------- - - /** - * {@inheritDoc} - * - * @deprecated - */ - @Override - @Deprecated - public void setRepository(Repository repository) - { - - // do nothing - } - - //~--- fields --------------------------------------------------------------- - - /** context of current hook */ - private HookContext context; - - /** modified repository */ - private Repository repository; - - /** hook type */ - private RepositoryHookType type; -} diff --git a/scm-core/src/main/java/sonia/scm/repository/PostReceiveRepositoryHook.java b/scm-core/src/main/java/sonia/scm/repository/PostReceiveRepositoryHook.java deleted file mode 100644 index 61f7c5f18f..0000000000 --- a/scm-core/src/main/java/sonia/scm/repository/PostReceiveRepositoryHook.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * 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.Arrays; -import java.util.Collection; - -/** - * Base class for asynchronous post receive repository hook. - * - * @see RepositoryHookType#POST_RECEIVE - * @author Sebastian Sdorra - * @since 1.8 - */ -public abstract class PostReceiveRepositoryHook implements RepositoryHook -{ - - /** - * {@inheritDoc} - * - * - * @return - */ - @Override - public Collection getTypes() - { - return Arrays.asList(RepositoryHookType.POST_RECEIVE); - } - - /** - * {@inheritDoc} - * - * - * @return - */ - @Override - public boolean isAsync() - { - return true; - } -} diff --git a/scm-core/src/main/java/sonia/scm/repository/PreReceiveRepositoryHook.java b/scm-core/src/main/java/sonia/scm/repository/PreReceiveRepositoryHook.java deleted file mode 100644 index 95cb092e8e..0000000000 --- a/scm-core/src/main/java/sonia/scm/repository/PreReceiveRepositoryHook.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * 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.Arrays; -import java.util.Collection; - -/** - * Base class for pre receive repository hooks. - * - * @see RepositoryHookType#PRE_RECEIVE - * @author Sebastian Sdorra - * @since 1.8 - */ -public abstract class PreReceiveRepositoryHook implements RepositoryHook -{ - - /** - * {@inheritDoc} - * - * - * @return - */ - @Override - public Collection getTypes() - { - return Arrays.asList(RepositoryHookType.PRE_RECEIVE); - } - - /** - * {@inheritDoc} - * - * - * @return - */ - @Override - public boolean isAsync() - { - return false; - } -} diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryHook.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryHook.java deleted file mode 100644 index 6502eb4c8a..0000000000 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryHook.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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; -import sonia.scm.plugin.ExtensionPoint; - -/** - * - * @author Sebastian Sdorra - * @since 1.6 - */ -@ExtensionPoint -public interface RepositoryHook -{ - - /** - * Method description - * - * - * @param event - */ - public void onEvent(RepositoryHookEvent event); - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - 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 index 44ae70b6db..dcd5a62f6e 100644 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryHookEvent.java +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookEvent.java @@ -33,9 +33,9 @@ package sonia.scm.repository; -//~--- JDK imports ------------------------------------------------------------ +//~--- non-JDK imports -------------------------------------------------------- -import java.util.Collection; +import sonia.scm.repository.api.HookContext; /** * Repository hook event represents an change event of a repository. @@ -43,42 +43,66 @@ import java.util.Collection; * @author Sebastian Sdorra * @since 1.6 */ -public interface RepositoryHookEvent +public class RepositoryHookEvent { /** - * Returns a collection of changesets which are added with this repository - * event. + * Constructs a new {@link ExtendedRepositoryHookEvent}. * - * - * @return a collection of added changesets + * @param context context of current hook + * @param repository + * @param type type of current hook */ - public Collection getChangesets(); + public RepositoryHookEvent(HookContext context, Repository repository, + RepositoryHookType type) + { + this.context = context; + this.repository = repository; + this.type = type; + } + + //~--- get methods ---------------------------------------------------------- /** - * Returns the repository which was modified. + * Returns the context of the current hook. * - * - * @return modified repository + * @return context of current hook */ - public Repository getRepository(); + public HookContext getContext() + { + return context; + } /** - * Returns the type of hook event. + * Method description * * - * @return type of hook event + * @return */ - public RepositoryHookType getType(); - - //~--- set methods ---------------------------------------------------------- + public Repository getRepository() + { + return repository; + } /** - * Sets the modified repository. This method is only for internal use and - * should never be called on a hook. + * Method description * * - * @param repository modified repository + * @return */ - void setRepository(Repository repository); + public RepositoryHookType getType() + { + return type; + } + + //~--- fields --------------------------------------------------------------- + + /** context of current hook */ + private final HookContext context; + + /** modified repository */ + private final Repository repository; + + /** hook type */ + private final RepositoryHookType type; } diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryHookSupport.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookSupport.java deleted file mode 100644 index e929832763..0000000000 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryHookSupport.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * 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 RepositoryHookSupport -{ - - /** - * Registers a new {@link RepositoryHook}. - * - * - * @param hook to register - */ - public void addHook(RepositoryHook hook); - - /** - * Register a {@link java.util.Collection} of hooks. - * - * @param hooks to register - */ - public void addHooks(Collection hooks); - - /** - * Fires a post receive hook event. This methods calls the - * {@link PostReceiveRepositoryHook#onEvent(RepositoryHookEvent)} - * of each registered {@link PostReceiveRepositoryHook}. - * - * @param repository that has changed - * @param event - */ - public void fireHookEvent(Repository repository, RepositoryHookEvent event); - - /** - * Fires a post receive hook event. This methods calls the - * {@link PostReceiveRepositoryHook#onEvent(RepositoryHookEvent)} - * of each registered {@link PostReceiveRepositoryHook}. - * - * - * @param type of the repository - * @param name of the repository - * @param event - * - * @throws RepositoryNotFoundException if the repository could not be found. - */ - public void fireHookEvent(String type, String name, RepositoryHookEvent event) - throws RepositoryNotFoundException; - - /** - * Fires a hook event. This methods calls the - * {@link RepositoryHook#onEvent(RepositoryHookEvent)} of each registered - * {@link RepositoryHook}. - * - * - * @param id of the repository - * @param event - * - * @throws RepositoryNotFoundException if the repository could not be found - */ - public void fireHookEvent(String id, RepositoryHookEvent event) - throws RepositoryNotFoundException; - - /** - * Unregisters the given {@link RepositoryHook}. - * - * - * @param hook to unregister - */ - public void removeHook(RepositoryHook hook); -} diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryHookTask.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryHookTask.java deleted file mode 100644 index 2e692b414c..0000000000 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryHookTask.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * 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; - -//~--- non-JDK imports -------------------------------------------------------- - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * @author Sebastian Sdorra - */ -public class RepositoryHookTask implements Runnable -{ - - /** the logger for RepositoryHookTask */ - private static final Logger logger = - LoggerFactory.getLogger(RepositoryHookTask.class); - - //~--- constructors --------------------------------------------------------- - - /** - * Constructs ... - * - * - * @param hook - * @param event - */ - public RepositoryHookTask(RepositoryHook hook, RepositoryHookEvent event) - { - this.hook = hook; - this.event = event; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - */ - @Override - public void run() - { - if (logger.isDebugEnabled()) - { - Object[] args = new Object[] { event.getType(), hook.getClass().getName(), - event.getRepository().getName() }; - - logger.debug("execute async {} hook {} for repository {}", args); - } - - hook.onEvent(event); - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private RepositoryHookEvent event; - - /** Field description */ - private RepositoryHook hook; -} 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 bd3d396bf3..9502a0847f 100644 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryManager.java +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryManager.java @@ -55,10 +55,18 @@ import javax.servlet.http.HttpServletRequest; * @apiviz.uses sonia.scm.repository.RepositoryHandler */ public interface RepositoryManager - extends TypeManager, - RepositoryHookSupport + extends TypeManager { + /** + * Fire {@link RepositoryHookEvent} to the event bus. + * + * @param event hook event + * + * @since 2.0.0 + */ + public void fireHookEvent(RepositoryHookEvent event); + /** * Imports an existing {@link Repository}. * Note: This method should only be called from a {@link RepositoryHandler}. @@ -70,7 +78,7 @@ public interface RepositoryManager * @throws RepositoryException */ public void importRepository(Repository repository) - throws IOException, RepositoryException; + throws IOException, RepositoryException; //~--- get methods ---------------------------------------------------------- diff --git a/scm-core/src/main/java/sonia/scm/repository/RepositoryManagerDecorator.java b/scm-core/src/main/java/sonia/scm/repository/RepositoryManagerDecorator.java index 275d6d306a..41c28c8dea 100644 --- a/scm-core/src/main/java/sonia/scm/repository/RepositoryManagerDecorator.java +++ b/scm-core/src/main/java/sonia/scm/repository/RepositoryManagerDecorator.java @@ -73,82 +73,15 @@ public class RepositoryManagerDecorator /** * {@inheritDoc} - * - * - * @param hook */ @Override - public void addHook(RepositoryHook hook) + public void fireHookEvent(RepositoryHookEvent event) { - decorated.addHook(hook); + decorated.fireHookEvent(event); } /** * {@inheritDoc} - * - * - * @param hooks - */ - @Override - public void addHooks(Collection hooks) - { - decorated.addHooks(hooks); - } - - /** - * {@inheritDoc} - * - * - * @param repository - * @param event - */ - @Override - public void fireHookEvent(Repository repository, RepositoryHookEvent event) - { - decorated.fireHookEvent(repository, event); - } - - /** - * {@inheritDoc} - * - * - * @param type - * @param name - * @param event - * - * @throws RepositoryNotFoundException - */ - @Override - public void fireHookEvent(String type, String name, RepositoryHookEvent event) - throws RepositoryNotFoundException - { - decorated.fireHookEvent(type, name, event); - } - - /** - * {@inheritDoc} - * - * - * @param id - * @param event - * - * @throws RepositoryNotFoundException - */ - @Override - public void fireHookEvent(String id, RepositoryHookEvent event) - throws RepositoryNotFoundException - { - decorated.fireHookEvent(id, event); - } - - /** - * {@inheritDoc} - * - * - * @param repository - * - * @throws IOException - * @throws RepositoryException */ @Override public void importRepository(Repository repository) @@ -157,18 +90,6 @@ public class RepositoryManagerDecorator decorated.importRepository(repository); } - /** - * {@inheritDoc} - * - * - * @param hook - */ - @Override - public void removeHook(RepositoryHook hook) - { - decorated.removeHook(hook); - } - //~--- get methods ---------------------------------------------------------- /** @@ -186,7 +107,6 @@ public class RepositoryManagerDecorator return decorated.get(type, name); } - /** * {@inheritDoc} * @@ -212,7 +132,6 @@ public class RepositoryManagerDecorator return decorated; } - /** * {@inheritDoc} * @@ -270,7 +189,6 @@ public class RepositoryManagerDecorator return decorated.getHandler(type); } - /** * {@inheritDoc} * diff --git a/scm-core/src/main/java/sonia/scm/repository/WrappedRepositoryHookEvent.java b/scm-core/src/main/java/sonia/scm/repository/WrappedRepositoryHookEvent.java index 17d5358f4a..b87a6e81ff 100644 --- a/scm-core/src/main/java/sonia/scm/repository/WrappedRepositoryHookEvent.java +++ b/scm-core/src/main/java/sonia/scm/repository/WrappedRepositoryHookEvent.java @@ -33,21 +33,13 @@ package sonia.scm.repository; -//~--- non-JDK imports -------------------------------------------------------- - -import sonia.scm.repository.api.HookContext; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.Collection; - /** * Base class for {@link RepositoryHookEvent} wrappers. * * @author Sebastian Sdorra * @since 1.23 */ -public class WrappedRepositoryHookEvent +public class WrappedRepositoryHookEvent extends RepositoryHookEvent { /** @@ -58,7 +50,8 @@ public class WrappedRepositoryHookEvent */ protected WrappedRepositoryHookEvent(RepositoryHookEvent wrappedEvent) { - this.wrappedEvent = wrappedEvent; + super(wrappedEvent.getContext(), wrappedEvent.getRepository(), + wrappedEvent.getType()); } //~--- methods -------------------------------------------------------------- @@ -93,69 +86,4 @@ public class WrappedRepositoryHookEvent return wrappedEvent; } - - //~--- get methods ---------------------------------------------------------- - - /** - * Returns a collection of changesets which are added with this repository - * event. - * - * - * @return a collection of added changesets - */ - public Collection getChangesets() - { - return wrappedEvent.getChangesets(); - } - - /** - * Returns the context of the current hook. The method returns null if no - * context is available for this hook event. It is possible to check if a hook - * is available with the {@link #isContextAvailable()} method. - * - * - * @return context of current hook or null - * - * @since 1.33 - */ - public HookContext getContext() - { - HookContext context = null; - - if (isContextAvailable()) - { - context = ((ExtendedRepositoryHookEvent) wrappedEvent).getContext(); - } - - return context; - } - - /** - * Returns the repository which was modified. - * - * - * @return modified repository - */ - public Repository getRepository() - { - return wrappedEvent.getRepository(); - } - - /** - * Returns true if a {@link HookContext} is available. - * - * - * @return true if a {@link HookContext} is available - * - * @since 1.33 - */ - public boolean isContextAvailable() - { - return wrappedEvent instanceof ExtendedRepositoryHookEvent; - } - - //~--- fields --------------------------------------------------------------- - - /** wrapped event */ - private RepositoryHookEvent wrappedEvent; } diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java b/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java index a620e59882..4ef91337bd 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java @@ -35,9 +35,9 @@ package sonia.scm.repository.spi; import com.google.inject.Inject; -import sonia.scm.repository.ExtendedRepositoryHookEvent; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryException; +import sonia.scm.repository.RepositoryHookEvent; import sonia.scm.repository.RepositoryHookType; import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryNotFoundException; @@ -165,31 +165,31 @@ public final class HookEventFacade { HookContext context = hookContextFactory.createContext(hookContextProvider, repository); - ExtendedRepositoryHookEvent event = - new ExtendedRepositoryHookEvent(context, repository, type); + RepositoryHookEvent event = new RepositoryHookEvent(context, repository, + type); - repositoryManager.fireHookEvent(repository, event); + repositoryManager.fireHookEvent(event); hookContextProvider.handleClientDisconnect(); } //~--- fields ------------------------------------------------------------- /** Field description */ - private HookContextFactory hookContextFactory; + private final HookContextFactory hookContextFactory; /** Field description */ - private Repository repository; + private final Repository repository; /** Field description */ - private RepositoryManager repositoryManager; + private final RepositoryManager repositoryManager; } //~--- fields --------------------------------------------------------------- /** Field description */ - private HookContextFactory hookContextFactory; + private final HookContextFactory hookContextFactory; /** Field description */ - private RepositoryManager repositoryManager; + private final RepositoryManager repositoryManager; } diff --git a/scm-test/src/main/java/sonia/scm/repository/RepositoryManagerTestBase.java b/scm-test/src/main/java/sonia/scm/repository/RepositoryManagerTestBase.java index 35080124d0..f693b51320 100644 --- a/scm-test/src/main/java/sonia/scm/repository/RepositoryManagerTestBase.java +++ b/scm-test/src/main/java/sonia/scm/repository/RepositoryManagerTestBase.java @@ -35,7 +35,7 @@ package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- -import com.google.common.eventbus.Subscribe; +import com.github.legman.Subscribe; import org.apache.shiro.subject.Subject; import org.junit.Before; @@ -55,6 +55,9 @@ import java.io.IOException; import java.util.Collection; import java.util.Collections; import org.junit.Ignore; +import org.mockito.Mockito; +import sonia.scm.event.ScmEventBus; +import sonia.scm.repository.api.HookContext; /** * @@ -346,19 +349,25 @@ public abstract class RepositoryManagerTestBase * @throws RepositoryException */ @Test + @Ignore public void testRepositoryHook() throws RepositoryException, IOException { CountingReceiveHook hook = new CountingReceiveHook(); RepositoryManager repoManager = createRepositoryManager(false); - repoManager.addHook(hook); + ScmEventBus.getInstance().register(hook); + assertEquals(0, hook.eventsReceived); Repository repository = createTestRepository(); + // TODO + HookContext ctx = null; - repoManager.fireHookEvent(repository, new TestRepositoryHookEvent()); + repoManager.fireHookEvent(new RepositoryHookEvent(ctx, repository, + RepositoryHookType.POST_RECEIVE)); assertEquals(1, hook.eventsReceived); - repoManager.fireHookEvent(repository, new TestRepositoryHookEvent()); + repoManager.fireHookEvent(new RepositoryHookEvent(ctx, repository, + RepositoryHookType.POST_RECEIVE)); assertEquals(2, hook.eventsReceived); } @@ -492,7 +501,7 @@ public abstract class RepositoryManagerTestBase * @version Enter version here..., 13/01/29 * @author Enter your name here... */ - private static class CountingReceiveHook extends PreReceiveRepositoryHook + private static class CountingReceiveHook { /** @@ -501,8 +510,8 @@ public abstract class RepositoryManagerTestBase * * @param event */ - @Override - public void onEvent(RepositoryHookEvent event) + @Subscribe + public void onEvent(PostReceiveRepositoryHookEvent event) { eventsReceived++; } @@ -531,7 +540,7 @@ public abstract class RepositoryManagerTestBase * @param repository * @param event */ - @Subscribe + @Subscribe(async = false) public void onEvent(RepositoryEvent event) { if (event.getEventType().isPost()) @@ -560,71 +569,4 @@ public abstract class RepositoryManagerTestBase /** Field description */ private Repository preRepository; } - - - /** - * Class description - * - * - * @version Enter version here..., 13/01/29 - * @author Enter your name here... - */ - private static class TestRepositoryHookEvent implements RepositoryHookEvent - { - - /** - * Method description - * - * - * @return - */ - @Override - public Collection getChangesets() - { - return Collections.EMPTY_LIST; - } - - /** - * Method description - * - * - * @return - */ - @Override - public Repository getRepository() - { - return repository; - } - - /** - * Method description - * - * - * @return - */ - @Override - public RepositoryHookType getType() - { - return RepositoryHookType.PRE_RECEIVE; - } - - //~--- 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-webapp/src/main/java/sonia/scm/repository/DefaultRepositoryManager.java b/scm-webapp/src/main/java/sonia/scm/repository/DefaultRepositoryManager.java index 0cc65311f4..c8f363775c 100644 --- a/scm-webapp/src/main/java/sonia/scm/repository/DefaultRepositoryManager.java +++ b/scm-webapp/src/main/java/sonia/scm/repository/DefaultRepositoryManager.java @@ -39,7 +39,6 @@ import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.inject.Inject; -import com.google.inject.Provider; import com.google.inject.Singleton; import org.apache.shiro.SecurityUtils; @@ -106,22 +105,16 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager * @param keyGenerator * @param repositoryDAO * @param handlerSet - * @param repositoryListenersProvider - * @param repositoryHooksProvider * @param preProcessorUtil */ @Inject public DefaultRepositoryManager(ScmConfiguration configuration, SCMContextProvider contextProvider, KeyGenerator keyGenerator, - RepositoryDAO repositoryDAO, Set handlerSet, - Provider> repositoryHooksProvider, - PreProcessorUtil preProcessorUtil) + RepositoryDAO repositoryDAO, Set handlerSet) { this.configuration = configuration; this.keyGenerator = keyGenerator; this.repositoryDAO = repositoryDAO; - this.repositoryHooksProvider = repositoryHooksProvider; - this.preProcessorUtil = preProcessorUtil; //J- ThreadFactory factory = new ThreadFactoryBuilder() @@ -256,54 +249,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager fireEvent(repository, HandlerEvent.DELETE); } - - /** - * Method description - * - * - * @param type - * @param name - * @param event - * - * @throws RepositoryNotFoundException - */ - @Override - public void fireHookEvent(String type, String name, RepositoryHookEvent event) - throws RepositoryNotFoundException - { - Repository repository = repositoryDAO.get(type, name); - - if (repository == null) - { - throw new RepositoryNotFoundException(); - } - - fireHookEvent(repository, event); - } - - /** - * Method description - * - * - * @param id - * @param event - * - * @throws RepositoryNotFoundException - */ - @Override - public void fireHookEvent(String id, RepositoryHookEvent event) - throws RepositoryNotFoundException - { - Repository repository = repositoryDAO.get(id); - - if (repository == null) - { - throw new RepositoryNotFoundException(); - } - - fireHookEvent(repository, event); - } - + /** * Method description * @@ -329,12 +275,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager @Override public void init(SCMContextProvider context) { - Set hooks = repositoryHooksProvider.get(); - - if (Util.isNotEmpty(hooks)) - { - addHooks(hooks); - } } /** @@ -712,53 +652,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager //~--- methods -------------------------------------------------------------- - /** - * Method description - * - * - * @param hook - * @param event - */ - @Override - protected void fireHookEvent(RepositoryHook hook, RepositoryHookEvent event) - { - if (hook.isAsync()) - { - executorService.execute(new RepositoryHookTask(hook, event)); - } - else - { - if (logger.isDebugEnabled()) - { - Object[] args = new Object[] { event.getType(), - hook.getClass().getName(), event.getRepository().getName() }; - - logger.debug("execute {} hook {} for repository {}", args); - } - - hook.onEvent(event); - } - } - - /** - * Method description - * - * - * @param event - * - * @return - */ - @Override - protected RepositoryHookEvent prepareHookEvent(RepositoryHookEvent event) - { - if (!(event instanceof ExtendedRepositoryHookEvent)) - { - event = SynchronizedRepositoryHookEvent.wrap(event, preProcessorUtil); - } - - return event; - } - /** * Method description * @@ -922,26 +815,20 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager //~--- fields --------------------------------------------------------------- /** Field description */ - private ScmConfiguration configuration; + private final ScmConfiguration configuration; /** Field description */ - private ExecutorService executorService; + private final ExecutorService executorService; /** Field description */ - private Map handlerMap; + private final Map handlerMap; /** Field description */ - private KeyGenerator keyGenerator; + private final KeyGenerator keyGenerator; /** Field description */ - private PreProcessorUtil preProcessorUtil; + private final RepositoryDAO repositoryDAO; /** Field description */ - private RepositoryDAO repositoryDAO; - - /** Field description */ - private Provider> repositoryHooksProvider; - - /** Field description */ - private Set types; + private final Set types; } diff --git a/scm-webapp/src/main/java/sonia/scm/repository/SynchronizedRepositoryHookEvent.java b/scm-webapp/src/main/java/sonia/scm/repository/SynchronizedRepositoryHookEvent.java deleted file mode 100644 index 4c178530a5..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/repository/SynchronizedRepositoryHookEvent.java +++ /dev/null @@ -1,224 +0,0 @@ -/** - * 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; - -//~--- non-JDK imports -------------------------------------------------------- - -import com.google.common.base.Stopwatch; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.Collection; - -/** - * - * @author Sebastian Sdorra - */ -public class SynchronizedRepositoryHookEvent implements RepositoryHookEvent -{ - - /** Field description */ - private static final Object LOCK = new Object(); - - /** - * the logger for SynchronizedRepositoryHookEvent - */ - private static final Logger logger = - LoggerFactory.getLogger(SynchronizedRepositoryHookEvent.class); - - //~--- constructors --------------------------------------------------------- - - /** - * Constructs ... - * - * - * @param wrappedEvent - * @param preProcessorUtil - */ - private SynchronizedRepositoryHookEvent(RepositoryHookEvent wrappedEvent, - PreProcessorUtil preProcessorUtil) - { - this.wrappedEvent = wrappedEvent; - this.preProcessorUtil = preProcessorUtil; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @param event - * @param preProcessorUtil - * - * @return - */ - public static SynchronizedRepositoryHookEvent wrap(RepositoryHookEvent event, - PreProcessorUtil preProcessorUtil) - { - SynchronizedRepositoryHookEvent syncedEvent; - - if (event instanceof SynchronizedRepositoryHookEvent) - { - syncedEvent = (SynchronizedRepositoryHookEvent) event; - } - else - { - syncedEvent = new SynchronizedRepositoryHookEvent(event, - preProcessorUtil); - } - - return syncedEvent; - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - @Override - public Collection getChangesets() - { - if (changesets == null) - { - synchronized (LOCK) - { - if (changesets == null) - { - fetchChangesets(); - - if (changesets != null) - { - prepareChangesetsForReturn(); - } - } - } - } - - return changesets; - } - - /** - * Method description - * - * - * @return - */ - @Override - public Repository getRepository() - { - return wrappedEvent.getRepository(); - } - - /** - * Method description - * - * - * @return - */ - @Override - public RepositoryHookType getType() - { - return wrappedEvent.getType(); - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param repository - */ - @Override - public void setRepository(Repository repository) - { - wrappedEvent.setRepository(repository); - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - */ - private void fetchChangesets() - { - if (logger.isDebugEnabled()) - { - Stopwatch sw = new Stopwatch().start(); - - changesets = wrappedEvent.getChangesets(); - sw.stop(); - logger.debug("getChangesets() took {}", sw); - } - else - { - changesets = wrappedEvent.getChangesets(); - } - } - - /** - * Method description - * - */ - private void prepareChangesetsForReturn() - { - Repository repository = getRepository(); - - logger.debug("prepare changesets of repository {} for return to hook", - repository.getName()); - - for (Changeset c : changesets) - { - preProcessorUtil.prepareForReturn(repository, c); - } - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private volatile Collection changesets; - - /** Field description */ - private PreProcessorUtil preProcessorUtil; - - /** Field description */ - private RepositoryHookEvent wrappedEvent; -} diff --git a/scm-webapp/src/test/java/sonia/scm/repository/DefaultRepositoryManagerTest.java b/scm-webapp/src/test/java/sonia/scm/repository/DefaultRepositoryManagerTest.java index 5b4e947dc6..e2c7c2f5e8 100644 --- a/scm-webapp/src/test/java/sonia/scm/repository/DefaultRepositoryManagerTest.java +++ b/scm-webapp/src/test/java/sonia/scm/repository/DefaultRepositoryManagerTest.java @@ -35,8 +35,6 @@ package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- -import com.google.inject.Provider; - import org.junit.Test; import sonia.scm.Type; @@ -48,8 +46,6 @@ import sonia.scm.store.StoreFactory; import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - //~--- JDK imports ------------------------------------------------------------ import java.io.IOException; @@ -140,10 +136,6 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase } }); - Provider> hookProvider = mock(Provider.class); - - when(hookProvider.get()).thenReturn(new HashSet()); - XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(factory); ScmConfiguration configuration = new ScmConfiguration(); @@ -151,28 +143,7 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase configuration.setEnableRepositoryArchive(archiveEnabled); return new DefaultRepositoryManager(configuration, contextProvider, - new DefaultKeyGenerator(), repositoryDAO, handlerSet, - hookProvider, createEmptyPreProcessorUtil()); - } - - /** - * Method description - * - * - * @return - */ - private PreProcessorUtil createEmptyPreProcessorUtil() - { - //J- - return new PreProcessorUtil( - new HashSet(), - new HashSet(), - new HashSet(), - new HashSet(), - new HashSet(), - new HashSet() - ); - //J+ + new DefaultKeyGenerator(), repositoryDAO, handlerSet); } /**