mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 12:05:52 +01:00
remove old hook system in favor of event bus
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -43,14 +43,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import sonia.scm.HandlerEvent;
|
import sonia.scm.HandlerEvent;
|
||||||
import sonia.scm.event.ScmEventBus;
|
import sonia.scm.event.ScmEventBus;
|
||||||
import sonia.scm.util.AssertUtil;
|
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
|
* Abstract base class for {@link RepositoryManager} implementations. This class
|
||||||
@@ -68,130 +60,24 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
|||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- 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<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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a {@link Collection} of {@link RepositoryHook}s
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param hooks hooks to register
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void addHooks(Collection<RepositoryHook> hooks)
|
|
||||||
{
|
|
||||||
for (RepositoryHook hook : hooks)
|
|
||||||
{
|
|
||||||
addHook(hook);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a {@link RepositoryHookEvent} to each registered
|
* Sends a {@link RepositoryHookEvent} to each registered
|
||||||
* {@link RepositoryHook} and sends the {@link RepositoryHookEvent} to
|
* {@link RepositoryHook} and sends the {@link RepositoryHookEvent} to
|
||||||
* the {@link ScmEventBus}.
|
* the {@link ScmEventBus}.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param repository changed repository
|
|
||||||
* @param event event to be fired
|
* @param event event to be fired
|
||||||
*/
|
*/
|
||||||
@Override
|
public void fireHookEvent(RepositoryHookEvent event)
|
||||||
public void fireHookEvent(Repository repository, RepositoryHookEvent event)
|
|
||||||
{
|
{
|
||||||
AssertUtil.assertIsNotNull(repository);
|
|
||||||
AssertUtil.assertIsNotNull(event);
|
AssertUtil.assertIsNotNull(event);
|
||||||
|
AssertUtil.assertIsNotNull(event.getRepository());
|
||||||
AssertUtil.assertIsNotNull(event.getType());
|
AssertUtil.assertIsNotNull(event.getType());
|
||||||
event.setRepository(repository);
|
|
||||||
|
|
||||||
// prepare the event
|
// prepare the event
|
||||||
event = prepareHookEvent(event);
|
event = prepareHookEvent(event);
|
||||||
|
|
||||||
// post wrapped hook to event system
|
// post wrapped hook to event system
|
||||||
ScmEventBus.getInstance().post(WrappedRepositoryHookEvent.wrap(event));
|
ScmEventBus.getInstance().post(WrappedRepositoryHookEvent.wrap(event));
|
||||||
|
|
||||||
List<RepositoryHook> 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<RepositoryHookType> types = hook.getTypes();
|
|
||||||
|
|
||||||
if (types != null)
|
|
||||||
{
|
|
||||||
for (RepositoryHookType type : types)
|
|
||||||
{
|
|
||||||
List<RepositoryHook> hooks = hookMap.get(type);
|
|
||||||
|
|
||||||
if (hooks != null)
|
|
||||||
{
|
|
||||||
hooks.remove(hook);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -218,10 +104,4 @@ public abstract class AbstractRepositoryManager implements RepositoryManager
|
|||||||
{
|
{
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** repository hooks map */
|
|
||||||
private Map<RepositoryHookType, List<RepositoryHook>> hookMap =
|
|
||||||
Maps.newEnumMap(RepositoryHookType.class);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.github.legman.Subscribe;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ import java.util.Collection;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
public class CacheClearHook implements RepositoryHook
|
public class CacheClearHook
|
||||||
{
|
{
|
||||||
|
|
||||||
/** the logger for CacheClearHook */
|
/** the logger for CacheClearHook */
|
||||||
@@ -106,8 +107,8 @@ public class CacheClearHook implements RepositoryHook
|
|||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Subscribe
|
||||||
public void onEvent(RepositoryHookEvent event)
|
public void onEvent(PostReceiveRepositoryHookEvent event)
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
@@ -122,30 +123,6 @@ public class CacheClearHook implements RepositoryHook
|
|||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Collection<RepositoryHookType> getTypes()
|
|
||||||
{
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isAsync()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,12 +143,10 @@ public class CacheClearHook implements RepositoryHook
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param manager
|
|
||||||
* @param cache
|
* @param cache
|
||||||
*/
|
*/
|
||||||
protected void init(RepositoryManager manager, Cache<?, ?> cache)
|
protected void init(Cache<?, ?> cache)
|
||||||
{
|
{
|
||||||
manager.addHook(this);
|
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,8 +154,4 @@ public class CacheClearHook implements RepositoryHook
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Cache<?, ?> cache;
|
private Cache<?, ?> cache;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Collection<RepositoryHookType> types =
|
|
||||||
Arrays.asList(RepositoryHookType.POST_RECEIVE);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Changeset> 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;
|
|
||||||
}
|
|
||||||
@@ -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<RepositoryHookType> getTypes()
|
|
||||||
{
|
|
||||||
return Arrays.asList(RepositoryHookType.POST_RECEIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isAsync()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<RepositoryHookType> getTypes()
|
|
||||||
{
|
|
||||||
return Arrays.asList(RepositoryHookType.PRE_RECEIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isAsync()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<RepositoryHookType> getTypes();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isAsync();
|
|
||||||
}
|
|
||||||
@@ -33,9 +33,9 @@
|
|||||||
|
|
||||||
package sonia.scm.repository;
|
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.
|
* Repository hook event represents an change event of a repository.
|
||||||
@@ -43,42 +43,66 @@ import java.util.Collection;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
public interface RepositoryHookEvent
|
public class RepositoryHookEvent
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a collection of changesets which are added with this repository
|
* Constructs a new {@link ExtendedRepositoryHookEvent}.
|
||||||
* event.
|
|
||||||
*
|
*
|
||||||
*
|
* @param context context of current hook
|
||||||
* @return a collection of added changesets
|
* @param repository
|
||||||
|
* @param type type of current hook
|
||||||
*/
|
*/
|
||||||
public Collection<Changeset> 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 context of current hook
|
||||||
* @return modified repository
|
|
||||||
*/
|
*/
|
||||||
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();
|
public Repository getRepository()
|
||||||
|
{
|
||||||
//~--- set methods ----------------------------------------------------------
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the modified repository. This method is only for internal use and
|
* Method description
|
||||||
* should never be called on a hook.
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<RepositoryHook> 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);
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -55,10 +55,18 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
* @apiviz.uses sonia.scm.repository.RepositoryHandler
|
* @apiviz.uses sonia.scm.repository.RepositoryHandler
|
||||||
*/
|
*/
|
||||||
public interface RepositoryManager
|
public interface RepositoryManager
|
||||||
extends TypeManager<Repository, RepositoryException>,
|
extends TypeManager<Repository, RepositoryException>
|
||||||
RepositoryHookSupport
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}.
|
* Imports an existing {@link Repository}.
|
||||||
* Note: This method should only be called from a {@link RepositoryHandler}.
|
* Note: This method should only be called from a {@link RepositoryHandler}.
|
||||||
|
|||||||
@@ -73,82 +73,15 @@ public class RepositoryManagerDecorator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param hook
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addHook(RepositoryHook hook)
|
public void fireHookEvent(RepositoryHookEvent event)
|
||||||
{
|
{
|
||||||
decorated.addHook(hook);
|
decorated.fireHookEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param hooks
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void addHooks(Collection<RepositoryHook> 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
|
@Override
|
||||||
public void importRepository(Repository repository)
|
public void importRepository(Repository repository)
|
||||||
@@ -157,18 +90,6 @@ public class RepositoryManagerDecorator
|
|||||||
decorated.importRepository(repository);
|
decorated.importRepository(repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param hook
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void removeHook(RepositoryHook hook)
|
|
||||||
{
|
|
||||||
decorated.removeHook(hook);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,7 +107,6 @@ public class RepositoryManagerDecorator
|
|||||||
return decorated.get(type, name);
|
return decorated.get(type, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
@@ -212,7 +132,6 @@ public class RepositoryManagerDecorator
|
|||||||
return decorated;
|
return decorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
@@ -270,7 +189,6 @@ public class RepositoryManagerDecorator
|
|||||||
return decorated.getHandler(type);
|
return decorated.getHandler(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -33,21 +33,13 @@
|
|||||||
|
|
||||||
package sonia.scm.repository;
|
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.
|
* Base class for {@link RepositoryHookEvent} wrappers.
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.23
|
* @since 1.23
|
||||||
*/
|
*/
|
||||||
public class WrappedRepositoryHookEvent
|
public class WrappedRepositoryHookEvent extends RepositoryHookEvent
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +50,8 @@ public class WrappedRepositoryHookEvent
|
|||||||
*/
|
*/
|
||||||
protected WrappedRepositoryHookEvent(RepositoryHookEvent wrappedEvent)
|
protected WrappedRepositoryHookEvent(RepositoryHookEvent wrappedEvent)
|
||||||
{
|
{
|
||||||
this.wrappedEvent = wrappedEvent;
|
super(wrappedEvent.getContext(), wrappedEvent.getRepository(),
|
||||||
|
wrappedEvent.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -93,69 +86,4 @@ public class WrappedRepositoryHookEvent
|
|||||||
|
|
||||||
return wrappedEvent;
|
return wrappedEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a collection of changesets which are added with this repository
|
|
||||||
* event.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return a collection of added changesets
|
|
||||||
*/
|
|
||||||
public Collection<Changeset> 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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import sonia.scm.repository.ExtendedRepositoryHookEvent;
|
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.RepositoryException;
|
import sonia.scm.repository.RepositoryException;
|
||||||
|
import sonia.scm.repository.RepositoryHookEvent;
|
||||||
import sonia.scm.repository.RepositoryHookType;
|
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;
|
||||||
@@ -165,31 +165,31 @@ public final class HookEventFacade
|
|||||||
{
|
{
|
||||||
HookContext context =
|
HookContext context =
|
||||||
hookContextFactory.createContext(hookContextProvider, repository);
|
hookContextFactory.createContext(hookContextProvider, repository);
|
||||||
ExtendedRepositoryHookEvent event =
|
RepositoryHookEvent event = new RepositoryHookEvent(context, repository,
|
||||||
new ExtendedRepositoryHookEvent(context, repository, type);
|
type);
|
||||||
|
|
||||||
repositoryManager.fireHookEvent(repository, event);
|
repositoryManager.fireHookEvent(event);
|
||||||
hookContextProvider.handleClientDisconnect();
|
hookContextProvider.handleClientDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields -------------------------------------------------------------
|
//~--- fields -------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private HookContextFactory hookContextFactory;
|
private final HookContextFactory hookContextFactory;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Repository repository;
|
private final Repository repository;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private RepositoryManager repositoryManager;
|
private final RepositoryManager repositoryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private HookContextFactory hookContextFactory;
|
private final HookContextFactory hookContextFactory;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private RepositoryManager repositoryManager;
|
private final RepositoryManager repositoryManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.github.legman.Subscribe;
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.subject.Subject;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -55,6 +55,9 @@ import java.io.IOException;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import org.junit.Ignore;
|
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
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testRepositoryHook() throws RepositoryException, IOException
|
public void testRepositoryHook() throws RepositoryException, IOException
|
||||||
{
|
{
|
||||||
CountingReceiveHook hook = new CountingReceiveHook();
|
CountingReceiveHook hook = new CountingReceiveHook();
|
||||||
RepositoryManager repoManager = createRepositoryManager(false);
|
RepositoryManager repoManager = createRepositoryManager(false);
|
||||||
|
|
||||||
repoManager.addHook(hook);
|
ScmEventBus.getInstance().register(hook);
|
||||||
|
|
||||||
assertEquals(0, hook.eventsReceived);
|
assertEquals(0, hook.eventsReceived);
|
||||||
|
|
||||||
Repository repository = createTestRepository();
|
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);
|
assertEquals(1, hook.eventsReceived);
|
||||||
repoManager.fireHookEvent(repository, new TestRepositoryHookEvent());
|
repoManager.fireHookEvent(new RepositoryHookEvent(ctx, repository,
|
||||||
|
RepositoryHookType.POST_RECEIVE));
|
||||||
assertEquals(2, hook.eventsReceived);
|
assertEquals(2, hook.eventsReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +501,7 @@ public abstract class RepositoryManagerTestBase
|
|||||||
* @version Enter version here..., 13/01/29
|
* @version Enter version here..., 13/01/29
|
||||||
* @author Enter your name here...
|
* @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
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Override
|
@Subscribe
|
||||||
public void onEvent(RepositoryHookEvent event)
|
public void onEvent(PostReceiveRepositoryHookEvent event)
|
||||||
{
|
{
|
||||||
eventsReceived++;
|
eventsReceived++;
|
||||||
}
|
}
|
||||||
@@ -531,7 +540,7 @@ public abstract class RepositoryManagerTestBase
|
|||||||
* @param repository
|
* @param repository
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe(async = false)
|
||||||
public void onEvent(RepositoryEvent event)
|
public void onEvent(RepositoryEvent event)
|
||||||
{
|
{
|
||||||
if (event.getEventType().isPost())
|
if (event.getEventType().isPost())
|
||||||
@@ -560,71 +569,4 @@ public abstract class RepositoryManagerTestBase
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private Repository preRepository;
|
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<Changeset> 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import com.google.common.base.Strings;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
@@ -106,22 +105,16 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
|||||||
* @param keyGenerator
|
* @param keyGenerator
|
||||||
* @param repositoryDAO
|
* @param repositoryDAO
|
||||||
* @param handlerSet
|
* @param handlerSet
|
||||||
* @param repositoryListenersProvider
|
|
||||||
* @param repositoryHooksProvider
|
|
||||||
* @param preProcessorUtil
|
* @param preProcessorUtil
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public DefaultRepositoryManager(ScmConfiguration configuration,
|
public DefaultRepositoryManager(ScmConfiguration configuration,
|
||||||
SCMContextProvider contextProvider, KeyGenerator keyGenerator,
|
SCMContextProvider contextProvider, KeyGenerator keyGenerator,
|
||||||
RepositoryDAO repositoryDAO, Set<RepositoryHandler> handlerSet,
|
RepositoryDAO repositoryDAO, Set<RepositoryHandler> handlerSet)
|
||||||
Provider<Set<RepositoryHook>> repositoryHooksProvider,
|
|
||||||
PreProcessorUtil preProcessorUtil)
|
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.keyGenerator = keyGenerator;
|
this.keyGenerator = keyGenerator;
|
||||||
this.repositoryDAO = repositoryDAO;
|
this.repositoryDAO = repositoryDAO;
|
||||||
this.repositoryHooksProvider = repositoryHooksProvider;
|
|
||||||
this.preProcessorUtil = preProcessorUtil;
|
|
||||||
|
|
||||||
//J-
|
//J-
|
||||||
ThreadFactory factory = new ThreadFactoryBuilder()
|
ThreadFactory factory = new ThreadFactoryBuilder()
|
||||||
@@ -257,53 +250,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
|||||||
fireEvent(repository, HandlerEvent.DELETE);
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -329,12 +275,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
|||||||
@Override
|
@Override
|
||||||
public void init(SCMContextProvider context)
|
public void init(SCMContextProvider context)
|
||||||
{
|
{
|
||||||
Set<RepositoryHook> hooks = repositoryHooksProvider.get();
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(hooks))
|
|
||||||
{
|
|
||||||
addHooks(hooks);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -712,53 +652,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
|||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- 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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -922,26 +815,20 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private ScmConfiguration configuration;
|
private final ScmConfiguration configuration;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private ExecutorService executorService;
|
private final ExecutorService executorService;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private Map<String, RepositoryHandler> handlerMap;
|
private final Map<String, RepositoryHandler> handlerMap;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private KeyGenerator keyGenerator;
|
private final KeyGenerator keyGenerator;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private PreProcessorUtil preProcessorUtil;
|
private final RepositoryDAO repositoryDAO;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private RepositoryDAO repositoryDAO;
|
private final Set<Type> types;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Provider<Set<RepositoryHook>> repositoryHooksProvider;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Set<Type> types;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Changeset> 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<Changeset> changesets;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private PreProcessorUtil preProcessorUtil;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private RepositoryHookEvent wrappedEvent;
|
|
||||||
}
|
|
||||||
@@ -35,8 +35,6 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import sonia.scm.Type;
|
import sonia.scm.Type;
|
||||||
@@ -48,8 +46,6 @@ import sonia.scm.store.StoreFactory;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -140,10 +136,6 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Provider<Set<RepositoryHook>> hookProvider = mock(Provider.class);
|
|
||||||
|
|
||||||
when(hookProvider.get()).thenReturn(new HashSet<RepositoryHook>());
|
|
||||||
|
|
||||||
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(factory);
|
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(factory);
|
||||||
|
|
||||||
ScmConfiguration configuration = new ScmConfiguration();
|
ScmConfiguration configuration = new ScmConfiguration();
|
||||||
@@ -151,28 +143,7 @@ public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
|
|||||||
configuration.setEnableRepositoryArchive(archiveEnabled);
|
configuration.setEnableRepositoryArchive(archiveEnabled);
|
||||||
|
|
||||||
return new DefaultRepositoryManager(configuration, contextProvider,
|
return new DefaultRepositoryManager(configuration, contextProvider,
|
||||||
new DefaultKeyGenerator(), repositoryDAO, handlerSet,
|
new DefaultKeyGenerator(), repositoryDAO, handlerSet);
|
||||||
hookProvider, createEmptyPreProcessorUtil());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private PreProcessorUtil createEmptyPreProcessorUtil()
|
|
||||||
{
|
|
||||||
//J-
|
|
||||||
return new PreProcessorUtil(
|
|
||||||
new HashSet<ChangesetPreProcessor>(),
|
|
||||||
new HashSet<ChangesetPreProcessorFactory>(),
|
|
||||||
new HashSet<FileObjectPreProcessor>(),
|
|
||||||
new HashSet<FileObjectPreProcessorFactory>(),
|
|
||||||
new HashSet<BlameLinePreProcessor>(),
|
|
||||||
new HashSet<BlameLinePreProcessorFactory>()
|
|
||||||
);
|
|
||||||
//J+
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user