mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-06-17 21:50:46 +02:00
use newer repository client api
This commit is contained in:
@@ -82,35 +82,22 @@ public class GitCommitCommand implements CommitCommand
|
||||
@Override
|
||||
public Changeset commit(CommitRequest request) throws IOException
|
||||
{
|
||||
Changeset changeset = null;
|
||||
GitChangesetConverter converter = null;
|
||||
|
||||
try
|
||||
try (GitChangesetConverter converter = new GitChangesetConverter(git.getRepository()))
|
||||
{
|
||||
RevCommit commit = git.commit().setAuthor(
|
||||
request.getAuthor().getName(),
|
||||
request.getAuthor().getMail()).setMessage(
|
||||
request.getMessage()).call();
|
||||
|
||||
converter = new GitChangesetConverter(git.getRepository());
|
||||
|
||||
changeset = converter.createChangeset(commit);
|
||||
return converter.createChangeset(commit);
|
||||
} catch (GitAPIException ex) {
|
||||
throw new RepositoryClientException("could not commit changes to repository", ex);
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryClientException(
|
||||
"could not commit changes to repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Closeables.closeQuietly(converter);
|
||||
}
|
||||
|
||||
return changeset;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Git git;
|
||||
private final Git git;
|
||||
}
|
||||
|
||||
@@ -105,13 +105,18 @@ public class GitRepositoryClientFactoryProvider
|
||||
{
|
||||
Git git = null;
|
||||
|
||||
CredentialsProvider credentialsProvider =
|
||||
new UsernamePasswordCredentialsProvider(username, password);
|
||||
CredentialsProvider credentialsProvider = null;
|
||||
if ( username != null && password != null ) {
|
||||
credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
git = Git.cloneRepository().setURI(url).setDirectory(
|
||||
workingCopy).setCredentialsProvider(credentialsProvider).call();
|
||||
git = Git.cloneRepository()
|
||||
.setURI(url)
|
||||
.setDirectory(workingCopy)
|
||||
.setCredentialsProvider(credentialsProvider)
|
||||
.call();
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.repository.client.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.transport.CredentialsProvider;
|
||||
@@ -188,6 +189,11 @@ public class GitRepositoryClientProvider extends RepositoryClientProvider
|
||||
return new GitTagCommand(git);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorkingCopy() {
|
||||
return git.getRepository().getDirectory();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
package sonia.scm.repository.client.spi;
|
||||
|
||||
import com.aragost.javahg.Repository;
|
||||
import com.aragost.javahg.commands.ExecutionException;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
|
||||
/**
|
||||
* Mercurial implementation of the {@link PushCommand}.
|
||||
@@ -55,7 +57,11 @@ public class HgPushCommand implements PushCommand
|
||||
{
|
||||
com.aragost.javahg.commands.PushCommand cmd = com.aragost.javahg.commands.PushCommand.on(repository);
|
||||
cmd.cmdAppend("--new-branch");
|
||||
cmd.execute(url);
|
||||
try {
|
||||
cmd.execute(url);
|
||||
} catch (ExecutionException ex) {
|
||||
throw new RepositoryClientException("push to repository failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ package sonia.scm.repository.client.spi;
|
||||
|
||||
import com.aragost.javahg.Repository;
|
||||
import com.aragost.javahg.RepositoryConfiguration;
|
||||
import com.aragost.javahg.commands.ExecutionException;
|
||||
import com.aragost.javahg.commands.PullCommand;
|
||||
import com.google.common.base.Strings;
|
||||
import java.io.File;
|
||||
@@ -40,6 +41,7 @@ import java.net.URL;
|
||||
import sonia.scm.io.INIConfiguration;
|
||||
import sonia.scm.io.INIConfigurationWriter;
|
||||
import sonia.scm.io.INISection;
|
||||
import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
/**
|
||||
@@ -53,19 +55,17 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
|
||||
private static final String TYPE = "hg";
|
||||
|
||||
@Override
|
||||
public RepositoryClientProvider create(File main, File workingCopy) throws IOException
|
||||
{
|
||||
public RepositoryClientProvider create(File main, File workingCopy) throws IOException {
|
||||
return create(main.toURI().toString(), null, null, workingCopy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositoryClientProvider create(String url, String username, String password, File workingCopy)
|
||||
throws IOException
|
||||
{
|
||||
throws IOException {
|
||||
RepositoryConfiguration configuration = new RepositoryConfiguration();
|
||||
String binary = IOUtil.search("hg");
|
||||
if (Strings.isNullOrEmpty(binary)){
|
||||
throw new IOException("could not find mercurial binary (hg)");
|
||||
throw new RepositoryClientException("could not find mercurial binary (hg)");
|
||||
}
|
||||
configuration.setHgBin(binary);
|
||||
|
||||
@@ -77,13 +77,18 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
|
||||
}
|
||||
|
||||
Repository repository = Repository.create(configuration, workingCopy);
|
||||
PullCommand.on(repository).execute(url);
|
||||
try {
|
||||
PullCommand command = PullCommand.on(repository);
|
||||
command.cmdAppend("-u");
|
||||
command.execute(url);
|
||||
} catch (ExecutionException ex) {
|
||||
throw new RepositoryClientException("failed to pull from remote repository", ex);
|
||||
}
|
||||
|
||||
return new HgRepositoryClientProvider(repository, hgrc, url);
|
||||
}
|
||||
|
||||
private File createHgrc(String url, String username, String password) throws IOException
|
||||
{
|
||||
private File createHgrc(String url, String username, String password) throws IOException {
|
||||
URL repositoryUrl = new URL(url);
|
||||
|
||||
INIConfiguration hgConfig = new INIConfiguration();
|
||||
@@ -101,8 +106,7 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
|
||||
);
|
||||
authSection.setParameter(prefix + "schemes", repositoryUrl.getProtocol());
|
||||
authSection.setParameter(prefix + "username", username);
|
||||
if (!Strings.isNullOrEmpty(password))
|
||||
{
|
||||
if (!Strings.isNullOrEmpty(password)) {
|
||||
authSection.setParameter(prefix + "password", password);
|
||||
}
|
||||
hgConfig.addSection(authSection);
|
||||
@@ -114,8 +118,7 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,11 @@ public class HgRepositoryClientProvider extends RepositoryClientProvider
|
||||
return new HgPushCommand(repository, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorkingCopy() {
|
||||
return repository.getDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
|
||||
@@ -32,7 +32,6 @@ 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;
|
||||
@@ -46,8 +45,10 @@ 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;
|
||||
import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,18 +72,14 @@ public class SvnCommitCommand implements CommitCommand {
|
||||
public Changeset commit(CommitRequest request) throws IOException {
|
||||
SVNWCClient wClient = client.getWCClient();
|
||||
|
||||
List<File> 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);
|
||||
throw new RepositoryClientException("failed to add files", ex);
|
||||
}
|
||||
|
||||
// remove files
|
||||
@@ -92,19 +89,15 @@ public class SvnCommitCommand implements CommitCommand {
|
||||
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);
|
||||
throw new RepositoryClientException("failed to remove files", ex);
|
||||
}
|
||||
|
||||
|
||||
SvnTarget workingCopyTarget = SvnTarget.fromFile(workingCopy);
|
||||
Changeset changeset;
|
||||
SVNCommitInfo info;
|
||||
|
||||
|
||||
|
||||
// commit files
|
||||
try {
|
||||
SvnCommit commit = client.getOperationFactory().createCommit();
|
||||
@@ -120,7 +113,7 @@ public class SvnCommitCommand implements CommitCommand {
|
||||
}
|
||||
|
||||
} catch (SVNException ex) {
|
||||
throw new IOException("failed to commit", ex);
|
||||
throw new RepositoryClientException("failed to commit", ex);
|
||||
}
|
||||
|
||||
// get log for commit
|
||||
@@ -133,7 +126,7 @@ public class SvnCommitCommand implements CommitCommand {
|
||||
|
||||
changeset = SvnUtil.createChangeset(log.run());
|
||||
} catch (SVNException ex) {
|
||||
throw new IOException("failed to create log entry for last commit", ex);
|
||||
throw new RepositoryClientException("failed to create log entry for last commit", ex);
|
||||
}
|
||||
|
||||
return changeset;
|
||||
|
||||
@@ -44,6 +44,7 @@ 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;
|
||||
import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
|
||||
/**
|
||||
* Client provider factory for subversion.
|
||||
@@ -60,7 +61,7 @@ public class SvnRepositoryClientFactoryProvider implements RepositoryClientFacto
|
||||
try {
|
||||
source = SVNURL.fromFile(workingCopy);
|
||||
} catch (SVNException ex) {
|
||||
throw new IOException("failed to parse svn url", ex);
|
||||
throw new RepositoryClientException("failed to parse svn url", ex);
|
||||
}
|
||||
|
||||
// create client
|
||||
@@ -69,11 +70,11 @@ public class SvnRepositoryClientFactoryProvider implements RepositoryClientFacto
|
||||
try {
|
||||
updateClient.doCheckout(source, workingCopy, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true);
|
||||
} catch (SVNException ex) {
|
||||
throw new IOException("failed to checkout repository", ex);
|
||||
throw new RepositoryClientException("failed to checkout repository", ex);
|
||||
}
|
||||
|
||||
// return client provider
|
||||
return new SvnRepositoryClientProvider(client, source, workingCopy);
|
||||
return new SvnRepositoryClientProvider(client, workingCopy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,7 +102,7 @@ public class SvnRepositoryClientFactoryProvider implements RepositoryClientFacto
|
||||
try {
|
||||
remoteUrl = SVNURL.parseURIEncoded(url);
|
||||
} catch (SVNException ex) {
|
||||
throw new IOException("failed to parse svn url", ex);
|
||||
throw new RepositoryClientException("failed to parse svn url", ex);
|
||||
}
|
||||
|
||||
// initial checkout
|
||||
@@ -109,11 +110,11 @@ public class SvnRepositoryClientFactoryProvider implements RepositoryClientFacto
|
||||
try {
|
||||
updateClient.doCheckout(remoteUrl, workingCopy, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true);
|
||||
} catch (SVNException ex) {
|
||||
throw new IOException("failed to checkout repository", ex);
|
||||
throw new RepositoryClientException("failed to checkout repository", ex);
|
||||
}
|
||||
|
||||
// return client provider
|
||||
return new SvnRepositoryClientProvider(client, remoteUrl, workingCopy);
|
||||
return new SvnRepositoryClientProvider(client, workingCopy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,15 +52,13 @@ public class SvnRepositoryClientProvider extends RepositoryClientProvider {
|
||||
);
|
||||
|
||||
private final SVNClientManager client;
|
||||
private final SVNURL remoteRepositoryURL;
|
||||
private final File workingCopy;
|
||||
|
||||
private final List<File> addedFiles = new ArrayList<>();
|
||||
private final List<File> removedFiles = new ArrayList<>();
|
||||
|
||||
SvnRepositoryClientProvider(SVNClientManager client, SVNURL remoteRepositoryURL, File workingCopy) {
|
||||
SvnRepositoryClientProvider(SVNClientManager client, File workingCopy) {
|
||||
this.client = client;
|
||||
this.remoteRepositoryURL = remoteRepositoryURL;
|
||||
this.workingCopy = workingCopy;
|
||||
}
|
||||
|
||||
@@ -78,6 +76,11 @@ public class SvnRepositoryClientProvider extends RepositoryClientProvider {
|
||||
public SvnCommitCommand getCommitCommand() {
|
||||
return new SvnCommitCommand(client, workingCopy, addedFiles, removedFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorkingCopy() {
|
||||
return workingCopy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ClientCommand> getSupportedClientCommands() {
|
||||
|
||||
@@ -44,6 +44,7 @@ import sonia.scm.repository.client.spi.RepositoryClientProvider;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -188,6 +189,16 @@ public final class RepositoryClient implements Closeable
|
||||
return new TagCommandBuilder(clientProvider.getTagCommand());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the working copy of the repository.
|
||||
*
|
||||
* @return working copy
|
||||
* @since 1.51
|
||||
*/
|
||||
public File getWorkingCopy() {
|
||||
return clientProvider.getWorkingCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -204,5 +215,5 @@ public final class RepositoryClient implements Closeable
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private RepositoryClientProvider clientProvider;
|
||||
private final RepositoryClientProvider clientProvider;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import sonia.scm.repository.client.api.ClientCommandNotSupportedException;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -138,4 +139,12 @@ public abstract class RepositoryClientProvider implements Closeable
|
||||
{
|
||||
throw new ClientCommandNotSupportedException(ClientCommand.TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the working copy of the repository client.
|
||||
*
|
||||
* @return working copy
|
||||
* @since 1.51
|
||||
*/
|
||||
public abstract File getWorkingCopy();
|
||||
}
|
||||
|
||||
@@ -52,9 +52,6 @@ import sonia.scm.repository.Permission;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
import sonia.scm.repository.client.RepositoryClient;
|
||||
import sonia.scm.repository.client.RepositoryClientException;
|
||||
import sonia.scm.repository.client.RepositoryClientFactory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -73,6 +70,9 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -189,14 +189,11 @@ public class AnonymousAccessITCase
|
||||
/**
|
||||
* Issue 97
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void testAllowedAnonymousPush()
|
||||
throws IOException, RepositoryClientException
|
||||
public void testAllowedAnonymousPush() throws IOException
|
||||
{
|
||||
Client client = createAdminClient();
|
||||
WebResource resource = createResource(client,
|
||||
@@ -208,7 +205,7 @@ public class AnonymousAccessITCase
|
||||
RepositoryClient repositoryClient = createAnonymousRepositoryClient();
|
||||
|
||||
createRandomFile(repositoryClient);
|
||||
repositoryClient.commit("added test files");
|
||||
commit(repositoryClient, "added test files");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,34 +213,30 @@ public class AnonymousAccessITCase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test
|
||||
public void testAnonymousClone() throws RepositoryClientException, IOException
|
||||
public void testAnonymousClone() throws IOException
|
||||
{
|
||||
testSimpleAdminPush();
|
||||
|
||||
RepositoryClient client = createAnonymousRepositoryClient();
|
||||
|
||||
client.checkout();
|
||||
// client.checkout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Ignore
|
||||
@Test(expected = RepositoryClientException.class)
|
||||
public void testDeniedAnonymousPush()
|
||||
throws IOException, RepositoryClientException
|
||||
@Test(expected = IOException.class)
|
||||
public void testDeniedAnonymousPush() throws IOException
|
||||
{
|
||||
RepositoryClient repositoryClient = createAnonymousRepositoryClient();
|
||||
|
||||
createRandomFile(repositoryClient);
|
||||
repositoryClient.commit("added anonymous test file");
|
||||
commit(repositoryClient, "added anonymous test file");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,81 +244,30 @@ public class AnonymousAccessITCase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test
|
||||
public void testSimpleAdminPush()
|
||||
throws RepositoryClientException, IOException
|
||||
public void testSimpleAdminPush() throws IOException
|
||||
{
|
||||
RepositoryClient client = createAdminRepositoryClient();
|
||||
RepositoryClient repositoryClient = createAdminRepositoryClient();
|
||||
|
||||
createRandomFile(client);
|
||||
client.commit("added random file");
|
||||
createRandomFile(repositoryClient);
|
||||
commit(repositoryClient, "added random file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
private RepositoryClient createAdminRepositoryClient()
|
||||
throws IOException, RepositoryClientException
|
||||
{
|
||||
private RepositoryClient createAdminRepositoryClient() throws IOException {
|
||||
return createRepositoryClient(ADMIN_USERNAME, ADMIN_PASSWORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
private RepositoryClient createAnonymousRepositoryClient()
|
||||
throws IOException, RepositoryClientException
|
||||
{
|
||||
private RepositoryClient createAnonymousRepositoryClient() throws IOException {
|
||||
return createRepositoryClient(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
private RepositoryClient createRepositoryClient(String username,
|
||||
String password)
|
||||
throws IOException, RepositoryClientException
|
||||
{
|
||||
private RepositoryClient createRepositoryClient(String username, String password) throws IOException {
|
||||
File directory = temporaryFolder.newFolder();
|
||||
RepositoryClient client = null;
|
||||
String remoteUrl = repository.createUrl(BASE_URL);
|
||||
|
||||
if ((username != null) && (password != null))
|
||||
{
|
||||
client = RepositoryClientFactory.createClient(repositoryType, directory,
|
||||
repository.getUrl(), username, password);
|
||||
}
|
||||
else
|
||||
{
|
||||
client = RepositoryClientFactory.createClient(repositoryType, directory,
|
||||
repository.getUrl());
|
||||
}
|
||||
|
||||
client.init();
|
||||
|
||||
return client;
|
||||
RepositoryClientFactory factory = new RepositoryClientFactory();
|
||||
return factory.create(repositoryType, remoteUrl, username, password, directory);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
@@ -338,5 +280,5 @@ public class AnonymousAccessITCase
|
||||
private Repository repository;
|
||||
|
||||
/** Field description */
|
||||
private String repositoryType;
|
||||
private final String repositoryType;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,7 @@ import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
import sonia.scm.repository.client.RepositoryClient;
|
||||
import sonia.scm.repository.client.RepositoryClientException;
|
||||
import sonia.scm.repository.client.RepositoryClientFactory;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@@ -72,6 +70,10 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import sonia.scm.repository.client.api.ClientCommand;
|
||||
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -112,16 +114,14 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void cachingTest()
|
||||
throws RepositoryClientException, IOException, InterruptedException
|
||||
public void cachingTest() throws IOException, InterruptedException
|
||||
{
|
||||
RepositoryClient rc = createRepositoryClient();
|
||||
|
||||
rc.checkout();
|
||||
// rc.checkout();
|
||||
addTestFile(rc, "a", 1, false);
|
||||
addTestFile(rc, "b", 2, true);
|
||||
}
|
||||
@@ -161,15 +161,13 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test
|
||||
public void simpleTest()
|
||||
throws RepositoryClientException, IOException, InterruptedException
|
||||
public void simpleTest() throws IOException, InterruptedException
|
||||
{
|
||||
RepositoryClient rc = createRepositoryClient();
|
||||
|
||||
rc.init();
|
||||
// rc.init();
|
||||
addTestFile(rc, "a", 1, false);
|
||||
}
|
||||
|
||||
@@ -188,29 +186,24 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
|
||||
*/
|
||||
private void addTestFile(RepositoryClient rc, String name, int count,
|
||||
boolean sleep)
|
||||
throws IOException, RepositoryClientException, InterruptedException
|
||||
throws IOException, InterruptedException
|
||||
{
|
||||
File file = new File(localDirectory, name.concat(".txt"));
|
||||
|
||||
writeRandomContent(file);
|
||||
rc.add(name.concat(".txt"));
|
||||
rc.commit("added-".concat(name).concat(".txt"));
|
||||
|
||||
if (sleep)
|
||||
{
|
||||
rc.getAddCommand().add(name.concat(".txt"));
|
||||
IntegrationTestUtil.commit(rc, "added-".concat(name).concat(".txt"));
|
||||
|
||||
if (sleep) {
|
||||
// cache clear is async
|
||||
Thread.sleep(500l);
|
||||
}
|
||||
|
||||
ChangesetPagingResult cpr = getChangesets(repository);
|
||||
|
||||
if ("svn".equals(repositoryType))
|
||||
{
|
||||
if ("svn".equals(repositoryType)) {
|
||||
assertEquals((count + 1), cpr.getTotal());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
assertEquals(count, cpr.getTotal());
|
||||
}
|
||||
|
||||
@@ -218,12 +211,9 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
|
||||
|
||||
assertNotNull(changesets);
|
||||
|
||||
if ("svn".equals(repositoryType))
|
||||
{
|
||||
if ("svn".equals(repositoryType)) {
|
||||
assertEquals((count + 1), changesets.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
assertEquals(count, changesets.size());
|
||||
}
|
||||
|
||||
@@ -253,75 +243,32 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
|
||||
//J+
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
private RepositoryClient createRepositoryClient()
|
||||
throws RepositoryClientException
|
||||
{
|
||||
return RepositoryClientFactory.createClient(repositoryType, localDirectory,
|
||||
repository.getUrl(), IntegrationTestUtil.ADMIN_USERNAME,
|
||||
IntegrationTestUtil.ADMIN_PASSWORD);
|
||||
private RepositoryClient createRepositoryClient() throws IOException {
|
||||
RepositoryClientFactory factory = new RepositoryClientFactory();
|
||||
return factory.create(
|
||||
repositoryType, repository.createUrl(BASE_URL),
|
||||
IntegrationTestUtil.ADMIN_USERNAME, IntegrationTestUtil.ADMIN_PASSWORD,
|
||||
localDirectory
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param file
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeRandomContent(File file) throws IOException
|
||||
{
|
||||
FileOutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
output = new FileOutputStream(file);
|
||||
|
||||
Random random = new Random();
|
||||
byte[] data = new byte[random.nextInt(1024)];
|
||||
|
||||
private void writeRandomContent(File file) throws IOException {
|
||||
Random random = new Random();
|
||||
byte[] data = new byte[random.nextInt(1024)];
|
||||
|
||||
try (FileOutputStream output = new FileOutputStream(file)) {
|
||||
random.nextBytes(data);
|
||||
output.write(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(output);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getChangesetViewerUri(Repository repository)
|
||||
{
|
||||
private String getChangesetViewerUri(Repository repository) {
|
||||
return "repositories/".concat(repository.getId()).concat("/changesets");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ChangesetPagingResult getChangesets(Repository repository)
|
||||
{
|
||||
private ChangesetPagingResult getChangesets(Repository repository) {
|
||||
WebResource resource = createResource(client,
|
||||
getChangesetViewerUri(repository));
|
||||
|
||||
@@ -348,5 +295,5 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
|
||||
private Repository repository;
|
||||
|
||||
/** Field description */
|
||||
private String repositoryType;
|
||||
private final String repositoryType;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ package sonia.scm.it;
|
||||
|
||||
import sonia.scm.ScmState;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.repository.client.RepositoryClient;
|
||||
import sonia.scm.repository.client.RepositoryClientException;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
@@ -63,6 +61,9 @@ import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.client.api.ClientCommand;
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -70,6 +71,8 @@ import javax.ws.rs.core.MultivaluedMap;
|
||||
*/
|
||||
public final class IntegrationTestUtil
|
||||
{
|
||||
|
||||
public static final Person AUTHOR = new Person("SCM Administrator", "scmadmin@scm-manager.org");
|
||||
|
||||
/** Field description */
|
||||
public static final String ADMIN_PASSWORD = "scmadmin";
|
||||
@@ -181,34 +184,41 @@ public final class IntegrationTestUtil
|
||||
return ApacheHttpClient.create(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit and push changes.
|
||||
*
|
||||
* @param repositoryClient repository client
|
||||
* @param message commit message
|
||||
*
|
||||
* @throws IOException
|
||||
*
|
||||
* @since 1.51
|
||||
*/
|
||||
public static void commit(RepositoryClient repositoryClient, String message) throws IOException {
|
||||
repositoryClient.getCommitCommand().commit(IntegrationTestUtil.AUTHOR, message);
|
||||
if ( repositoryClient.isCommandSupported(ClientCommand.PUSH) ) {
|
||||
repositoryClient.getPushCommand().push();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
public static void createRandomFile(RepositoryClient client)
|
||||
throws IOException, RepositoryClientException
|
||||
public static void createRandomFile(RepositoryClient client) throws IOException
|
||||
{
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String name = "file-" + uuid + ".uuid";
|
||||
FileOutputStream out = null;
|
||||
|
||||
try
|
||||
{
|
||||
out = new FileOutputStream(new File(client.getLocalRepository(), name));
|
||||
File file = new File(client.getWorkingCopy(), name);
|
||||
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||
out.write(uuid.getBytes());
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(out);
|
||||
}
|
||||
|
||||
client.add(name);
|
||||
client.getAddCommand().add(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +229,7 @@ public final class IntegrationTestUtil
|
||||
*/
|
||||
public static Collection<String[]> createRepositoryTypeParameters()
|
||||
{
|
||||
Collection<String[]> params = new ArrayList<String[]>();
|
||||
Collection<String[]> params = new ArrayList<>();
|
||||
|
||||
params.add(new String[] { "git" });
|
||||
params.add(new String[] { "svn" });
|
||||
@@ -258,7 +268,7 @@ public final class IntegrationTestUtil
|
||||
{
|
||||
return REST_BASE_URL.concat(url).concat(EXTENSION);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -42,8 +42,6 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.client.RepositoryClient;
|
||||
import sonia.scm.repository.client.RepositoryClientException;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
@@ -56,6 +54,9 @@ import static sonia.scm.it.IntegrationTestUtil.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
import sonia.scm.repository.client.api.RepositoryClientException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -100,14 +101,14 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws RepositoryClientException
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test(expected = RepositoryClientException.class)
|
||||
public void readFailed() throws RepositoryClientException
|
||||
public void readFailed() throws IOException
|
||||
{
|
||||
RepositoryClient rc = createRepositoryClient(nopermUser, directory);
|
||||
|
||||
rc.checkout();
|
||||
// rc.checkout();
|
||||
|
||||
// ugly workaround
|
||||
if (repository.getType().equals("git"))
|
||||
@@ -120,7 +121,7 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
||||
}
|
||||
}
|
||||
|
||||
throw new RepositoryClientException("checkout failed");
|
||||
throw new IOException("checkout failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,47 +140,40 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test
|
||||
public void simpleRead() throws RepositoryClientException, IOException
|
||||
public void simpleRead() throws IOException
|
||||
{
|
||||
RepositoryClient rc = createRepositoryClient(readUser, directory);
|
||||
|
||||
rc.checkout();
|
||||
// rc.checkout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test
|
||||
public void simpleWrite() throws RepositoryClientException, IOException
|
||||
public void simpleWrite() throws IOException
|
||||
{
|
||||
RepositoryClient rc = createRepositoryClient(writeUser, directory);
|
||||
|
||||
rc.checkout();
|
||||
// rc.checkout();
|
||||
addTestFiles(rc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Test(expected = RepositoryClientException.class)
|
||||
public void writeFailed() throws RepositoryClientException, IOException
|
||||
@Test(expected = IOException.class)
|
||||
public void writeFailed() throws IOException
|
||||
{
|
||||
RepositoryClient rc = createRepositoryClient(readUser, directory);
|
||||
|
||||
rc.checkout();
|
||||
// rc.checkout();
|
||||
addTestFiles(rc);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +44,6 @@ import sonia.scm.repository.Permission;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
import sonia.scm.repository.client.RepositoryClient;
|
||||
import sonia.scm.repository.client.RepositoryClientException;
|
||||
import sonia.scm.repository.client.RepositoryClientFactory;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserTestData;
|
||||
import sonia.scm.util.IOUtil;
|
||||
@@ -69,6 +66,9 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -107,45 +107,40 @@ public class RepositoryITCaseBase
|
||||
* @param client
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
public static void addTestFiles(RepositoryClient client)
|
||||
throws RepositoryClientException, IOException
|
||||
public static void addTestFiles(RepositoryClient client) throws IOException
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
createRandomFile(client);
|
||||
}
|
||||
|
||||
client.commit("added some test files");
|
||||
commit(client, "added some test files");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param username
|
||||
* @param password
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
public static void addTestFiles(Repository repository, String username,
|
||||
String password)
|
||||
throws RepositoryClientException, IOException
|
||||
throws IOException
|
||||
{
|
||||
File directory = createTempDirectory();
|
||||
|
||||
try
|
||||
{
|
||||
RepositoryClient rc =
|
||||
RepositoryClientFactory.createClient(repository.getType(), directory,
|
||||
repository.getUrl(), username, password);
|
||||
|
||||
rc.init();
|
||||
addTestFiles(rc);
|
||||
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
|
||||
RepositoryClient client = clientFactory.create(
|
||||
repository.getType(), repository.createUrl(BASE_URL), username, password, directory
|
||||
);
|
||||
|
||||
addTestFiles(client);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -190,11 +185,9 @@ public class RepositoryITCaseBase
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
@Parameters
|
||||
public static Collection<Object[]> createParameters()
|
||||
throws RepositoryClientException, IOException
|
||||
public static Collection<Object[]> createParameters() throws IOException
|
||||
{
|
||||
Client client = createClient();
|
||||
ScmState state = authenticateAdmin(client);
|
||||
@@ -202,7 +195,7 @@ public class RepositoryITCaseBase
|
||||
assertNotNull(state);
|
||||
assertTrue(state.isSuccess());
|
||||
|
||||
Collection<Object[]> params = new ArrayList<Object[]>();
|
||||
Collection<Object[]> params = new ArrayList<>();
|
||||
User owner = UserTestData.createTrillian();
|
||||
|
||||
createUser(owner);
|
||||
@@ -242,16 +235,14 @@ public class RepositoryITCaseBase
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
private static void appendTestParemeter(Collection<Object[]> params,
|
||||
String type, User owner, User write, User read, User noperm)
|
||||
throws RepositoryClientException, IOException
|
||||
String type, User owner, User write, User read, User noperm) throws IOException
|
||||
{
|
||||
Repository repository = createTestRepository(null, type, owner, write,
|
||||
read);
|
||||
|
||||
Repository repository = createTestRepository(null, type, owner, write, read);
|
||||
params.add(new Object[]
|
||||
{
|
||||
repository, owner, write, read, noperm, "secret"
|
||||
});
|
||||
|
||||
repository = createTestRepository("test", type, owner, write, read);
|
||||
params.add(new Object[]
|
||||
{
|
||||
@@ -276,8 +267,7 @@ public class RepositoryITCaseBase
|
||||
* @throws RepositoryClientException
|
||||
*/
|
||||
private static Repository createTestRepository(String prefix, String type,
|
||||
User owner, User write, User read)
|
||||
throws RepositoryClientException, IOException
|
||||
User owner, User write, User read) throws IOException
|
||||
{
|
||||
Client client = createAdminClient();
|
||||
Repository repository = RepositoryTestData.createHeartOfGold(type);
|
||||
@@ -296,6 +286,7 @@ public class RepositoryITCaseBase
|
||||
//J+
|
||||
repository = createRepository(client, repository);
|
||||
client.destroy();
|
||||
|
||||
addTestFiles(repository, ADMIN_USERNAME, ADMIN_PASSWORD);
|
||||
|
||||
return repository;
|
||||
@@ -336,14 +327,14 @@ public class RepositoryITCaseBase
|
||||
* @param directory
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryClientException
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
protected RepositoryClient createRepositoryClient(User user, File directory)
|
||||
throws RepositoryClientException
|
||||
protected RepositoryClient createRepositoryClient(User user, File directory) throws IOException
|
||||
{
|
||||
return RepositoryClientFactory.createClient(repository.getType(),
|
||||
directory, repository.getUrl(), user.getName(), password);
|
||||
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
|
||||
return clientFactory.create(repository.getType(), repository.createUrl(BASE_URL),
|
||||
user.getName(), password, directory);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -65,12 +65,10 @@ public final class RepositoryITUtil
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param other
|
||||
*/
|
||||
public static void assertRepositoriesEquals(Repository repository,
|
||||
Repository other)
|
||||
public static void assertRepositoriesEquals(Repository repository, Repository other)
|
||||
{
|
||||
assertEquals(repository.getName(), other.getName());
|
||||
assertEquals(repository.getDescription(), other.getDescription());
|
||||
@@ -82,8 +80,6 @@ public final class RepositoryITUtil
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
* @param repository
|
||||
*
|
||||
@@ -116,8 +112,6 @@ public final class RepositoryITUtil
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
* @param id
|
||||
*/
|
||||
@@ -141,10 +135,6 @@ public final class RepositoryITUtil
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
* @param url
|
||||
*
|
||||
@@ -168,11 +158,6 @@ public final class RepositoryITUtil
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param client
|
||||
* @param id
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user