From e8db50a9e566e3c7390f2aee6dfc9d7dfe6a5cae Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 22 Feb 2011 14:06:21 +0100 Subject: [PATCH] added subversion integration tests --- scm-test/pom.xml | 10 + .../client/GitRepositoryClient.java | 32 --- .../repository/client/RepositoryClient.java | 28 +-- .../client/RepositoryClientFactory.java | 5 + .../client/SvnRepositoryClient.java | 198 ++++++++++++++++++ .../scm/it/RepositoryExtendedITCase.java | 8 +- 6 files changed, 227 insertions(+), 54 deletions(-) create mode 100644 scm-test/src/main/java/sonia/scm/repository/client/SvnRepositoryClient.java diff --git a/scm-test/pom.xml b/scm-test/pom.xml index 8890c0c252..9200209c39 100644 --- a/scm-test/pom.xml +++ b/scm-test/pom.xml @@ -47,6 +47,8 @@ ${slf4j.version} + + org.eclipse.jgit org.eclipse.jgit @@ -59,6 +61,14 @@ 0.1.42 + + + + org.tmatesoft.svnkit + svnkit + 1.3.5 + + diff --git a/scm-test/src/main/java/sonia/scm/repository/client/GitRepositoryClient.java b/scm-test/src/main/java/sonia/scm/repository/client/GitRepositoryClient.java index 42ba7459ae..ca38889e0b 100644 --- a/scm-test/src/main/java/sonia/scm/repository/client/GitRepositoryClient.java +++ b/scm-test/src/main/java/sonia/scm/repository/client/GitRepositoryClient.java @@ -39,7 +39,6 @@ import org.eclipse.jgit.api.AddCommand; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.GitCommand; -import org.eclipse.jgit.api.RmCommand; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.errors.IncorrectObjectTypeException; @@ -219,34 +218,6 @@ public class GitRepositoryClient implements RepositoryClient } } - /** - * Method description - * - * - * @param file - * @param others - * - * @throws RepositoryClientException - */ - @Override - public void delete(String file, String... others) - throws RepositoryClientException - { - RmCommand cmd = new Git(repository).rm(); - - cmd = cmd.addFilepattern(file); - - if (others != null) - { - for (String f : others) - { - cmd = cmd.addFilepattern(f); - } - } - - callCommand(cmd); - } - /** * Method description * @@ -452,7 +423,4 @@ public class GitRepositoryClient implements RepositoryClient /** Field description */ private URIish uri; - - /** Field description */ - private String username; } diff --git a/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClient.java b/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClient.java index c9b3aebace..bbe6a5b371 100644 --- a/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClient.java +++ b/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClient.java @@ -52,6 +52,14 @@ public interface RepositoryClient public void add(String file, String... others) throws RepositoryClientException; + /** + * Method description + * + * + * @throws RepositoryClientException + */ + public void checkout() throws RepositoryClientException; + /** * Method description * @@ -62,18 +70,6 @@ public interface RepositoryClient */ public void commit(String message) throws RepositoryClientException; - /** - * Method description - * - * - * @param file - * @param others - * - * @throws RepositoryClientException - */ - public void delete(String file, String... others) - throws RepositoryClientException; - /** * Method description * @@ -81,12 +77,4 @@ public interface RepositoryClient * @throws RepositoryClientException */ public void init() throws RepositoryClientException; - - /** - * Method description - * - * - * @throws RepositoryClientException - */ - public void checkout() throws RepositoryClientException; } diff --git a/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClientFactory.java b/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClientFactory.java index c75910fbd1..a307c15ad5 100644 --- a/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClientFactory.java +++ b/scm-test/src/main/java/sonia/scm/repository/client/RepositoryClientFactory.java @@ -91,6 +91,11 @@ public class RepositoryClientFactory client = new GitRepositoryClient(localRepository, remoteRepository, username, password); } + else if ("svn".equals(type)) + { + client = new SvnRepositoryClient(localRepository, remoteRepository, + username, password); + } } catch (Exception ex) { diff --git a/scm-test/src/main/java/sonia/scm/repository/client/SvnRepositoryClient.java b/scm-test/src/main/java/sonia/scm/repository/client/SvnRepositoryClient.java new file mode 100644 index 0000000000..15d91f8aee --- /dev/null +++ b/scm-test/src/main/java/sonia/scm/repository/client/SvnRepositoryClient.java @@ -0,0 +1,198 @@ +/** + * 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.client; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.tmatesoft.svn.core.SVNDepth; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNURL; +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.SVNCommitClient; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.File; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * + * @author Sebastian Sdorra + */ +public class SvnRepositoryClient implements RepositoryClient +{ + + /** + * Constructs ... + * + * + * @param localRepository + * @param remoteRepository + * @param username + * @param password + * + * @throws SVNException + */ + SvnRepositoryClient(File localRepository, String remoteRepository, + String username, String password) + throws SVNException + { + this.localRepository = localRepository; + + DefaultSVNOptions options = new DefaultSVNOptions(); + + if ((username != null) && (password != null)) + { + client = SVNClientManager.newInstance(options, username, password); + } + else + { + client = SVNClientManager.newInstance(options); + } + + removeRepositoryURL = SVNURL.parseURIDecoded(remoteRepository); + DAVRepositoryFactory.setup(); + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param file + * @param others + * + * @throws RepositoryClientException + */ + @Override + public void add(String file, String... others) + throws RepositoryClientException + { + files.add(file); + + if (others != null) + { + files.addAll(Arrays.asList(others)); + } + } + + /** + * Method description + * + * + * @throws RepositoryClientException + */ + @Override + public void checkout() throws RepositoryClientException + { + try + { + SVNUpdateClient updateClient = client.getUpdateClient(); + + updateClient.doCheckout(removeRepositoryURL, localRepository, + SVNRevision.UNDEFINED, SVNRevision.HEAD, + SVNDepth.FILES, false); + } + catch (SVNException ex) + { + throw new RepositoryClientException(ex); + } + } + + /** + * Method description + * + * + * @param message + * + * @throws RepositoryClientException + */ + @Override + public void commit(String message) throws RepositoryClientException + { + checkout(); + + SVNCommitClient cc = client.getCommitClient(); + + try + { + for (String name : files) + { + File file = new File(localRepository, name); + + cc.doImport(file, removeRepositoryURL.appendPath(name, true), message, + null, false, true, SVNDepth.FILES); + } + } + catch (SVNException ex) + { + throw new RepositoryClientException(ex); + } + } + + /** + * Method description + * + * + * @throws RepositoryClientException + */ + @Override + public void init() throws RepositoryClientException + { + + // do nothing + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private SVNClientManager client; + + /** Field description */ + private List files = new ArrayList(); + + /** Field description */ + private File localRepository; + + /** Field description */ + private SVNURL removeRepositoryURL; +} diff --git a/scm-webapp/src/test/java/sonia/scm/it/RepositoryExtendedITCase.java b/scm-webapp/src/test/java/sonia/scm/it/RepositoryExtendedITCase.java index cb7146e8e0..b572b219e6 100644 --- a/scm-webapp/src/test/java/sonia/scm/it/RepositoryExtendedITCase.java +++ b/scm-webapp/src/test/java/sonia/scm/it/RepositoryExtendedITCase.java @@ -138,9 +138,13 @@ public class RepositoryExtendedITCase public static Collection createParameters() { Collection params = new ArrayList(); - Repository repository = createRepository("git", "trillian"); + Repository gitRepository = createRepository("git", "trillian"); - params.add(new Object[] { repository, "trillian", "secret" }); + params.add(new Object[] { gitRepository, "trillian", "secret" }); + + Repository svnRepository = createRepository("svn", "trillian"); + + params.add(new Object[] { svnRepository, "trillian", "secret" }); return params; }