diff --git a/scm-core/src/main/java/sonia/scm/repository/api/HookException.java b/scm-core/src/main/java/sonia/scm/repository/api/HookException.java new file mode 100644 index 0000000000..e17ec33621 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/api/HookException.java @@ -0,0 +1,88 @@ +/** + * 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; + +/** + * Base exception for all exceptions which can occur during the hook + * initialization. + * + * @author Sebastian Sdorra + * @since 1.33 + */ +public class HookException extends RuntimeException +{ + + /** Field description */ + private static final long serialVersionUID = 2572704247316715734L; + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + */ + public HookException() {} + + /** + * Constructs ... + * + * + * @param message + */ + public HookException(String message) + { + super(message); + } + + /** + * Constructs ... + * + * + * @param cause + */ + public HookException(Throwable cause) + { + super(cause); + } + + /** + * Constructs ... + * + * + * @param message + * @param cause + */ + public HookException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/scm-core/src/main/java/sonia/scm/repository/api/HookFeatureIsNotSupportedException.java b/scm-core/src/main/java/sonia/scm/repository/api/HookFeatureIsNotSupportedException.java new file mode 100644 index 0000000000..08f8d4bba3 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/api/HookFeatureIsNotSupportedException.java @@ -0,0 +1,92 @@ +/** + * 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; + +/** + * This exception is thrown if the underlying provider of the + * {@link HookContext} does not support the requested {@link HookFeature}. + * + * @author Sebastian Sdorra + * @since 1.33 + */ +public class HookFeatureIsNotSupportedException extends HookException +{ + + /** Field description */ + private static final long serialVersionUID = -7670872902321373610L; + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs a new {@link HookFeatureIsNotSupportedException}. + * + * + * @param unsupportedFeature feature which is not supported + */ + public HookFeatureIsNotSupportedException(HookFeature unsupportedFeature) + { + super(unsupportedFeature.toString().concat(" is not supported")); + this.unsupportedFeature = unsupportedFeature; + } + + /** + * Constructs a new {@link HookFeatureIsNotSupportedException}. + * + * + * @param message message for the exception + * @param unsupportedFeature feature which is not supported + */ + public HookFeatureIsNotSupportedException(String message, + HookFeature unsupportedFeature) + { + super(message); + this.unsupportedFeature = unsupportedFeature; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Returns the feature which is not supported. + * + * + * @return unsupported hook feature + */ + public HookFeature getUnsupportedFeature() + { + return unsupportedFeature; + } + + //~--- fields --------------------------------------------------------------- + + /** unsupported hook feature */ + private HookFeature unsupportedFeature; +} diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/HookContextProvider.java b/scm-core/src/main/java/sonia/scm/repository/spi/HookContextProvider.java index 5d67715cd8..0bc91679b7 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/HookContextProvider.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/HookContextProvider.java @@ -33,7 +33,9 @@ package sonia.scm.repository.spi; //~--- non-JDK imports -------------------------------------------------------- +import sonia.scm.repository.api.HookException; import sonia.scm.repository.api.HookFeature; +import sonia.scm.repository.api.HookFeatureIsNotSupportedException; import sonia.scm.repository.api.HookMessageProvider; //~--- JDK imports ------------------------------------------------------------ @@ -56,16 +58,28 @@ public abstract class HookContextProvider */ public final HookMessageProvider getMessageProvider() { - if (clientFinalization) + if (clientDisconnected) { - - // TODO - throw new IllegalArgumentException(); + throw new HookException( + "message provider is only available in a synchronous hook execution."); } return createMessageProvider(); } + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + */ + final void handleClientDisconnect() + { + clientDisconnected = true; + } + + //~--- get methods ---------------------------------------------------------- + /** * Method description * @@ -82,20 +96,12 @@ public abstract class HookContextProvider */ public HookChangesetProvider getChangesetProvider() { - return null; + throw new HookFeatureIsNotSupportedException( + HookFeature.CHANGESET_PROVIDER); } //~--- methods -------------------------------------------------------------- - /** - * Method description - * - */ - void handleClientFinalization() - { - clientFinalization = true; - } - /** * Method description * @@ -104,11 +110,11 @@ public abstract class HookContextProvider */ protected HookMessageProvider createMessageProvider() { - return null; + throw new HookFeatureIsNotSupportedException(HookFeature.MESSAGE_PROVIDER); } //~--- fields --------------------------------------------------------------- /** Field description */ - private boolean clientFinalization = false; + private boolean clientDisconnected = false; } diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java b/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java index 9c2f996786..a620e59882 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/HookEventFacade.java @@ -169,7 +169,7 @@ public final class HookEventFacade new ExtendedRepositoryHookEvent(context, repository, type); repositoryManager.fireHookEvent(repository, event); - hookContextProvider.handleClientFinalization(); + hookContextProvider.handleClientDisconnect(); } //~--- fields -------------------------------------------------------------