2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.lib
.svn
;
20 import java
.io
.OutputStream
;
21 import java
.util
.List
;
22 import java
.util
.Vector
;
24 import org
.argeo
.slc
.SlcException
;
25 import org
.argeo
.slc
.deploy
.VersioningDriver
;
26 import org
.tmatesoft
.svn
.core
.SVNException
;
27 import org
.tmatesoft
.svn
.core
.SVNURL
;
28 import org
.tmatesoft
.svn
.core
.internal
.io
.dav
.DAVRepositoryFactory
;
29 import org
.tmatesoft
.svn
.core
.internal
.io
.fs
.FSRepositoryFactory
;
30 import org
.tmatesoft
.svn
.core
.io
.SVNRepository
;
31 import org
.tmatesoft
.svn
.core
.wc
.SVNClientManager
;
32 import org
.tmatesoft
.svn
.core
.wc
.SVNRevision
;
33 import org
.tmatesoft
.svn
.core
.wc
.admin
.ISVNChangeEntryHandler
;
34 import org
.tmatesoft
.svn
.core
.wc
.admin
.SVNChangeEntry
;
36 public class SvnKitDriver
implements VersioningDriver
{
37 private final SVNClientManager manager
;
39 public SvnKitDriver() {
40 DAVRepositoryFactory
.setup();
41 FSRepositoryFactory
.setup();
42 manager
= SVNClientManager
.newInstance();
45 @SuppressWarnings("deprecation")
46 public void updateToHead(File fileOrDir
) {
48 manager
.getUpdateClient().doUpdate(fileOrDir
, SVNRevision
.HEAD
,
50 } catch (Exception e
) {
51 throw new SlcException("Cannot update " + fileOrDir
, e
);
55 @SuppressWarnings("deprecation")
56 public void importFileOrDir(String repositoryUrl
, File fileOrDir
) {
58 manager
.getCommitClient().doImport(fileOrDir
,
59 SVNURL
.parseURIDecoded(repositoryUrl
),
60 "Import " + fileOrDir
, true);
61 } catch (Exception e
) {
62 throw new SlcException("Cannot import " + repositoryUrl
+ " to "
67 @SuppressWarnings("deprecation")
68 public void checkout(String repositoryUrl
, File destDir
, Boolean recursive
) {
70 manager
.getUpdateClient().doCheckout(
71 SVNURL
.parseURIDecoded(repositoryUrl
), destDir
,
72 SVNRevision
.UNDEFINED
, SVNRevision
.HEAD
, recursive
);
73 } catch (Exception e
) {
74 throw new SlcException("Cannot checkout " + repositoryUrl
+ " to "
79 public void getFileFromRepository(String repositoryBaseUrl
,
80 String location
, OutputStream out
) {
82 SVNURL url
= SVNURL
.parseURIDecoded(repositoryBaseUrl
);
83 SVNRepository repo
= manager
.createRepository(url
, true);
84 repo
.getFile(location
, -1, null, out
);
85 } catch (Exception e
) {
86 throw new SlcException("Cannot retrieve file " + location
87 + " from " + repositoryBaseUrl
, e
);
92 public String
getRelativePath(String repositoryUrl
) {
94 SVNURL url
= SVNURL
.parseURIDecoded(repositoryUrl
);
95 SVNRepository repo
= manager
.createRepository(url
, true);
96 return repo
.getRepositoryPath("");
97 } catch (Exception e
) {
98 throw new SlcException("Cannot get relative path for "
103 public String
getRepositoryRoot(String repositoryUrl
) {
105 SVNURL url
= SVNURL
.parseURIDecoded(repositoryUrl
);
106 SVNRepository repo
= manager
.createRepository(url
, true);
107 return repo
.getRepositoryRoot(true).toDecodedString();
108 } catch (Exception e
) {
109 throw new SlcException("Cannot get repository root for "
114 public List
<String
> getChangedPaths(File repositoryRoot
, Long revision
) {
116 final List
<String
> paths
= new Vector
<String
>();
117 ISVNChangeEntryHandler handler
= new ISVNChangeEntryHandler() {
118 public void handleEntry(SVNChangeEntry entry
)
119 throws SVNException
{
120 paths
.add(entry
.getPath());
123 manager
.getLookClient().doGetChanged(repositoryRoot
,
124 SVNRevision
.create(revision
), handler
, false);
126 } catch (Exception e
) {
127 throw new SlcException("Cannot get changed paths at "
128 + repositoryRoot
+ " for revision " + revision
, e
);
132 public void createRepository(String filePath
) {
134 manager
.getAdminClient().doCreateRepository(new File(filePath
),
136 } catch (Exception e
) {
137 throw new SlcException("Cannot create repository " + filePath
, e
);
141 @SuppressWarnings("deprecation")
142 public void commit(File fileOrDir
, String commitMessage
) {
144 manager
.getCommitClient().doCommit(new File
[] { fileOrDir
}, true,
145 commitMessage
, false, true);
146 } catch (Exception e
) {
147 throw new SlcException("Cannot commit " + fileOrDir
, e
);