1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.ant.tasks;
11
12 import java.io.File;
13
14 import org.apache.tools.ant.BuildException;
15 import org.apache.tools.ant.Project;
16 import org.apache.tools.ant.Task;
17 import org.eclipse.jgit.api.CloneCommand;
18 import org.eclipse.jgit.api.Git;
19 import org.eclipse.jgit.api.errors.GitAPIException;
20 import org.eclipse.jgit.api.errors.JGitInternalException;
21 import org.eclipse.jgit.lib.Constants;
22 import org.eclipse.jgit.transport.URIish;
23
24
25
26
27
28
29
30 public class GitCloneTask extends Task {
31
32 private String uri;
33 private File destination;
34 private boolean bare;
35 private String branch = Constants.HEAD;
36
37
38
39
40
41
42
43 public void setUri(String uri) {
44 this.uri = uri;
45 }
46
47
48
49
50
51
52
53
54
55 public void setDest(File destination) {
56 this.destination = destination;
57 }
58
59
60
61
62
63
64
65 public void setBare(boolean bare) {
66 this.bare = bare;
67 }
68
69
70
71
72
73
74
75 public void setBranch(String branch) {
76 this.branch = branch;
77 }
78
79
80 @Override
81 public void execute() throws BuildException {
82 log("Cloning repository " + uri);
83
84 CloneCommand clone = Git.cloneRepository();
85 try {
86 clone.setURI(uri).setDirectory(destination).setBranch(branch).setBare(bare);
87 clone.call().getRepository().close();
88 } catch (GitAPIException | JGitInternalException e) {
89 log("Could not clone repository: " + e, e, Project.MSG_ERR);
90 throw new BuildException("Could not clone repository: " + e.getMessage(), e);
91 }
92 }
93 }