mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-22 00:09:47 +01:00
merge
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -79,11 +80,11 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws RevisionNotFoundException {
|
||||
String path = request.getPath();
|
||||
String path = Strings.nullToEmpty(request.getPath());
|
||||
long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision());
|
||||
|
||||
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;
|
||||
@@ -91,34 +92,21 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
try
|
||||
{
|
||||
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) {
|
||||
revisionNumber = svnRepository.getLatestRevision();
|
||||
}
|
||||
|
||||
result = new BrowserResult();
|
||||
result.setRevision(String.valueOf(revisionNumber));
|
||||
result.setFiles(children);
|
||||
SVNDirEntry rootEntry = svnRepository.info(path, revisionNumber);
|
||||
FileObject root = createFileObject(request, svnRepository, revisionNumber, rootEntry, path);
|
||||
root.setPath(path);
|
||||
|
||||
if (root.isDirectory()) {
|
||||
traverse(svnRepository, revisionNumber, request, root, createBasePath(path));
|
||||
}
|
||||
|
||||
|
||||
result = new BrowserResult(String.valueOf(revisionNumber), root);
|
||||
}
|
||||
catch (SVNException ex)
|
||||
{
|
||||
@@ -130,52 +118,24 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param svnRepository
|
||||
* @param revisionNumber
|
||||
* @param request
|
||||
* @param children
|
||||
* @param entries
|
||||
* @param basePath
|
||||
*
|
||||
* @throws SVNException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void browseRecursive(SVNRepository svnRepository,
|
||||
long revisionNumber, BrowseCommandRequest request,
|
||||
List<FileObject> children, Collection<SVNDirEntry> entries, String basePath)
|
||||
private void traverse(SVNRepository svnRepository, long revisionNumber, BrowseCommandRequest request,
|
||||
FileObject parent, String basePath)
|
||||
throws SVNException
|
||||
{
|
||||
Collection<SVNDirEntry> entries = svnRepository.getDir(parent.getPath(), revisionNumber, null, (Collection) null);
|
||||
for (SVNDirEntry entry : entries)
|
||||
{
|
||||
FileObject fo = createFileObject(request, svnRepository, revisionNumber,
|
||||
entry, basePath);
|
||||
FileObject child = createFileObject(request, svnRepository, revisionNumber, entry, basePath);
|
||||
|
||||
children.add(fo);
|
||||
parent.addChild(child);
|
||||
|
||||
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()));
|
||||
if (child.isDirectory() && request.isRecursive()) {
|
||||
traverse(svnRepository, revisionNumber, request, child, createBasePath(child.getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String createBasePath(String path)
|
||||
{
|
||||
String basePath = Util.EMPTY_STRING;
|
||||
@@ -193,20 +153,6 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
return basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param repository
|
||||
* @param revision
|
||||
* @param entry
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private FileObject createFileObject(BrowseCommandRequest request,
|
||||
SVNRepository repository, long revision, SVNDirEntry entry, String path)
|
||||
{
|
||||
@@ -237,15 +183,6 @@ public class SvnBrowseCommand extends AbstractSvnCommand
|
||||
return fileObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param revision
|
||||
* @param entry
|
||||
* @param fileObject
|
||||
*/
|
||||
private void fetchExternalsProperty(SVNRepository repository, long revision,
|
||||
SVNDirEntry entry, FileObject fileObject)
|
||||
{
|
||||
|
||||
@@ -2,22 +2,24 @@
|
||||
import React from "react";
|
||||
import { repositories } from "@scm-manager/ui-components";
|
||||
import type { Repository } from "@scm-manager/ui-types";
|
||||
import { translate } from "react-i18next";
|
||||
|
||||
type Props = {
|
||||
repository: Repository
|
||||
repository: Repository,
|
||||
t: string => string
|
||||
}
|
||||
|
||||
class ProtocolInformation extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const { repository } = this.props;
|
||||
const { repository, t } = this.props;
|
||||
const href = repositories.getProtocolLinkByType(repository, "http");
|
||||
if (!href) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<h4>Checkout the repository</h4>
|
||||
<h4>{t("scm-svn-plugin.information.checkout")}</h4>
|
||||
<pre>
|
||||
<code>svn checkout {href}</code>
|
||||
</pre>
|
||||
@@ -27,4 +29,4 @@ class ProtocolInformation extends React.Component<Props> {
|
||||
|
||||
}
|
||||
|
||||
export default ProtocolInformation;
|
||||
export default translate("plugins")(ProtocolInformation);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"scm-svn-plugin": {
|
||||
"information": {
|
||||
"checkout" : "Repository auschecken"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"scm-svn-plugin": {
|
||||
"information": {
|
||||
"checkout" : "Checkout repository"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,15 +33,13 @@
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
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;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -49,8 +47,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -58,9 +54,19 @@ import static org.junit.Assert.assertTrue;
|
||||
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
|
||||
public void testBrowse() throws RevisionNotFoundException {
|
||||
List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
|
||||
Collection<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
|
||||
|
||||
FileObject a = getFileObject(foList, "a.txt");
|
||||
FileObject c = getFileObject(foList, "c");
|
||||
@@ -92,7 +98,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
|
||||
assertNotNull(result);
|
||||
|
||||
List<FileObject> foList = result.getFiles();
|
||||
Collection<FileObject> foList = result.getFile().getChildren();
|
||||
|
||||
assertNotNull(foList);
|
||||
assertFalse(foList.isEmpty());
|
||||
@@ -135,7 +141,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
|
||||
request.setDisableLastCommit(true);
|
||||
|
||||
List<FileObject> foList = getRootFromTip(request);
|
||||
Collection<FileObject> foList = getRootFromTip(request);
|
||||
|
||||
FileObject a = getFileObject(foList, "a.txt");
|
||||
|
||||
@@ -151,15 +157,16 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
|
||||
assertNotNull(result);
|
||||
|
||||
List<FileObject> foList = result.getFiles();
|
||||
Collection<FileObject> foList = result.getFile().getChildren();
|
||||
|
||||
assertNotNull(foList);
|
||||
assertFalse(foList.isEmpty());
|
||||
assertEquals(4, foList.size());
|
||||
|
||||
for ( FileObject fo : foList ){
|
||||
System.out.println(fo);
|
||||
}
|
||||
assertEquals(2, foList.size());
|
||||
|
||||
FileObject c = getFileObject(foList, "c");
|
||||
assertEquals("c", c.getName());
|
||||
assertTrue(c.isDirectory());
|
||||
assertEquals(2, c.getChildren().size());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,31 +191,20 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private FileObject getFileObject(List<FileObject> foList, String name)
|
||||
private FileObject getFileObject(Collection<FileObject> foList, String name)
|
||||
{
|
||||
FileObject a = null;
|
||||
|
||||
for (FileObject f : foList)
|
||||
{
|
||||
if (name.equals(f.getName()))
|
||||
{
|
||||
a = f;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(a);
|
||||
|
||||
return a;
|
||||
return foList.stream()
|
||||
.filter(f -> name.equals(f.getName()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("file " + name + " not found"));
|
||||
}
|
||||
|
||||
private List<FileObject> getRootFromTip(BrowseCommandRequest request) throws RevisionNotFoundException {
|
||||
private Collection<FileObject> getRootFromTip(BrowseCommandRequest request) throws RevisionNotFoundException {
|
||||
BrowserResult result = createCommand().getBrowserResult(request);
|
||||
|
||||
assertNotNull(result);
|
||||
|
||||
List<FileObject> foList = result.getFiles();
|
||||
Collection<FileObject> foList = result.getFile().getChildren();
|
||||
|
||||
assertNotNull(foList);
|
||||
assertFalse(foList.isEmpty());
|
||||
|
||||
Reference in New Issue
Block a user