Commit 4c5aa346 authored by Can's avatar Can
Browse files

SVN+SSH

parent 90e44805
Pipeline #9151 passed with stage
...@@ -64,24 +64,7 @@ public class JGitUtil { ...@@ -64,24 +64,7 @@ public class JGitUtil {
cloneCommand.call().close(); cloneCommand.call().close();
} }
else { else {
SVNURL svnUrl = SVNURL.parseURIDecoded(config.group(1)); SVNUtil.checkoutRepository(config.group(1), config.group(2), config.group(3), targetPath);
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
final SvnCheckout checkout = svnOperationFactory.createCheckout();
checkout.setSingleTarget(SvnTarget.fromFile(checkoutDirectory));
checkout.setSource(SvnTarget.fromURL(svnUrl));
if (!config.group(2).equals("none") && !config.group(3).equals("none")) {
LOG.debug("Setting credentials");
svnOperationFactory.setAuthenticationManager(new BasicAuthenticationManager(config.group(2), config.group(3)));
}
checkout.run();
LOG.debug("SVN checkout completed successfully.");
} finally {
svnOperationFactory.dispose();
}
} }
//if an optional directory parameter was given //if an optional directory parameter was given
...@@ -98,8 +81,6 @@ public class JGitUtil { ...@@ -98,8 +81,6 @@ public class JGitUtil {
catch (GitAPIException e) { catch (GitAPIException e) {
LOG.error(String.format("Error while cloning from %s: could not read from Git", config.group(1)), e); LOG.error(String.format("Error while cloning from %s: could not read from Git", config.group(1)), e);
} }
catch (SVNException e) {
LOG.error(String.format("Error while cloning from %s: could not read from Svn", config.group(1)), e);
}
} }
} }
package de.hftstuttgart.dtabackend.utils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.auth.SVNAuthentication;
import org.tmatesoft.svn.core.auth.SVNSSHAuthentication;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import org.tmatesoft.svn.core.wc2.SvnCheckout;
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import java.io.File;
public class SVNUtil {
private static final Logger LOG = LogManager.getLogger(SVNUtil.class);
public static void checkoutRepository(String svnUrl, String username, String password, String targetPath) {
try {
SVNURL url = SVNURL.parseURIDecoded(svnUrl);
SvnOperationFactory operationFactory = new SvnOperationFactory();
SvnCheckout checkout = operationFactory.createCheckout();
checkout.setSingleTarget(SvnTarget.fromFile(new File(targetPath)));
checkout.setSource(SvnTarget.fromURL(url));
String protocol = url.getProtocol();
if (protocol.equals("https")) {
if (username != null && password != null) {
LOG.debug("Setting SVN credentials");
operationFactory.setAuthenticationManager(new BasicAuthenticationManager(username, password));
}
} else if (protocol.equals("svn+ssh")) {
LOG.debug("Setting credentials for SVN+SSH Authentication");
ISVNAuthenticationManager authManager = new BasicAuthenticationManager(new SVNAuthentication[] { new SVNSSHAuthentication(username, password, -1, false)});//SVNWCUtil.createDefaultAuthenticationManager(username, password);
operationFactory.setAuthenticationManager(authManager);
}
checkout.run();
LOG.debug("SVN checkout completed successfully.");
} catch (SVNException e) {
LOG.error("Error during SVN checkout", e);
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment