]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/svn/SvnKitDriver.java
Introduction of annotation to handle MVC flows // Class cleaning
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / lib / svn / SvnKitDriver.java
1 package org.argeo.slc.lib.svn;
2
3 import java.io.File;
4 import java.io.OutputStream;
5 import java.util.List;
6 import java.util.Vector;
7
8 import org.argeo.slc.SlcException;
9 import org.argeo.slc.deploy.VersioningDriver;
10 import org.tmatesoft.svn.core.SVNException;
11 import org.tmatesoft.svn.core.SVNURL;
12 import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
13 import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
14 import org.tmatesoft.svn.core.io.SVNRepository;
15 import org.tmatesoft.svn.core.wc.SVNClientManager;
16 import org.tmatesoft.svn.core.wc.SVNRevision;
17 import org.tmatesoft.svn.core.wc.admin.ISVNChangeEntryHandler;
18 import org.tmatesoft.svn.core.wc.admin.SVNChangeEntry;
19
20 public class SvnKitDriver implements VersioningDriver {
21 private final SVNClientManager manager;
22
23 public SvnKitDriver() {
24 DAVRepositoryFactory.setup();
25 FSRepositoryFactory.setup();
26 manager = SVNClientManager.newInstance();
27 }
28
29 public void updateToHead(File fileOrDir) {
30 try {
31 manager.getUpdateClient().doUpdate(fileOrDir, SVNRevision.HEAD,
32 true);
33 } catch (Exception e) {
34 throw new SlcException("Cannot update " + fileOrDir, e);
35 }
36 }
37
38 public void importFileOrDir(String repositoryUrl, File fileOrDir) {
39 try {
40 manager.getCommitClient().doImport(fileOrDir,
41 SVNURL.parseURIDecoded(repositoryUrl),
42 "Import " + fileOrDir, true);
43 } catch (Exception e) {
44 throw new SlcException("Cannot import " + repositoryUrl + " to "
45 + fileOrDir, e);
46 }
47 }
48
49 public void checkout(String repositoryUrl, File destDir, Boolean recursive) {
50 try {
51 manager.getUpdateClient().doCheckout(
52 SVNURL.parseURIDecoded(repositoryUrl), destDir,
53 SVNRevision.UNDEFINED, SVNRevision.HEAD, recursive);
54 } catch (Exception e) {
55 throw new SlcException("Cannot checkout " + repositoryUrl + " to "
56 + destDir, e);
57 }
58 }
59
60 public void getFileFromRepository(String repositoryBaseUrl,
61 String location, OutputStream out) {
62 try {
63 SVNURL url = SVNURL.parseURIDecoded(repositoryBaseUrl);
64 SVNRepository repo = manager.createRepository(url, true);
65 repo.getFile(location, -1, null, out);
66 } catch (Exception e) {
67 throw new SlcException("Cannot retrieve file " + location
68 + " from " + repositoryBaseUrl, e);
69 }
70
71 }
72
73 public String getRelativePath(String repositoryUrl) {
74 try {
75 SVNURL url = SVNURL.parseURIDecoded(repositoryUrl);
76 SVNRepository repo = manager.createRepository(url, true);
77 return repo.getRepositoryPath("");
78 } catch (Exception e) {
79 throw new SlcException("Cannot get relative path for "
80 + repositoryUrl, e);
81 }
82 }
83
84 public String getRepositoryRoot(String repositoryUrl) {
85 try {
86 SVNURL url = SVNURL.parseURIDecoded(repositoryUrl);
87 SVNRepository repo = manager.createRepository(url, true);
88 return repo.getRepositoryRoot(true).toDecodedString();
89 } catch (Exception e) {
90 throw new SlcException("Cannot get repository root for "
91 + repositoryUrl, e);
92 }
93 }
94
95 public List<String> getChangedPaths(File repositoryRoot, Long revision) {
96 try {
97 final List<String> paths = new Vector<String>();
98 ISVNChangeEntryHandler handler = new ISVNChangeEntryHandler() {
99 public void handleEntry(SVNChangeEntry entry)
100 throws SVNException {
101 paths.add(entry.getPath());
102 }
103 };
104 manager.getLookClient().doGetChanged(repositoryRoot,
105 SVNRevision.create(revision), handler, false);
106 return paths;
107 } catch (Exception e) {
108 throw new SlcException("Cannot get changed paths at "
109 + repositoryRoot + " for revision " + revision, e);
110 }
111 }
112
113 public void createRepository(String filePath) {
114 try {
115 manager.getAdminClient().doCreateRepository(new File(filePath),
116 null, false, false);
117 } catch (Exception e) {
118 throw new SlcException("Cannot create repository " + filePath, e);
119 }
120 }
121
122 public void commit(File fileOrDir, String commitMessage) {
123 try {
124 manager.getCommitClient().doCommit(new File[] { fileOrDir }, true,
125 commitMessage, false, true);
126 } catch (Exception e) {
127 throw new SlcException("Cannot commit " + fileOrDir, e);
128 }
129 }
130
131 }