start creation of a new hook api

This commit is contained in:
Sebastian Sdorra
2013-07-21 17:34:07 +02:00
parent bfcf2a8fed
commit e48e0089bd
11 changed files with 1078 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
/**
* 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;
}

View File

@@ -30,8 +30,13 @@
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.api.HookContext;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
@@ -103,6 +108,28 @@ public class WrappedRepositoryHookEvent
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.
*
@@ -114,6 +141,19 @@ public class WrappedRepositoryHookEvent
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 */

View File

@@ -0,0 +1,187 @@
/**
* 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.api;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.io.DeepCopy;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.PreProcessorUtil;
import sonia.scm.repository.Repository;
import sonia.scm.repository.spi.HookChangesetProvider;
import sonia.scm.repository.spi.HookChangesetRequest;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.List;
/**
* The {@link HookChangesetBuilder} is able to return all {@link Changeset}s
* which are added during the current push/commit.
*
* @author Sebastian Sdorra
* @since 1.33
*/
public final class HookChangesetBuilder
{
/** request */
private static final HookChangesetRequest request =
new HookChangesetRequest();
/**
* the logger for HookChangesetBuilder
*/
private static final Logger logger =
LoggerFactory.getLogger(HookChangesetBuilder.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new HookChangesetBuilder.
*
*
* @param repository changed repository
* @param preProcessorUtil pre processor util
* @param provider implementation of {@link HookChangesetProvider}
*/
HookChangesetBuilder(Repository repository,
PreProcessorUtil preProcessorUtil, HookChangesetProvider provider)
{
this.repository = repository;
this.provider = provider;
this.preProcessorUtil = preProcessorUtil;
}
//~--- get methods ----------------------------------------------------------
/**
* Returns a immutable {@link List} of added {@link Changeset}'s.
* <strong>Note:</strong> Use this method only if you need a {@link List}, if
* you just want to iterate over the {@link Changeset}'s use
* {@link #getChangesets()} instead. The {@link #getChangesets()} needs less
* memory and should be much more faster then this method.
*
* @return immutable {@link List} of added {@link Changeset}'s
*/
public List<Changeset> getChangesetList()
{
return ImmutableList.copyOf(getChangesets());
}
/**
* Returns an {@link Iterable} which is able to return all {@link Changeset}s
* which are added to the repository.
*
* @return {@link Iterable} for added {@link Changeset}s
*/
public Iterable<Changeset> getChangesets()
{
Iterable<Changeset> changesets =
provider.handleRequest(request).getChangesets();
if (!disablePreProcessors)
{
changesets = Iterables.transform(changesets,
new Function<Changeset, Changeset>()
{
@Override
public Changeset apply(Changeset c)
{
Changeset copy = null;
try
{
copy = DeepCopy.copy(c);
preProcessorUtil.prepareForReturn(repository, copy);
}
catch (IOException ex)
{
logger.error("could not create a copy of changeset", ex);
}
if (copy == null)
{
copy = c;
}
return copy;
}
});
}
return changesets;
}
//~--- set methods ----------------------------------------------------------
/**
* Disable the execution of pre processors.
*
*
* @param disablePreProcessors true to disable the pre processors execution
*
* @return {@code this}
*/
public HookChangesetBuilder setDisablePreProcessors(
boolean disablePreProcessors)
{
this.disablePreProcessors = disablePreProcessors;
return this;
}
//~--- fields ---------------------------------------------------------------
/** disable pre processors marker */
private boolean disablePreProcessors = false;
/** PreProcessorUtil */
private PreProcessorUtil preProcessorUtil;
/** provider implementation */
private HookChangesetProvider provider;
/** changed repository */
private Repository repository;
}

View File

@@ -0,0 +1,110 @@
/**
* 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.api;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.Changeset;
import sonia.scm.repository.PreProcessorUtil;
import sonia.scm.repository.Repository;
import sonia.scm.repository.spi.HookContextProvider;
/**
*
* @author Sebastian Sdorra
* @since 1.33
*/
public final class HookContext
{
/**
* Constructs ...
*
*
* @param provider
* @param repository
* @param preProcessorUtil
*/
HookContext(HookContextProvider provider, Repository repository,
PreProcessorUtil preProcessorUtil)
{
this.provider = provider;
this.repository = repository;
this.preProcessorUtil = preProcessorUtil;
}
//~--- get methods ----------------------------------------------------------
/**
* Returns a {@link HookChangesetBuilder} which is able to return all
* {@link Changeset}'s during this push/commit.
*
*
* @return {@link HookChangesetBuilder}
*/
public HookChangesetBuilder getChangesetProvider()
{
//J-
return new HookChangesetBuilder(
repository,
preProcessorUtil,
provider.getChangesetProvider()
);
//J+
}
/**
* Returns a {@link HookMessageProvider} which is able to send message back to
* the scm client.
* <strong>Note:</strong> The {@link HookMessageProvider} is only available if
* the underlying {@link HookContextProvider} supports the handling of
* messages and the hook is executed synchronous.
*
* @return {@link HookMessageProvider} which is able to send message back to
* the scm client
*/
public HookMessageProvider getMessageProvider()
{
return provider.getMessageProvider();
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private PreProcessorUtil preProcessorUtil;
/** Field description */
private HookContextProvider provider;
/** Field description */
private Repository repository;
}

View File

@@ -0,0 +1,84 @@
/**
* 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.api;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import sonia.scm.repository.PreProcessorUtil;
import sonia.scm.repository.Repository;
import sonia.scm.repository.spi.HookContextProvider;
/**
* Injectable factory for {@link HookContext} objects.
*
* @author Sebastian Sdorra
* @since 1.33
*/
public final class HookContextFactory
{
/**
* Constructs a new {@link HookContextFactory}.
*
*
* @param preProcessorUtil pre processor util
*/
@Inject
public HookContextFactory(PreProcessorUtil preProcessorUtil)
{
this.preProcessorUtil = preProcessorUtil;
}
//~--- methods --------------------------------------------------------------
/**
* Creates a new {@link HookContext}.
*
*
* @param provider provider implementation
* @param repository changed repository
*
* @return new {@link HookContext}
*/
public HookContext createContext(HookContextProvider provider,
Repository repository)
{
return new HookContext(provider, repository, preProcessorUtil);
}
//~--- fields ---------------------------------------------------------------
/** pre processor util */
private PreProcessorUtil preProcessorUtil;
}

View File

@@ -0,0 +1,57 @@
/**
* 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.api;
/**
* Send messages back to scm client during hook execution.
*
* @author Sebastian Sdorra
* @since 1.33
*/
public interface HookMessageProvider
{
/**
* Send error message back to scm client.
*
* @param message error message to send
*/
public void sendError(String message);
/**
* Send message back tp scm client. If the message is a notification about an
* error, please use {@link #sendError(String)} instead.
*
* @param message error message to send
*/
public void sendMessage(String message);
}

View File

@@ -0,0 +1,51 @@
/**
* 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.spi;
/**
*
* @author Sebastian Sdorra
* @since 1.33
*/
public interface HookChangesetProvider
{
/**
* Method description
*
*
* @param request
*
* @return
*/
public HookChangesetResponse handleRequest(HookChangesetRequest request);
}

View File

@@ -0,0 +1,44 @@
/**
* 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.spi;
import sonia.scm.repository.Changeset;
/**
* Request object to retrieve {@link Changeset}s during a hook. At the moment
* this object has no functionality, but it is used to be prepared for further
* functions.
*
* @author Sebastian Sdorra
* @since 1.33
*/
public final class HookChangesetRequest {}

View File

@@ -0,0 +1,75 @@
/**
* 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.spi;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.Changeset;
/**
* Response object to retrieve {@link Changeset}s during a hook.
*
* @author Sebastian Sdorra
* @since 1.33
*/
public final class HookChangesetResponse
{
/**
* Constructs a new {@link HookChangesetResponse}.
*
*
* @param changesets added changesets
*/
public HookChangesetResponse(Iterable<Changeset> changesets)
{
this.changesets = changesets;
}
//~--- get methods ----------------------------------------------------------
/**
* Return added changesets.
*
*
* @return added changesets
*/
public Iterable<Changeset> getChangesets()
{
return changesets;
}
//~--- fields ---------------------------------------------------------------
/** added changesets */
private Iterable<Changeset> changesets;
}

View File

@@ -0,0 +1,100 @@
/**
* 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.spi;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.api.HookMessageProvider;
/**
*
* @author Sebastian Sdorra
* @since 1.33
*/
public abstract class HookContextProvider
{
/**
* Method description
*
*
* @return
*/
public final HookMessageProvider getMessageProvider()
{
if (clientFinalization)
{
// TODO
throw new IllegalArgumentException();
}
return createMessageProvider();
}
/**
* Method description
*
*
* @return
*/
public HookChangesetProvider getChangesetProvider()
{
return null;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*/
void handleClientFinalization() {
clientFinalization = true;
}
/**
* Method description
*
*
* @return
*/
protected HookMessageProvider createMessageProvider()
{
return null;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean clientFinalization = false;
}

View File

@@ -0,0 +1,195 @@
/**
* 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.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import sonia.scm.repository.ExtendedRepositoryHookEvent;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RepositoryHookType;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryNotFoundException;
import sonia.scm.repository.api.HookContext;
import sonia.scm.repository.api.HookContextFactory;
/**
*
* @author Sebastian Sdorra
* @since 1.33
*/
public final class HookEventFacade
{
/**
* Constructs ...
*
*
* @param repositoryManager
* @param hookContextFactory
*/
@Inject
public HookEventFacade(RepositoryManager repositoryManager,
HookContextFactory hookContextFactory)
{
this.repositoryManager = repositoryManager;
this.hookContextFactory = hookContextFactory;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param id
*
* @return
*
* @throws RepositoryException
*/
public HookEventHandler handle(String id) throws RepositoryException
{
return handle(repositoryManager.get(id));
}
/**
* Method description
*
*
* @param type
* @param repositoryName
*
* @return
*
* @throws RepositoryException
*/
public HookEventHandler handle(String type, String repositoryName)
throws RepositoryException
{
return handle(repositoryManager.get(type, repositoryName));
}
/**
* Method description
*
*
* @param repository
*
* @return
*
* @throws RepositoryException
*/
public HookEventHandler handle(Repository repository)
throws RepositoryException
{
if (repository == null)
{
throw new RepositoryNotFoundException("could not find repository");
}
return new HookEventHandler(repositoryManager, hookContextFactory,
repository);
}
//~--- inner classes --------------------------------------------------------
/**
* Class description
*
*
* @version Enter version here..., 13/07/21
* @author Enter your name here...
*/
public static class HookEventHandler
{
/**
* Constructs ...
*
*
* @param repositoryManager
* @param hookContextFactory
* @param repository
*/
public HookEventHandler(RepositoryManager repositoryManager,
HookContextFactory hookContextFactory, Repository repository)
{
this.repositoryManager = repositoryManager;
this.hookContextFactory = hookContextFactory;
this.repository = repository;
}
//~--- methods ------------------------------------------------------------
/**
* Method description
*
*
* @param type
* @param hookContextProvider
*/
public void fireHookEvent(RepositoryHookType type,
HookContextProvider hookContextProvider)
{
HookContext context =
hookContextFactory.createContext(hookContextProvider, repository);
ExtendedRepositoryHookEvent event =
new ExtendedRepositoryHookEvent(context, repository, type);
repositoryManager.fireHookEvent(repository, event);
hookContextProvider.handleClientFinalization();
}
//~--- fields -------------------------------------------------------------
/** Field description */
private HookContextFactory hookContextFactory;
/** Field description */
private Repository repository;
/** Field description */
private RepositoryManager repositoryManager;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private HookContextFactory hookContextFactory;
/** Field description */
private RepositoryManager repositoryManager;
}