From 90580e902dc0d6d5842ae397f2a45e082b725485 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 7 Oct 2020 16:39:26 +0200 Subject: [PATCH] Fix review finding --- .../scm/repository/spi/SvnBrowseCommand.java | 69 ++++++++----------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBrowseCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBrowseCommand.java index 04d0e73fd7..573184ea1f 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBrowseCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBrowseCommand.java @@ -54,12 +54,10 @@ import static sonia.scm.NotFoundException.notFound; //~--- JDK imports ------------------------------------------------------------ /** - * * @author Sebastian Sdorra */ public class SvnBrowseCommand extends AbstractSvnCommand - implements BrowseCommand -{ + implements BrowseCommand { /** * the logger for SvnBrowseCommand @@ -69,8 +67,7 @@ public class SvnBrowseCommand extends AbstractSvnCommand private int resultCount = 0; - SvnBrowseCommand(SvnContext context) - { + SvnBrowseCommand(SvnContext context) { super(context); } @@ -86,8 +83,7 @@ public class SvnBrowseCommand extends AbstractSvnCommand BrowserResult result = null; - try - { + try { SVNRepository svnRepository = open(); if (revisionNumber == -1) { @@ -104,9 +100,7 @@ public class SvnBrowseCommand extends AbstractSvnCommand result = new BrowserResult(String.valueOf(revisionNumber), root); - } - catch (SVNException ex) - { + } catch (SVNException ex) { if (FS_NO_SUCH_REVISION.equals(ex.getErrorMessage().getErrorCode())) { throw notFound(entity("Revision", Long.toString(revisionNumber)).in(this.repository)); } @@ -120,9 +114,8 @@ public class SvnBrowseCommand extends AbstractSvnCommand @SuppressWarnings("unchecked") private void traverse(SVNRepository svnRepository, long revisionNumber, BrowseCommandRequest request, - FileObject parent, String basePath) - throws SVNException - { + FileObject parent, String basePath) + throws SVNException { List entries = new ArrayList<>(svnRepository.getDir(parent.getPath(), revisionNumber, null, (Collection) null)); sort(entries, entry -> entry.getKind() == SVNNodeKind.DIR, SVNDirEntry::getName); for (Iterator iterator = entries.iterator(); resultCount < request.getLimit() + request.getOffset() && iterator.hasNext(); ) { @@ -146,16 +139,13 @@ public class SvnBrowseCommand extends AbstractSvnCommand } } - private String createBasePath(String path) - { + private String createBasePath(String path) { String basePath = Util.EMPTY_STRING; - if (Util.isNotEmpty(path)) - { + if (Util.isNotEmpty(path)) { basePath = path; - if (!basePath.endsWith("/")) - { + if (!basePath.endsWith("/")) { basePath = basePath.concat("/"); } } @@ -164,8 +154,7 @@ public class SvnBrowseCommand extends AbstractSvnCommand } private FileObject createFileObject(BrowseCommandRequest request, - SVNRepository repository, long revision, SVNDirEntry entry, String path) - { + SVNRepository repository, long revision, SVNDirEntry entry, String path) { if (entry == null) { throw notFound(entity("Path", path).in("Revision", Long.toString(revision)).in(this.repository)); } @@ -175,10 +164,8 @@ public class SvnBrowseCommand extends AbstractSvnCommand fileObject.setPath(path.concat(entry.getRelativePath())); fileObject.setDirectory(entry.getKind() == SVNNodeKind.DIR); - if (!request.isDisableLastCommit()) - { - if (entry.getDate() != null) - { + if (!request.isDisableLastCommit()) { + if (entry.getDate() != null) { fileObject.setCommitDate(entry.getDate().getTime()); } @@ -188,43 +175,41 @@ public class SvnBrowseCommand extends AbstractSvnCommand fileObject.setLength(entry.getSize()); if (!request.isDisableSubRepositoryDetection() && fileObject.isDirectory() - && entry.hasProperties()) - { + && entry.hasProperties()) { fetchExternalsProperty(repository, revision, entry, fileObject); } return fileObject; } + private boolean shouldSetExternal(String external) { + return (external.startsWith("http://") || external.startsWith("https://") || external.startsWith("../") + || external.startsWith("^/") || external.startsWith("/")); + } + private void fetchExternalsProperty(SVNRepository repository, long revision, - SVNDirEntry entry, FileObject fileObject) - { - try - { + SVNDirEntry entry, FileObject fileObject) { + try { SVNProperties properties = new SVNProperties(); repository.getDir(entry.getRelativePath(), revision, properties, (Collection) null); String externals = properties.getStringValue(SVNProperty.EXTERNALS).replaceAll("[\\r\\n]+", ""); String[] externalsArray = externals.split(" "); - for(String external: externalsArray) - { - if(external.startsWith("http://") || external.startsWith("https://") || external.startsWith("../") - || external.startsWith("^/") || external.startsWith("/")) - { + for (String external : externalsArray) { + if (shouldSetExternal(external)) { externals = external; } } - if (Util.isNotEmpty(externals)) - { + if (Util.isNotEmpty(externals)) { SubRepository subRepository = new SubRepository(externals); - fileObject.setSubRepository(subRepository); + FileObject subRepositoryDirectory = new FileObject(); + subRepositoryDirectory.setSubRepository(subRepository); + fileObject.addChild(subRepositoryDirectory); } - } - catch (SVNException ex) - { + } catch (SVNException ex) { logger.error("could not fetch file properties", ex); } }