mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
added subversion integration tests
This commit is contained in:
@@ -47,6 +47,8 @@
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- jgit -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jgit</groupId>
|
||||
<artifactId>org.eclipse.jgit</artifactId>
|
||||
@@ -59,6 +61,14 @@
|
||||
<version>0.1.42</version>
|
||||
</dependency>
|
||||
|
||||
<!-- svnkit -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.tmatesoft.svnkit</groupId>
|
||||
<artifactId>svnkit</artifactId>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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<String> files = new ArrayList<String>();
|
||||
|
||||
/** Field description */
|
||||
private File localRepository;
|
||||
|
||||
/** Field description */
|
||||
private SVNURL removeRepositoryURL;
|
||||
}
|
||||
@@ -138,9 +138,13 @@ public class RepositoryExtendedITCase
|
||||
public static Collection<Object[]> createParameters()
|
||||
{
|
||||
Collection<Object[]> params = new ArrayList<Object[]>();
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user