Skip to content

Commit aa69509

Browse files
authored
Merge pull request #51 from Taeradan/master
configure SVN proxy using system properties
2 parents 56bdd2e + 57f1ec4 commit aa69509

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/main/groovy/net/nemerosa/versioning/svn/SVNInfoService.groovy

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.tmatesoft.svn.core.SVNDirEntry
1111
import org.tmatesoft.svn.core.SVNException
1212
import org.tmatesoft.svn.core.SVNURL
1313
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager
14+
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager
1415
import org.tmatesoft.svn.core.auth.SVNAuthentication
1516
import org.tmatesoft.svn.core.wc.*
1617

@@ -182,19 +183,38 @@ class SVNInfoService implements SCMInfoService {
182183
*/
183184
protected static SVNClientManager getClientManager(VersioningExtension extension) {
184185
def clientManager = SVNClientManager.newInstance()
186+
ISVNAuthenticationManager authenticationManager
185187
if (extension.user && extension.password) {
186188
LOGGER.info("[version] Authenticating with ${extension.user}")
187-
clientManager.setAuthenticationManager(BasicAuthenticationManager.newInstance(extension.user, extension.password.toCharArray()))
189+
authenticationManager = configureProxy(BasicAuthenticationManager.newInstance(extension.user, extension.password.toCharArray()))
188190
// The BasicAuthenticationManager trusts the certificates by default
189191
} else if (extension.trustServerCert) {
190192
LOGGER.info("[version] Trusting certificate by default")
191193
LOGGER.warn("[version] WARNING The `trustServerCert` is now deprecated - and should not be used any longer.")
192-
clientManager.setAuthenticationManager(BasicAuthenticationManager.newInstance(new SVNAuthentication[0]))
194+
authenticationManager = configureProxy(BasicAuthenticationManager.newInstance(new SVNAuthentication[0]))
193195
} else {
194196
LOGGER.info("[version] Using default SVN configuration")
195-
clientManager.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager())
197+
authenticationManager = SVNWCUtil.createDefaultAuthenticationManager()
196198
}
199+
clientManager.setAuthenticationManager(authenticationManager)
197200
return clientManager
198201
}
199202

203+
private static BasicAuthenticationManager configureProxy(BasicAuthenticationManager authenticationManager) {
204+
def properties= System.properties
205+
def proxyHost = properties.getProperty('http.proxyHost')
206+
def proxyPort = properties.getProperty('http.proxyPort')
207+
def proxyUser = properties.getProperty('http.proxyUser')
208+
def proxyPassword = properties.getProperty('http.proxyPassword')
209+
if (proxyHost != null && proxyPort != null) {
210+
if (proxyUser != null && proxyPassword != null) {
211+
authenticationManager.setProxy(proxyHost, proxyPort as int, proxyUser, proxyPassword.toCharArray())
212+
} else {
213+
authenticationManager.setProxy(proxyHost, proxyPort as int, null, [] as char[])
214+
}
215+
}
216+
217+
return authenticationManager
218+
}
219+
200220
}

0 commit comments

Comments
 (0)