mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 18:46:07 +01:00 
			
		
		
		
	Merge with 2.0.0-m3
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; | ||||
| @@ -78,11 +79,11 @@ public class SvnBrowseCommand extends AbstractSvnCommand | ||||
|   @Override | ||||
|   @SuppressWarnings("unchecked") | ||||
|   public BrowserResult getBrowserResult(BrowseCommandRequest request) { | ||||
|     String path = request.getPath(); | ||||
|     String path = Strings.nullToEmpty(request.getPath()); | ||||
|     long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision(), repository); | ||||
|  | ||||
|     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; | ||||
| @@ -90,34 +91,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) | ||||
|     { | ||||
| @@ -129,52 +117,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; | ||||
| @@ -192,20 +152,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) | ||||
|   { | ||||
| @@ -236,15 +182,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,14 +33,12 @@ | ||||
|  | ||||
| package sonia.scm.repository.spi; | ||||
|  | ||||
| //~--- non-JDK imports -------------------------------------------------------- | ||||
|  | ||||
| import org.junit.Test; | ||||
| import sonia.scm.repository.BrowserResult; | ||||
| import sonia.scm.repository.FileObject; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
| import java.util.Collection; | ||||
|  | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import static org.junit.Assert.assertFalse; | ||||
| @@ -48,8 +46,6 @@ import static org.junit.Assert.assertNotNull; | ||||
| import static org.junit.Assert.assertNull; | ||||
| import static org.junit.Assert.assertTrue; | ||||
|  | ||||
| //~--- JDK imports ------------------------------------------------------------ | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author Sebastian Sdorra | ||||
| @@ -57,9 +53,19 @@ import static org.junit.Assert.assertTrue; | ||||
| public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase | ||||
| { | ||||
|  | ||||
|   @Test | ||||
|   public void testBrowseWithFilePath() { | ||||
|     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() { | ||||
|     List<FileObject> foList = getRootFromTip(new BrowseCommandRequest()); | ||||
|     Collection<FileObject> foList = getRootFromTip(new BrowseCommandRequest()); | ||||
|  | ||||
|     FileObject a = getFileObject(foList, "a.txt"); | ||||
|     FileObject c = getFileObject(foList, "c"); | ||||
| @@ -91,7 +97,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase | ||||
|  | ||||
|     assertNotNull(result); | ||||
|  | ||||
|     List<FileObject> foList = result.getFiles(); | ||||
|     Collection<FileObject> foList = result.getFile().getChildren(); | ||||
|  | ||||
|     assertNotNull(foList); | ||||
|     assertFalse(foList.isEmpty()); | ||||
| @@ -134,7 +140,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"); | ||||
|  | ||||
| @@ -150,15 +156,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()); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @@ -183,31 +190,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) { | ||||
|   private Collection<FileObject> getRootFromTip(BrowseCommandRequest request) { | ||||
|     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