diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java index ced9de8909..a788f1f8b0 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/AbstractGitCommand.java @@ -35,11 +35,8 @@ package sonia.scm.repository.spi; import org.eclipse.jgit.lib.Repository; -import sonia.scm.repository.GitUtil; - //~--- JDK imports ------------------------------------------------------------ -import java.io.File; import java.io.IOException; /** @@ -53,14 +50,16 @@ public class AbstractGitCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - protected AbstractGitCommand(sonia.scm.repository.Repository repository, - File repositoryDirectory) + protected AbstractGitCommand(GitContext context, + sonia.scm.repository.Repository repository) { this.repository = repository; - this.repositoryDirectory = repositoryDirectory; + this.context = context; } //~--- methods -------------------------------------------------------------- @@ -75,14 +74,14 @@ public class AbstractGitCommand */ protected Repository open() throws IOException { - return GitUtil.open(repositoryDirectory); + return context.open(); } //~--- fields --------------------------------------------------------------- /** Field description */ - protected sonia.scm.repository.Repository repository; + protected GitContext context; /** Field description */ - protected File repositoryDirectory; + protected sonia.scm.repository.Repository repository; } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java index e210a51d18..f7d84cbedb 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBlameCommand.java @@ -53,7 +53,6 @@ import sonia.scm.repository.RepositoryException; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -78,12 +77,14 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - public GitBlameCommand(Repository repository, File repositoryDirectory) + public GitBlameCommand(GitContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -111,70 +112,56 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand Preconditions.checkArgument(!Strings.isNullOrEmpty(request.getPath()), "path is empty or null"); - org.eclipse.jgit.blame.BlameResult gitBlameResult = null; - sonia.scm.repository.BlameResult blameResult = null; - org.eclipse.jgit.lib.Repository gr = null; + org.eclipse.jgit.lib.Repository gr = open(); + org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame(); - try + blame.setFilePath(request.getPath()); + + ObjectId revId = GitUtil.getRevisionId(gr, request.getRevision()); + + blame.setStartCommit(revId); + + org.eclipse.jgit.blame.BlameResult gitBlameResult = blame.call(); + + if (gitBlameResult == null) { - gr = open(); - - org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame(); - - blame.setFilePath(request.getPath()); - - ObjectId revId = GitUtil.getRevisionId(gr, request.getRevision()); - - blame.setStartCommit(revId); - gitBlameResult = blame.call(); - - if (gitBlameResult == null) - { - throw new RepositoryException( - "could not create blame result for path ".concat( - request.getPath())); - } - - List blameLines = new ArrayList(); - int total = gitBlameResult.getResultContents().size(); - int i = 0; - - for (; i < total; i++) - { - RevCommit commit = gitBlameResult.getSourceCommit(i); - - if (commit != null) - { - PersonIdent author = gitBlameResult.getSourceAuthor(i); - BlameLine blameLine = new BlameLine(); - - blameLine.setLineNumber(i + 1); - blameLine.setAuthor(new Person(author.getName(), - author.getEmailAddress())); - blameLine.setDescription(commit.getShortMessage()); - - long when = GitUtil.getCommitTime(commit); - - blameLine.setWhen(when); - - String rev = commit.getId().getName(); - - blameLine.setRevision(rev); - - String content = gitBlameResult.getResultContents().getString(i); - - blameLine.setCode(content); - blameLines.add(blameLine); - } - } - - blameResult = new sonia.scm.repository.BlameResult(i, blameLines); - } - finally - { - GitUtil.close(gr); + throw new RepositoryException( + "could not create blame result for path ".concat(request.getPath())); } - return blameResult; + List blameLines = new ArrayList(); + int total = gitBlameResult.getResultContents().size(); + int i = 0; + + for (; i < total; i++) + { + RevCommit commit = gitBlameResult.getSourceCommit(i); + + if (commit != null) + { + PersonIdent author = gitBlameResult.getSourceAuthor(i); + BlameLine blameLine = new BlameLine(); + + blameLine.setLineNumber(i + 1); + blameLine.setAuthor(new Person(author.getName(), + author.getEmailAddress())); + blameLine.setDescription(commit.getShortMessage()); + + long when = GitUtil.getCommitTime(commit); + + blameLine.setWhen(when); + + String rev = commit.getId().getName(); + + blameLine.setRevision(rev); + + String content = gitBlameResult.getResultContents().getString(i); + + blameLine.setCode(content); + blameLines.add(blameLine); + } + } + + return new sonia.scm.repository.BlameResult(i, blameLines); } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java index 0663eb6067..b6799f0612 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitBrowseCommand.java @@ -61,7 +61,6 @@ import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -92,12 +91,14 @@ public class GitBrowseCommand extends AbstractGitCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - public GitBrowseCommand(Repository repository, File repositoryDirectory) + public GitBrowseCommand(GitContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -109,53 +110,49 @@ public class GitBrowseCommand extends AbstractGitCommand * @param request * * @return + * + * @throws IOException + * @throws RepositoryException */ @Override - public BrowserResult getBrowserResult(BrowseCommandRequest request) throws IOException, RepositoryException + public BrowserResult getBrowserResult(BrowseCommandRequest request) + throws IOException, RepositoryException { - if ( logger.isDebugEnabled() ){ + if (logger.isDebugEnabled()) + { logger.debug("try to create browse result for {}", request); } + BrowserResult result = null; - org.eclipse.jgit.lib.Repository repo = null; + org.eclipse.jgit.lib.Repository repo = open(); + ObjectId revId = null; - try + if (Util.isEmpty(request.getRevision())) { - repo = open(); - - ObjectId revId = null; - - if (Util.isEmpty(request.getRevision())) - { - revId = GitUtil.getRepositoryHead(repo); - } - else - { - revId = GitUtil.getRevisionId(repo, request.getRevision()); - } - - if (revId != null) - { - result = getResult(repo, revId, request.getPath()); - } - else - { - if (Util.isNotEmpty(request.getRevision())) - { - logger.error("could not find revision {}", request.getRevision()); - } - else if (logger.isWarnEnabled()) - { - logger.warn("coul not find head of repository, empty?"); - } - - result = new BrowserResult(Constants.HEAD, null, null, - new ArrayList()); - } + revId = GitUtil.getRepositoryHead(repo); } - finally + else { - GitUtil.close(repo); + revId = GitUtil.getRevisionId(repo, request.getRevision()); + } + + if (revId != null) + { + result = getResult(repo, revId, request.getPath()); + } + else + { + if (Util.isNotEmpty(request.getRevision())) + { + logger.error("could not find revision {}", request.getRevision()); + } + else if (logger.isWarnEnabled()) + { + logger.warn("coul not find head of repository, empty?"); + } + + result = new BrowserResult(Constants.HEAD, null, null, + new ArrayList()); } return result; @@ -457,8 +454,8 @@ public class GitBrowseCommand extends AbstractGitCommand try { - new GitCatCommand(repository, repositoryDirectory).getContent(repo, - revision, PATH_MODULES, baos); + new GitCatCommand(context, repository).getContent(repo, revision, + PATH_MODULES, baos); subRepositories = GitSubModuleParser.parse(baos.toString()); } catch (PathNotFoundException ex) diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java index d4028f9d79..ebc77abc89 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitCatCommand.java @@ -52,7 +52,6 @@ import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -75,13 +74,15 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - public GitCatCommand(sonia.scm.repository.Repository repository, - File repositoryDirectory) + public GitCatCommand(GitContext context, + sonia.scm.repository.Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -107,18 +108,11 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand org.eclipse.jgit.lib.Repository repo = null; - try - { - repo = open(); + repo = open(); - ObjectId revId = GitUtil.getRevisionId(repo, request.getRevision()); + ObjectId revId = GitUtil.getRevisionId(repo, request.getRevision()); - getContent(repo, revId, request.getPath(), output); - } - finally - { - GitUtil.close(repo); - } + getContent(repo, revId, request.getPath(), output); } /** diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitContext.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitContext.java new file mode 100644 index 0000000000..f53dfd718a --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitContext.java @@ -0,0 +1,121 @@ +/** + * 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 sonia.scm.repository.GitUtil; + +//~--- JDK imports ------------------------------------------------------------ + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; + +/** + * + * @author Sebastian Sdorra + */ +public class GitContext implements Closeable +{ + + /** + * the logger for GitContext + */ + private static final Logger logger = + LoggerFactory.getLogger(GitContext.class); + + //~--- constructors --------------------------------------------------------- + + /** + * Constructs ... + * + * + * @param directory + */ + public GitContext(File directory) + { + this.directory = directory; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + */ + @Override + public void close() + { + if (logger.isTraceEnabled()) + { + logger.trace("close git repository {}", directory); + } + + GitUtil.close(repository); + repository = null; + } + + /** + * Method description + * + * + * @return + * + * @throws IOException + */ + public org.eclipse.jgit.lib.Repository open() throws IOException + { + if (repository == null) + { + if (logger.isTraceEnabled()) + { + logger.trace("open git repository {}", directory); + } + + repository = GitUtil.open(directory); + } + + return repository; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private File directory; + + /** Field description */ + private org.eclipse.jgit.lib.Repository repository; +} diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java index 27e5dc4183..8b24eea53f 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitDiffCommand.java @@ -52,7 +52,6 @@ import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ import java.io.BufferedOutputStream; -import java.io.File; import java.io.OutputStream; import java.util.List; @@ -76,12 +75,14 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - public GitDiffCommand(Repository repository, File repositoryDirectory) + public GitDiffCommand(GitContext context, Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -96,14 +97,14 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand @Override public void getDiffResult(DiffCommandRequest request, OutputStream output) { - org.eclipse.jgit.lib.Repository gr = null; RevWalk walk = null; TreeWalk treeWalk = null; DiffFormatter formatter = null; try { - gr = open(); + org.eclipse.jgit.lib.Repository gr = open(); + walk = new RevWalk(gr); RevCommit commit = walk.parseCommit(gr.resolve(request.getRevision())); @@ -155,6 +156,7 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand } catch (Exception ex) { + // TODO throw exception logger.error("could not create diff", ex); } @@ -163,7 +165,6 @@ public class GitDiffCommand extends AbstractGitCommand implements DiffCommand GitUtil.release(walk); GitUtil.release(treeWalk); GitUtil.release(formatter); - GitUtil.close(gr); } } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java index 51d4748b6e..b7423a2940 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java @@ -54,7 +54,6 @@ import sonia.scm.util.IOUtil; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -79,13 +78,14 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand * Constructs ... * * + * + * @param context * @param repository * @param repositoryDirectory */ - GitLogCommand(sonia.scm.repository.Repository repository, - File repositoryDirectory) + GitLogCommand(GitContext context, sonia.scm.repository.Repository repository) { - super(repository, repositoryDirectory); + super(context, repository); } //~--- get methods ---------------------------------------------------------- @@ -164,12 +164,11 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand } ChangesetPagingResult changesets = null; - org.eclipse.jgit.lib.Repository gr = null; GitChangesetConverter converter = null; try { - gr = open(); + org.eclipse.jgit.lib.Repository gr = open(); if (!gr.getAllRefs().isEmpty()) { @@ -260,7 +259,6 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand finally { IOUtil.close(converter); - GitUtil.close(gr); } return changesets; diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java index b300af1762..3a55da1237 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitRepositoryServiceProvider.java @@ -41,7 +41,7 @@ import sonia.scm.repository.api.Command; //~--- JDK imports ------------------------------------------------------------ -import java.io.File; +import java.io.IOException; import java.util.Set; @@ -70,7 +70,21 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider Repository repository) { this.repository = repository; - this.repositoryDirectory = handler.getDirectory(repository); + context = new GitContext(handler.getDirectory(repository)); + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @throws IOException + */ + @Override + public void close() throws IOException + { + context.close(); } //~--- get methods ---------------------------------------------------------- @@ -84,7 +98,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider @Override public BlameCommand getBlameCommand() { - return new GitBlameCommand(repository, repositoryDirectory); + return new GitBlameCommand(context, repository); } /** @@ -96,7 +110,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider @Override public BrowseCommand getBrowseCommand() { - return new GitBrowseCommand(repository, repositoryDirectory); + return new GitBrowseCommand(context, repository); } /** @@ -108,7 +122,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider @Override public CatCommand getCatCommand() { - return new GitCatCommand(repository, repositoryDirectory); + return new GitCatCommand(context, repository); } /** @@ -120,7 +134,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider @Override public DiffCommand getDiffCommand() { - return new GitDiffCommand(repository, repositoryDirectory); + return new GitDiffCommand(context, repository); } /** @@ -132,7 +146,7 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider @Override public LogCommand getLogCommand() { - return new GitLogCommand(repository, repositoryDirectory); + return new GitLogCommand(context, repository); } /** @@ -150,8 +164,8 @@ public class GitRepositoryServiceProvider extends RepositoryServiceProvider //~--- fields --------------------------------------------------------------- /** Field description */ - private Repository repository; + private GitContext context; /** Field description */ - private File repositoryDirectory; + private Repository repository; } diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractGitCommandTestBase.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractGitCommandTestBase.java index 32b2ad826d..98e2399c8f 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractGitCommandTestBase.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractGitCommandTestBase.java @@ -31,6 +31,10 @@ package sonia.scm.repository.spi; +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.After; + /** * * @author Sebastian Sdorra @@ -38,6 +42,34 @@ package sonia.scm.repository.spi; public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase { + /** + * Method description + * + */ + @After + public void close() + { + context.close(); + } + + /** + * Method description + * + * + * @return + */ + protected GitContext createContext() + { + if (context == null) + { + context = new GitContext(repositoryDirectory); + } + + return context; + } + + //~--- get methods ---------------------------------------------------------- + /** * Method description * @@ -61,4 +93,9 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase { return "sonia/scm/repository/spi/scm-git-spi-test.zip"; } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private GitContext context; } diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBlameCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBlameCommandTest.java index 8cb1d5d13c..05649f64d8 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBlameCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBlameCommandTest.java @@ -66,8 +66,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase request.setPath("a.txt"); - BlameResult result = new GitBlameCommand(repository, - repositoryDirectory).getBlameResult(request); + BlameResult result = createCommand().getBlameResult(request); assertNotNull(result); assertEquals(2, result.getTotal()); @@ -103,8 +102,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase request.setPath("a.txt"); request.setRevision("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1"); - BlameResult result = new GitBlameCommand(repository, - repositoryDirectory).getBlameResult(request); + BlameResult result = createCommand().getBlameResult(request); assertNotNull(result); assertEquals(1, result.getTotal()); @@ -131,4 +129,15 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase assertEquals("Douglas Adams", line.getAuthor().getName()); assertEquals("douglas.adams@hitchhiker.com", line.getAuthor().getMail()); } + + /** + * Method description + * + * + * @return + */ + private GitBlameCommand createCommand() + { + return new GitBlameCommand(createContext(), repository); + } } diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBrowseCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBrowseCommandTest.java index faa6b4b041..70a55a1050 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBrowseCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitBrowseCommandTest.java @@ -64,10 +64,8 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase @Test public void testBrowse() throws IOException, RepositoryException { - BrowserResult result = new GitBrowseCommand( - repository, - repositoryDirectory).getBrowserResult( - new BrowseCommandRequest()); + BrowserResult result = + createCommand().getBrowserResult(new BrowseCommandRequest()); assertNotNull(result); @@ -119,8 +117,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase request.setPath("c"); - BrowserResult result = new GitBrowseCommand(repository, - repositoryDirectory).getBrowserResult(request); + BrowserResult result = createCommand().getBrowserResult(request); assertNotNull(result); @@ -160,4 +157,15 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase assertTrue(e.getLength() > 0); checkDate(e.getLastModified()); } + + /** + * Method description + * + * + * @return + */ + private GitBrowseCommand createCommand() + { + return new GitBrowseCommand(createContext(), repository); + } } diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitCatCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitCatCommandTest.java index 431051aeac..2a8943f6f8 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitCatCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitCatCommandTest.java @@ -104,7 +104,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase try { - new GitCatCommand(repository, repositoryDirectory).getCatResult(request, + new GitCatCommand(createContext(), repository).getCatResult(request, baos); } finally diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandTest.java index 5acaca69cc..0381b2d514 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitLogCommandTest.java @@ -63,10 +63,8 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase @Test public void testGetAll() throws IOException { - ChangesetPagingResult result = new GitLogCommand( - repository, - repositoryDirectory).getChangesets( - new LogCommandRequest()); + ChangesetPagingResult result = + createCommand().getChangesets(new LogCommandRequest()); assertNotNull(result); assertEquals(5, result.getTotal()); @@ -86,8 +84,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase request.setPath("a.txt"); - ChangesetPagingResult result = - new GitLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(3, result.getTotal()); @@ -110,8 +107,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase request.setPagingLimit(2); - ChangesetPagingResult result = - new GitLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(5, result.getTotal()); @@ -142,8 +138,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase request.setPagingStart(1); request.setPagingLimit(2); - ChangesetPagingResult result = - new GitLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(5, result.getTotal()); @@ -167,7 +162,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase @Test public void testGetCommit() { - GitLogCommand command = new GitLogCommand(repository, repositoryDirectory); + GitLogCommand command = createCommand(); Changeset c = command.getChangeset("435df2f061add3589cb3"); assertNotNull(c); @@ -202,8 +197,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase request.setStartChangeset("592d797cd36432e59141"); request.setEndChangeset("435df2f061add3589cb3"); - ChangesetPagingResult result = - new GitLogCommand(repository, repositoryDirectory).getChangesets(request); + ChangesetPagingResult result = createCommand().getChangesets(request); assertNotNull(result); assertEquals(2, result.getTotal()); @@ -217,4 +211,15 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase assertNotNull(c2); assertEquals("435df2f061add3589cb3", c2.getId()); } + + /** + * Method description + * + * + * @return + */ + private GitLogCommand createCommand() + { + return new GitLogCommand(createContext(), repository); + } }