diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnAddCommand.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnAddCommand.java new file mode 100644 index 0000000000..110211ef8b --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnAddCommand.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2014, 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.client.spi; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * Add files to subversion repository. + * + * @author Sebastian Sdorra + * @since 1.51 + */ +public final class SvnAddCommand extends SvnFileCommand implements AddCommand { + + SvnAddCommand(File workingCopy, List pendingFiles) { + super(workingCopy, pendingFiles); + } + + @Override + public void add(String path) throws IOException { + append(path); + } + +} diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnCommitCommand.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnCommitCommand.java new file mode 100644 index 0000000000..11f848bf84 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnCommitCommand.java @@ -0,0 +1,142 @@ +/** + * Copyright (c) 2014, 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.client.spi; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.tmatesoft.svn.core.SVNCommitInfo; +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNErrorMessage; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.wc.SVNClientManager; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNWCClient; +import org.tmatesoft.svn.core.wc2.SvnCommit; +import org.tmatesoft.svn.core.wc2.SvnLog; +import org.tmatesoft.svn.core.wc2.SvnRevisionRange; +import org.tmatesoft.svn.core.wc2.SvnTarget; +import sonia.scm.repository.Changeset; +import sonia.scm.repository.SvnUtil; + +/** + * + * @author Sebastian Sdorra + */ +public class SvnCommitCommand implements CommitCommand { + + private final SVNClientManager client; + private final File workingCopy; + private final List addedFiles; + private final List removedFiles; + + SvnCommitCommand(SVNClientManager client, File workingCopy, List addedFiles, List removedFiles) { + this.client = client; + this.workingCopy = workingCopy; + this.addedFiles = addedFiles; + this.removedFiles = removedFiles; + } + + @Override + public Changeset commit(CommitRequest request) throws IOException { + SVNWCClient wClient = client.getWCClient(); + + List filesToCommit = new ArrayList<>(); + + // add files + try { + wClient.doAdd(addedFiles.toArray(new File[0]), true, false, false, + SVNDepth.INFINITY, false, false, false); + + filesToCommit.addAll(addedFiles); + addedFiles.clear(); + + } catch (SVNException ex) { + throw new IOException("failed to add files", ex); + } + + // remove files + try { + Iterator removeIt = removedFiles.iterator(); + while (removeIt.hasNext()) { + File file = removeIt.next(); + wClient.doDelete(file, false, true, false); + removeIt.remove(); + filesToCommit.add(file); + } + } catch (SVNException ex) { + throw new IOException("failed to remove files", ex); + } + + + SvnTarget workingCopyTarget = SvnTarget.fromFile(workingCopy); + Changeset changeset; + SVNCommitInfo info; + + + + // commit files + try { + SvnCommit commit = client.getOperationFactory().createCommit(); + commit.setDepth(SVNDepth.INFINITY); + commit.setCommitMessage(request.getMessage()); + commit.setSingleTarget(workingCopyTarget); + + info = commit.run(); + + SVNErrorMessage msg = info.getErrorMessage(); + if (msg != null) { + throw new IOException(msg.getFullMessage()); + } + + } catch (SVNException ex) { + throw new IOException("failed to commit", ex); + } + + // get log for commit + try { + SVNRevision revision = SVNRevision.create(info.getNewRevision()); + + SvnLog log = client.getOperationFactory().createLog(); + log.addRange(SvnRevisionRange.create(revision, revision)); + log.setSingleTarget(workingCopyTarget); + + changeset = SvnUtil.createChangeset(log.run()); + } catch (SVNException ex) { + throw new IOException("failed to create log entry for last commit", ex); + } + + return changeset; + } + +} diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnFileCommand.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnFileCommand.java new file mode 100644 index 0000000000..528923a0d8 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnFileCommand.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2014, 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.client.spi; + +import java.io.File; +import java.io.FileNotFoundException; + +import java.util.List; + +/** + * Abstract file based svn command. + * + * @author Sebastian Sdorra + * @since 1.51 + */ +public abstract class SvnFileCommand { + + private final File workingCopy; + private final List pendingFiles; + + protected SvnFileCommand(File workingCopy, List pendingFiles) { + this.workingCopy = workingCopy; + this.pendingFiles = pendingFiles; + } + + protected void append(String path) throws FileNotFoundException { + File file = new File(workingCopy, path); + if (!file.exists()) { + throw new FileNotFoundException("could not find file ".concat(path)); + } + pendingFiles.add(file); + } + +} diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRemoveCommand.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRemoveCommand.java new file mode 100644 index 0000000000..38e7f70de9 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRemoveCommand.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2014, 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.client.spi; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * Remove files from subversion repository. + * + * @author Sebastian Sdorra + * @since 1.51 + */ +public class SvnRemoveCommand extends SvnFileCommand implements RemoveCommand { + + SvnRemoveCommand(File workingCopy, List pendingFiles) { + super(workingCopy, pendingFiles); + } + + @Override + public void remove(String path) throws IOException { + append(path); + } + +} diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRepositoryClientFactoryProvider.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRepositoryClientFactoryProvider.java new file mode 100644 index 0000000000..2acd816382 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRepositoryClientFactoryProvider.java @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2014, 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.client.spi; + +import java.io.File; +import java.io.IOException; +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; +import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; +import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions; +import org.tmatesoft.svn.core.wc.SVNClientManager; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; +import org.tmatesoft.svn.core.wc.SVNWCUtil; +import org.tmatesoft.svn.core.wc2.SvnOperationFactory; +import sonia.scm.repository.SvnRepositoryHandler; + +/** + * Client provider factory for subversion. + * + * @author Sebastian Sdorra + * @since 1.51 + */ +public class SvnRepositoryClientFactoryProvider implements RepositoryClientFactoryProvider { + + @Override + public RepositoryClientProvider create(File main, File workingCopy) throws IOException { + // create uri from file + SVNURL source; + try { + source = SVNURL.fromFile(workingCopy); + } catch (SVNException ex) { + throw new IOException("failed to parse svn url", ex); + } + + // create client + SVNClientManager client = SVNClientManager.newInstance(); + SVNUpdateClient updateClient = client.getUpdateClient(); + try { + updateClient.doCheckout(source, workingCopy, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true); + } catch (SVNException ex) { + throw new IOException("failed to checkout repository", ex); + } + + // return client provider + return new SvnRepositoryClientProvider(client, source, workingCopy); + } + + @Override + public RepositoryClientProvider create(String url, String username, String password, File workingCopy) + throws IOException { + + // create svn options + DefaultSVNOptions options = new DefaultSVNOptions(); + options.setAuthStorageEnabled(false); + options.setUseAutoProperties(false); + + // create client + SVNClientManager client = SVNClientManager.newInstance(new SvnOperationFactory()); + client.setOptions(options); + if ((username != null) && (password != null)) { + ISVNAuthenticationManager auth = SVNWCUtil.createDefaultAuthenticationManager(null, username, password, false); + client.setAuthenticationManager(auth); + } + + // init dav + DAVRepositoryFactory.setup(); + + // parse remote uri + SVNURL remoteUrl; + try { + remoteUrl = SVNURL.parseURIEncoded(url); + } catch (SVNException ex) { + throw new IOException("failed to parse svn url", ex); + } + + // initial checkout + SVNUpdateClient updateClient = client.getUpdateClient(); + try { + updateClient.doCheckout(remoteUrl, workingCopy, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true); + } catch (SVNException ex) { + throw new IOException("failed to checkout repository", ex); + } + + // return client provider + return new SvnRepositoryClientProvider(client, remoteUrl, workingCopy); + } + + @Override + public String getType() { + return SvnRepositoryHandler.TYPE_NAME; + } + +} diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRepositoryClientProvider.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRepositoryClientProvider.java new file mode 100644 index 0000000000..6bae8d7483 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/client/spi/SvnRepositoryClientProvider.java @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2014, 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.client.spi; + +import com.google.common.collect.ImmutableSet; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.wc.SVNClientManager; +import sonia.scm.repository.client.api.ClientCommand; + +/** + * Subversion repository client provider. + * + * @author Sebastian Sdorra + * @since 1.51 + */ +public class SvnRepositoryClientProvider extends RepositoryClientProvider { + + private static final Set SUPPORTED_COMMANDS = ImmutableSet.of( + ClientCommand.ADD, ClientCommand.REMOVE, ClientCommand.COMMIT + ); + + private final SVNClientManager client; + private final SVNURL remoteRepositoryURL; + private final File workingCopy; + + private final List addedFiles = new ArrayList<>(); + private final List removedFiles = new ArrayList<>(); + + SvnRepositoryClientProvider(SVNClientManager client, SVNURL remoteRepositoryURL, File workingCopy) { + this.client = client; + this.remoteRepositoryURL = remoteRepositoryURL; + this.workingCopy = workingCopy; + } + + @Override + public SvnAddCommand getAddCommand() { + return new SvnAddCommand(workingCopy, addedFiles); + } + + @Override + public SvnRemoveCommand getRemoveCommand() { + return new SvnRemoveCommand(workingCopy, removedFiles); + } + + @Override + public SvnCommitCommand getCommitCommand() { + return new SvnCommitCommand(client, workingCopy, addedFiles, removedFiles); + } + + @Override + public Set getSupportedClientCommands() { + return SUPPORTED_COMMANDS; + } + +} diff --git a/scm-plugins/scm-svn-plugin/src/test/resources/META-INF/services/sonia.scm.repository.client.spi.RepositoryClientFactoryProvider b/scm-plugins/scm-svn-plugin/src/test/resources/META-INF/services/sonia.scm.repository.client.spi.RepositoryClientFactoryProvider new file mode 100644 index 0000000000..a37aa54fd0 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/test/resources/META-INF/services/sonia.scm.repository.client.spi.RepositoryClientFactoryProvider @@ -0,0 +1 @@ +sonia.scm.repository.client.spi.SvnRepositoryClientFactoryProvider \ No newline at end of file diff --git a/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java b/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java index 4c5b3ec951..4f3af7ecd7 100644 --- a/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java +++ b/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java @@ -40,6 +40,7 @@ import java.util.Collection; import org.junit.After; import static org.junit.Assert.*; import static org.hamcrest.Matchers.*; +import org.junit.Assume; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -55,6 +56,7 @@ import sonia.scm.repository.Changeset; import sonia.scm.repository.Person; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryTestData; +import sonia.scm.repository.client.api.ClientCommand; import sonia.scm.repository.client.api.RepositoryClient; import sonia.scm.repository.client.api.RepositoryClientFactory; import sonia.scm.util.IOUtil; @@ -120,13 +122,10 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase @Test public void testSimpleHook() throws IOException, InterruptedException { - // push commit + // commit and push commit Files.write("a", new File(workingCopy, "a.txt"), Charsets.UTF_8); repositoryClient.getAddCommand().add("a.txt"); - Changeset changeset = repositoryClient.getCommitCommand().commit( - new Person("scmadmin", "scmadmin@scm-manager.org"), "added a" - ); - repositoryClient.getPushCommand().push(); + Changeset changeset = commit("added a"); // wait some time, because the debug hook is asnychron Thread.sleep(125); @@ -147,22 +146,21 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase @Test public void testOnlyNewCommit() throws IOException, InterruptedException { + // skip test if branches are not supported by repository type + Assume.assumeTrue(repositoryClient.isCommandSupported(ClientCommand.BANCH)); + // push commit Files.write("a", new File(workingCopy, "a.txt"), Charsets.UTF_8); repositoryClient.getAddCommand().add("a.txt"); - Changeset a = repositoryClient.getCommitCommand().commit( - new Person("scmadmin", "scmadmin@scm-manager.org"), "added a" - ); - repositoryClient.getPushCommand().push(); + Changeset a = commit("added a"); - // create branch, commit and push again + // create branch repositoryClient.getBranchCommand().branch("feature/added-b"); + + // commit and push again Files.write("b", new File(workingCopy, "b.txt"), Charsets.UTF_8); repositoryClient.getAddCommand().add("a.txt"); - Changeset b = repositoryClient.getCommitCommand().commit( - new Person("scmadmin", "scmadmin@scm-manager.org"), "added b" - ); - repositoryClient.getPushCommand().push(); + Changeset b = commit("added b"); // wait some time, because the debug hook is asnychron Thread.sleep(125); @@ -179,6 +177,16 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase )); } + private Changeset commit(String message) throws IOException { + Changeset a = repositoryClient.getCommitCommand().commit( + new Person("scmadmin", "scmadmin@scm-manager.org"), "added a" + ); + if ( repositoryClient.isCommandSupported(ClientCommand.PUSH) ) { + repositoryClient.getPushCommand().push(); + } + return a; + } + private RepositoryClient createRepositoryClient() throws IOException { return REPOSITORY_CLIENT_FACTORY.create(repositoryType, @@ -198,11 +206,10 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase { Collection params = Lists.newArrayList(); params.add(new String[] { "git" }); - // params.add(new String[] { "svn" }); - if (IOUtil.search("hg") != null) - { + params.add(new String[] { "svn" }); + if (IOUtil.search("hg") != null) { params.add(new String[] { "hg" }); - } + } return params; }