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

enable modification of the execution environment options

parent 0117afd0
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ public class GitWrapper extends ToolWrapper {
private static final String GIT_VERSION_C = "--version";
private static final String GIT_VERSION_PREFIX = "git version";
private static final Map<String, String> environment;
private static final Map<String, String> defaultEnvironment;
private static final List<String> defaultOptions;
static {
......@@ -53,7 +53,7 @@ public class GitWrapper extends ToolWrapper {
env.put("LANGUAGE", locale);
env.put("LC_ALL", locale);
env.put("LANG", locale);
environment = Collections.unmodifiableMap(env);
defaultEnvironment = Collections.unmodifiableMap(env);
List<String> defOptions = new ArrayList<>();
......@@ -347,6 +347,24 @@ public class GitWrapper extends ToolWrapper {
* @return the result of the execution
*/
public Optional<ExecRes> exec(File workingDirectory, String firstParameter, String... parameters) {
return exec(workingDirectory, null, firstParameter, parameters);
}
/**
* Executes '&lt;git command&gt; &lt;firstParameter&gt; &lt;parameters&gt;' 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 environment
* additional environment variables for the command execution
* @param firstParameter
* the first git parameter
* @param parameters
* the git parameters
* @return the result of the execution
*/
public Optional<ExecRes> exec(File workingDirectory, Map<String, String> environment, String firstParameter, String... parameters) {
List<String> pars = new ArrayList<>(defaultOptions.size() + ((parameters != null) ? parameters.length + 1 : 1));
pars.addAll(defaultOptions);
......@@ -356,6 +374,16 @@ public class GitWrapper extends ToolWrapper {
Collections.addAll(pars, parameters);
}
return exec(workingDirectory, true, environment, pars);
Map<String, String> env;
if (environment != null) {
env = new HashMap<>(defaultEnvironment.size() + environment.size());
env.putAll(environment);
env.putAll(defaultEnvironment);
} else {
env = GitWrapper.defaultEnvironment;
}
return exec(workingDirectory, true, env, pars);
}
}
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