From 51c6aa8606c966bd78f4253adab38d2332dda6bc Mon Sep 17 00:00:00 2001 From: Georg Seibt <seibt@fim.uni-passau.de> Date: Tue, 12 Apr 2016 14:17:21 +0200 Subject: [PATCH] doc --- .../repo/{Git.java => GitWrapper.java} | 35 +++++++++++++++++-- .../fim/seibt/gitwrapper/repo/Repository.java | 6 ++-- 2 files changed, 35 insertions(+), 6 deletions(-) rename src/de/uni_passau/fim/seibt/gitwrapper/repo/{Git.java => GitWrapper.java} (75%) diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Git.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java similarity index 75% rename from src/de/uni_passau/fim/seibt/gitwrapper/repo/Git.java rename to src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java index aa70b2a..08ae56e 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Git.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java @@ -12,12 +12,15 @@ import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; -public class Git { +/** + * A wrapper for executing git commands on the command line. + */ +public class GitWrapper { public static final int EXIT_SUCCESS = 0; public static final int EXIT_FAIL = 1; - private static final Logger LOG = Logger.getLogger(Git.class.getCanonicalName()); + private static final Logger LOG = Logger.getLogger(GitWrapper.class.getCanonicalName()); private static final Pattern CLONING_INTO = Pattern.compile("Cloning into '(.*)'\\.\\.\\."); private static final Pattern ALREADY_EXISTS = Pattern.compile("fatal: destination path '(.*)' already exists and is not an empty directory\\."); @@ -29,10 +32,26 @@ public class Git { private String git; - public Git(String git) { + /** + * Constructs a new {@link GitWrapper} + * + * @param git the git command, e.g. '/usr/bin/git' or just 'git' + */ + public GitWrapper(String git) { this.git = git; } + /** + * Attempts to clone the git repository at the given <code>url</code> into a directory under <code>parentDir</code>. + * If <code>parentDir</code> already contains a git repository with the name that would be produced when cloning + * <code>url</code> it is assumed to be a clone of <code>url</code> and returned as a {@link Repository}. + * + * @param parentDir + * the directory in which to place the clone of <code>url</code> + * @param url + * the git repository to clone + * @return the resulting {@link Repository} or an empty {@link Optional} if there is an error + */ public Optional<Repository> clone(File parentDir, String url) { LOG.fine(() -> String.format("Cloning '%s'.", url)); @@ -100,6 +119,16 @@ public class Git { return status.map(res -> res.code == EXIT_SUCCESS).orElse(false); } + /** + * Executes 'git <parameters>' and returns the exit code and the output of the command. If there is an + * exception executing the command an empty {@link Optional} will be returned. + * + * @param workingDirectory + * the working directory for the command execution + * @param parameters + * the git parameters + * @return the result of the execution + */ public Optional<ExecRes> exec(File workingDirectory, String... parameters) { ProcessBuilder b = new ProcessBuilder(); String[] cmdArray = new String[parameters.length + 1]; diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java index 4218b22..111895c 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java @@ -4,13 +4,13 @@ import java.io.File; public class Repository { - private Git git; + private GitWrapper gitWrapper; private String url; private File dir; - Repository(Git git, String url, File dir) { - this.git = git; + Repository(GitWrapper gitWrapper, String url, File dir) { + this.gitWrapper = gitWrapper; this.url = url; this.dir = dir; } -- GitLab