diff --git a/gb-command/src/main/java/com/g2forge/gearbox/command/converter/dumb/DumbCommandConverter.java b/gb-command/src/main/java/com/g2forge/gearbox/command/converter/dumb/DumbCommandConverter.java index 9c0898c9..af325834 100644 --- a/gb-command/src/main/java/com/g2forge/gearbox/command/converter/dumb/DumbCommandConverter.java +++ b/gb-command/src/main/java/com/g2forge/gearbox/command/converter/dumb/DumbCommandConverter.java @@ -217,11 +217,6 @@ public ProcessInvocation apply(ProcessInvocation processInvocation, Me environmentBuilder.base(SystemEnvironment.create()); } - // Compute the IO redirection - if ((processInvocation.getCommandInvocation() == null) || (processInvocation.getCommandInvocation().getIo() == null)) { - if (returnTypeRef.getErasedType().isAssignableFrom(Void.class) || returnTypeRef.getErasedType().isAssignableFrom(Void.TYPE)) commandInvocationBuilder.io(StandardIO.builder().standardInput(InheritRedirect.create()).standardOutput(InheritRedirect.create()).standardError(InheritRedirect.create()).build()); - } - final ISubject methodSubject = getMetadata().of(methodInvocation.getMethod()); // Compute the command name & initial arguments @@ -246,9 +241,17 @@ public ProcessInvocation apply(ProcessInvocation processInvocation, Me } // Compute the result generator + final IResultSupplier resultSupplier; if (processInvocation.getResultSupplier() == null) { - final IResultSupplier standard = getStandard(returnTypeRef); - processInvocationBuilder.resultSupplier(standard); + resultSupplier = getStandard(returnTypeRef); + processInvocationBuilder.resultSupplier(resultSupplier); + } else resultSupplier = processInvocation.getResultSupplier(); + + // Compute the IO redirection + if ((processInvocation.getCommandInvocation() == null) || (processInvocation.getCommandInvocation().getIo() == null)) { + final StandardIO redirect = resultSupplier.createRedirect(); + if (redirect != null) commandInvocationBuilder.io(redirect); + else if (returnTypeRef.getErasedType().isAssignableFrom(Void.class) || returnTypeRef.getErasedType().isAssignableFrom(Void.TYPE)) commandInvocationBuilder.io(StandardIO.of(InheritRedirect.create())); } // Generate the command & environment from the method arguments diff --git a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/BooleanResultSupplier.java b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/BooleanResultSupplier.java index 87c280e6..9bfdff65 100644 --- a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/BooleanResultSupplier.java +++ b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/BooleanResultSupplier.java @@ -1,7 +1,9 @@ package com.g2forge.gearbox.command.proxy.result; +import com.g2forge.alexandria.command.stdio.StandardIO; import com.g2forge.alexandria.java.core.marker.ISingleton; import com.g2forge.gearbox.command.process.IProcess; +import com.g2forge.gearbox.command.process.redirect.IRedirect; public class BooleanResultSupplier implements IResultSupplier, ISingleton { protected static final BooleanResultSupplier INSTANCE = new BooleanResultSupplier(); @@ -19,4 +21,9 @@ public Boolean apply(IProcess process) { process.close(); } } + + @Override + public StandardIO createRedirect() { + return STDIO_INHERIT; + } } \ No newline at end of file diff --git a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IResultSupplier.java b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IResultSupplier.java index 07427773..4e3c4deb 100644 --- a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IResultSupplier.java +++ b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IResultSupplier.java @@ -1,7 +1,18 @@ package com.g2forge.gearbox.command.proxy.result; +import com.g2forge.alexandria.command.stdio.StandardIO; import com.g2forge.alexandria.java.function.IFunction1; import com.g2forge.gearbox.command.process.IProcess; +import com.g2forge.gearbox.command.process.redirect.IRedirect; +import com.g2forge.gearbox.command.process.redirect.InheritRedirect; @FunctionalInterface -public interface IResultSupplier extends IFunction1 {} +public interface IResultSupplier extends IFunction1 { + public static final StandardIO STDIO_INHERIT = StandardIO.of(InheritRedirect.create()); + + public static final StandardIO STDIO_DEFAULT = null; + + public default StandardIO createRedirect() { + return STDIO_DEFAULT; + } +} diff --git a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IntegerResultSupplier.java b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IntegerResultSupplier.java index d4497994..007adc47 100644 --- a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IntegerResultSupplier.java +++ b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/IntegerResultSupplier.java @@ -1,7 +1,9 @@ package com.g2forge.gearbox.command.proxy.result; +import com.g2forge.alexandria.command.stdio.StandardIO; import com.g2forge.alexandria.java.core.marker.ISingleton; import com.g2forge.gearbox.command.process.IProcess; +import com.g2forge.gearbox.command.process.redirect.IRedirect; public class IntegerResultSupplier implements IResultSupplier, ISingleton { protected static final IntegerResultSupplier INSTANCE = new IntegerResultSupplier(); @@ -18,4 +20,9 @@ public Integer apply(IProcess process) { process.close(); } } + + @Override + public StandardIO createRedirect() { + return STDIO_INHERIT; + } } \ No newline at end of file diff --git a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/VoidResultSupplier.java b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/VoidResultSupplier.java index e426f9df..623e7441 100644 --- a/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/VoidResultSupplier.java +++ b/gb-command/src/main/java/com/g2forge/gearbox/command/proxy/result/VoidResultSupplier.java @@ -1,7 +1,9 @@ package com.g2forge.gearbox.command.proxy.result; +import com.g2forge.alexandria.command.stdio.StandardIO; import com.g2forge.alexandria.java.core.marker.ISingleton; import com.g2forge.gearbox.command.process.IProcess; +import com.g2forge.gearbox.command.process.redirect.IRedirect; public class VoidResultSupplier implements IResultSupplier, ISingleton { protected static final VoidResultSupplier INSTANCE = new VoidResultSupplier(); @@ -19,4 +21,9 @@ public Void apply(IProcess process) { process.close(); } } + + @Override + public StandardIO createRedirect() { + return STDIO_INHERIT; + } } \ No newline at end of file diff --git a/gb-command/src/test/java/com/g2forge/gearbox/command/proxy/TestCommandProxyFactory.java b/gb-command/src/test/java/com/g2forge/gearbox/command/proxy/TestCommandProxyFactory.java index df7152da..c6cb4bda 100644 --- a/gb-command/src/test/java/com/g2forge/gearbox/command/proxy/TestCommandProxyFactory.java +++ b/gb-command/src/test/java/com/g2forge/gearbox/command/proxy/TestCommandProxyFactory.java @@ -3,10 +3,12 @@ import org.junit.Test; import com.g2forge.alexandria.command.invocation.CommandInvocation; +import com.g2forge.alexandria.command.stdio.StandardIO; import com.g2forge.alexandria.java.core.helpers.HCollection; import com.g2forge.alexandria.test.HAssert; import com.g2forge.gearbox.command.converter.dumb.DumbCommandConverter; import com.g2forge.gearbox.command.process.redirect.IRedirect; +import com.g2forge.gearbox.command.process.redirect.InheritRedirect; import com.g2forge.gearbox.command.proxy.method.ITestCommandInterface; import com.g2forge.gearbox.command.proxy.process.ProcessInvocation; import com.g2forge.gearbox.command.proxy.process.ReturnProcessInvocationException; @@ -46,7 +48,7 @@ public void returnProcessInvocationException() { final CommandInvocation commandInvocation = processInvocation.getCommandInvocation(); HAssert.assertEquals(HCollection.asList("method", "0"), commandInvocation.getArguments()); HAssert.assertNull(commandInvocation.getWorking()); - HAssert.assertNull(commandInvocation.getIo()); + HAssert.assertEquals(commandInvocation.getIo(), StandardIO.of(InheritRedirect.create())); HAssert.assertSame(IntegerResultSupplier.create(), processInvocation.getResultSupplier()); } }