]> 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
Restructure SLC development environment
[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 @SuppressWarnings("deprecation")
30 public void updateToHead(File fileOrDir) {
31 try {
32 manager.getUpdateClient().doUpdate(fileOrDir, SVNRevision.HEAD,
33 true);
34 } catch (Exception e) {
35 throw new SlcException("Cannot update " + fileOrDir, e);
36 }
37 }
38
39 @SuppressWarnings("deprecation")
40 public void importFileOrDir(String repositoryUrl, File fileOrDir) {
41 try {
42 manager.getCommitClient().doImport(fileOrDir,
43 SVNURL.parseURIDecoded(repositoryUrl),
44 "Import " + fileOrDir, true);
45 } catch (Exception e) {
46 throw new SlcException("Cannot import " + repositoryUrl + " to "
47 + fileOrDir, e);
48 }
49 }
50
51 @SuppressWarnings("deprecation")
52 public void checkout(String repositoryUrl, File destDir, Boolean recursive) {
53 try {
54 manager.getUpdateClient().doCheckout(
55 SVNURL.parseURIDecoded(repositoryUrl), destDir,
56 SVNRevision.UNDEFINED, SVNRevision.HEAD, recursive);
57 } catch (Exception e) {
58 throw new SlcException("Cannot checkout " + repositoryUrl + " to "
59 + destDir, e);
60 }
61 }
62
63 public void getFileFromRepository(String repositoryBaseUrl,
64 String location, OutputStream out) {
65 try {
66 SVNURL url = SVNURL.parseURIDecoded(repositoryBaseUrl);
67 SVNRepository repo = manager.createRepository(url, true);
68 repo.getFile(location, -1, null, out);
69 } catch (Exception e) {
70 throw new SlcException("Cannot retrieve file " + location
71 + " from " + repositoryBaseUrl, e);
72 }
73
74 }
75
76 public String getRelativePath(String repositoryUrl) {
77 try {
78 SVNURL url = SVNURL.parseURIDecoded(repositoryUrl);
79 SVNRepository repo = manager.createRepository(url, true);
80 return repo.getRepositoryPath("");
81 } catch (Exception e) {
82 throw new SlcException("Cannot get relative path for "
83 + repositoryUrl, e);
84 }
85 }
86
87 public String getRepositoryRoot(String repositoryUrl) {
88 try {
89 SVNURL url = SVNURL.parseURIDecoded(repositoryUrl);
90 SVNRepository repo = manager.createRepository(url, true);
91 return repo.getRepositoryRoot(true).toDecodedString();
92 } catch (Exception e) {
93 throw new SlcException("Cannot get repository root for "
94 + repositoryUrl, e);
95 }
96 }
97
98 public List<String> getChangedPaths(File repositoryRoot, Long revision) {
99 try {
100 final List<String> paths = new Vector<String>();
101 ISVNChangeEntryHandler handler = new ISVNChangeEntryHandler() {
102 public void handleEntry(SVNChangeEntry entry)
103 throws SVNException {
104 paths.add(entry.getPath());
105 }
106 };
107 manager.getLookClient().doGetChanged(repositoryRoot,
108 SVNRevision.create(revision), handler, false);
109 return paths;
110 } catch (Exception e) {
111 throw new SlcException("Cannot get changed paths at "
112 + repositoryRoot + " for revision " + revision, e);
113 }
114 }
115
116 public void createRepository(String filePath) {
117 try {
118 manager.getAdminClient().doCreateRepository(new File(filePath),
119 null, false, false);
120 } catch (Exception e) {
121 throw new SlcException("Cannot create repository " + filePath, e);
122 }
123 }
124
125 @SuppressWarnings("deprecation")
126 public void commit(File fileOrDir, String commitMessage) {
127 try {
128 manager.getCommitClient().doCommit(new File[] { fileOrDir }, true,
129 commitMessage, false, true);
130 } catch (Exception e) {
131 throw new SlcException("Cannot commit " + fileOrDir, e);
132 }
133 }
134
135 }