1 package org
.argeo
.slc
.lib
.svn
;
4 import java
.io
.OutputStream
;
6 import java
.util
.Vector
;
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
;
20 public class SvnKitDriver
implements VersioningDriver
{
21 private final SVNClientManager manager
;
23 public SvnKitDriver() {
24 DAVRepositoryFactory
.setup();
25 FSRepositoryFactory
.setup();
26 manager
= SVNClientManager
.newInstance();
29 @SuppressWarnings("deprecation")
30 public void updateToHead(File fileOrDir
) {
32 manager
.getUpdateClient().doUpdate(fileOrDir
, SVNRevision
.HEAD
,
34 } catch (Exception e
) {
35 throw new SlcException("Cannot update " + fileOrDir
, e
);
39 @SuppressWarnings("deprecation")
40 public void importFileOrDir(String repositoryUrl
, File fileOrDir
) {
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 "
51 @SuppressWarnings("deprecation")
52 public void checkout(String repositoryUrl
, File destDir
, Boolean recursive
) {
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 "
63 public void getFileFromRepository(String repositoryBaseUrl
,
64 String location
, OutputStream out
) {
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
);
76 public String
getRelativePath(String repositoryUrl
) {
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 "
87 public String
getRepositoryRoot(String repositoryUrl
) {
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 "
98 public List
<String
> getChangedPaths(File repositoryRoot
, Long revision
) {
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());
107 manager
.getLookClient().doGetChanged(repositoryRoot
,
108 SVNRevision
.create(revision
), handler
, false);
110 } catch (Exception e
) {
111 throw new SlcException("Cannot get changed paths at "
112 + repositoryRoot
+ " for revision " + revision
, e
);
116 public void createRepository(String filePath
) {
118 manager
.getAdminClient().doCreateRepository(new File(filePath
),
120 } catch (Exception e
) {
121 throw new SlcException("Cannot create repository " + filePath
, e
);
125 @SuppressWarnings("deprecation")
126 public void commit(File fileOrDir
, String commitMessage
) {
128 manager
.getCommitClient().doCommit(new File
[] { fileOrDir
}, true,
129 commitMessage
, false, true);
130 } catch (Exception e
) {
131 throw new SlcException("Cannot commit " + fileOrDir
, e
);