merge with branch 1.x

This commit is contained in:
Sebastian Sdorra
2017-01-14 13:25:25 +01:00
22 changed files with 260 additions and 377 deletions

View File

@@ -50,12 +50,14 @@ import sonia.scm.repository.spi.GitRepositoryServiceProvider;
import java.io.File;
import java.io.IOException;
import sonia.scm.store.ConfigurationStoreFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.SCMContextProvider;
import sonia.scm.schedule.Scheduler;
import sonia.scm.schedule.Task;
import sonia.scm.store.ConfigurationStoreFactory;
/**
*
@@ -195,21 +197,17 @@ public class GitRepositoryHandler
protected void create(Repository repository, File directory)
throws RepositoryException, IOException
{
org.eclipse.jgit.lib.Repository gitRepository = null;
try
{
gitRepository = new FileRepositoryBuilder().setGitDir(
directory).readEnvironment().findGitDir().build();
try (org.eclipse.jgit.lib.Repository gitRepository = build(directory)) {
gitRepository.create(true);
}
finally
{
if (gitRepository != null)
{
gitRepository.close();
}
}
private org.eclipse.jgit.lib.Repository build(File directory) throws IOException {
return new FileRepositoryBuilder()
.setGitDir(directory)
.readEnvironment()
.findGitDir()
.build();
}
/**

View File

@@ -271,7 +271,7 @@ public class GitBrowseCommand extends AbstractGitCommand
walk.markStart(commit);
result = Util.getFirst(walk);
}
catch (Exception ex)
catch (IOException ex)
{
logger.error("could not parse commit for file", ex);
}
@@ -417,12 +417,9 @@ public class GitBrowseCommand extends AbstractGitCommand
revision);
}
Map<String, SubRepository> subRepositories = null;
ByteArrayOutputStream baos = null;
try
Map<String, SubRepository> subRepositories;
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() )
{
baos = new ByteArrayOutputStream();
new GitCatCommand(context, repository).getContent(repo, revision,
PATH_MODULES, baos);
subRepositories = GitSubModuleParser.parse(baos.toString());
@@ -431,8 +428,6 @@ public class GitBrowseCommand extends AbstractGitCommand
{
logger.trace("could not find .gitmodules", ex);
subRepositories = Collections.EMPTY_MAP;
} finally {
IOUtil.close(baos);
}
return subRepositories;
@@ -462,7 +457,6 @@ public class GitBrowseCommand extends AbstractGitCommand
//~--- fields ---------------------------------------------------------------
/** Field description */
private final Map<ObjectId, Map<String, SubRepository>> subrepositoryCache =
Maps.newHashMap();
/** sub repository cache */
private final Map<ObjectId, Map<String, SubRepository>> subrepositoryCache = Maps.newHashMap();
}

View File

@@ -35,8 +35,6 @@ package sonia.scm.repository.client.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -48,7 +46,6 @@ import sonia.scm.repository.client.api.RepositoryClientException;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import sonia.scm.util.IOUtil;
/**
*
@@ -83,31 +80,17 @@ 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();
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
{
IOUtil.close(converter);
}
return changeset;
}
//~--- fields ---------------------------------------------------------------

View File

@@ -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)
{

View File

@@ -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 */

View File

@@ -35,8 +35,6 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -164,7 +162,7 @@ public class AbstractHgHandler
*/
protected Map<String, String> createEnvironment(String revision, String path)
{
Map<String, String> env = new HashMap<String, String>();
Map<String, String> env = new HashMap<>();
env.put(ENV_REVISION, HgUtil.getRevision(revision));
env.put(ENV_PATH, Util.nonNull(path));
@@ -300,29 +298,15 @@ public class AbstractHgHandler
throws IOException, RepositoryException
{
Process p = createScriptProcess(script, extraEnv);
T result = null;
InputStream input = null;
try
{
handleErrorStream(p.getErrorStream());
input = p.getInputStream();
result =
(T) handler.getJaxbContext().createUnmarshaller().unmarshal(input);
input.close();
}
catch (JAXBException ex)
{
try (InputStream input = p.getInputStream()) {
return (T) handler.getJaxbContext().createUnmarshaller().unmarshal(input);
} catch (JAXBException ex) {
logger.error("could not parse result", ex);
throw new RepositoryException("could not parse result", ex);
}
finally
{
Closeables.close(input, true);
}
return result;
}
//~--- methods --------------------------------------------------------------

View File

@@ -34,7 +34,6 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import com.google.common.io.Resources;
import org.junit.Rule;
@@ -109,20 +108,13 @@ public class HgWindowsPackageFixTest
*/
private File createHgBat(String number) throws IOException
{
URL url =
Resources.getResource("sonia/scm/repository/hg.bat.".concat(number));
URL url = Resources.getResource("sonia/scm/repository/hg.bat.".concat(number));
File file = tempFolder.newFile(number);
FileOutputStream fos = null;
try
try (FileOutputStream fos = new FileOutputStream(file))
{
fos = new FileOutputStream(file);
Resources.copy(url, fos);
}
finally
{
Closeables.close(fos, true);
}
return file;
}

View File

@@ -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");
try {
cmd.execute(url);
} catch (ExecutionException ex) {
throw new RepositoryClientException("push to repository failed", ex);
}
}
}

