Skip to content

Instantly share code, notes, and snippets.

@vs
Created February 16, 2011 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vs/829335 to your computer and use it in GitHub Desktop.
Save vs/829335 to your computer and use it in GitHub Desktop.
SVNKit API to work with ~/.subversion/ configuration area.
package org.tmatesoft.svn.util;
import java.io.File;
import java.util.Arrays;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNHostOptionsProvider;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.internal.wc.ISVNHostOptionsProvider;
import org.tmatesoft.svn.core.internal.wc.SVNCompositeConfigFile;
import org.tmatesoft.svn.core.internal.wc.SVNConfigFile;
import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
/**
* @author <a href="semen.vadishev@svnkit.com">Semen Vadishev</a>
*/
public class Test {
public static void main(String[] args) throws SVNException {
DefaultSVNAuthenticationManager manager = (DefaultSVNAuthenticationManager) SVNWCUtil.createDefaultAuthenticationManager();
// API to work with ~/.subversion/config
DefaultSVNOptions defaultOptions = manager.getDefaultOptions();
// API to work with ~/.subversion/servers
ISVNHostOptionsProvider hostOptionsProvider = manager.getHostOptionsProvider();
// 1. Get password storage types:
String[] passwordStorageTypes = defaultOptions.getPasswordStorageTypes();
System.out.println(Arrays.toString(passwordStorageTypes));
// Be careful: SVNKit default password storage types != Subversion default password storage types
// SVNKit doesn't yet support 'kwallet', so this type won't be listed if ~/.subversion/config has no option
// [auth] password-stores = XXX
// (or this option is commented)
// To workaround that you may try do the following:
File configDirectory = SVNWCUtil.getDefaultConfigurationDirectory();
// Ensure all configuration files exist
SVNConfigFile.createDefaultConfiguration(configDirectory);
SVNConfigFile userConfig = new SVNConfigFile(new File(configDirectory, "config"));
SVNConfigFile systemConfig = new SVNConfigFile(new File(SVNFileUtil.getSystemConfigurationDirectory(), "config"));
SVNCompositeConfigFile configFile = new SVNCompositeConfigFile(systemConfig, userConfig);
String passwordStoresValue = configFile.getPropertyValue("auth", "password-stores");
// Then you may parse passwordStoresValue or use our API.
if (passwordStoresValue == null) {
passwordStorageTypes = new String[]{"gnome-keyring", "kwallet", "keychain", "windows-cryptoapi"};
} else {
passwordStorageTypes = defaultOptions.getPasswordStorageTypes();
}
System.out.println(Arrays.toString(passwordStorageTypes));
// 2. Get necessary options from ~/.subversion/servers with fallback to ~/.subversion/config options.
SVNURL url = SVNURL.parseURIEncoded("http://svn.svnkit.com/repos/svnkit");
hostOptionsProvider.getHostOptions(url).isAuthStorageEnabled();
hostOptionsProvider.getHostOptions(url).isStorePasswords();
hostOptionsProvider.getHostOptions(url).isStorePlainTextPasswords(null, null);
hostOptionsProvider.getHostOptions(url).isStorePlainTextPasswords(null, null);
// etc.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment