mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-14 20:02:41 +02:00
implemented new browse api for svn
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -79,11 +80,11 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws RevisionNotFoundException {
|
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws RevisionNotFoundException {
|
||||||
String path = request.getPath();
|
String path = Strings.nullToEmpty(request.getPath());
|
||||||
long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision());
|
long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision());
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("browser repository {} in path {} at revision {}", repository.getName(), path, revisionNumber);
|
logger.debug("browser repository {} in path \"{}\" at revision {}", repository.getName(), path, revisionNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserResult result = null;
|
BrowserResult result = null;
|
||||||
@@ -91,34 +92,21 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
SVNRepository svnRepository = open();
|
SVNRepository svnRepository = open();
|
||||||
Collection<SVNDirEntry> entries =
|
|
||||||
svnRepository.getDir(Util.nonNull(path), revisionNumber, null,
|
|
||||||
(Collection) null);
|
|
||||||
List<FileObject> children = Lists.newArrayList();
|
|
||||||
String basePath = createBasePath(path);
|
|
||||||
|
|
||||||
if (request.isRecursive())
|
|
||||||
{
|
|
||||||
browseRecursive(svnRepository, revisionNumber, request, children,
|
|
||||||
entries, basePath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (SVNDirEntry entry : entries)
|
|
||||||
{
|
|
||||||
children.add(createFileObject(request, svnRepository, revisionNumber,
|
|
||||||
entry, basePath));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (revisionNumber == -1) {
|
if (revisionNumber == -1) {
|
||||||
revisionNumber = svnRepository.getLatestRevision();
|
revisionNumber = svnRepository.getLatestRevision();
|
||||||
}
|
}
|
||||||
|
|
||||||
result = new BrowserResult();
|
SVNDirEntry rootEntry = svnRepository.info(path, revisionNumber);
|
||||||
result.setRevision(String.valueOf(revisionNumber));
|
FileObject root = createFileObject(request, svnRepository, revisionNumber, rootEntry, path);
|
||||||
result.setFiles(children);
|
root.setPath(path);
|
||||||
|
|
||||||
|
if (root.isDirectory()) {
|
||||||
|
traverse(svnRepository, revisionNumber, request, root, createBasePath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
result = new BrowserResult(String.valueOf(revisionNumber), root);
|
||||||
}
|
}
|
||||||
catch (SVNException ex)
|
catch (SVNException ex)
|
||||||
{
|
{
|
||||||
@@ -130,52 +118,24 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param svnRepository
|
|
||||||
* @param revisionNumber
|
|
||||||
* @param request
|
|
||||||
* @param children
|
|
||||||
* @param entries
|
|
||||||
* @param basePath
|
|
||||||
*
|
|
||||||
* @throws SVNException
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void browseRecursive(SVNRepository svnRepository,
|
private void traverse(SVNRepository svnRepository, long revisionNumber, BrowseCommandRequest request,
|
||||||
long revisionNumber, BrowseCommandRequest request,
|
FileObject parent, String basePath)
|
||||||
List<FileObject> children, Collection<SVNDirEntry> entries, String basePath)
|
|
||||||
throws SVNException
|
throws SVNException
|
||||||
{
|
{
|
||||||
|
Collection<SVNDirEntry> entries = svnRepository.getDir(parent.getPath(), revisionNumber, null, (Collection) null);
|
||||||
for (SVNDirEntry entry : entries)
|
for (SVNDirEntry entry : entries)
|
||||||
{
|
{
|
||||||
FileObject fo = createFileObject(request, svnRepository, revisionNumber,
|
FileObject child = createFileObject(request, svnRepository, revisionNumber, entry, basePath);
|
||||||
entry, basePath);
|
|
||||||
|
|
||||||
children.add(fo);
|
parent.addChild(child);
|
||||||
|
|
||||||
if (fo.isDirectory())
|
if (child.isDirectory() && request.isRecursive()) {
|
||||||
{
|
traverse(svnRepository, revisionNumber, request, child, createBasePath(child.getPath()));
|
||||||
Collection<SVNDirEntry> subEntries =
|
|
||||||
svnRepository.getDir(Util.nonNull(fo.getPath()), revisionNumber,
|
|
||||||
null, (Collection) null);
|
|
||||||
|
|
||||||
browseRecursive(svnRepository, revisionNumber, request, children,
|
|
||||||
subEntries, createBasePath(fo.getPath()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param path
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String createBasePath(String path)
|
private String createBasePath(String path)
|
||||||
{
|
{
|
||||||
String basePath = Util.EMPTY_STRING;
|
String basePath = Util.EMPTY_STRING;
|
||||||
@@ -193,20 +153,6 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
return basePath;
|
return basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
* @param repository
|
|
||||||
* @param revision
|
|
||||||
* @param entry
|
|
||||||
* @param path
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private FileObject createFileObject(BrowseCommandRequest request,
|
private FileObject createFileObject(BrowseCommandRequest request,
|
||||||
SVNRepository repository, long revision, SVNDirEntry entry, String path)
|
SVNRepository repository, long revision, SVNDirEntry entry, String path)
|
||||||
{
|
{
|
||||||
@@ -237,15 +183,6 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
return fileObject;
|
return fileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repository
|
|
||||||
* @param revision
|
|
||||||
* @param entry
|
|
||||||
* @param fileObject
|
|
||||||
*/
|
|
||||||
private void fetchExternalsProperty(SVNRepository repository, long revision,
|
private void fetchExternalsProperty(SVNRepository repository, long revision,
|
||||||
SVNDirEntry entry, FileObject fileObject)
|
SVNDirEntry entry, FileObject fileObject)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,16 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBrowseWithFilePath() throws RevisionNotFoundException {
|
||||||
|
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||||
|
request.setPath("a.txt");
|
||||||
|
FileObject file = createCommand().getBrowserResult(request).getFile();
|
||||||
|
assertEquals("a.txt", file.getName());
|
||||||
|
assertFalse(file.isDirectory());
|
||||||
|
assertTrue(file.getChildren().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBrowse() throws RevisionNotFoundException {
|
public void testBrowse() throws RevisionNotFoundException {
|
||||||
List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
|
List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
|
||||||
@@ -92,7 +102,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
|
|
||||||
List<FileObject> foList = result.getFiles();
|
List<FileObject> foList = result.getFile().getChildren();
|
||||||
|
|
||||||
assertNotNull(foList);
|
assertNotNull(foList);
|
||||||
assertFalse(foList.isEmpty());
|
assertFalse(foList.isEmpty());
|
||||||
@@ -151,15 +161,16 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
|
|
||||||
List<FileObject> foList = result.getFiles();
|
List<FileObject> foList = result.getFile().getChildren();
|
||||||
|
|
||||||
assertNotNull(foList);
|
assertNotNull(foList);
|
||||||
assertFalse(foList.isEmpty());
|
assertFalse(foList.isEmpty());
|
||||||
assertEquals(4, foList.size());
|
assertEquals(2, foList.size());
|
||||||
|
|
||||||
for ( FileObject fo : foList ){
|
FileObject c = getFileObject(foList, "c");
|
||||||
System.out.println(fo);
|
assertEquals("c", c.getName());
|
||||||
}
|
assertTrue(c.isDirectory());
|
||||||
|
assertEquals(2, c.getChildren().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,7 +219,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
|
|
||||||
List<FileObject> foList = result.getFiles();
|
List<FileObject> foList = result.getFile().getChildren();
|
||||||
|
|
||||||
assertNotNull(foList);
|
assertNotNull(foList);
|
||||||
assertFalse(foList.isEmpty());
|
assertFalse(foList.isEmpty());
|
||||||
|
|||||||
Reference in New Issue
Block a user