Skip to content

Commit

Permalink
Use a Collection instead of a List to hold the command and arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Jun 21, 2024
1 parent e601ffa commit 35287d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 12 additions & 2 deletions src/main/java/rife/bld/extension/ExecOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class ExecOperation extends AbstractOperation<ExecOperation> {
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 BaseProject project_;
private int timeout_ = 30;
Expand All @@ -61,6 +61,16 @@ public ExecOperation command(String... arg) {
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.
*
Expand Down Expand Up @@ -92,7 +102,7 @@ public void execute() throws Exception {
if (workDir.isDirectory()) {
var pb = new ProcessBuilder();
pb.inheritIO();
pb.command(args_);
pb.command(args_.stream().toList());
pb.directory(workDir);

if (LOGGER.isLoggable(Level.INFO)) {
Expand Down
14 changes: 4 additions & 10 deletions src/test/java/rife/bld/extension/ExecOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ class ExecOperationTest {
private static final String FOO = "foo";

@Test
void testCat() throws Exception {
var tmpFile = new File("hello.tmp");
tmpFile.deleteOnExit();
new ExecOperation()
.fromProject(new Project())
.timeout(10)
.command("touch", tmpFile.getName())
.execute();

assertThat(tmpFile).exists();
void testCommand() {
var op = new ExecOperation().fromProject(new WebProject())
.command(FOO, "bar");
assertThat(op.command()).isEqualTo(List.of(FOO, "bar"));
}

@Test
Expand Down

0 comments on commit 35287d7

Please sign in to comment.