mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 19:45:51 +01:00
remove deprecated stuff
This commit is contained in:
@@ -1,148 +0,0 @@
|
||||
/**
|
||||
* 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.SVNURL;
|
||||
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||
import org.tmatesoft.svn.core.wc.SVNLogClient;
|
||||
import org.tmatesoft.svn.core.wc.SVNRevision;
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class description
|
||||
*
|
||||
*
|
||||
* @version Enter version here..., 11/09/14
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
public class SvnBlameViewer implements BlameViewer
|
||||
{
|
||||
|
||||
/** the logger for SvnChangesetViewer */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SvnChangesetViewer.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param repository
|
||||
*/
|
||||
public SvnBlameViewer(SvnRepositoryHandler handler, Repository repository)
|
||||
{
|
||||
this.handler = handler;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BlameResult getBlame(String revision, String path)
|
||||
{
|
||||
List<BlameLine> blameLines = new ArrayList<BlameLine>();
|
||||
File directory = handler.getDirectory(repository);
|
||||
SVNRepository svnRepository = null;
|
||||
SVNURL svnurl = null;
|
||||
SVNRevision endRevision = null;
|
||||
|
||||
if (Util.isNotEmpty(revision))
|
||||
{
|
||||
endRevision = SVNRevision.create(Long.parseLong(revision));
|
||||
}
|
||||
else
|
||||
{
|
||||
endRevision = SVNRevision.HEAD;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
svnurl = SVNURL.fromFile(new File(directory, path));
|
||||
svnRepository = SVNRepositoryFactory.create(SVNURL.fromFile(directory));
|
||||
|
||||
ISVNAuthenticationManager svnManager =
|
||||
svnRepository.getAuthenticationManager();
|
||||
SVNLogClient svnLogClient = new SVNLogClient(svnManager, null);
|
||||
|
||||
svnLogClient.doAnnotate(svnurl, SVNRevision.UNDEFINED,
|
||||
SVNRevision.create(1l), endRevision,
|
||||
new SvnBlameHandler(svnRepository, path,
|
||||
blameLines));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("could not create blame view", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SvnUtil.closeSession(svnRepository);
|
||||
}
|
||||
|
||||
return new BlameResult(blameLines.size(), blameLines);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SvnRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
private Repository repository;
|
||||
}
|
||||
@@ -1,303 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
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 revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Changeset getChangeset(String revision)
|
||||
{
|
||||
Changeset changeset = null;
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("fetch changeset {}", revision);
|
||||
}
|
||||
|
||||
SVNRepository repository = null;
|
||||
|
||||
try
|
||||
{
|
||||
long revisioNumber = Long.parseLong(revision);
|
||||
|
||||
repository = createRepository();
|
||||
|
||||
Collection<SVNLogEntry> entries = repository.log(null, null,
|
||||
revisioNumber, revisioNumber, true,
|
||||
true);
|
||||
|
||||
if (Util.isNotEmpty(entries))
|
||||
{
|
||||
changeset = SvnUtil.createChangeset(entries.iterator().next());
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not convert revision", ex);
|
||||
}
|
||||
}
|
||||
catch (SVNException ex)
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SvnUtil.closeSession(repository);
|
||||
}
|
||||
|
||||
return changeset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param start
|
||||
* @param max
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ChangesetPagingResult getChangesets(int start, int max)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("fetch changesets. start: {}, max: {}", start, max);
|
||||
}
|
||||
|
||||
ChangesetPagingResult changesets = null;
|
||||
SVNRepository repository = null;
|
||||
|
||||
try
|
||||
{
|
||||
repository = createRepository();
|
||||
|
||||
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(null, null, startRev,
|
||||
endRev, true, true);
|
||||
|
||||
for (SVNLogEntry entry : entries)
|
||||
{
|
||||
changesetList.add(SvnUtil.createChangeset(entry));
|
||||
}
|
||||
|
||||
total++;
|
||||
changesets = new ChangesetPagingResult((int) total, changesetList);
|
||||
}
|
||||
catch (SVNException ex)
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SvnUtil.closeSession(repository);
|
||||
}
|
||||
|
||||
return changesets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
* @param revision
|
||||
* @param start
|
||||
* @param max
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ChangesetPagingResult getChangesets(String path, String revision,
|
||||
int start, int max)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(
|
||||
"fetch changesets for path {} and revision {}. start: {}, max: {}",
|
||||
new Object[] { path,
|
||||
revision, start, max });
|
||||
}
|
||||
|
||||
ChangesetPagingResult changesets = null;
|
||||
SVNRepository repository = null;
|
||||
|
||||
try
|
||||
{
|
||||
repository = createRepository();
|
||||
|
||||
long startRev = repository.getLatestRevision();
|
||||
long endRev = 0;
|
||||
long maxRev = startRev;
|
||||
|
||||
if (Util.isNotEmpty(revision))
|
||||
{
|
||||
try
|
||||
{
|
||||
maxRev = Long.parseLong(revision);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
logger.error("could not parse revision ".concat(revision), ex);
|
||||
}
|
||||
}
|
||||
|
||||
List<Changeset> changesetList = new ArrayList<Changeset>();
|
||||
Collection<SVNLogEntry> entries = repository.log(new String[] { path },
|
||||
null, startRev, endRev, true, true);
|
||||
|
||||
for (SVNLogEntry entry : entries)
|
||||
{
|
||||
if (entry.getRevision() <= maxRev)
|
||||
{
|
||||
changesetList.add(SvnUtil.createChangeset(entry));
|
||||
}
|
||||
}
|
||||
|
||||
int total = changesetList.size();
|
||||
int end = total - start;
|
||||
|
||||
if (end > max)
|
||||
{
|
||||
end = max;
|
||||
}
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
start = 0;
|
||||
}
|
||||
|
||||
changesetList = changesetList.subList(start, end);
|
||||
changesets = new ChangesetPagingResult(total, changesetList);
|
||||
}
|
||||
catch (SVNException ex)
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SvnUtil.closeSession(repository);
|
||||
}
|
||||
|
||||
return changesets;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SVNException
|
||||
*/
|
||||
private SVNRepository createRepository() throws SVNException
|
||||
{
|
||||
return SVNRepositoryFactory.create(
|
||||
SVNURL.fromFile(handler.getDirectory(repostory)));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SvnRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
private Repository repostory;
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
/**
|
||||
* 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.SVNDepth;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.wc.DefaultSVNDiffGenerator;
|
||||
import org.tmatesoft.svn.core.wc.ISVNDiffGenerator;
|
||||
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
||||
import org.tmatesoft.svn.core.wc.SVNDiffClient;
|
||||
import org.tmatesoft.svn.core.wc.SVNRevision;
|
||||
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class SvnDiffViewer implements DiffViewer
|
||||
{
|
||||
|
||||
/** the logger for SvnDiffViewer */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SvnDiffViewer.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
public SvnDiffViewer(File directory)
|
||||
{
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param repository
|
||||
*/
|
||||
public SvnDiffViewer(SvnRepositoryHandler handler, Repository repository)
|
||||
{
|
||||
this(handler.getDirectory(repository));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
* @param path
|
||||
* @param output
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void getDiff(String revision, String path, OutputStream output)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
AssertUtil.assertIsNotEmpty(revision);
|
||||
AssertUtil.assertIsNotNull(output);
|
||||
|
||||
SVNClientManager clientManager = null;
|
||||
|
||||
try
|
||||
{
|
||||
SVNURL svnurl = SVNURL.fromFile(directory);
|
||||
|
||||
if (Util.isNotEmpty(path))
|
||||
{
|
||||
svnurl = svnurl.appendPath(path, true);
|
||||
}
|
||||
|
||||
clientManager = SVNClientManager.newInstance();
|
||||
|
||||
SVNDiffClient diffClient = clientManager.getDiffClient();
|
||||
ISVNDiffGenerator diffGenerator = diffClient.getDiffGenerator();
|
||||
|
||||
if (diffGenerator == null)
|
||||
{
|
||||
diffGenerator = new DefaultSVNDiffGenerator();
|
||||
}
|
||||
|
||||
diffGenerator.setDiffAdded(true);
|
||||
diffGenerator.setDiffDeleted(true);
|
||||
diffClient.setDiffGenerator(diffGenerator);
|
||||
|
||||
long currentRev = Long.parseLong(revision);
|
||||
|
||||
diffClient.doDiff(svnurl, SVNRevision.HEAD,
|
||||
SVNRevision.create(currentRev - 1),
|
||||
SVNRevision.create(currentRev), SVNDepth.INFINITY,
|
||||
false, output);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("could not create diff", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SvnUtil.dispose(clientManager);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private File directory;
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
/**
|
||||
* 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.SVNDirEntry;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNNodeKind;
|
||||
import org.tmatesoft.svn.core.SVNProperties;
|
||||
import org.tmatesoft.svn.core.SVNProperty;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class SvnRepositoryBrowser implements RepositoryBrowser
|
||||
{
|
||||
|
||||
/** the logger for SvnRepositoryBrowser */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(SvnRepositoryBrowser.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param handler
|
||||
* @param repository
|
||||
*/
|
||||
public SvnRepositoryBrowser(SvnRepositoryHandler handler,
|
||||
Repository repository)
|
||||
{
|
||||
this.handler = handler;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* http://wiki.svnkit.com/Printing_Out_File_Contents
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
* @param path
|
||||
* @param output
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public void getContent(String revision, String path, OutputStream output)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
long revisionNumber = getRevisionNumber(revision);
|
||||
SVNRepository svnRepository = null;
|
||||
|
||||
try
|
||||
{
|
||||
svnRepository = getSvnRepository();
|
||||
svnRepository.getFile(path, revisionNumber, new SVNProperties(), output);
|
||||
}
|
||||
catch (SVNException ex)
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SvnUtil.closeSession(svnRepository);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public BrowserResult getResult(String revision, String path)
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
long revisionNumber = getRevisionNumber(revision);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("browser repository {} in path {} at revision {}",
|
||||
new Object[] { repository.getName(),
|
||||
path, revision });
|
||||
}
|
||||
|
||||
BrowserResult result = null;
|
||||
SVNRepository svnRepository = null;
|
||||
|
||||
try
|
||||
{
|
||||
svnRepository = getSvnRepository();
|
||||
|
||||
Collection<SVNDirEntry> entries =
|
||||
svnRepository.getDir(Util.nonNull(path), revisionNumber, null,
|
||||
(Collection) null);
|
||||
List<FileObject> children = new ArrayList<FileObject>();
|
||||
String basePath = Util.EMPTY_STRING;
|
||||
|
||||
if (Util.isNotEmpty(path))
|
||||
{
|
||||
basePath = path;
|
||||
|
||||
if (!basePath.endsWith("/"))
|
||||
{
|
||||
basePath = basePath.concat("/");
|
||||
}
|
||||
}
|
||||
|
||||
for (SVNDirEntry entry : entries)
|
||||
{
|
||||
children.add(createFileObject(svnRepository, revisionNumber, entry,
|
||||
basePath));
|
||||
}
|
||||
|
||||
result = new BrowserResult();
|
||||
result.setRevision(revision);
|
||||
result.setFiles(children);
|
||||
}
|
||||
catch (SVNException ex)
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SvnUtil.closeSession(svnRepository);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param revision
|
||||
* @param entry
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private FileObject createFileObject(SVNRepository repository, long revision,
|
||||
SVNDirEntry entry, String path)
|
||||
{
|
||||
FileObject fileObject = new FileObject();
|
||||
|
||||
fileObject.setName(entry.getName());
|
||||
fileObject.setPath(path.concat(entry.getRelativePath()));
|
||||
fileObject.setDirectory(entry.getKind() == SVNNodeKind.DIR);
|
||||
|
||||
if (entry.getDate() != null)
|
||||
{
|
||||
fileObject.setLastModified(entry.getDate().getTime());
|
||||
}
|
||||
|
||||
fileObject.setLength(entry.getSize());
|
||||
fileObject.setDescription(entry.getCommitMessage());
|
||||
|
||||
if (fileObject.isDirectory() && entry.hasProperties())
|
||||
{
|
||||
fetchExternalsProperty(repository, revision, entry, fileObject);
|
||||
}
|
||||
|
||||
return fileObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
* @param revision
|
||||
* @param entry
|
||||
* @param fileObject
|
||||
*/
|
||||
private void fetchExternalsProperty(SVNRepository repository, long revision,
|
||||
SVNDirEntry entry, FileObject fileObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
SVNProperties properties = new SVNProperties();
|
||||
|
||||
repository.getFile(entry.getRelativePath(), revision, properties, null);
|
||||
|
||||
String externals = properties.getStringValue(SVNProperty.EXTERNALS);
|
||||
|
||||
if (Util.isNotEmpty(externals))
|
||||
{
|
||||
SubRepository subRepository = new SubRepository(externals);
|
||||
|
||||
fileObject.setSubRepository(subRepository);
|
||||
}
|
||||
}
|
||||
catch (SVNException ex)
|
||||
{
|
||||
logger.error("could not fetch file properties");
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private long getRevisionNumber(String revision) throws RepositoryException
|
||||
{
|
||||
long revisionNumber = -1;
|
||||
|
||||
if (Util.isNotEmpty(revision))
|
||||
{
|
||||
try
|
||||
{
|
||||
revisionNumber = Long.parseLong(revision);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
throw new RepositoryException("given revision is not a svnrevision");
|
||||
}
|
||||
}
|
||||
|
||||
return revisionNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws SVNException
|
||||
*/
|
||||
private SVNRepository getSvnRepository() throws SVNException
|
||||
{
|
||||
File directory = handler.getDirectory(repository);
|
||||
|
||||
return SVNRepositoryFactory.create(SVNURL.fromFile(directory));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SvnRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
private Repository repository;
|
||||
}
|
||||
@@ -132,99 +132,6 @@ public class SvnRepositoryHandler
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BlameViewer getBlameViewer(Repository repository)
|
||||
{
|
||||
SvnBlameViewer blameViewer = null;
|
||||
|
||||
AssertUtil.assertIsNotNull(repository);
|
||||
|
||||
String type = repository.getType();
|
||||
|
||||
AssertUtil.assertIsNotEmpty(type);
|
||||
|
||||
if (TYPE_NAME.equals(type))
|
||||
{
|
||||
blameViewer = new SvnBlameViewer(this, repository);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("svn repository is required");
|
||||
}
|
||||
|
||||
return blameViewer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("svn repository is required");
|
||||
}
|
||||
|
||||
return changesetViewer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DiffViewer getDiffViewer(Repository repository)
|
||||
{
|
||||
SvnDiffViewer diffViewer = null;
|
||||
|
||||
AssertUtil.assertIsNotNull(repository);
|
||||
|
||||
String type = repository.getType();
|
||||
|
||||
AssertUtil.assertIsNotEmpty(type);
|
||||
|
||||
if (TYPE_NAME.equals(type))
|
||||
{
|
||||
diffViewer = new SvnDiffViewer(this, repository);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("svn repository is required");
|
||||
}
|
||||
|
||||
return diffViewer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -237,22 +144,6 @@ public class SvnRepositoryHandler
|
||||
return new SvnImportHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public RepositoryBrowser getRepositoryBrowser(Repository repository)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(repository);
|
||||
|
||||
return new SvnRepositoryBrowser(this, repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user