From 0a221cee5b0a05a441da5af366527e0515989e4c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 10 May 2013 15:37:56 +0200 Subject: [PATCH] added api for pull command --- .../sonia/scm/repository/api/Command.java | 4 +- .../repository/api/PullCommandBuilder.java | 83 +++++++++++++++++++ .../scm/repository/api/PullResponse.java | 48 +++++++++++ .../scm/repository/api/PushResponse.java | 21 ++++- .../scm/repository/api/RepositoryService.java | 19 +++++ .../sonia/scm/repository/spi/PullCommand.java | 55 ++++++++++++ .../repository/spi/PullCommandRequest.java | 39 +++++++++ .../spi/RepositoryServiceProvider.java | 11 +++ 8 files changed, 277 insertions(+), 3 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java create mode 100644 scm-core/src/main/java/sonia/scm/repository/api/PullResponse.java create mode 100644 scm-core/src/main/java/sonia/scm/repository/spi/PullCommand.java create mode 100644 scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java diff --git a/scm-core/src/main/java/sonia/scm/repository/api/Command.java b/scm-core/src/main/java/sonia/scm/repository/api/Command.java index 3fe4662204..baf228fa94 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/Command.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/Command.java @@ -52,9 +52,9 @@ public enum Command * @since 1.18 */ BRANCHES, - + /** * @since 1.31 */ - INCOMING, OUTGOING, PUSH; + INCOMING, OUTGOING, PUSH, PULL; } diff --git a/scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java new file mode 100644 index 0000000000..5365fb3f72 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java @@ -0,0 +1,83 @@ +/** + * 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.Repository; +import sonia.scm.repository.spi.PullCommand; +import sonia.scm.repository.spi.PullCommandRequest; + +/** + * + * @author Sebastian Sdorra + * @since 1.31 + */ +public final class PullCommandBuilder +{ + + /** + * Constructs ... + * + * + * @param command + */ + PullCommandBuilder(PullCommand command) + { + this.command = command; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param remoteRepository + * + * @return + */ + public PullResponse pull(Repository remoteRepository) + { + request.setRemoteRepository(remoteRepository); + + return command.pull(request); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private PullCommand command; + + /** Field description */ + private PullCommandRequest request = new PullCommandRequest(); +} diff --git a/scm-core/src/main/java/sonia/scm/repository/api/PullResponse.java b/scm-core/src/main/java/sonia/scm/repository/api/PullResponse.java new file mode 100644 index 0000000000..35d6b108ec --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/api/PullResponse.java @@ -0,0 +1,48 @@ +/** + * 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; + +/** + * + * @author Sebastian Sdorra + * @since 1.31 + */ +public final class PullResponse extends AbstractPushOrPullResponse +{ + + public PullResponse() + { + } + + public PullResponse(int changesetCount) + { + super(changesetCount); + } + +} diff --git a/scm-core/src/main/java/sonia/scm/repository/api/PushResponse.java b/scm-core/src/main/java/sonia/scm/repository/api/PushResponse.java index 5ca01a4e66..ce0908ca06 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/PushResponse.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/PushResponse.java @@ -41,4 +41,23 @@ import javax.xml.bind.annotation.XmlRootElement; * @since 1.31 */ @XmlRootElement(name = "push-response") -public final class PushResponse extends AbstractPushOrPullResponse {} +public final class PushResponse extends AbstractPushOrPullResponse +{ + + /** + * Constructs ... + * + */ + public PushResponse() {} + + /** + * Constructs ... + * + * + * @param changesetCount + */ + public PushResponse(int changesetCount) + { + super(changesetCount); + } +} diff --git a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java index 2085b23b06..c21a31084c 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/RepositoryService.java @@ -300,6 +300,25 @@ public final class RepositoryService implements Closeable provider.getOutgoingCommand(), repository, preProcessorUtil); } + /** + * The pull command pull changes from a other repository. + * + * @return instance of {@link PullCommandBuilder} + * @throws CommandNotSupportedException if the command is not supported + * by the implementation of the repository service provider. + * @since 1.31 + */ + public PullCommandBuilder getPullCommand() + { + if (logger.isDebugEnabled()) + { + logger.debug("create pull command for repository {}", + repository.getName()); + } + + return new PullCommandBuilder(provider.getPullCommand()); + } + /** * The push command push changes to a other repository. * diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/PullCommand.java b/scm-core/src/main/java/sonia/scm/repository/spi/PullCommand.java new file mode 100644 index 0000000000..1a6e6b42bd --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/spi/PullCommand.java @@ -0,0 +1,55 @@ +/** + * 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.PullResponse; + +/** + * + * @author Sebastian Sdorra + * @since 1.31 + */ +public interface PullCommand +{ + + /** + * Method description + * + * + * @param request + * + * @return + */ + public PullResponse pull(PullCommandRequest request); +} diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java new file mode 100644 index 0000000000..4ee962ecf1 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java @@ -0,0 +1,39 @@ +/** + * 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.31 + */ +public final class PullCommandRequest extends RemoteCommandRequest {} diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java b/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java index 40c517c9cf..4ff54f012e 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/RepositoryServiceProvider.java @@ -172,6 +172,17 @@ public abstract class RepositoryServiceProvider implements Closeable throw new CommandNotSupportedException(Command.OUTGOING); } + /** + * Method description + * + * + * @return + */ + public PullCommand getPullCommand() + { + throw new CommandNotSupportedException(Command.PULL); + } + /** * Method description *