mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-21 15:59:48 +01:00
Introduce default error object with context for not found exceptions
This commit is contained in:
@@ -49,6 +49,7 @@ import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil;
|
||||
import org.tmatesoft.svn.core.internal.util.SVNXMLUtil;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -102,7 +103,7 @@ public final class SvnUtil
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
public static long parseRevision(String v) throws RevisionNotFoundException {
|
||||
public static long parseRevision(String v, Repository repository) {
|
||||
long result = -1l;
|
||||
|
||||
if (!Strings.isNullOrEmpty(v))
|
||||
@@ -113,7 +114,7 @@ public final class SvnUtil
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
throw new RevisionNotFoundException(v);
|
||||
throw NotFoundException.notFound("Revision", v).in(repository).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +340,7 @@ public final class SvnUtil
|
||||
}
|
||||
}
|
||||
|
||||
public static long getRevisionNumber(String revision) throws RevisionNotFoundException {
|
||||
public static long getRevisionNumber(String revision, Repository repository) {
|
||||
// REVIEW Bei SVN wird ohne Revision die -1 genommen, was zu einem Fehler führt
|
||||
long revisionNumber = -1;
|
||||
|
||||
@@ -351,7 +352,7 @@ public final class SvnUtil
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
throw new RevisionNotFoundException(revision);
|
||||
throw NotFoundException.notFound("Revision", revision).in(repository).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@ import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.FileObject;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.repository.SubRepository;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
import sonia.scm.util.Util;
|
||||
@@ -78,9 +77,9 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws RevisionNotFoundException {
|
||||
public BrowserResult getBrowserResult(BrowseCommandRequest request) {
|
||||
String path = request.getPath();
|
||||
long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision());
|
||||
long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision(), repository);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("browser repository {} in path {} at revision {}", repository.getName(), path, revisionNumber);
|
||||
|
||||
@@ -43,10 +43,9 @@ import org.tmatesoft.svn.core.SVNProperties;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
||||
import org.tmatesoft.svn.core.wc.admin.SVNLookClient;
|
||||
import sonia.scm.NotFoundException;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.PathNotFoundException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -79,7 +78,7 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void getCatResult(CatCommandRequest request, OutputStream output) throws RevisionNotFoundException, PathNotFoundException {
|
||||
public void getCatResult(CatCommandRequest request, OutputStream output) {
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("try to get content for {}", request);
|
||||
@@ -96,14 +95,14 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand
|
||||
else
|
||||
{
|
||||
|
||||
long revisionNumber = SvnUtil.getRevisionNumber(revision);
|
||||
long revisionNumber = SvnUtil.getRevisionNumber(revision, repository);
|
||||
|
||||
getCatFromRevision(request, output, revisionNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getCatResultStream(CatCommandRequest request) throws RevisionNotFoundException, PathNotFoundException {
|
||||
public InputStream getCatResultStream(CatCommandRequest request) {
|
||||
// There seems to be no method creating an input stream as a result, so
|
||||
// we have no other possibility then to copy the content into a buffer and
|
||||
// stream it from there.
|
||||
@@ -112,7 +111,7 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand
|
||||
return new ByteArrayInputStream(output.toByteArray());
|
||||
}
|
||||
|
||||
private void getCatFromRevision(CatCommandRequest request, OutputStream output, long revision) throws PathNotFoundException, RevisionNotFoundException {
|
||||
private void getCatFromRevision(CatCommandRequest request, OutputStream output, long revision) {
|
||||
logger.debug("try to read content from revision {} and path {}", revision,
|
||||
request.getPath());
|
||||
|
||||
@@ -129,12 +128,12 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSvnException(CatCommandRequest request, SVNException ex) throws PathNotFoundException, RevisionNotFoundException {
|
||||
private void handleSvnException(CatCommandRequest request, SVNException ex) {
|
||||
int svnErrorCode = ex.getErrorMessage().getErrorCode().getCode();
|
||||
if (SVNErrorCode.FS_NOT_FOUND.getCode() == svnErrorCode) {
|
||||
throw new PathNotFoundException(request.getPath());
|
||||
throw NotFoundException.notFound("Path", request.getPath()).in("Revision", request.getRevision()).in(repository).build();
|
||||
} else if (SVNErrorCode.FS_NO_SUCH_REVISION.getCode() == svnErrorCode) {
|
||||
throw new RevisionNotFoundException(request.getRevision());
|
||||
throw NotFoundException.notFound("Revision", request.getRevision()).in(repository).build();
|
||||
} else {
|
||||
throw new InternalRepositoryException("could not get content from revision", ex);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.tmatesoft.svn.core.wc.SVNDiffClient;
|
||||
import org.tmatesoft.svn.core.wc.SVNRevision;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
import sonia.scm.repository.api.DiffFormat;
|
||||
import sonia.scm.util.Util;
|
||||
@@ -76,7 +75,7 @@ public class SvnDiffCommand extends AbstractSvnCommand implements DiffCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDiffResult(DiffCommandRequest request, OutputStream output) throws RevisionNotFoundException {
|
||||
public void getDiffResult(DiffCommandRequest request, OutputStream output) {
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("create diff for {}", request);
|
||||
@@ -111,7 +110,7 @@ public class SvnDiffCommand extends AbstractSvnCommand implements DiffCommand
|
||||
diffGenerator.setDiffDeleted(true);
|
||||
diffClient.setDiffGenerator(diffGenerator);
|
||||
|
||||
long currentRev = SvnUtil.getRevisionNumber(request.getRevision());
|
||||
long currentRev = SvnUtil.getRevisionNumber(request.getRevision(), repository);
|
||||
|
||||
diffClient.setGitDiffFormat(request.getFormat() == DiffFormat.GIT);
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@ import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
@@ -76,7 +75,7 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Changeset getChangeset(String revision) throws RevisionNotFoundException {
|
||||
public Changeset getChangeset(String revision) {
|
||||
Changeset changeset = null;
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
@@ -86,7 +85,7 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand
|
||||
|
||||
try
|
||||
{
|
||||
long revisioNumber = parseRevision(revision);
|
||||
long revisioNumber = parseRevision(revision, repository);
|
||||
SVNRepository repo = open();
|
||||
Collection<SVNLogEntry> entries = repo.log(null, null, revisioNumber,
|
||||
revisioNumber, true, true);
|
||||
@@ -106,7 +105,7 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChangesetPagingResult getChangesets(LogCommandRequest request) throws RevisionNotFoundException {
|
||||
public ChangesetPagingResult getChangesets(LogCommandRequest request) {
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("fetch changesets for {}", request);
|
||||
@@ -115,8 +114,8 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand
|
||||
ChangesetPagingResult changesets = null;
|
||||
int start = request.getPagingStart();
|
||||
int limit = request.getPagingLimit();
|
||||
long startRevision = parseRevision(request.getStartChangeset());
|
||||
long endRevision = parseRevision(request.getEndChangeset());
|
||||
long startRevision = parseRevision(request.getStartChangeset(), repository);
|
||||
long endRevision = parseRevision(request.getEndChangeset(), repository);
|
||||
String[] pathArray = null;
|
||||
|
||||
if (!Strings.isNullOrEmpty(request.getPath()))
|
||||
|
||||
@@ -7,11 +7,9 @@ import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
@Slf4j
|
||||
@@ -24,11 +22,11 @@ public class SvnModificationsCommand extends AbstractSvnCommand implements Modif
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Modifications getModifications(String revision) throws IOException, RevisionNotFoundException {
|
||||
public Modifications getModifications(String revision) {
|
||||
Modifications modifications = null;
|
||||
log.debug("get modifications {}", revision);
|
||||
try {
|
||||
long revisionNumber = SvnUtil.parseRevision(revision);
|
||||
long revisionNumber = SvnUtil.parseRevision(revision, repository);
|
||||
SVNRepository repo = open();
|
||||
Collection<SVNLogEntry> entries = repo.log(null, null, revisionNumber,
|
||||
revisionNumber, true, true);
|
||||
@@ -42,7 +40,7 @@ public class SvnModificationsCommand extends AbstractSvnCommand implements Modif
|
||||
}
|
||||
|
||||
@Override
|
||||
public Modifications getModifications(ModificationsCommandRequest request) throws IOException, RevisionNotFoundException {
|
||||
public Modifications getModifications(ModificationsCommandRequest request) {
|
||||
return getModifications(request.getRevision());
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ package sonia.scm.repository.spi;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.FileObject;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -59,7 +58,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testBrowse() throws RevisionNotFoundException {
|
||||
public void testBrowse() {
|
||||
List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
|
||||
|
||||
FileObject a = getFileObject(foList, "a.txt");
|
||||
@@ -83,7 +82,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void testBrowseSubDirectory() throws RevisionNotFoundException {
|
||||
public void testBrowseSubDirectory() {
|
||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||
|
||||
request.setPath("c");
|
||||
@@ -130,7 +129,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableLastCommit() throws RevisionNotFoundException {
|
||||
public void testDisableLastCommit() {
|
||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||
|
||||
request.setDisableLastCommit(true);
|
||||
@@ -144,7 +143,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursive() throws RevisionNotFoundException {
|
||||
public void testRecursive() {
|
||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||
request.setRecursive(true);
|
||||
BrowserResult result = createCommand().getBrowserResult(request);
|
||||
@@ -203,7 +202,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
return a;
|
||||
}
|
||||
|
||||
private List<FileObject> getRootFromTip(BrowseCommandRequest request) throws RevisionNotFoundException {
|
||||
private List<FileObject> getRootFromTip(BrowseCommandRequest request) {
|
||||
BrowserResult result = createCommand().getBrowserResult(request);
|
||||
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -32,9 +32,12 @@
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.PathNotFoundException;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import sonia.scm.NotFoundException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -46,8 +49,11 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SvnCatCommandTest extends AbstractSvnCommandTestBase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testCat() throws PathNotFoundException, RevisionNotFoundException {
|
||||
public void testCat() {
|
||||
CatCommandRequest request = new CatCommandRequest();
|
||||
|
||||
request.setPath("a.txt");
|
||||
@@ -56,35 +62,59 @@ public class SvnCatCommandTest extends AbstractSvnCommandTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleCat() throws PathNotFoundException, RevisionNotFoundException {
|
||||
public void testSimpleCat() {
|
||||
CatCommandRequest request = new CatCommandRequest();
|
||||
|
||||
request.setPath("c/d.txt");
|
||||
assertEquals("d", execute(request));
|
||||
}
|
||||
|
||||
@Test(expected = PathNotFoundException.class)
|
||||
public void testUnknownFile() throws PathNotFoundException, RevisionNotFoundException {
|
||||
@Test
|
||||
public void testUnknownFile() {
|
||||
CatCommandRequest request = new CatCommandRequest();
|
||||
|
||||
request.setPath("unknown");
|
||||
request.setRevision("1");
|
||||
|
||||
execute(request);
|
||||
}
|
||||
expectedException.expect(new BaseMatcher<Object>() {
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("expected NotFoundException for path");
|
||||
}
|
||||
|
||||
@Test(expected = RevisionNotFoundException.class)
|
||||
public void testUnknownRevision() throws PathNotFoundException, RevisionNotFoundException {
|
||||
CatCommandRequest request = new CatCommandRequest();
|
||||
|
||||
request.setPath("a.txt");
|
||||
request.setRevision("42");
|
||||
@Override
|
||||
public boolean matches(Object item) {
|
||||
return "Path".equals(((NotFoundException)item).getContext().get(0).getType());
|
||||
}
|
||||
});
|
||||
|
||||
execute(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleStream() throws IOException, PathNotFoundException, RevisionNotFoundException {
|
||||
public void testUnknownRevision() {
|
||||
CatCommandRequest request = new CatCommandRequest();
|
||||
|
||||
request.setPath("a.txt");
|
||||
request.setRevision("42");
|
||||
|
||||
expectedException.expect(new BaseMatcher<Object>() {
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("expected NotFoundException for revision");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object item) {
|
||||
return "Revision".equals(((NotFoundException)item).getContext().get(0).getType());
|
||||
}
|
||||
});
|
||||
|
||||
execute(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleStream() throws IOException {
|
||||
CatCommandRequest request = new CatCommandRequest();
|
||||
request.setPath("a.txt");
|
||||
request.setRevision("1");
|
||||
@@ -98,7 +128,7 @@ public class SvnCatCommandTest extends AbstractSvnCommandTestBase {
|
||||
catResultStream.close();
|
||||
}
|
||||
|
||||
private String execute(CatCommandRequest request) throws PathNotFoundException, RevisionNotFoundException {
|
||||
private String execute(CatCommandRequest request) {
|
||||
String content = null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.junit.Test;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -57,7 +56,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testGetAll() throws RevisionNotFoundException {
|
||||
public void testGetAll() {
|
||||
ChangesetPagingResult result =
|
||||
createCommand().getChangesets(new LogCommandRequest());
|
||||
|
||||
@@ -67,7 +66,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllByPath() throws RevisionNotFoundException {
|
||||
public void testGetAllByPath() {
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
request.setPath("a.txt");
|
||||
@@ -83,7 +82,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllWithLimit() throws RevisionNotFoundException {
|
||||
public void testGetAllWithLimit() {
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
request.setPagingLimit(2);
|
||||
@@ -106,7 +105,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllWithPaging() throws RevisionNotFoundException {
|
||||
public void testGetAllWithPaging() {
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
request.setPagingStart(1);
|
||||
@@ -130,7 +129,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommit() throws RevisionNotFoundException, IOException {
|
||||
public void testGetCommit() {
|
||||
Changeset c = createCommand().getChangeset("3");
|
||||
|
||||
assertNotNull(c);
|
||||
@@ -151,7 +150,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRange() throws RevisionNotFoundException {
|
||||
public void testGetRange() {
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
request.setStartChangeset("2");
|
||||
|
||||
Reference in New Issue
Block a user