Skip to content

Commit

Permalink
Revert "Revert "Allow specifying custom environment variables in the …
Browse files Browse the repository at this point in the history
…execute step""

This reverts commit 252974b.
  • Loading branch information
redxdev committed Feb 6, 2018
1 parent 844a6e0 commit 1b4e613
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/main/java/io/playpen/core/p3/step/ExecuteStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Log4j2
public class ExecuteStep implements IPackageStep {
Expand Down Expand Up @@ -65,9 +67,17 @@ public boolean runStep(P3Package p3, PackageContext ctx, JSONObject config) {
}
}

Map<String, String> environment = new HashMap<>();
if(config.has("environment")) {
JSONObject environmentObj = config.getJSONObject("environment");
for (String s : environmentObj.keySet()) {
environment.put(s, environmentObj.getString(s));
}
}

log.info("Running command " + command.get(0));

XProcess proc = new XProcess(command, ctx.getDestination().toString(), server == null);
XProcess proc = new XProcess(command, ctx.getDestination().toString(), environment, server == null);

if(server != null) {
log.info("Registering process with server " + server.getUuid());
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/io/playpen/core/utils/process/XProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
Expand All @@ -20,20 +21,22 @@
public class XProcess extends NuAbstractCharsetHandler {
public static final int MAX_LINE_STORAGE = 25;

private List<String> command;
private String workingDir;
private final List<String> command;
private final String workingDir;
private NuProcess process = null;
private List<IProcessListener> listeners = new CopyOnWriteArrayList<>();
private OutputBuffer outputBuffer = new OutputBuffer();
private final List<IProcessListener> listeners = new CopyOnWriteArrayList<>();
private final OutputBuffer outputBuffer = new OutputBuffer();
private final Map<String, String> environment;
private boolean wait;

@Getter
private ConcurrentLinkedQueue<String> lastLines = new ConcurrentLinkedQueue<>();

public XProcess(List<String> command, String workingDir, boolean wait) {
public XProcess(List<String> command, String workingDir, Map<String, String> environment, boolean wait) {
super(StandardCharsets.UTF_8);
this.command = command;
this.workingDir = workingDir;
this.environment = environment;
this.wait = wait;
}

Expand All @@ -60,6 +63,7 @@ public boolean run() {
NuProcessBuilder builder = new NuProcessBuilder(command);
builder.setCwd(Paths.get(workingDir));
builder.setProcessListener(this);
builder.environment().putAll(environment);
process = builder.start();

if (wait) {
Expand Down

0 comments on commit 1b4e613

Please sign in to comment.