package io.digdag.standards.command;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import com.google.inject.Inject;
import com.google.common.base.Optional;
import io.digdag.spi.CommandExecutor;
import io.digdag.spi.TaskRequest;

public class SimpleCommandExecutor
    implements CommandExecutor
{
    @Inject
    public SimpleCommandExecutor()
    { }

    public Process start(Path projectPath, TaskRequest request, ProcessBuilder pb)
        throws IOException
    {
        // TODO set TZ environment variable
        return pb.start();
    }
}

@@ -42,148 +42,241 @@
 ort 
-java.io.File;%0Aimport java.io.IOException;%0Aimport java.nio.file.Path;%0Aimport com.google.inject.Inject;%0Aimport com.google.common.base.Optional
+com.fasterxml.jackson.databind.node.ObjectNode;%0Aimport com.google.common.base.Throwables;%0Aimport com.google.inject.Inject;%0Aimport io.digdag.spi.CommandExecutor;%0Aimport io.digdag.spi.CommandContext;%0Aimport io.digdag.spi.CommandRequest
 ;%0Aim
@@ -293,39 +293,37 @@
 gdag.spi.Command
-Executo
+Logge
 r;%0Aimport io.dig
@@ -330,27 +330,84 @@
 dag.spi.
-TaskRequest
+CommandStatus;%0Aimport java.io.IOException;%0Aimport java.nio.file.Path
 ;%0A%0Apubli
@@ -440,16 +440,20 @@
 tor%0A    
+ 
+   
 implemen
@@ -473,16 +473,55 @@
 cutor%0A%7B%0A
+    private final CommandLogger clog;%0A%0A
     @Inj
@@ -561,203 +561,1514 @@
 tor(
-)%0A    %7B %7D%0A%0A    public Process start(Path projectPath, TaskRequest request, ProcessBuilder pb)%0A        throws IOException%0A    %7B%0A        // TODO set TZ environment variable%0A        return pb.start(
+final CommandLogger clog)%0A    %7B%0A        this.clog = clog;%0A    %7D%0A%0A    @Override%0A    public CommandStatus run(final CommandContext context, final CommandRequest request)%0A            throws IOException%0A    %7B%0A        final ProcessBuilder pb = new ProcessBuilder(request.getCommandLine());%0A        final Path workingDirectory = context.getLocalProjectPath().resolve(request.getWorkingDirectory()).normalize();%0A        pb.directory(workingDirectory.toFile());%0A        pb.redirectErrorStream(true);%0A        pb.environment().putAll(request.getEnvironments());%0A%0A        // TODO set TZ environment variable%0A        final Process p = pb.start();%0A%0A        // copy stdout to System.out and logger%0A        clog.copyStdout(p, System.out);%0A%0A        // Need waiting and blocking. Because the process is running on a single instance.%0A        // The command task could not be taken by other digdag-servers on other instances.%0A        try %7B%0A            p.waitFor();%0A        %7D%0A        catch (InterruptedException e) %7B%0A            throw Throwables.propagate(e);%0A        %7D%0A%0A        return SimpleCommandStatus.of(p, request.getIoDirectory());%0A    %7D%0A%0A    /**%0A     * This method is never called. The status of the task that is executed by the executor cannot be%0A     * polled by non-blocking.%0A     */%0A    @Override%0A    public CommandStatus poll(final CommandContext context, final ObjectNode previousStatusJson)%0A            throws IOException%0A    %7B%0A        throw new UnsupportedOperationException(%22This method should not be called.%22
 );%0A 

Update standards.command.SimpleCommandExecutor