org.tmatesoft.svn.core.auth.ISVNAuthenticationManager Java Examples

The following examples show how to use org.tmatesoft.svn.core.auth.ISVNAuthenticationManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SvnUtil.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
public static SVNRepository connectToSVNInstance(String url, String usr, String pass){
	SvnUtil.setupLibrary();
    SVNRepository repository = null;
    try {
    	repository = SvnUtil.createRepository(url);
    } 
    catch (SVNException svne) {
        System.err.println("error while creating an SVNRepository for location '"+ url + "': " + svne.getMessage());
        return null;
    }
    
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(usr, pass);
    repository.setAuthenticationManager(authManager);
    
    try {
    	SvnUtil.verifySVNLocation(repository, url);
	} catch (SVNException e) {
		e.printStackTrace();
	}
    
    return repository;
}
 
Example #2
Source File: SvnKitUtil.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 判断当前仓库url是否匹配
 *
 * @param wcDir    仓库路径
 * @param url      url
 * @param userName 用户名
 * @param userPwd  密码
 * @return true 匹配
 * @throws SVNException 异常
 */
private static Boolean checkUrl(File wcDir, String url, String userName, String userPwd) throws SVNException {
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(userName, userPwd.toCharArray());
    DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
    // 实例化客户端管理类
    SVNClientManager clientManager = SVNClientManager.newInstance(options, authManager);
    try {
        // 通过客户端管理类获得updateClient类的实例。
        SVNWCClient wcClient = clientManager.getWCClient();
        SVNInfo svnInfo = null;
        do {
            try {
                svnInfo = wcClient.doInfo(wcDir, SVNRevision.HEAD);
            } catch (SVNException svn) {
                if (svn.getErrorMessage().getErrorCode() == SVNErrorCode.FS_NOT_FOUND) {
                    checkOut(clientManager, url, wcDir);
                } else {
                    throw svn;
                }
            }
        } while (svnInfo == null);
        String reUrl = svnInfo.getURL().toString();
        return reUrl.equals(url);
    } finally {
        clientManager.dispose();
    }
}
 
Example #3
Source File: SvnClient.java    From steady with Apache License 2.0 5 votes vote down vote up
public File checkoutFile(String _rev, String _rel_path) {
	final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
	File f = null;
	SVNURL url = null;
	try {
		// Create subdir for given rev
		final String rel_dir = _rel_path.substring(0, _rel_path.lastIndexOf('/'));
		final Path rev_dir = Paths.get(this.workDir.toString(), _rev, rel_dir);
		Path p = Files.createDirectories(rev_dir);

		// Create SVNURL for specific file
		url = SVNURL.parseURIEncoded(this.rootRepo.getRepositoryRoot(false) + "/" + rel_dir);

		// Perform checkout
		SVNRevision revision = SVNRevision.create(Long.valueOf(_rev));

		SVNUpdateClient clnt = new SVNUpdateClient((ISVNAuthenticationManager)this.authManager, null);
		clnt.doCheckout(url, p.toFile(), revision, revision, SVNDepth.FILES, false); //IMMEDIATES, FILES, INFINITY

		//
		//			final SvnCheckout checkout = svnOperationFactory.createCheckout();
		//			checkout.setSingleTarget(SvnTarget.fromFile(p.toFile()));
		//			checkout.setSource(SvnTarget.fromURL(url));
		//			checkout.setDepth(SVNDepth.IMMEDIATES); //INFINITY
		//			checkout.setRevision(revision);
		//
		//			// Checkout and get file
		//			checkout.run();
		f = Paths.get(this.workDir.toString(), _rev, _rel_path).toFile();
	} catch (Exception e) {
		SvnClient.log.error("Error while checking out URL '" + url + "', revision "+ _rev + ": " + e.getMessage());
	} finally {
		svnOperationFactory.dispose();
	}
	return f;
}
 
Example #4
Source File: SvnTesterExternal.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
public SvnTesterExternal(@NotNull SVNURL url, @Nullable ISVNAuthenticationManager authManager) throws SVNException {
  this.url = url;
  this.authManager = authManager;
  this.suffix = UUID.randomUUID().toString();
  final SVNRepository repo = openSvnRepository(url);
  try {
    final ISVNEditor editor = repo.getCommitEditor("Create subdir for test", null, false, null);
    editor.openRoot(-1);
    editor.addDir(suffix, null, -1);
    editor.closeDir();
    editor.closeEdit();
  } finally {
    repo.closeSession();
  }
}
 
Example #5
Source File: SvnUtil.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
public static void authenticate(String usr, String pass, SVNRepository repo){
	ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(usr, pass);
    repo.setAuthenticationManager(authManager);
}