View File

@@ -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;
}

View File

@@ -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
{

View File

@@ -113,11 +113,8 @@ public class SvnBrowseCommand extends AbstractSvnCommand
String path = request.getPath();
long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision());
if (logger.isDebugEnabled())
{
logger.debug("browser repository {} in path {} at revision {}",
new Object[] { repository.getName(),
path, revisionNumber });
if (logger.isDebugEnabled()) {
logger.debug("browser repository {} in path {} at revision {}", repository.getName(), path, revisionNumber);
}
BrowserResult result = null;

View File

@@ -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;

View File

@@ -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

View File

@@ -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;
}
@@ -79,6 +77,11 @@ public class SvnRepositoryClientProvider extends RepositoryClientProvider {
return new SvnCommitCommand(client, workingCopy, addedFiles, removedFiles);
}
@Override
public File getWorkingCopy() {
return workingCopy;
}
@Override
public Set<ClientCommand> getSupportedClientCommands() {
return SUPPORTED_COMMANDS;

View File

@@ -44,6 +44,7 @@ import sonia.scm.util.IOUtil;
//~--- 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
*

View File

@@ -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();
}

View File

@@ -51,9 +51,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.*;
@@ -68,10 +65,14 @@ import com.sun.jersey.api.client.WebResource;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Ignore;
import sonia.scm.repository.client.api.RepositoryClient;
import sonia.scm.repository.client.api.RepositoryClientFactory;
/**
*
* @author Sebastian Sdorra
@@ -185,39 +186,58 @@ public class AnonymousAccessITCase
logoutClient(client);
}
/**
* Method description
*
* @throws IOException
*/
@Test
@Ignore
public void testAllowedAnonymousPush() throws IOException
{
Client client = createAdminClient();
WebResource resource = createResource(client,
"repository/".concat(repository.getId()));
repository.setPermissions(Arrays.asList(PERMISSION_ANONYMOUS_WRITE));
resource.post(ClientResponse.class, repository);
RepositoryClient repositoryClient = createAnonymousRepositoryClient();
createRandomFile(repositoryClient);
commit(repositoryClient, "added test files");
}
/**
* Method description
*
* TODO fix test case
*
* @throws IOException
* @throws RepositoryClientException
*/
@Test @Ignore
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
*/
@Test(expected = RepositoryClientException.class)
public void testDeniedAnonymousPush()
throws IOException, RepositoryClientException
@Ignore
@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");
}
/**
@@ -225,83 +245,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);
String url = repository.createUrl(BASE_URL);
if ((username != null) && (password != null))
{
client = RepositoryClientFactory.createClient(repositoryType, directory,
url, username, password);
}
else
{
client = RepositoryClientFactory.createClient(repositoryType, directory,
url);
}
client.init();
return client;
RepositoryClientFactory factory = new RepositoryClientFactory();
return factory.create(repositoryType, remoteUrl, username, password, directory);
}
//~--- fields ---------------------------------------------------------------
@@ -314,5 +281,5 @@ public class AnonymousAccessITCase
private Repository repository;
/** Field description */
private String repositoryType;
private final String repositoryType;
}

View File

@@ -47,9 +47,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,9 @@ import java.util.Collection;
import java.util.List;
import java.util.Random;
import sonia.scm.repository.client.api.RepositoryClient;
import sonia.scm.repository.client.api.RepositoryClientFactory;
/**
*
* @author Sebastian Sdorra
@@ -111,15 +112,13 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
*
* @throws IOException
* @throws InterruptedException
* @throws RepositoryClientException
*/
@Test
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);
}
@@ -159,15 +158,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);
}
@@ -186,29 +183,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());
}
@@ -216,12 +208,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());
}
@@ -251,75 +240,32 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
//J+
}
/**
* Method description
*
*
* @return
*
* @throws RepositoryClientException
*/
private RepositoryClient createRepositoryClient()
throws RepositoryClientException
{
return RepositoryClientFactory.createClient(repositoryType, localDirectory,
repository.createUrl(BASE_URL), 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);
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));
@@ -346,5 +292,5 @@ public class ChangesetViewerITCase extends AbstractAdminITCaseBase
private Repository repository;
/** Field description */
private String repositoryType;
private final String repositoryType;
}

View File

@@ -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;
@@ -64,6 +62,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;
/**
*
@@ -72,6 +73,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";
@@ -182,34 +185,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);
}
/**
@@ -220,7 +230,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" });

View File

@@ -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);
}

View File

@@ -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.createUrl(BASE_URL), username, password);
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
RepositoryClient client = clientFactory.create(
repository.getType(), repository.createUrl(BASE_URL), username, password, directory
);
rc.init();
addTestFiles(rc);
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;
@@ -337,13 +328,13 @@ public class RepositoryITCaseBase
*
* @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.createUrl(BASE_URL), user.getName(), password);
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
return clientFactory.create(repository.getType(), repository.createUrl(BASE_URL),
user.getName(), password, directory);
}
//~--- fields ---------------------------------------------------------------

View File

@@ -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
*