rename BlamePagingResult to BlameResult

This commit is contained in:
Sebastian Sdorra
2011-09-16 09:05:06 +02:00
parent 0e82fc1ffe
commit 668600b65d
8 changed files with 65 additions and 41 deletions

View File

@@ -52,14 +52,26 @@ import javax.xml.bind.annotation.XmlRootElement;
*/ */
@XmlRootElement(name = "blame-paging") @XmlRootElement(name = "blame-paging")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class BlamePagingResult public class BlameResult
{ {
/** /**
* Constructs ... * Constructs ...
* *
*/ */
public BlamePagingResult() {} public BlameResult() {}
/**
* Constructs ...
*
*
* @param blameLines
*/
public BlameResult(List<BlameLine> blameLines)
{
this.blameLines = blameLines;
this.total = blameLines.size();
}
/** /**
* Constructs ... * Constructs ...
@@ -68,7 +80,7 @@ public class BlamePagingResult
* @param total * @param total
* @param blameLines * @param blameLines
*/ */
public BlamePagingResult(int total, List<BlameLine> blameLines) public BlameResult(int total, List<BlameLine> blameLines)
{ {
this.total = total; this.total = total;
this.blameLines = blameLines; this.blameLines = blameLines;
@@ -87,6 +99,19 @@ public class BlamePagingResult
return blameLines; return blameLines;
} }
/**
* Method description
*
*
* @param i
*
* @return
*/
public BlameLine getLine(int i)
{
return blameLines.get(i);
}
/** /**
* Method description * Method description
* *

View File

@@ -59,6 +59,6 @@ public interface BlameViewer
* @throws IOException * @throws IOException
* @throws RepositoryException * @throws RepositoryException
*/ */
public BlamePagingResult getBlame(String revision, String path) public BlameResult getBlame(String revision, String path)
throws IOException, RepositoryException; throws IOException, RepositoryException;
} }

View File

