Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ public <T> ProcessInvocation<T> apply(ProcessInvocation<T> 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.<IRedirect, IRedirect>builder().standardInput(InheritRedirect.create()).standardOutput(InheritRedirect.create()).standardError(InheritRedirect.create()).build());
}

final ISubject methodSubject = getMetadata().of(methodInvocation.getMethod());

// Compute the command name & initial arguments
Expand All @@ -246,9 +241,17 @@ public <T> ProcessInvocation<T> apply(ProcessInvocation<T> processInvocation, Me
}

// Compute the result generator
final IResultSupplier<? extends T> resultSupplier;
if (processInvocation.getResultSupplier() == null) {
final IResultSupplier<T> 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<IRedirect, IRedirect> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Boolean>, ISingleton {
protected static final BooleanResultSupplier INSTANCE = new BooleanResultSupplier();
Expand All @@ -19,4 +21,9 @@ public Boolean apply(IProcess process) {
process.close();
}
}

@Override
public StandardIO<IRedirect, IRedirect> createRedirect() {
return STDIO_INHERIT;
}
}
Original file line number Diff line number Diff line change
@@ -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<T> extends IFunction1<IProcess, T> {}
public interface IResultSupplier<T> extends IFunction1<IProcess, T> {
public static final StandardIO<IRedirect, IRedirect> STDIO_INHERIT = StandardIO.of(InheritRedirect.create());

public static final StandardIO<IRedirect, IRedirect> STDIO_DEFAULT = null;

public default StandardIO<IRedirect, IRedirect> createRedirect() {
return STDIO_DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -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<Integer>, ISingleton {
protected static final IntegerResultSupplier INSTANCE = new IntegerResultSupplier();
Expand All @@ -18,4 +20,9 @@ public Integer apply(IProcess process) {
process.close();
}
}

@Override
public StandardIO<IRedirect, IRedirect> createRedirect() {
return STDIO_INHERIT;
}
}
Original file line number Diff line number Diff line change
@@ -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<Void>, ISingleton {
protected static final VoidResultSupplier INSTANCE = new VoidResultSupplier();
Expand All @@ -19,4 +21,9 @@ public Void apply(IProcess process) {
process.close();
}
}

@Override
public StandardIO<IRedirect, IRedirect> createRedirect() {
return STDIO_INHERIT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +48,7 @@ public void returnProcessInvocationException() {
final CommandInvocation<IRedirect, IRedirect> 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());
}
}
Expand Down