org.snapscript.common.command.MapEnvironment Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.common.command;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class MapEnvironment implements Environment {
private final Map variables;
public MapEnvironment(Map variables) {
this.variables = variables;
}
@Override
public ProcessBuilder createProcess(String... command) {
return createProcess(Arrays.asList(command));
}
@Override
public ProcessBuilder createProcess(List command) {
ProcessBuilder builder = new ProcessBuilder(command);
if (!variables.isEmpty()) {
Set names = variables.keySet();
for (String name : names) {
String value = variables.get(name);
builder.environment().put(name, value);
}
}
return builder;
}
}