diff --git a/src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java b/src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java index 8f4678ce1c1b09e27e702fb7ea6c1b82f37044a6..711ecf98fdb63438bbe3db09af0ef545e6860089 100644 --- a/src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java +++ b/src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java @@ -10,6 +10,8 @@ import org.springframework.stereotype.Component; import org.springframework.util.FileSystemUtils; import org.tmatesoft.svn.core.*; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; +import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions; +import org.tmatesoft.svn.core.wc.SVNClientManager; import org.tmatesoft.svn.core.wc.SVNWCUtil; import org.tmatesoft.svn.core.wc2.SvnCheckout; import org.tmatesoft.svn.core.wc2.SvnOperationFactory; @@ -34,7 +36,7 @@ public class RepoUtil { String repoUrl = config.group(1); String username = config.group(2); - String password = config.group(3); // Not used for SSH authentication + String password = config.group(3); LOG.debug("Cloning repository: {}", repoUrl); @@ -57,7 +59,7 @@ public class RepoUtil { LOG.debug("Preparing clone..."); if (repoUrl.endsWith(".git")) { - // GIT Repository Clone + LOG.debug("Cloning Git repository..."); CloneCommand cloneCommand = Git.cloneRepository() .setDirectory(checkoutDirectory) .setURI(repoUrl); @@ -67,11 +69,9 @@ public class RepoUtil { cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)); } - LOG.debug("Cloning Git repository..."); cloneCommand.call().close(); - + LOG.info("Git repository successfully cloned to {}", checkoutDirectory.getAbsolutePath()); } else { - // SVN Repository Clone (including svn+ssh support) SvnOperationFactory operationFactory = new SvnOperationFactory(); try { SVNURL svnUrl = SVNURL.parseURIEncoded(repoUrl); @@ -80,37 +80,29 @@ public class RepoUtil { checkout.setSource(SvnTarget.fromURL(svnUrl)); checkout.setDepth(SVNDepth.INFINITY); - // **Use SSH authentication if URL starts with svn+ssh://** if (repoUrl.startsWith("svn+ssh://")) { - LOG.debug("Setting up SSH authentication for SVN..."); - - String sshPrivateKeyPath = "/home/appuser/.ssh/id_rsa"; - File privateKeyFile = new File(sshPrivateKeyPath); - + LOG.debug("Using SSH authentication for SVN..."); + File privateKeyFile = new File("/home/appuser/.ssh/id_rsa"); if (!privateKeyFile.exists()) { - LOG.error("SSH private key not found at: {}", sshPrivateKeyPath); + LOG.error("SSH private key not found at: {}", privateKeyFile.getAbsolutePath()); throw new SVNException(SVNErrorMessage.create(SVNErrorCode.AUTHN_CREDS_UNAVAILABLE, "SSH key not found")); } - + ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( - new File("/home/appuser/.ssh/id_rsa"), // Explicit SSH Key - username, - null, - new File("/home/appuser/.ssh/known_hosts"), // Explicit Known Hosts - false - ); - + privateKeyFile, username, new char[0], null, false); + DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true); + SVNClientManager clientManager = SVNClientManager.newInstance(options, authManager); operationFactory.setAuthenticationManager(authManager); } LOG.debug("Performing SVN checkout..."); checkout.run(); + LOG.info("SVN repository successfully cloned to {}", checkoutDirectory.getAbsolutePath()); } finally { operationFactory.dispose(); } } - // Handle subdirectory case if (!subDir.isEmpty()) { File sourceSubDir = new File(checkoutDirectory, subDir); if (sourceSubDir.exists()) { @@ -121,10 +113,8 @@ public class RepoUtil { } LOG.debug("Repository successfully cloned from {} to {}", repoUrl, targetDirectory); - } catch (IOException | GitAPIException | SVNException e) { LOG.error("Error while cloning repository: " + repoUrl, e); } } } -