From 7a7579edefcb2ed4fe6ada94dca0d1d86c913324 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 21 Jun 2012 20:18:05 +0200 Subject: [PATCH] improve performance of subversion repository api --- .../repository/spi/AbstractSvnCommand.java | 16 +- .../scm/repository/spi/SvnBlameCommand.java | 20 +-- .../scm/repository/spi/SvnBrowseCommand.java | 15 +- .../scm/repository/spi/SvnCatCommand.java | 15 +- .../sonia/scm/repository/spi/SvnContext.java | 153 ++++++++++++++++++ .../scm/repository/spi/SvnDiffCommand.java | 8 +- .../scm/repository/spi/SvnLogCommand.java | 25 +-- .../spi/SvnRepositoryServiceProvider.java | 18 +-- .../spi/AbstractSvnCommandTestBase.java | 46 ++++++ .../repository/spi/SvnBlameCommandTest.java | 17 +- .../repository/spi/SvnBrowseCommandTest.java | 35 +++- .../scm/repository/spi/SvnCatCommandTest.java | 20 ++- .../scm/repository/spi/SvnLogCommandTest.java | 75 +++++---- 13 files changed, 340 insertions(+), 123 deletions(-) create mode 100644 scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnContext.java diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/AbstractSvnCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/AbstractSvnCommand.java index 27ce9637ec..1060337cd0 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/AbstractSvnCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/AbstractSvnCommand.java @@ -40,10 +40,6 @@ import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import sonia.scm.repository.Repository; -//~--- JDK imports ------------------------------------------------------------ - -import java.io.File; - /** * * @author Sebastian Sdorra @@ -55,13 +51,15 @@ public class AbstractSvnCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - protected AbstractSvnCommand(Repository repository, File repositoryDirectory) + protected AbstractSvnCommand(SvnContext context, Repository repository) { + this.context = context; this.repository = repository; - this.repositoryDirectory = repositoryDirectory; } //~--- methods -------------------------------------------------------------- @@ -76,14 +74,14 @@ public class AbstractSvnCommand */ public SVNRepository open() throws SVNException { - return SVNRepositoryFactory.create(SVNURL.fromFile(repositoryDirectory)); + return context.open(); } //~--- fields --------------------------------------------------------------- /** Field description */ - protected Repository repository; + protected SvnContext context; /** Field description */ - protected File repositoryDirectory; + protected Repository repository; } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBlameCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBlameCommand.java index e7a50d9d52..527d381eed 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBlameCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnBlameCommand.java @@ -48,7 +48,6 @@ import sonia.scm.repository.BlameResult; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryException; import sonia.scm.repository.SvnBlameHandler; -import sonia.scm.repository.SvnUtil; import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ @@ -69,12 +68,14 @@ public class SvnBlameCommand extends AbstractSvnCommand implements BlameCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - public SvnBlameCommand(Repository repository, File repositoryDirectory) + public SvnBlameCommand(SvnContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -97,8 +98,6 @@ public class SvnBlameCommand extends AbstractSvnCommand implements BlameCommand String path = request.getPath(); String revision = request.getRevision(); List blameLines = Lists.newArrayList(); - SVNRepository svnRepository = null; - SVNURL svnurl = null; SVNRevision endRevision = null; if (Util.isNotEmpty(revision)) @@ -112,10 +111,9 @@ public class SvnBlameCommand extends AbstractSvnCommand implements BlameCommand try { - svnurl = SVNURL.fromFile(new File(repositoryDirectory, path)); - svnRepository = - SVNRepositoryFactory.create(SVNURL.fromFile(repositoryDirectory)); - + SVNURL svnurl = SVNURL.fromFile(new File(context.getDirectory(), path)); + SVNRepository svnRepository = + SVNRepositoryFactory.create(context.createUrl()); ISVNAuthenticationManager svnManager = svnRepository.getAuthenticationManager(); SVNLogClient svnLogClient = new SVNLogClient(svnManager, null); @@ -129,10 +127,6 @@ public class SvnBlameCommand extends AbstractSvnCommand implements BlameCommand { throw new RepositoryException("could not create blame result", ex); } - finally - { - SvnUtil.closeSession(svnRepository); - } return new BlameResult(blameLines.size(), blameLines); } 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 6b7d6e4d17..d261a567f8 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 @@ -53,7 +53,6 @@ import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -80,12 +79,14 @@ public class SvnBrowseCommand extends AbstractSvnCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - SvnBrowseCommand(Repository repository, File repositoryDirectory) + SvnBrowseCommand(SvnContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -116,12 +117,10 @@ public class SvnBrowseCommand extends AbstractSvnCommand } BrowserResult result = null; - SVNRepository svnRepository = null; try { - svnRepository = open(); - + SVNRepository svnRepository = open(); Collection entries = svnRepository.getDir(Util.nonNull(path), revisionNumber, null, (Collection) null); @@ -152,10 +151,6 @@ public class SvnBrowseCommand extends AbstractSvnCommand { logger.error("could not open repository", ex); } - finally - { - SvnUtil.closeSession(svnRepository); - } return result; } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java index 57f01c74dd..7ff45073cb 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnCatCommand.java @@ -46,7 +46,6 @@ import sonia.scm.repository.SvnUtil; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -69,12 +68,14 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - SvnCatCommand(Repository repository, File repositoryDirectory) + SvnCatCommand(SvnContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -99,11 +100,11 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand } long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision()); - SVNRepository svnRepository = null; try { - svnRepository = open(); + SVNRepository svnRepository = open(); + svnRepository.getFile(request.getPath(), revisionNumber, new SVNProperties(), output); } @@ -111,9 +112,5 @@ public class SvnCatCommand extends AbstractSvnCommand implements CatCommand { logger.error("could not open repository", ex); } - finally - { - SvnUtil.closeSession(svnRepository); - } } } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnContext.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnContext.java new file mode 100644 index 0000000000..478632c633 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnContext.java @@ -0,0 +1,153 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.repository.spi; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.io.SVNRepository; +import org.tmatesoft.svn.core.io.SVNRepositoryFactory; + +import sonia.scm.repository.SvnUtil; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class SvnContext implements Closeable +{ + + /** + * the logger for SvnContext + */ + private static final Logger logger = + LoggerFactory.getLogger(SvnContext.class); + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + * + * @param directory + */ + public SvnContext(File directory) + { + this.directory = directory; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @throws IOException + */ + @Override + public void close() throws IOException + { + if (logger.isTraceEnabled()) + { + logger.trace("close svn repository {}", directory); + } + + SvnUtil.closeSession(repository); + } + + /** + * Method description + * + * + * @return + * + * @throws SVNException + */ + public SVNURL createUrl() throws SVNException + { + return SVNURL.fromFile(directory); + } + + /** + * Method description + * + * + * @return + * + * @throws SVNException + */ + public SVNRepository open() throws SVNException + { + if (repository == null) + { + if (logger.isTraceEnabled()) + { + logger.trace("open svn repository {}", directory); + } + + repository = SVNRepositoryFactory.create(createUrl()); + } + + return repository; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public File getDirectory() + { + return directory; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private File directory; + + /** Field description */ + private SVNRepository repository; +} diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnDiffCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnDiffCommand.java index 10053d99fa..f4f6649e96 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnDiffCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnDiffCommand.java @@ -77,12 +77,14 @@ public class SvnDiffCommand extends AbstractSvnCommand implements DiffCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - public SvnDiffCommand(Repository repository, File repositoryDirectory) + public SvnDiffCommand(SvnContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -114,7 +116,7 @@ public class SvnDiffCommand extends AbstractSvnCommand implements DiffCommand try { - SVNURL svnurl = SVNURL.fromFile(repositoryDirectory); + SVNURL svnurl = context.createUrl(); if (Util.isNotEmpty(path)) { diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLogCommand.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLogCommand.java index 9167c63388..57fcd4fe13 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLogCommand.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnLogCommand.java @@ -52,7 +52,6 @@ import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; import java.io.IOException; import java.util.Collection; @@ -77,12 +76,14 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - SvnLogCommand(Repository repository, File repositoryDirectory) + SvnLogCommand(SvnContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -109,14 +110,10 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand logger.debug("fetch changeset {}", revision); } - SVNRepository repository = null; - try { long revisioNumber = Long.parseLong(revision); - - repository = open(); - + SVNRepository repository = open(); Collection entries = repository.log(null, null, revisioNumber, revisioNumber, true, true); @@ -134,10 +131,6 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand { throw new RepositoryException("could not open repository", ex); } - finally - { - SvnUtil.closeSession(repository); - } return changeset; } @@ -163,14 +156,12 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand } ChangesetPagingResult changesets = null; - SVNRepository repository = null; String startRevision = request.getStartChangeset(); String endRevision = request.getEndChangeset(); try { - repository = open(); - + SVNRepository repository = open(); long startRev = repository.getLatestRevision(); long endRev = 0; long maxRev = startRev; @@ -231,10 +222,6 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand { throw new RepositoryException("could not open repository", ex); } - finally - { - SvnUtil.closeSession(repository); - } return changesets; } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java index ddc49b479d..f089d01216 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/spi/SvnRepositoryServiceProvider.java @@ -41,8 +41,6 @@ import sonia.scm.repository.api.Command; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; - import java.util.Set; /** @@ -70,7 +68,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider Repository repository) { this.repository = repository; - this.repositoryDirectory = handler.getDirectory(repository); + this.context = new SvnContext(handler.getDirectory(repository)); } //~--- get methods ---------------------------------------------------------- @@ -84,7 +82,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider @Override public SvnBlameCommand getBlameCommand() { - return new SvnBlameCommand(repository, repositoryDirectory); + return new SvnBlameCommand(context, repository); } /** @@ -96,7 +94,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider @Override public SvnBrowseCommand getBrowseCommand() { - return new SvnBrowseCommand(repository, repositoryDirectory); + return new SvnBrowseCommand(context, repository); } /** @@ -108,7 +106,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider @Override public SvnCatCommand getCatCommand() { - return new SvnCatCommand(repository, repositoryDirectory); + return new SvnCatCommand(context, repository); } /** @@ -120,7 +118,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider @Override public SvnDiffCommand getDiffCommand() { - return new SvnDiffCommand(repository, repositoryDirectory); + return new SvnDiffCommand(context, repository); } /** @@ -132,7 +130,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider @Override public SvnLogCommand getLogCommand() { - return new SvnLogCommand(repository, repositoryDirectory); + return new SvnLogCommand(context, repository); } /** @@ -150,8 +148,8 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider //~--- fields --------------------------------------------------------------- /** Field description */ - private Repository repository; + private SvnContext context; /** Field description */ - private File repositoryDirectory; + private Repository repository; } diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/AbstractSvnCommandTestBase.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/AbstractSvnCommandTestBase.java index a4ff8eab88..b8eee112c0 100644 --- a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/AbstractSvnCommandTestBase.java +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/AbstractSvnCommandTestBase.java @@ -31,6 +31,14 @@ package sonia.scm.repository.spi; +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.After; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + /** * * @author Sebastian Sdorra @@ -38,6 +46,39 @@ package sonia.scm.repository.spi; public class AbstractSvnCommandTestBase extends ZippedRepositoryTestBase { + /** + * Method description + * + * + * @throws IOException + */ + @After + public void close() throws IOException + { + if (context != null) + { + context.close(); + } + } + + /** + * Method description + * + * + * @return + */ + public SvnContext createContext() + { + if (context == null) + { + context = new SvnContext(repositoryDirectory); + } + + return context; + } + + //~--- get methods ---------------------------------------------------------- + /** * Method description * @@ -61,4 +102,9 @@ public class AbstractSvnCommandTestBase extends ZippedRepositoryTestBase { return "sonia/scm/repository/spi/scm-svn-spi-test.zip"; } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private SvnContext context; } diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBlameCommandTest.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBlameCommandTest.java index a4b49baffc..7585535716 100644 --- a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBlameCommandTest.java +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBlameCommandTest.java @@ -66,8 +66,7 @@ public class SvnBlameCommandTest extends AbstractSvnCommandTestBase request.setPath("a.txt"); - BlameResult result = new SvnBlameCommand(repository, - repositoryDirectory).getBlameResult(request); + BlameResult result = createCommand().getBlameResult(request); assertNotNull(result); assertEquals(2, result.getTotal()); @@ -101,8 +100,7 @@ public class SvnBlameCommandTest extends AbstractSvnCommandTestBase request.setPath("a.txt"); request.setRevision("3"); - BlameResult result = new SvnBlameCommand(repository, - repositoryDirectory).getBlameResult(request); + BlameResult result = createCommand().getBlameResult(request); assertNotNull(result); assertEquals(1, result.getTotal()); @@ -128,4 +126,15 @@ public class SvnBlameCommandTest extends AbstractSvnCommandTestBase assertEquals("perfect", line.getAuthor().getName()); assertNull(line.getAuthor().getMail()); } + + /** + * Method description + * + * + * @return + */ + private SvnBlameCommand createCommand() + { + return new SvnBlameCommand(createContext(), repository); + } } diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBrowseCommandTest.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBrowseCommandTest.java index 354fab6501..b346507fa5 100644 --- a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBrowseCommandTest.java +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnBrowseCommandTest.java @@ -26,23 +26,34 @@ * http://bitbucket.org/sdorra/scm-manager * */ + + + package sonia.scm.repository.spi; -import java.io.IOException; -import java.util.List; +//~--- non-JDK imports -------------------------------------------------------- + import org.junit.Test; + import sonia.scm.repository.BrowserResult; import sonia.scm.repository.FileObject; import sonia.scm.repository.RepositoryException; import static org.junit.Assert.*; +//~--- JDK imports ------------------------------------------------------------ + +import java.io.IOException; + +import java.util.List; + /** * * @author Sebastian Sdorra */ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase { + /** * Method description * @@ -53,10 +64,8 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase @Test public void testBrowse() throws IOException, RepositoryException { - BrowserResult result = new SvnBrowseCommand( - repository, - repositoryDirectory).getBrowserResult( - new BrowseCommandRequest()); + BrowserResult result = + createCommand().getBrowserResult(new BrowseCommandRequest()); assertNotNull(result); @@ -108,8 +117,7 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase request.setPath("c"); - BrowserResult result = new SvnBrowseCommand(repository, - repositoryDirectory).getBrowserResult(request); + BrowserResult result = createCommand().getBrowserResult(request); assertNotNull(result); @@ -149,4 +157,15 @@ public class SvnBrowseCommandTest extends AbstractSvnCommandTestBase assertTrue(e.getLength() > 0); checkDate(e.getLastModified()); } + + /** + * Method description + * + * + * @return + */ + private SvnBrowseCommand createCommand() + { + return new SvnBrowseCommand(createContext(), repository); + } } diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java index add8d01e65..2048c9dbb4 100644 --- a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnCatCommandTest.java @@ -26,23 +26,32 @@ * http://bitbucket.org/sdorra/scm-manager * */ + + + package sonia.scm.repository.spi; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +//~--- non-JDK imports -------------------------------------------------------- + import org.junit.Test; + import sonia.scm.repository.RepositoryException; import static org.junit.Assert.*; +//~--- JDK imports ------------------------------------------------------------ + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + /** * * @author Sebastian Sdorra */ public class SvnCatCommandTest extends AbstractSvnCommandTestBase { - - /** + + /** * Method description * * @@ -94,7 +103,7 @@ public class SvnCatCommandTest extends AbstractSvnCommandTestBase try { - new SvnCatCommand(repository, repositoryDirectory).getCatResult(request, + new SvnCatCommand(createContext(), repository).getCatResult(request, baos); } finally @@ -104,5 +113,4 @@ public class SvnCatCommandTest extends AbstractSvnCommandTestBase return content; } - } diff --git a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLogCommandTest.java b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLogCommandTest.java index 62824c3081..166305bb61 100644 --- a/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLogCommandTest.java +++ b/scm-plugins/scm-svn-plugin/src/test/java/sonia/scm/repository/spi/SvnLogCommandTest.java @@ -35,7 +35,9 @@ package sonia.scm.repository.spi; import org.junit.Test; +import sonia.scm.repository.Changeset; import sonia.scm.repository.ChangesetPagingResult; +import sonia.scm.repository.Modifications; import sonia.scm.repository.RepositoryException; import static org.junit.Assert.*; @@ -43,8 +45,6 @@ import static org.junit.Assert.*; //~--- JDK imports ------------------------------------------------------------ import java.io.IOException; -import sonia.scm.repository.Changeset; -import sonia.scm.repository.Modifications; /** * @@ -55,29 +55,28 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase /** * Method description - * - * + * + * * @throws IOException * @throws RepositoryException */ @Test public void testGetAll() throws IOException, RepositoryException { - ChangesetPagingResult result = new SvnLogCommand( - repository, - repositoryDirectory).getChangesets( - new LogCommandRequest()); + ChangesetPagingResult result = + createCommand().getChangesets(new LogCommandRequest()); assertNotNull(result); assertEquals(6, result.getTotal()); assertEquals(6, result.getChangesets().size()); } - + /** * Method description * * * @throws IOException + * @throws RepositoryException */ @Test public void testGetAllByPath() throws IOException, RepositoryException @@ -86,8 +85,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase request.setPath("a.txt"); - ChangesetPagingResult result = - new SvnLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(3, result.getTotal()); @@ -96,12 +94,13 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase assertEquals("3", result.getChangesets().get(1).getId()); assertEquals("1", result.getChangesets().get(2).getId()); } - - /** - * Method description + + /** + * Method description * * - * @throws IOException + * @throws IOException + * @throws RepositoryException */ @Test public void testGetAllWithLimit() throws IOException, RepositoryException @@ -110,8 +109,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase request.setPagingLimit(2); - ChangesetPagingResult result = - new SvnLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(6, result.getTotal()); @@ -127,12 +125,13 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase assertNotNull(c2); assertEquals("4", c2.getId()); } - - /** + + /** * Method description * * * @throws IOException + * @throws RepositoryException */ @Test public void testGetAllWithPaging() throws IOException, RepositoryException @@ -142,8 +141,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase request.setPagingStart(1); request.setPagingLimit(2); - ChangesetPagingResult result = - new SvnLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(6, result.getTotal()); @@ -159,16 +157,18 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase assertNotNull(c2); assertEquals("3", c2.getId()); } - - /** - * Method description + + /** + * Method description * + * + * @throws IOException + * @throws RepositoryException */ @Test public void testGetCommit() throws IOException, RepositoryException { - SvnLogCommand command = new SvnLogCommand(repository, repositoryDirectory); - Changeset c = command.getChangeset("3"); + Changeset c = createCommand().getChangeset("3"); assertNotNull(c); assertEquals("3", c.getId()); @@ -186,12 +186,13 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase assertEquals("a.txt", mods.getModified().get(0)); assertEquals("b.txt", mods.getRemoved().get(0)); } - - /** - * Method description + + /** + * Method description * * - * @throws IOException + * @throws IOException + * @throws RepositoryException */ @Test public void testGetRange() throws IOException, RepositoryException @@ -201,8 +202,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase request.setStartChangeset("2"); request.setEndChangeset("1"); - ChangesetPagingResult result = - new SvnLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(2, result.getTotal()); @@ -216,4 +216,15 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase assertNotNull(c2); assertEquals("1", c2.getId()); } + + /** + * Method description + * + * + * @return + */ + private SvnLogCommand createCommand() + { + return new SvnLogCommand(createContext(), repository); + } }