@@ -83,7 +83,7 @@ public class BlameViewerUtil extends CacheClearHook
{ {
this.repositoryManager = repositoryManager; this.repositoryManager = repositoryManager;
this.cache = cacheManager.getCache(BlameViewerCacheKey.class, this.cache = cacheManager.getCache(BlameViewerCacheKey.class,
BlamePagingResult.class, CACHE_NAME); BlameResult.class, CACHE_NAME);
init(repositoryManager, cache); init(repositoryManager, cache);
} }
@@ -104,7 +104,7 @@ public class BlameViewerUtil extends CacheClearHook
* @throws NotSupportedFeatuerException * @throws NotSupportedFeatuerException
* @throws RepositoryException * @throws RepositoryException
*/ */
public BlamePagingResult getBlame(String repositoryId, String revision, public BlameResult getBlame(String repositoryId, String revision,
String path) String path)
throws RepositoryException, NotSupportedFeatuerException, IOException throws RepositoryException, NotSupportedFeatuerException, IOException
{ {
@@ -136,7 +136,7 @@ public class BlameViewerUtil extends CacheClearHook
* @throws NotSupportedFeatuerException * @throws NotSupportedFeatuerException
* @throws RepositoryException * @throws RepositoryException
*/ */
public BlamePagingResult getBlame(Repository repository, String revision, public BlameResult getBlame(Repository repository, String revision,
String path) String path)
throws RepositoryException, NotSupportedFeatuerException, IOException throws RepositoryException, NotSupportedFeatuerException, IOException
{ {
@@ -153,7 +153,7 @@ public class BlameViewerUtil extends CacheClearHook
BlameViewerCacheKey key = new BlameViewerCacheKey(repository.getId(), BlameViewerCacheKey key = new BlameViewerCacheKey(repository.getId(),
revision, path); revision, path);
BlamePagingResult result = cache.get(key); BlameResult result = cache.get(key);
if (result == null) if (result == null)
{ {
@@ -285,7 +285,7 @@ public class BlameViewerUtil extends CacheClearHook
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */
private Cache<BlameViewerCacheKey, BlamePagingResult> cache; private Cache<BlameViewerCacheKey, BlameResult> cache;
/** Field description */ /** Field description */
private RepositoryManager repositoryManager; private RepositoryManager repositoryManager;

View File

@@ -38,6 +38,7 @@ package sonia.scm.repository;
import org.eclipse.jgit.api.BlameCommand; import org.eclipse.jgit.api.BlameCommand;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.blame.BlameResult; import org.eclipse.jgit.blame.BlameResult;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
@@ -53,8 +54,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.jgit.lib.ObjectId;
import sonia.scm.util.Util;
/** /**
* Class description * Class description
@@ -96,12 +95,12 @@ public class GitBlameViewer implements BlameViewer
* @return * @return
*/ */
@Override @Override
public BlamePagingResult getBlame(String revision, String path) public sonia.scm.repository.BlameResult getBlame(String revision, String path)
{ {
AssertUtil.assertIsNotEmpty(path); AssertUtil.assertIsNotEmpty(path);
BlameResult blameResult = null; BlameResult gitBlameResult = null;
BlamePagingResult blamePagingResult = null; sonia.scm.repository.BlameResult blameResult = null;
org.eclipse.jgit.lib.Repository gr = null; org.eclipse.jgit.lib.Repository gr = null;
File directory = handler.getDirectory(repository); File directory = handler.getDirectory(repository);
Git git = null; Git git = null;
@@ -112,28 +111,28 @@ public class GitBlameViewer implements BlameViewer
git = new Git(gr); git = new Git(gr);
BlameCommand blame = git.blame(); BlameCommand blame = git.blame();
blame.setFilePath(path);
ObjectId revId = GitUtil.getRevisionId(gr, revision);
blame.setStartCommit(revId);
blameResult = blame.call(); blame.setFilePath(path);
AssertUtil.assertIsNotNull(blameResult);
ObjectId revId = GitUtil.getRevisionId(gr, revision);
blame.setStartCommit(revId);
gitBlameResult = blame.call();
AssertUtil.assertIsNotNull(gitBlameResult);
List<BlameLine> blameLines = new ArrayList<BlameLine>(); List<BlameLine> blameLines = new ArrayList<BlameLine>();
int total = blameResult.getResultContents().size(); int total = gitBlameResult.getResultContents().size();
for (int i = 0; i < total; i++) for (int i = 0; i < total; i++)
{ {
PersonIdent author = blameResult.getSourceAuthor(i); PersonIdent author = gitBlameResult.getSourceAuthor(i);
BlameLine blameLine = new BlameLine(); BlameLine blameLine = new BlameLine();
blameLine.setLineNumber(i + 1); blameLine.setLineNumber(i + 1);
blameLine.setAuthor(new Person(author.getName(), blameLine.setAuthor(new Person(author.getName(),
author.getEmailAddress())); author.getEmailAddress()));
RevCommit commit = blameResult.getSourceCommit(i); RevCommit commit = gitBlameResult.getSourceCommit(i);
long when = GitUtil.getCommitTime(commit); long when = GitUtil.getCommitTime(commit);
blameLine.setWhen(when); blameLine.setWhen(when);
@@ -142,20 +141,20 @@ public class GitBlameViewer implements BlameViewer
blameLine.setRevision(rev); blameLine.setRevision(rev);
String content = blameResult.getResultContents().getString(i); String content = gitBlameResult.getResultContents().getString(i);
blameLine.setCode(content); blameLine.setCode(content);
blameLines.add(blameLine); blameLines.add(blameLine);
} }
blamePagingResult = new BlamePagingResult(total, blameLines); blameResult = new sonia.scm.repository.BlameResult(total, blameLines);
} }
catch (IOException ex) catch (IOException ex)
{ {
logger.error("could not open repository", ex); logger.error("could not open repository", ex);
} }
return blamePagingResult; return blameResult;
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------

View File

@@ -118,7 +118,7 @@ public class HgBlameViewer implements BlameViewer
* @throws IOException * @throws IOException
*/ */
@Override @Override
public BlamePagingResult getBlame(String revision, String path) public BlameResult getBlame(String revision, String path)
throws IOException throws IOException
{ {
AssertUtil.assertIsNotEmpty(path); AssertUtil.assertIsNotEmpty(path);
@@ -146,7 +146,7 @@ public class HgBlameViewer implements BlameViewer
Process p = builder.directory(repositoryDirectory).start(); Process p = builder.directory(repositoryDirectory).start();
BufferedReader reader = null; BufferedReader reader = null;
BlamePagingResult result = null; BlameResult result = null;
try try
{ {
@@ -173,7 +173,7 @@ public class HgBlameViewer implements BlameViewer
* *
* @throws IOException * @throws IOException
*/ */
private BlamePagingResult parseBlameInput(BufferedReader reader) private BlameResult parseBlameInput(BufferedReader reader)
throws IOException throws IOException
{ {
List<BlameLine> blameLines = new ArrayList<BlameLine>(); List<BlameLine> blameLines = new ArrayList<BlameLine>();
@@ -191,7 +191,7 @@ public class HgBlameViewer implements BlameViewer
line = reader.readLine(); line = reader.readLine();
} }
return new BlamePagingResult(blameLines.size(), blameLines); return new BlameResult(blameLines.size(), blameLines);
} }
/** /**

View File

@@ -95,7 +95,7 @@ public class SvnBlameViewer implements BlameViewer
* @return * @return
*/ */
@Override @Override
public BlamePagingResult getBlame(String revision, String path) public BlameResult getBlame(String revision, String path)
{ {
List<BlameLine> blameLines = new ArrayList<BlameLine>(); List<BlameLine> blameLines = new ArrayList<BlameLine>();
File directory = handler.getDirectory(repository); File directory = handler.getDirectory(repository);
@@ -130,7 +130,7 @@ public class SvnBlameViewer implements BlameViewer
logger.error("could not create blame view", ex); logger.error("could not create blame view", ex);
} }
return new BlamePagingResult(blameLines.size(), blameLines); return new BlameResult(blameLines.size(), blameLines);
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------

View File

@@ -36,7 +36,7 @@ package sonia.scm.api.rest;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import sonia.scm.repository.BlameLine; import sonia.scm.repository.BlameLine;
import sonia.scm.repository.BlamePagingResult; import sonia.scm.repository.BlameResult;
import sonia.scm.util.Util; import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
@@ -62,7 +62,7 @@ import javax.ws.rs.ext.Provider;
*/ */
@Provider @Provider
public class PlainBlameProvider public class PlainBlameProvider
extends AbstractMessageReaderWriterProvider<BlamePagingResult> extends AbstractMessageReaderWriterProvider<BlameResult>
{ {
/** /**
@@ -82,7 +82,7 @@ public class PlainBlameProvider
* @throws WebApplicationException * @throws WebApplicationException
*/ */
@Override @Override
public BlamePagingResult readFrom(Class<BlamePagingResult> type, public BlameResult readFrom(Class<BlameResult> type,
Type genericType, Annotation[] annotations, Type genericType, Annotation[] annotations,
MediaType mediaType, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, MultivaluedMap<String, String> httpHeaders,
@@ -108,7 +108,7 @@ public class PlainBlameProvider
* @throws WebApplicationException * @throws WebApplicationException
*/ */
@Override @Override
public void writeTo(BlamePagingResult bpr, Class<?> type, Type genericType, public void writeTo(BlameResult bpr, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) OutputStream entityStream)
@@ -166,7 +166,7 @@ public class PlainBlameProvider
public boolean isWriteable(Class<?> type, Type genericType, public boolean isWriteable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) Annotation[] annotations, MediaType mediaType)
{ {
return (type == BlamePagingResult.class) return (type == BlameResult.class)
&& mediaType.equals(MediaType.TEXT_PLAIN_TYPE); && mediaType.equals(MediaType.TEXT_PLAIN_TYPE);
} }
} }

View File

@@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
import sonia.scm.NotSupportedFeatuerException; import sonia.scm.NotSupportedFeatuerException;
import sonia.scm.config.ScmConfiguration; import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.BlamePagingResult; import sonia.scm.repository.BlameResult;
import sonia.scm.repository.BlameViewerUtil; import sonia.scm.repository.BlameViewerUtil;
import sonia.scm.repository.BrowserResult; import sonia.scm.repository.BrowserResult;
import sonia.scm.repository.ChangesetPagingResult; import sonia.scm.repository.ChangesetPagingResult;
@@ -161,7 +161,7 @@ public class RepositoryResource
{ {
AssertUtil.assertIsNotNull(path); AssertUtil.assertIsNotNull(path);
BlamePagingResult blamePagingResult = blameViewerUtil.getBlame(id, BlameResult blamePagingResult = blameViewerUtil.getBlame(id,
revision, path); revision, path);
if (blamePagingResult != null) if (blamePagingResult != null)