Commit 2a5ad27c authored by Kammleiter's avatar Kammleiter
Browse files

add public clone possibility

parent cb390af4
...@@ -118,8 +118,8 @@ public class TaskUpload { ...@@ -118,8 +118,8 @@ public class TaskUpload {
this.jGitUtil.cloneRepository("http://" + this.modocotProperties.getDockerHostIp() this.jGitUtil.cloneRepository("http://" + this.modocotProperties.getDockerHostIp()
+ ":3000/" + this.modocotProperties.getGitTeaUsername() + "/" + ":3000/" + this.modocotProperties.getGitTeaUsername() + "/"
+ assignmentId + ".git", + assignmentId + ".git",
unit, null, false); unit, null, true, false);
this.jGitUtil.cloneRepository(repoUrl, task, credentials, true); this.jGitUtil.cloneRepository(repoUrl, task, credentials, credentials != null, true);
} }
} }
} }
...@@ -90,7 +90,7 @@ public class UnitTestUpload { ...@@ -90,7 +90,7 @@ public class UnitTestUpload {
String credentials = ((lines.size() > 1) && !lines.get(1).equals("")) ? String credentials = ((lines.size() > 1) && !lines.get(1).equals("")) ?
lines.get(1) : null; lines.get(1) : null;
// cloning repository repoUrl into work-directory, using credentials from second line in repo.txt // cloning repository repoUrl into work-directory, using credentials from second line in repo.txt
this.jGitUtil.cloneRepository(repoUrl, workDirectory, credentials, true); this.jGitUtil.cloneRepository(repoUrl, workDirectory, credentials, credentials != null,true);
} }
// creating repository on internal giTea, name = assignmentId // creating repository on internal giTea, name = assignmentId
......
...@@ -41,7 +41,7 @@ public class JGitUtil { ...@@ -41,7 +41,7 @@ public class JGitUtil {
* @param token AuthToken, when cloning Repository. If {@code null} use {@code ModocotProperties} * @param token AuthToken, when cloning Repository. If {@code null} use {@code ModocotProperties}
* @param proxy boolean if a proxy should be used * @param proxy boolean if a proxy should be used
*/ */
public void cloneRepository(String uriToClone, File cloneDirectory, String token, boolean proxy) { public void cloneRepository(String uriToClone, File cloneDirectory, String token, boolean useToken, boolean proxy) {
if (!cloneDirectory.isDirectory()) { if (!cloneDirectory.isDirectory()) {
String error = String.format("%s is not a directory, cannot clone", cloneDirectory.getAbsolutePath()); String error = String.format("%s is not a directory, cannot clone", cloneDirectory.getAbsolutePath());
LOG.error(error); LOG.error(error);
...@@ -50,21 +50,23 @@ public class JGitUtil { ...@@ -50,21 +50,23 @@ public class JGitUtil {
LOG.info(String.format("Cloning all files from %s into %s", uriToClone, cloneDirectory.getAbsolutePath())); LOG.info(String.format("Cloning all files from %s into %s", uriToClone, cloneDirectory.getAbsolutePath()));
try { try {
deleteDotGitFolder(cloneDirectory); deleteDotGitFolder(cloneDirectory);
UsernamePasswordCredentialsProvider credProvider; UsernamePasswordCredentialsProvider credProvider = null;
if (token != null) { if (useToken) {
LOG.info("Using token: " + token); if (token != null) {
String[] credentials = token.split(":"); LOG.info("Using token: " + token);
credProvider = new UsernamePasswordCredentialsProvider(credentials[0], credentials[1]); String[] credentials = token.split(":");
} else { credProvider = new UsernamePasswordCredentialsProvider(credentials[0], credentials[1]);
LOG.info("Using credentials: " + this.modocotProperties.getGitTeaUsername() + ", " + this.modocotProperties.getGitTeaPassword()); } else {
credProvider = new UsernamePasswordCredentialsProvider( LOG.info("Using credentials: " + this.modocotProperties.getGitTeaUsername() + ", " + this.modocotProperties.getGitTeaPassword());
this.modocotProperties.getGitTeaUsername(), credProvider = new UsernamePasswordCredentialsProvider(
this.modocotProperties.getGitTeaPassword()); this.modocotProperties.getGitTeaUsername(),
this.modocotProperties.getGitTeaPassword());
}
} }
LOG.info("Starting cloning, url: " + uriToClone); LOG.info("Starting cloning, url: " + uriToClone);
setProxy(proxy); setProxy(proxy);
Git.cloneRepository() Git.cloneRepository()
.setCredentialsProvider(credProvider) .setCredentialsProvider(useToken ? credProvider : null)
.setURI(uriToClone) .setURI(uriToClone)
.setDirectory(cloneDirectory) .setDirectory(cloneDirectory)
.call() .call()
......
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