Use a Collection instead of a List to hold the command and arguments
This commit is contained in:
parent
e601ffab91
commit
35287d7d6d
2 changed files with 16 additions and 12 deletions
|
@ -37,7 +37,7 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class ExecOperation extends AbstractOperation<ExecOperation> {
|
public class ExecOperation extends AbstractOperation<ExecOperation> {
|
||||||
private static final Logger LOGGER = Logger.getLogger(ExecOperation.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ExecOperation.class.getName());
|
||||||
private final List<String> args_ = new ArrayList<>();
|
private final Collection<String> args_ = new ArrayList<>();
|
||||||
private boolean failOnExit_ = true;
|
private boolean failOnExit_ = true;
|
||||||
private BaseProject project_;
|
private BaseProject project_;
|
||||||
private int timeout_ = 30;
|
private int timeout_ = 30;
|
||||||
|
@ -61,6 +61,16 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the command and arguments to be executed.
|
||||||
|
*
|
||||||
|
* @return the command and arguments
|
||||||
|
*/
|
||||||
|
public Collection<String> command() {
|
||||||
|
return args_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the command and arguments to be executed.
|
* Configures the command and arguments to be executed.
|
||||||
*
|
*
|
||||||
|
@ -92,7 +102,7 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
|
||||||
if (workDir.isDirectory()) {
|
if (workDir.isDirectory()) {
|
||||||
var pb = new ProcessBuilder();
|
var pb = new ProcessBuilder();
|
||||||
pb.inheritIO();
|
pb.inheritIO();
|
||||||
pb.command(args_);
|
pb.command(args_.stream().toList());
|
||||||
pb.directory(workDir);
|
pb.directory(workDir);
|
||||||
|
|
||||||
if (LOGGER.isLoggable(Level.INFO)) {
|
if (LOGGER.isLoggable(Level.INFO)) {
|
||||||
|
|
|
@ -31,16 +31,10 @@ class ExecOperationTest {
|
||||||
private static final String FOO = "foo";
|
private static final String FOO = "foo";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCat() throws Exception {
|
void testCommand() {
|
||||||
var tmpFile = new File("hello.tmp");
|
var op = new ExecOperation().fromProject(new WebProject())
|
||||||
tmpFile.deleteOnExit();
|
.command(FOO, "bar");
|
||||||
new ExecOperation()
|
assertThat(op.command()).isEqualTo(List.of(FOO, "bar"));
|
||||||
.fromProject(new Project())
|
|
||||||
.timeout(10)
|
|
||||||
.command("touch", tmpFile.getName())
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertThat(tmpFile).exists();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue