mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
improve exception handling
This commit is contained in:
@@ -33,6 +33,7 @@ package sonia.scm.repository.api;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.subject.Subject;
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ import sonia.scm.repository.ChangesetPagingResult;
|
|||||||
import sonia.scm.repository.PermissionType;
|
import sonia.scm.repository.PermissionType;
|
||||||
import sonia.scm.repository.PreProcessorUtil;
|
import sonia.scm.repository.PreProcessorUtil;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.RepositoryException;
|
||||||
import sonia.scm.repository.spi.IncomingCommand;
|
import sonia.scm.repository.spi.IncomingCommand;
|
||||||
import sonia.scm.repository.spi.IncomingCommandRequest;
|
import sonia.scm.repository.spi.IncomingCommandRequest;
|
||||||
import sonia.scm.security.RepositoryPermission;
|
import sonia.scm.security.RepositoryPermission;
|
||||||
@@ -82,7 +84,7 @@ public final class IncomingCommandBuilder
|
|||||||
* @return incoming changesets
|
* @return incoming changesets
|
||||||
*/
|
*/
|
||||||
public ChangesetPagingResult getIncomingChangesets(
|
public ChangesetPagingResult getIncomingChangesets(
|
||||||
Repository remoteRepository)
|
Repository remoteRepository) throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
Subject subject = SecurityUtils.getSubject();
|
Subject subject = SecurityUtils.getSubject();
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
package sonia.scm.repository.api;
|
package sonia.scm.repository.api;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.subject.Subject;
|
||||||
import sonia.scm.cache.CacheManager;
|
import sonia.scm.cache.CacheManager;
|
||||||
@@ -35,6 +36,7 @@ import sonia.scm.repository.ChangesetPagingResult;
|
|||||||
import sonia.scm.repository.PermissionType;
|
import sonia.scm.repository.PermissionType;
|
||||||
import sonia.scm.repository.PreProcessorUtil;
|
import sonia.scm.repository.PreProcessorUtil;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.RepositoryException;
|
||||||
import sonia.scm.repository.spi.OutgoingCommand;
|
import sonia.scm.repository.spi.OutgoingCommand;
|
||||||
import sonia.scm.repository.spi.OutgoingCommandRequest;
|
import sonia.scm.repository.spi.OutgoingCommandRequest;
|
||||||
import sonia.scm.security.RepositoryPermission;
|
import sonia.scm.security.RepositoryPermission;
|
||||||
@@ -76,7 +78,7 @@ public final class OutgoingCommandBuilder
|
|||||||
* @return outgoing changesets
|
* @return outgoing changesets
|
||||||
*/
|
*/
|
||||||
public ChangesetPagingResult getOutgoingChangesets(
|
public ChangesetPagingResult getOutgoingChangesets(
|
||||||
Repository remoteRepository)
|
Repository remoteRepository) throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
Subject subject = SecurityUtils.getSubject();
|
Subject subject = SecurityUtils.getSubject();
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ package sonia.scm.repository.spi;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.repository.RepositoryException;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -50,7 +55,11 @@ public interface IncomingCommand
|
|||||||
* @param request
|
* @param request
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
public ChangesetPagingResult getIncomingChangesets(
|
public ChangesetPagingResult getIncomingChangesets(
|
||||||
IncomingCommandRequest request);
|
IncomingCommandRequest request)
|
||||||
|
throws IOException, RepositoryException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ package sonia.scm.repository.spi;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.repository.RepositoryException;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -50,7 +55,11 @@ public interface OutgoingCommand
|
|||||||
* @param request
|
* @param request
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
public ChangesetPagingResult getOutgoingChangesets(
|
public ChangesetPagingResult getOutgoingChangesets(
|
||||||
OutgoingCommandRequest request);
|
OutgoingCommandRequest request)
|
||||||
|
throws IOException, RepositoryException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,16 +33,20 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.aragost.javahg.commands.ExecutionException;
|
||||||
|
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.RepositoryException;
|
||||||
import sonia.scm.repository.spi.javahg.HgIncomingChangesetCommand;
|
import sonia.scm.repository.spi.javahg.HgIncomingChangesetCommand;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +57,11 @@ public class HgIncomingCommand extends AbstractCommand
|
|||||||
implements IncomingCommand
|
implements IncomingCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private static final int NO_INCOMING_CHANGESETS = 1;
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
@@ -77,10 +86,13 @@ public class HgIncomingCommand extends AbstractCommand
|
|||||||
* @param request
|
* @param request
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
*
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ChangesetPagingResult getIncomingChangesets(
|
public ChangesetPagingResult getIncomingChangesets(
|
||||||
IncomingCommandRequest request)
|
IncomingCommandRequest request)
|
||||||
|
throws RepositoryException
|
||||||
{
|
{
|
||||||
File remoteRepository = handler.getDirectory(request.getRemoteRepository());
|
File remoteRepository = handler.getDirectory(request.getRemoteRepository());
|
||||||
|
|
||||||
@@ -88,8 +100,25 @@ public class HgIncomingCommand extends AbstractCommand
|
|||||||
|
|
||||||
// TODO implement paging
|
// TODO implement paging
|
||||||
|
|
||||||
List<Changeset> changesets =
|
List<Changeset> changesets;
|
||||||
on(repository).execute(remoteRepository.getAbsolutePath());
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
changesets = on(repository).execute(remoteRepository.getAbsolutePath());
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ExecutionException ex)
|
||||||
|
{
|
||||||
|
if (ex.getCommand().getReturnCode() == NO_INCOMING_CHANGESETS)
|
||||||
|
{
|
||||||
|
changesets = Collections.EMPTY_LIST;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new RepositoryException("could not execute incoming command", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new ChangesetPagingResult(changesets.size(), changesets);
|
return new ChangesetPagingResult(changesets.size(), changesets);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.aragost.javahg.Changeset;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
|
import sonia.scm.repository.RepositoryException;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -57,9 +58,11 @@ public class HgIncomingCommandTest extends IncomingOutgoingTestBase
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetIncomingChangesets() throws IOException
|
public void testGetIncomingChangesets()
|
||||||
|
throws IOException, RepositoryException
|
||||||
{
|
{
|
||||||
writeNewFile(outgoing, outgoingDirectory, "a.txt", "Content of file a.txt");
|
writeNewFile(outgoing, outgoingDirectory, "a.txt", "Content of file a.txt");
|
||||||
writeNewFile(outgoing, outgoingDirectory, "b.txt", "Content of file b.txt");
|
writeNewFile(outgoing, outgoingDirectory, "b.txt", "Content of file b.txt");
|
||||||
@@ -84,6 +87,56 @@ public class HgIncomingCommandTest extends IncomingOutgoingTestBase
|
|||||||
assertChangesetsEqual(c2, cpr.getChangesets().get(1));
|
assertChangesetsEqual(c2, cpr.getChangesets().get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws RepositoryException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetIncomingChangesetsWithEmptyRepository()
|
||||||
|
throws RepositoryException
|
||||||
|
{
|
||||||
|
HgIncomingCommand cmd = createIncomingCommand();
|
||||||
|
IncomingCommandRequest request = new IncomingCommandRequest();
|
||||||
|
|
||||||
|
request.setRemoteRepository(outgoingRepository);
|
||||||
|
|
||||||
|
ChangesetPagingResult cpr = cmd.getIncomingChangesets(request);
|
||||||
|
|
||||||
|
assertNotNull(cpr);
|
||||||
|
assertEquals(0, cpr.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
|
*/
|
||||||
|
@Test(expected = RepositoryException.class)
|
||||||
|
public void testGetIncomingChangesetsWithUnrelatedRepository()
|
||||||
|
throws IOException, RepositoryException
|
||||||
|
{
|
||||||
|
writeNewFile(outgoing, outgoingDirectory, "a.txt", "Content of file a.txt");
|
||||||
|
writeNewFile(outgoing, outgoingDirectory, "b.txt", "Content of file b.txt");
|
||||||
|
|
||||||
|
commit(outgoing, "added a and b");
|
||||||
|
|
||||||
|
writeNewFile(incoming, incomingDirectory, "c.txt", "Content of file c.txt");
|
||||||
|
writeNewFile(incoming, incomingDirectory, "d.txt", "Content of file d.txt");
|
||||||
|
|
||||||
|
commit(incoming, "added c and d");
|
||||||
|
|
||||||
|
HgIncomingCommand cmd = createIncomingCommand();
|
||||||
|
IncomingCommandRequest request = new IncomingCommandRequest();
|
||||||
|
|
||||||
|
request.setRemoteRepository(outgoingRepository);
|
||||||
|
|
||||||
|
cmd.getIncomingChangesets(request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user