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 public void updateToHead(File fileOrDir
) {
31 manager
.getUpdateClient().doUpdate(fileOrDir
, SVNRevision
.HEAD
,
33 } catch (Exception e
) {
34 throw new SlcException("Cannot update " + fileOrDir
, e
);
38 public void importFileOrDir(String repositoryUrl
, File fileOrDir
) {
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 "
49 public void checkout(String repositoryUrl
, File destDir
, Boolean recursive
) {
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 "
60 public void getFileFromRepository(String repositoryBaseUrl
,
61 String location
, OutputStream out
) {
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
);
73 public String
getRelativePath(String repositoryUrl
) {
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 "
84 public String
getRepositoryRoot(String repositoryUrl
) {
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 "
95 public List
<String
> getChangedPaths(File repositoryRoot
, Long revision
) {
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());
104 manager
.getLookClient().doGetChanged(repositoryRoot
,
105 SVNRevision
.create(revision
), handler
, false);
107 } catch (Exception e
) {
108 throw new SlcException("Cannot get changed paths at "
109 + repositoryRoot
+ " for revision " + revision
, e
);
113 public void createRepository(String filePath
) {
115 manager
.getAdminClient().doCreateRepository(new File(filePath
),
117 } catch (Exception e
) {
118 throw new SlcException("Cannot create repository " + filePath
, e
);
122 public void commit(File fileOrDir
, String commitMessage
) {
124 manager
.getCommitClient().doCommit(new File
[] { fileOrDir
}, true,
125 commitMessage
, false, true);
126 } catch (Exception e
) {
127 throw new SlcException("Cannot commit " + fileOrDir
, e
);