2727import io .serverlessworkflow .impl .expressions .ExpressionUtils ;
2828import java .io .IOException ;
2929import java .io .OutputStream ;
30- import java .nio .file .Path ;
3130import java .util .Map ;
3231import java .util .concurrent .CompletableFuture ;
3332
3433public class RunShellExecutor implements RunnableTask <RunShell > {
3534
36- private ProcessResultSupplier processResultSupplier ;
37- private CommandSupplier commandSupplier ;
35+ private ShellResultSupplier shellResultSupplier ;
36+ private ProcessBuilderSupplier processBuilderSupplier ;
3837
3938 @ FunctionalInterface
40- private interface ProcessResultSupplier {
39+ private interface ShellResultSupplier {
4140 WorkflowModel apply (
4241 TaskContext taskContext , ProcessBuilder processBuilder , WorkflowModel input );
4342 }
4443
45- private interface CommandSupplier {
44+ private interface ProcessBuilderSupplier {
4645 ProcessBuilder apply (TaskContext taskContext , WorkflowContext workflowContext );
4746 }
4847
4948 @ Override
5049 public CompletableFuture <WorkflowModel > apply (
5150 WorkflowContext workflowContext , TaskContext taskContext , WorkflowModel input ) {
52- ProcessBuilder processBuilder = this .commandSupplier .apply (taskContext , workflowContext );
51+ ProcessBuilder processBuilder = this .processBuilderSupplier .apply (taskContext , workflowContext );
5352 WorkflowModel workflowModel =
54- this .processResultSupplier .apply (taskContext , processBuilder , input );
53+ this .shellResultSupplier .apply (taskContext , processBuilder , input );
5554 return CompletableFuture .completedFuture (workflowModel );
5655 }
5756
@@ -60,7 +59,7 @@ public void init(RunShell taskConfiguration, WorkflowDefinition definition) {
6059 Shell shell = taskConfiguration .getShell ();
6160 final String shellCommand = shell .getCommand ();
6261
63- this .commandSupplier =
62+ this .processBuilderSupplier =
6463 (taskContext , workflowContext ) -> {
6564 WorkflowApplication application = definition .application ();
6665
@@ -71,6 +70,7 @@ public void init(RunShell taskConfiguration, WorkflowDefinition definition) {
7170 .apply (workflowContext , taskContext , taskContext .input ())
7271 : shellCommand ;
7372
73+ // TODO: support Windows cmd.exe
7474 ProcessBuilder builder = new ProcessBuilder ("sh" , "-c" , command );
7575
7676 if (shell .getEnvironment () != null
@@ -89,12 +89,10 @@ public void init(RunShell taskConfiguration, WorkflowDefinition definition) {
8989 }
9090 }
9191
92- builder .directory (Path .of (System .getProperty ("user.dir" )).toFile ());
93-
9492 return builder ;
9593 };
9694
97- this .processResultSupplier =
95+ this .shellResultSupplier =
9896 (taskContext , processBuilder , input ) -> {
9997 if (shellCommand == null || shellCommand .isBlank ()) {
10098 throw new IllegalStateException (
0 commit comments