added api to fetch a single changeset

This commit is contained in:
Sebastian Sdorra
2012-01-18 19:14:01 +01:00
parent 2d54bd540e
commit 9d29bcd743
6 changed files with 188 additions and 5 deletions

View File

@@ -44,6 +44,18 @@ import java.io.IOException;
public interface ChangesetViewer
{
/**
* Method description
*
*
* @param revision
*
* @return
*
* @since 1.12
*/
public Changeset getChangeset(String revision);
/**
* Method description
*

View File

@@ -50,6 +50,7 @@ import sonia.scm.util.Util;
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
/**
@@ -94,6 +95,100 @@ public class ChangesetViewerUtil extends PartCacheClearHook
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repository
* @param revision
*
* @return
*
* @since 1.12
*
* @throws NotSupportedFeatuerException
* @throws RepositoryException
*/
public Changeset getChangeset(Repository repository, String revision)
throws RepositoryException, NotSupportedFeatuerException
{
AssertUtil.assertIsNotNull(repository);
ChangesetViewer viewer = repositoryManager.getChangesetViewer(repository);
if (viewer == null)
{
throw new NotSupportedFeatuerException(
"ChangesetViewer is not supported for type ".concat(
repository.getType()));
}
Changeset changeset = null;
ChangesetViewerCacheKey key =
new ChangesetViewerCacheKey(repository.getId(), -1, -1);
ChangesetPagingResult result = cache.get(key);
if (result == null)
{
changeset = viewer.getChangeset(revision);
if (changeset != null)
{
callPreProcessors(changeset);
callPreProcessorFactories(repository, changeset);
result = new ChangesetPagingResult(1, Arrays.asList(changeset));
cache.put(key, result);
}
else
{
throw new RepositoryException("could not find changeset");
}
}
else
{
if (logger.isDebugEnabled())
{
logger.debug("fetch changesetviewer result from cache");
}
changeset = result.getChangesets().get(0);
}
return changeset;
}
/**
* Method description
*
*
* @param repositoryId
* @param revision
*
* @return
*
* @since 1.12
*
* @throws NotSupportedFeatuerException
* @throws RepositoryException
* @throws RepositoryNotFoundException
*/
public Changeset getChangeset(String repositoryId, String revision)
throws RepositoryNotFoundException, RepositoryException,
NotSupportedFeatuerException
{
AssertUtil.assertIsNotEmpty(repositoryId);
Repository repository = repositoryManager.get(repositoryId);
if (repository == null)
{
throw new RepositoryNotFoundException(
"could not find repository with id ".concat(repositoryId));
}
return getChangeset(repository, revision);
}
/**
* Method description
*
@@ -316,6 +411,30 @@ public class ChangesetViewerUtil extends PartCacheClearHook
}
}
/**
* Method description
*
*
* @param repository
* @param c
*/
private void callPreProcessorFactories(Repository repository, Changeset c)
{
if (Util.isNotEmpty(changesetPreProcessorFactorySet))
{
for (ChangesetPreProcessorFactory factory :
changesetPreProcessorFactorySet)
{
ChangesetPreProcessor cpp = factory.createPreProcessor(repository);
if (cpp != null)
{
cpp.process(c);
}
}
}
}
/**
* Method description
*
@@ -327,14 +446,25 @@ public class ChangesetViewerUtil extends PartCacheClearHook
if (Util.isNotEmpty(changesetPreProcessorSet))
{
for (Changeset c : changesets.getChangesets())
{
callPreProcessors(c);
}
}
}
/**
* Method description
*
*
* @param c
*/
private void callPreProcessors(Changeset c)
{
for (ChangesetPreProcessor cpp : changesetPreProcessorSet)
{
cpp.process(c);
}
}
}
}
//~--- inner classes --------------------------------------------------------

View File

@@ -81,6 +81,20 @@ public class GitChangesetViewer implements ChangesetViewer
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param revision
*
* @return
*/
@Override
public Changeset getChangeset(String revision)
{
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Method description
*

View File

@@ -41,7 +41,6 @@ import com.google.inject.Singleton;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import sonia.scm.NotSupportedFeatuerException;
import sonia.scm.Type;
import sonia.scm.io.FileSystem;
import sonia.scm.plugin.ext.Extension;

View File

@@ -103,6 +103,20 @@ public class HgChangesetViewer extends AbstractHgHandler
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param revision
*
* @return
*/
@Override
public Changeset getChangeset(String revision)
{
throw new UnsupportedOperationException("Not supported yet.");
}
/**
*
*

View File

@@ -82,6 +82,20 @@ public class SvnChangesetViewer implements ChangesetViewer
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param revision
*
* @return
*/
@Override
public Changeset getChangeset(String revision)
{
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Method description
*