2323import io .serverlessworkflow .impl .WorkflowModel ;
2424import io .serverlessworkflow .impl .WorkflowValueResolver ;
2525import io .serverlessworkflow .impl .scripts .ScriptUtils ;
26+ import java .io .File ;
2627import java .util .ArrayList ;
2728import java .util .List ;
2829import java .util .Map ;
3233public class RunShellExecutor implements CallableTask {
3334 private final WorkflowValueResolver <String > shellCommand ;
3435 private final List <WorkflowValueResolver <String >> shellArguments ;
36+ private final Optional <WorkflowValueResolver <String >> shellDirectory ;
3537 private final Optional <WorkflowValueResolver <Map <String , Object >>> shellEnv ;
3638 private final Optional <ProcessReturnType > returnType ;
3739
3840 public RunShellExecutor (
3941 WorkflowValueResolver <String > shellCommand ,
4042 List <WorkflowValueResolver <String >> shellArguments ,
43+ Optional <WorkflowValueResolver <String >> shellDirectory ,
4144 Optional <WorkflowValueResolver <Map <String , Object >>> shellEnv ,
4245 Optional <ProcessReturnType > returnType ) {
4346 this .shellCommand = shellCommand ;
4447 this .shellArguments = shellArguments ;
48+ this .shellDirectory = shellDirectory ;
4549 this .shellEnv = shellEnv ;
4650 this .returnType = returnType ;
4751 }
@@ -64,6 +68,9 @@ public CompletableFuture<WorkflowModel> apply(
6468 shellArguments .forEach (f -> commandAndArgs .add (f .apply (workflowContext , taskContext , model )));
6569
6670 ProcessBuilder builder = new ProcessBuilder (commandAndArgs );
71+ shellDirectory .ifPresent (
72+ directory ->
73+ builder .directory (new File (directory .apply (workflowContext , taskContext , model ))));
6774 shellEnv .ifPresent (
6875 map -> ScriptUtils .addEnviromment (builder , map .apply (workflowContext , taskContext , model )));
6976
0 commit comments