mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
implement recursive option for subversion browse command
This commit is contained in:
@@ -35,6 +35,8 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -57,7 +59,6 @@ import sonia.scm.util.Util;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -126,23 +127,22 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
Collection<SVNDirEntry> entries =
|
Collection<SVNDirEntry> entries =
|
||||||
svnRepository.getDir(Util.nonNull(path), revisionNumber, null,
|
svnRepository.getDir(Util.nonNull(path), revisionNumber, null,
|
||||||
(Collection) null);
|
(Collection) null);
|
||||||
List<FileObject> children = new ArrayList<FileObject>();
|
List<FileObject> children = Lists.newArrayList();
|
||||||
String basePath = Util.EMPTY_STRING;
|
String basePath = createBasePath(path);
|
||||||
|
|
||||||
if (Util.isNotEmpty(path))
|
if (request.isRecursive())
|
||||||
{
|
{
|
||||||
basePath = path;
|
browseRecursive(svnRepository, revisionNumber, request, children,
|
||||||
|
entries, basePath);
|
||||||
if (!basePath.endsWith("/"))
|
|
||||||
{
|
|
||||||
basePath = basePath.concat("/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
for (SVNDirEntry entry : entries)
|
|
||||||
{
|
{
|
||||||
children.add(createFileObject(request, svnRepository, revisionNumber,
|
for (SVNDirEntry entry : entries)
|
||||||
entry, basePath));
|
{
|
||||||
|
children.add(createFileObject(request, svnRepository, revisionNumber,
|
||||||
|
entry, basePath));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = new BrowserResult();
|
result = new BrowserResult();
|
||||||
@@ -159,6 +159,68 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
|||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param svnRepository
|
||||||
|
* @param revisionNumber
|
||||||
|
* @param request
|
||||||
|
* @param children
|
||||||
|
* @param entries
|
||||||
|
* @param basePath
|
||||||
|
*
|
||||||
|
* @throws SVNException
|
||||||
|
*/
|
||||||
|
private void browseRecursive(SVNRepository svnRepository,
|
||||||
|
long revisionNumber, BrowseCommandRequest request,
|
||||||
|
List<FileObject> children, Collection<SVNDirEntry> entries, String basePath)
|
||||||
|
throws SVNException
|
||||||
|
{
|
||||||
|
for (SVNDirEntry entry : entries)
|
||||||
|
{
|
||||||
|
FileObject fo = createFileObject(request, svnRepository, revisionNumber,
|
||||||
|
entry, basePath);
|
||||||
|
|
||||||
|
children.add(fo);
|
||||||
|
|
||||||
|
if (fo.isDirectory())
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
String basePath = Util.EMPTY_STRING;
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(path))
|
||||||
|
{
|
||||||
|
basePath = path;
|
||||||
|
|
||||||
|
if (!basePath.endsWith("/"))
|
||||||
|
{
|
||||||
|
basePath = basePath.concat("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return basePath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -158,6 +158,26 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
|||||||
assertNull(a.getDescription());
|
assertNull(a.getDescription());
|
||||||
assertNull(a.getLastModified());
|
assertNull(a.getLastModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRecursive() throws IOException, RepositoryException
|
||||||
|
{
|
||||||
|
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||||
|
request.setRecursive(true);
|
||||||
|
BrowserResult result = createCommand().getBrowserResult(request);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
|
List<FileObject> foList = result.getFiles();
|
||||||
|
|
||||||
|
assertNotNull(foList);
|
||||||
|
assertFalse(foList.isEmpty());
|
||||||
|
assertEquals(4, foList.size());
|
||||||
|
|
||||||
|
for ( FileObject fo : foList ){
|
||||||
|
System.out.println(fo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
|
|||||||
Reference in New Issue
Block a user