added SvnRepositoryViewer

This commit is contained in:
Sebastian Sdorra
2011-04-04 08:07:27 +02:00
parent fa6b85f627
commit e2eabd7d3c
2 changed files with 191 additions and 0 deletions

View File

@@ -0,0 +1,159 @@
/**
* 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;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
*
* @author Sebastian Sdorra
*/
public class SvnChangesetViewer implements ChangesetViewer
{
/** the logger for SvnChangesetViewer */
private static final Logger logger =
LoggerFactory.getLogger(SvnChangesetViewer.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param handler
* @param repostory
*/
public SvnChangesetViewer(SvnRepositoryHandler handler, Repository repostory)
{
this.handler = handler;
this.repostory = repostory;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param start
* @param max
*
* @return
*/
@Override
public ChangesetPagingResult getChangesets(int start, int max)
{
ChangesetPagingResult changesets = null;
File directory = handler.getDirectory(repostory);
SVNRepository repository = null;
try
{
repository = SVNRepositoryFactory.create(SVNURL.fromFile(directory));
long total = repository.getLatestRevision();
long startRev = total - start;
long endRev = total - start - (max - 1);
if (endRev < 0)
{
endRev = 0;
}
List<Changeset> changesetList = new ArrayList<Changeset>();
Collection<SVNLogEntry> entries = repository.log(new String[] { "" },
null, startRev, endRev, true, true);
for (SVNLogEntry entry : entries)
{
changesetList.add(createChangeset(entry));
}
changesets = new ChangesetPagingResult((int) total, changesetList);
}
catch (SVNException ex)
{
logger.error("could not open repository", ex);
}
finally
{
repository.closeSession();
}
return changesets;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param entry
*
* @return
*/
private Changeset createChangeset(SVNLogEntry entry)
{
return new Changeset(String.valueOf(entry.getRevision()),
entry.getDate().getTime(), entry.getAuthor(),
entry.getMessage());
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private SvnRepositoryHandler handler;
/** Field description */
private Repository repostory;
}

View File

@@ -45,6 +45,7 @@ import sonia.scm.Type;
import sonia.scm.io.FileSystem;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.store.StoreFactory;
import sonia.scm.util.AssertUtil;
//~--- JDK imports ------------------------------------------------------------
@@ -87,6 +88,37 @@ public class SvnRepositoryHandler
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
public ChangesetViewer getChangesetViewer(Repository repository)
{
SvnChangesetViewer changesetViewer = null;
AssertUtil.assertIsNotNull(repository);
String type = repository.getType();
AssertUtil.assertIsNotEmpty(type);
if (TYPE_NAME.equals(type))
{
changesetViewer = new SvnChangesetViewer(this, repository);
}
else
{
throw new IllegalArgumentException("mercurial repository is required");
}
return changesetViewer;
}
/**
* Method description
*