From 30f514449459e50acf9e30eb75ef28492fd4c245 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 14 Feb 2010 22:01:41 +0000 Subject: [PATCH] Introduce Subversion support git-svn-id: https://svn.argeo.org/slc/trunk@3334 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../org/argeo/slc/lib/svn/SvnKitDriver.java | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/svn/SvnKitDriver.java diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/svn/SvnKitDriver.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/svn/SvnKitDriver.java new file mode 100644 index 000000000..6ad668dfd --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/svn/SvnKitDriver.java @@ -0,0 +1,131 @@ +package org.argeo.slc.lib.svn; + +import java.io.File; +import java.io.OutputStream; +import java.util.List; +import java.util.Vector; + +import org.argeo.slc.SlcException; +import org.argeo.slc.deploy.VersioningDriver; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; +import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; +import org.tmatesoft.svn.core.io.SVNRepository; +import org.tmatesoft.svn.core.wc.SVNClientManager; +import org.tmatesoft.svn.core.wc.SVNRevision; +import org.tmatesoft.svn.core.wc.admin.ISVNChangeEntryHandler; +import org.tmatesoft.svn.core.wc.admin.SVNChangeEntry; + +public class SvnKitDriver implements VersioningDriver { + private final SVNClientManager manager; + + public SvnKitDriver() { + DAVRepositoryFactory.setup(); + FSRepositoryFactory.setup(); + manager = SVNClientManager.newInstance(); + } + + public void updateToHead(File fileOrDir) { + try { + manager.getUpdateClient().doUpdate(fileOrDir, SVNRevision.HEAD, + true); + } catch (Exception e) { + throw new SlcException("Cannot update " + fileOrDir, e); + } + } + + public void importFileOrDir(String repositoryUrl, File fileOrDir) { + try { + manager.getCommitClient().doImport(fileOrDir, + SVNURL.parseURIDecoded(repositoryUrl), + "Import " + fileOrDir, true); + } catch (Exception e) { + throw new SlcException("Cannot import " + repositoryUrl + " to " + + fileOrDir, e); + } + } + + public void checkout(String repositoryUrl, File destDir, Boolean recursive) { + try { + manager.getUpdateClient().doCheckout( + SVNURL.parseURIDecoded(repositoryUrl), destDir, + SVNRevision.UNDEFINED, SVNRevision.HEAD, recursive); + } catch (Exception e) { + throw new SlcException("Cannot checkout " + repositoryUrl + " to " + + destDir, e); + } + } + + public void getFileFromRepository(String repositoryBaseUrl, + String location, OutputStream out) { + try { + SVNURL url = SVNURL.parseURIDecoded(repositoryBaseUrl); + SVNRepository repo = manager.createRepository(url, true); + repo.getFile(location, -1, null, out); + } catch (Exception e) { + throw new SlcException("Cannot retrieve file " + location + + " from " + repositoryBaseUrl, e); + } + + } + + public String getRelativePath(String repositoryUrl) { + try { + SVNURL url = SVNURL.parseURIDecoded(repositoryUrl); + SVNRepository repo = manager.createRepository(url, true); + return repo.getRepositoryPath(""); + } catch (Exception e) { + throw new SlcException("Cannot get relative path for " + + repositoryUrl, e); + } + } + + public String getRepositoryRoot(String repositoryUrl) { + try { + SVNURL url = SVNURL.parseURIDecoded(repositoryUrl); + SVNRepository repo = manager.createRepository(url, true); + return repo.getRepositoryRoot(true).toDecodedString(); + } catch (Exception e) { + throw new SlcException("Cannot get repository root for " + + repositoryUrl, e); + } + } + + public List getChangedPaths(File repositoryRoot, Long revision) { + try { + final List paths = new Vector(); + ISVNChangeEntryHandler handler = new ISVNChangeEntryHandler() { + public void handleEntry(SVNChangeEntry entry) + throws SVNException { + paths.add(entry.getPath()); + } + }; + manager.getLookClient().doGetChanged(repositoryRoot, + SVNRevision.create(revision), handler, false); + return paths; + } catch (Exception e) { + throw new SlcException("Cannot get changed paths at " + + repositoryRoot + " for revision " + revision, e); + } + } + + public void createRepository(String filePath) { + try { + manager.getAdminClient().doCreateRepository(new File(filePath), + null, false, false); + } catch (Exception e) { + throw new SlcException("Cannot create repository " + filePath, e); + } + } + + public void commit(File fileOrDir, String commitMessage) { + try { + manager.getCommitClient().doCommit(new File[] { fileOrDir }, true, + commitMessage, false, true); + } catch (Exception e) { + throw new SlcException("Cannot commit " + fileOrDir, e); + } + } + +} -- 2.39.5