]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Introduce Subversion support
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 14 Feb 2010 22:01:41 +0000 (22:01 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 14 Feb 2010 22:01:41 +0000 (22:01 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3334 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/svn/SvnKitDriver.java [new file with mode: 0644]

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 (file)
index 0000000..6ad668d
--- /dev/null
@@ -0,0 +1,131 @@
+package org.argeo.slc.lib.svn;\r
+\r
+import java.io.File;\r
+import java.io.OutputStream;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
+import org.argeo.slc.SlcException;\r
+import org.argeo.slc.deploy.VersioningDriver;\r
+import org.tmatesoft.svn.core.SVNException;\r
+import org.tmatesoft.svn.core.SVNURL;\r
+import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;\r
+import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;\r
+import org.tmatesoft.svn.core.io.SVNRepository;\r
+import org.tmatesoft.svn.core.wc.SVNClientManager;\r
+import org.tmatesoft.svn.core.wc.SVNRevision;\r
+import org.tmatesoft.svn.core.wc.admin.ISVNChangeEntryHandler;\r
+import org.tmatesoft.svn.core.wc.admin.SVNChangeEntry;\r
+\r
+public class SvnKitDriver implements VersioningDriver {\r
+       private final SVNClientManager manager;\r
+\r
+       public SvnKitDriver() {\r
+                DAVRepositoryFactory.setup();\r
+                FSRepositoryFactory.setup();\r
+               manager = SVNClientManager.newInstance();\r
+       }\r
+\r
+       public void updateToHead(File fileOrDir) {\r
+               try {\r
+                       manager.getUpdateClient().doUpdate(fileOrDir, SVNRevision.HEAD,\r
+                                       true);\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot update " + fileOrDir, e);\r
+               }\r
+       }\r
+\r
+       public void importFileOrDir(String repositoryUrl, File fileOrDir) {\r
+               try {\r
+                       manager.getCommitClient().doImport(fileOrDir,\r
+                                       SVNURL.parseURIDecoded(repositoryUrl),\r
+                                       "Import " + fileOrDir, true);\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot import " + repositoryUrl + " to "\r
+                                       + fileOrDir, e);\r
+               }\r
+       }\r
+\r
+       public void checkout(String repositoryUrl, File destDir, Boolean recursive) {\r
+               try {\r
+                       manager.getUpdateClient().doCheckout(\r
+                                       SVNURL.parseURIDecoded(repositoryUrl), destDir,\r
+                                       SVNRevision.UNDEFINED, SVNRevision.HEAD, recursive);\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot checkout " + repositoryUrl + " to "\r
+                                       + destDir, e);\r
+               }\r
+       }\r
+\r
+       public void getFileFromRepository(String repositoryBaseUrl,\r
+                       String location, OutputStream out) {\r
+               try {\r
+                       SVNURL url = SVNURL.parseURIDecoded(repositoryBaseUrl);\r
+                       SVNRepository repo = manager.createRepository(url, true);\r
+                       repo.getFile(location, -1, null, out);\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot retrieve file " + location\r
+                                       + " from " + repositoryBaseUrl, e);\r
+               }\r
+\r
+       }\r
+\r
+       public String getRelativePath(String repositoryUrl) {\r
+               try {\r
+                       SVNURL url = SVNURL.parseURIDecoded(repositoryUrl);\r
+                       SVNRepository repo = manager.createRepository(url, true);\r
+                       return repo.getRepositoryPath("");\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot get relative path for "\r
+                                       + repositoryUrl, e);\r
+               }\r
+       }\r
+\r
+       public String getRepositoryRoot(String repositoryUrl) {\r
+               try {\r
+                       SVNURL url = SVNURL.parseURIDecoded(repositoryUrl);\r
+                       SVNRepository repo = manager.createRepository(url, true);\r
+                       return repo.getRepositoryRoot(true).toDecodedString();\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot get repository root for "\r
+                                       + repositoryUrl, e);\r
+               }\r
+       }\r
+\r
+       public List<String> getChangedPaths(File repositoryRoot, Long revision) {\r
+               try {\r
+                       final List<String> paths = new Vector<String>();\r
+                       ISVNChangeEntryHandler handler = new ISVNChangeEntryHandler() {\r
+                               public void handleEntry(SVNChangeEntry entry)\r
+                                               throws SVNException {\r
+                                       paths.add(entry.getPath());\r
+                               }\r
+                       };\r
+                       manager.getLookClient().doGetChanged(repositoryRoot,\r
+                                       SVNRevision.create(revision), handler, false);\r
+                       return paths;\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot get changed paths at "\r
+                                       + repositoryRoot + " for revision " + revision, e);\r
+               }\r
+       }\r
+\r
+       public void createRepository(String filePath) {\r
+               try {\r
+                       manager.getAdminClient().doCreateRepository(new File(filePath),\r
+                                       null, false, false);\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot create repository " + filePath, e);\r
+               }\r
+       }\r
+\r
+       public void commit(File fileOrDir, String commitMessage) {\r
+               try {\r
+                       manager.getCommitClient().doCommit(new File[] { fileOrDir }, true,\r
+                                       commitMessage, false, true);\r
+               } catch (Exception e) {\r
+                       throw new SlcException("Cannot commit " + fileOrDir, e);\r
+               }\r
+       }\r
+\r
+}\r