Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • C cota-backend
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 2
    • Issues 2
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CoTA
  • cota-backend
  • Merge requests
  • !2

SVN functionality support.

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged mamunozgil requested to merge amg-svn into master 7 months ago
  • Overview 2
  • Commits 4
  • Pipelines 2
  • Changes 1
1 unresolved thread

This branch fixes the code for SVN cloning. Solving issue #2 (closed)

  • mamunozgil @miguel.munoz-gil requested review from @gero.lueckemeyer 7 months ago

    requested review from @gero.lueckemeyer

  • mamunozgil @miguel.munoz-gil assigned to @miguel.munoz-gil 7 months ago

    assigned to @miguel.munoz-gil

    • Lückemeyer
      Lückemeyer @gero.lueckemeyer · 7 months ago

      Remark:

      • line 55: if (config.group(1).endsWith(".git") || config.group(1).contains("git")) { will interpret https://mylegitimatesvnproject as git. Please cut the || part.
    • mamunozgil
      mamunozgil @miguel.munoz-gil · 7 months ago

      You are right, I added a missbehaviour. Fixed now.

    • Please register or sign in to reply
  • mamunozgil @miguel.munoz-gil added 1 commit 7 months ago

    added 1 commit

    • 08131b4e - Fix: identify git repo

    Compare with previous version

  • mamunozgil @miguel.munoz-gil merged 6 months ago

    merged

  • mamunozgil @miguel.munoz-gil mentioned in commit 818a8421 6 months ago

    mentioned in commit 818a8421

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
Please register or sign in to reply
Compare
  • version 1
    be643784
    7 months ago

  • master (base)

and
  • latest version
    08131b4e
    4 commits, 7 months ago

  • version 1
    be643784
    3 commits, 7 months ago

1 file
+ 76
- 63

    Preferences

    File browser
    Compare changes
src/main/java/de/hftstuttgart/dtabackend/utils/RepoUtil.java
+ 76
- 63
  • View file @ 08131b4e

  • Edit in single-file editor

  • Open in Web IDE


@@ -13,9 +13,6 @@ import org.tmatesoft.svn.core.SVNException;
@@ -13,9 +13,6 @@ import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import org.tmatesoft.svn.core.wc2.SvnCheckout;
import org.tmatesoft.svn.core.wc2.SvnCheckout;
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
@@ -23,7 +20,6 @@ import org.tmatesoft.svn.core.wc2.SvnTarget;
@@ -23,7 +20,6 @@ import org.tmatesoft.svn.core.wc2.SvnTarget;
import java.io.File;
import java.io.File;
import java.io.IOException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Matcher;
@@ -35,85 +31,102 @@ public class RepoUtil {
@@ -35,85 +31,102 @@ public class RepoUtil {
public RepoUtil() {}
public RepoUtil() {}
public void cloneRepository(Matcher config, String targetPath, String subDir) {
public void cloneRepository(Matcher config, String targetPath, String subDir) {
LOG.debug(String.format("cloning repository: %s", config.group(1)));
LOG.info(String.format("Cloning repository: %s", config.group(1)));
File targetDirectory = new File(targetPath);
File targetDirectory = new File(targetPath);
if (targetDirectory.exists()) {
if (targetDirectory.exists()) {
LOG.debug("clone target directory existing yet, deleting now");
LOG.info("Target directory exists. Deleting...");
FileSystemUtils.deleteRecursively(targetDirectory);
FileSystemUtils.deleteRecursively(targetDirectory);
}
}
File checkoutDirectory = targetDirectory;
File checkoutDirectory = targetDirectory;
//if an optional directory parameter was given
// If an optional subdirectory parameter is provided
if(subDir!="")
if (!subDir.isEmpty()) {
{
checkoutDirectory = new File(targetPath + "_checkout");
//create companion checkout dir "targetPath"+"_checkout"
checkoutDirectory = new File(targetPath+"_checkout");
if (checkoutDirectory.exists()) {
if (checkoutDirectory.exists()) {
LOG.debug("clone checkout directory existing yet, deleting now");
LOG.info("Checkout directory exists. Deleting...");
FileSystemUtils.deleteRecursively(checkoutDirectory);
FileSystemUtils.deleteRecursively(checkoutDirectory);
}
}
}
}
try {
try {
LOG.debug("preparing clone");
LOG.info("Preparing to clone...");
if (config.group(1).endsWith(".git")) {
if (config.group(1).endsWith(".git")) {
CloneCommand cloneCommand = Git.cloneRepository()
// Git cloning
.setDirectory(checkoutDirectory)
CloneCommand cloneCommand = Git.cloneRepository()
.setURI(config.group(1));
.setDirectory(checkoutDirectory)
.setURI(config.group(1));
if (!config.group(2).equals("none") && !config.group(3).equals("none")) {
LOG.debug("setting credentials");
if (!config.group(2).equals("none") && !config.group(3).equals("none")) {
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(config.group(2), config.group(3)));
LOG.info("Setting Git credentials...");
}
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(config.group(2), config.group(3)));
}
LOG.debug("cloning...");
cloneCommand.call().close();
LOG.info("Cloning Git repository...");
}
cloneCommand.call().close();
else {
URL sourceUrl=new URL(config.group(1));
} else {
 
// SVN Checkout
 
URL sourceUrl = new URL(config.group(1));
SVNURL url = SVNURL.create(sourceUrl.getProtocol(), null, sourceUrl.getHost(), sourceUrl.getPort(), sourceUrl.getPath(), false);
SVNURL url = SVNURL.create(sourceUrl.getProtocol(), null, sourceUrl.getHost(), sourceUrl.getPort(), sourceUrl.getPath(), false);
SvnOperationFactory operationFactory = new SvnOperationFactory();
SvnOperationFactory operationFactory = new SvnOperationFactory();
SvnCheckout checkout = operationFactory.createCheckout();
SvnCheckout checkout = operationFactory.createCheckout();
checkout.setSingleTarget(SvnTarget.fromFile(new File(targetPath)));
 
String directoryString = checkoutDirectory.toString();
 
File directory = new File(directoryString);
 
if (!directory.exists()) {
 
LOG.info("Target directory does not exist. Creating: " + directoryString);
 
if (!directory.mkdirs()) {
 
throw new IOException("Failed to create target directory: " + directoryString);
 
}
 
}
 
 
checkout.setSingleTarget(SvnTarget.fromFile(directory));
checkout.setSource(SvnTarget.fromURL(url));
checkout.setSource(SvnTarget.fromURL(url));
checkout.setDepth(SVNDepth.INFINITY);
String protocol = url.getProtocol();
 
String protocol = url.getProtocol();
if (!config.group(2).equals("none") && !config.group(3).equals("none")) {
if (!config.group(2).equals("none") && !config.group(3).equals("none")) {
if (protocol.equals("https")) {
if (protocol.equalsIgnoreCase("https")) {
LOG.debug("Setting SVN credentials for HTTPS checkout with username/password");
LOG.info("Setting SVN credentials for HTTPS...");
operationFactory.setAuthenticationManager(new BasicAuthenticationManager(config.group(2), config.group(3)));
operationFactory.setAuthenticationManager(BasicAuthenticationManager.newInstance(config.group(2), config.group(3).toCharArray()));
}
} else if (protocol.equalsIgnoreCase("svn+ssh")) {
else if (protocol.equals("svn+ssh")) {
LOG.info("Setting SVN credentials for SVN+SSH...");
LOG.debug("Setting credentials for SVN+SSH Authentication with username/password");
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(config.group(2), config.group(3).toCharArray());
//ISVNAuthenticationManager authManager = new BasicAuthenticationManager(new SVNAuthentication[] { new SVNSSHAuthentication(username, password, -1, false)});//SVNWCUtil.createDefaultAuthenticationManager(username, password);
operationFactory.setAuthenticationManager(authManager);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(config.group(2), config.group(3).toCharArray());
}
operationFactory.setAuthenticationManager(authManager);
}
}
}
checkout.run();
try {
LOG.debug("SVN checkout completed successfully.");
LOG.info("Performing SVN checkout...");
}
checkout.run();
LOG.info("SVN checkout completed successfully.");
//if an optional directory parameter was given
} catch (Exception e) {
if(subDir!="")
LOG.error("Error during SVN checkout: " + e.getMessage(), e);
{
throw e;
//copy appropriate path from checkout directory to target directory
}
FileSystemUtils.copyRecursively(new File(checkoutDirectory+subDir), new File(targetPath));
}
}
LOG.debug(String.format("cloned from %s via %s to %s", config.group(1), checkoutDirectory+subDir, targetDirectory));
}
// If an optional subdirectory parameter is provided
catch (IOException e) {
if (!subDir.isEmpty()) {
LOG.error(String.format("Error while cloning from %s: could not copy to unit test dir", config.group(1)), e);
File subDirPath = new File(checkoutDirectory, subDir);
}
if (!subDirPath.exists() || !subDirPath.isDirectory()) {
catch (GitAPIException e) {
LOG.error("Specified subdirectory does not exist in the repository: " + subDirPath.getPath());
LOG.error(String.format("Error while cloning from %s: could not read from Git", config.group(1)), e);
throw new IllegalArgumentException("Invalid subdirectory: " + subDirPath.getPath());
}
}
catch (SVNException e) {
LOG.info("Copying subdirectory to target...");
LOG.error(String.format("Error while cloning from %s: could not read from Svn", config.group(1)), e);
FileSystemUtils.copyRecursively(subDirPath, new File(targetPath));
 
}
 
 
LOG.info(String.format("Cloned from %s via %s to %s", config.group(1), checkoutDirectory + subDir, targetDirectory));
 
 
} catch (IOException e) {
 
LOG.error(String.format("Error while cloning from %s: could not copy to target directory", config.group(1)), e);
 
} catch (GitAPIException e) {
 
LOG.error(String.format("Error while cloning Git repository %s: %s", config.group(1), e.getMessage()), e);
 
} catch (SVNException e) {
 
LOG.error(String.format("Error while cloning SVN repository %s: %s", config.group(1), e.getMessage()), e);
}
}
}
}
}
}
0 Assignees
Assign to
0 Reviewers
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
Lock merge request
Unlocked
participants
Reference:
Source branch: amg-svn

Menu

Explore Projects Groups Snippets

Dies ist die Gitlab-Instanz des Transferportals der Hochschule für Technik Stuttgart. Hier geht es zurück zum Portal