diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java b/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java index 36e2befd41a8c11b8cc49df58e3b499d975564b3..75ae757aee30a270ed5f09b76795529bca45a161 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/process/ProcessExecutor.java @@ -3,7 +3,6 @@ package de.uni_passau.fim.seibt.gitwrapper.process; import java.io.File; import java.io.IOException; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -39,6 +38,8 @@ public class ProcessExecutor { */ public static final class ExecRes { + public static final int EXIT_SUCCESS = 0; + /** * The exit code of the process that produced this {@link ExecRes}. */ @@ -100,6 +101,25 @@ public class ProcessExecutor { return stdErrTrimmed; } + + /** + * Returns whether the exit code contained in this {@link ExecRes} is {@value ExecRes#EXIT_SUCCESS}. + * + * @return whether the exit code in this {@link ExecRes} indicates successful execution + */ + public boolean succeeded() { + return exitCode == EXIT_SUCCESS; + } + + /** + * Returns whether the exit code contained in this {@link ExecRes} is anything other than + * {@value ExecRes#EXIT_SUCCESS}. + * + * @return whether the exit code in this {@link ExecRes} indicates a failed execution + */ + public boolean failed() { + return exitCode != EXIT_SUCCESS; + } } /** diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/process/ToolWrapper.java b/src/de/uni_passau/fim/seibt/gitwrapper/process/ToolWrapper.java index f960c2bf73639258f720d14074c703e302fa4484..3d44b03313c6d247a8d37f3567135700ad6c3f4a 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/process/ToolWrapper.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/process/ToolWrapper.java @@ -14,8 +14,6 @@ import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes; */ public abstract class ToolWrapper { - protected static final int EXIT_SUCCESS = 0; - protected String cmd; /** diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java index 89beddd3d5fc345d4ef381a1574433bfe24325eb..84e88d22fb9925805ae20b613ef6f4c7e6a2bf3e 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/GitWrapper.java @@ -110,7 +110,7 @@ public class GitWrapper extends ToolWrapper { String firstLine = sc.nextLine(); Matcher matcher; - if (execRes.exitCode == EXIT_SUCCESS) { + if (execRes.succeeded()) { matcher = CLONING_INTO.matcher(firstLine); } else { matcher = ALREADY_EXISTS.matcher(firstLine); @@ -125,7 +125,7 @@ public class GitWrapper extends ToolWrapper { File repoDir = new File(parentDir, name); String repoPath = repoDir.getAbsolutePath(); - if (execRes.exitCode == EXIT_SUCCESS) { + if (execRes.succeeded()) { LOG.fine(() -> String.format("Cloned '%s' into '%s'.", url, repoPath)); return new Repository(this, url, repoDir); } else { @@ -222,8 +222,19 @@ public class GitWrapper extends ToolWrapper { * @return whether the git command failed */ public boolean failed(ExecRes res) { - return res.exitCode != EXIT_SUCCESS || res.getStdOutTrimmed().startsWith(FATAL_PREFIX) - || res.getStdOutTrimmed().startsWith(ERROR_PREFIX); + return res.failed() || failedPrefix(res); + } + + /** + * Returns whether the given git command failed by checking whether the output starts with either + * "{@value FATAL_PREFIX}" or "{@value ERROR_PREFIX}". This method ignores the exit code. + * + * @param res + * the {@link ExecRes} to check + * @return whether the git command failed + */ + public boolean failedPrefix(ExecRes res) { + return res.getStdOutTrimmed().startsWith(FATAL_PREFIX) || res.getStdOutTrimmed().startsWith(ERROR_PREFIX); } /**