Skip to content
Snippets Groups Projects
Commit 63af3357 authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

doc, ensure the isSane() method only performs its checks once (if it returned successful)

parent a218ff59
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,23 @@ import java.util.Optional;
import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes;
/**
* Abstract superclass of all wrappers for external tools.
*/
public abstract class ToolWrapper {
protected String cmd;
public ToolWrapper(String cmd) throws ToolNotWorkingException {
/**
* Constructs a new {@link ToolWrapper} wrapping the given external command <code>cmd</code>. Calls
* {@link #isWorking()} and throws a {@link ToolNotWorkingException} if it returns <code>false</code>.
*
* @param cmd
* the external command to wrap
* @throws ToolNotWorkingException
* if {@link #isWorking()} returns <code>false</code>
*/
protected ToolWrapper(String cmd) throws ToolNotWorkingException {
this.cmd = cmd;
if (!isWorking()) {
......@@ -19,8 +31,25 @@ public abstract class ToolWrapper {
}
}
/**
* Determines whether the wrapped command is working as expected.
*
* @return true iff the command is working
*/
protected abstract boolean isWorking();
/**
* Prepends the wrapped external command to (a copy of) the <code>parameters</code> and calls
* {@link ProcessExecutor#exec(File, boolean, List)}.
*
* @param workingDir
* the working directory for the execution
* @param redirectError
* whether to merge the standard output and error streams
* @param parameters
* the parameters for the external command
* @return the result of the execution or an empty {@link Optional} if there is an exception executing the command
*/
protected Optional<ExecRes> exec(File workingDir, boolean redirectError, List<String> parameters) {
LinkedList<String> pars = new LinkedList<>(parameters);
pars.addFirst(cmd);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment