-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathSvnToolsPluginExtension.groovy
60 lines (52 loc) · 1.98 KB
/
SvnToolsPluginExtension.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package at.bxm.gradleplugins.svntools
import at.bxm.gradleplugins.svntools.api.SvnData
import at.bxm.gradleplugins.svntools.api.SvnVersionData
import at.bxm.gradleplugins.svntools.internal.SvnProxy
import at.bxm.gradleplugins.svntools.internal.SvnSupport
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Project
import org.tmatesoft.svn.core.SVNException
import org.tmatesoft.svn.core.SVNURL
/** Holds configuration values shared by all SVN tasks and provides SVN information about the current workspace */
class SvnToolsPluginExtension {
private final Project project
String username
String password
final SvnProxy proxy = new SvnProxy()
SvnData info
SvnVersionData version
SvnToolsPluginExtension(Project project) {
this.project = project
}
/** @return svn-info for the project directory (cached) */
SvnData getInfo() {
if (!info) {
info = SvnSupport.createSvnData(project.projectDir, username, password, proxy, true)
}
return info
}
/** Convenience method for receiving SVN status data for an arbitrary path (https://github.com/martoe/gradle-svntools-plugin/issues/21) */
SvnData getInfo(File file) {
return SvnSupport.createSvnData(file, username, password, proxy, false)
}
/** @return svn-version for the project directory (cached) */
SvnVersionData getVersion() {
if (!version) {
version = SvnSupport.createSvnVersionData(project.projectDir, username, password, proxy, true)
}
return version
}
/**
* Retrieves SVN status data for a path within a remote repository
* @param repoUrl An SVN repository URL
* @param filePath An optional path within the repository
*/
SvnData getRemoteInfo(String repoUrl, String filePath = null) {
try {
SVNURL url = SVNURL.parseURIEncoded(repoUrl)
return SvnSupport.createSvnData(url, filePath ?: "/", username, password, proxy, false)
} catch (SVNException e) {
throw new InvalidUserDataException("Invalid svnUrl value: $repoUrl", e)
}
}
}