From 9548ddea2306b5f1a908f4b67da4ac917aca8fcd Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 27 Aug 2024 13:24:44 -0700 Subject: [PATCH] Cleaned up API to match bld operations and options APIs --- .../rife/bld/extension/ExecOperationBuild.java | 6 +++--- .../java/rife/bld/extension/ExecOperation.java | 15 +++++++++++++-- .../rife/bld/extension/ExecOperationTest.java | 11 ++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/bld/java/rife/bld/extension/ExecOperationBuild.java b/src/bld/java/rife/bld/extension/ExecOperationBuild.java index 9514143..12d8a7c 100644 --- a/src/bld/java/rife/bld/extension/ExecOperationBuild.java +++ b/src/bld/java/rife/bld/extension/ExecOperationBuild.java @@ -33,7 +33,7 @@ public class ExecOperationBuild extends Project { public ExecOperationBuild() { pkg = "rife.bld.extension"; name = "ExecOperation"; - version = version(1, 0, 2); + version = version(1, 0, 3, "SNAPSHOT"); javaRelease = 17; @@ -44,8 +44,8 @@ public class ExecOperationBuild extends Project { scope(compile) .include(dependency("com.uwyn.rife2", "bld", version(2, 0, 1))); scope(test) - .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3))) - .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3))) + .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 0))) + .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 0))) .include(dependency("org.assertj", "assertj-core", version(3, 26, 3))); javadocOperation() diff --git a/src/main/java/rife/bld/extension/ExecOperation.java b/src/main/java/rife/bld/extension/ExecOperation.java index 94f40ed..8c8c1e0 100644 --- a/src/main/java/rife/bld/extension/ExecOperation.java +++ b/src/main/java/rife/bld/extension/ExecOperation.java @@ -21,6 +21,7 @@ import rife.bld.operations.AbstractOperation; import rife.bld.operations.exceptions.ExitStatusException; import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -57,8 +58,7 @@ public class ExecOperation extends AbstractOperation { * @see #command(Collection) */ public ExecOperation command(String... arg) { - args_.addAll(List.of(arg)); - return this; + return command(List.of(arg)); } /** @@ -199,6 +199,17 @@ public class ExecOperation extends AbstractOperation { return this; } + /** + * Configures the working directory. + * + * @param dir the directory + * @return this operation instance + */ + public ExecOperation workDir(Path dir) { + return workDir(dir.toFile()); + } + + /** * Configures the working directory. * diff --git a/src/test/java/rife/bld/extension/ExecOperationTest.java b/src/test/java/rife/bld/extension/ExecOperationTest.java index a73cd98..8bb27bd 100644 --- a/src/test/java/rife/bld/extension/ExecOperationTest.java +++ b/src/test/java/rife/bld/extension/ExecOperationTest.java @@ -100,7 +100,16 @@ class ExecOperationTest { .fromProject(new BaseProject()) .command("echo", FOO) .workDir(workDir); - assertThat(op.workDir()).isEqualTo(workDir); + assertThat(op.workDir()).as("as file").isEqualTo(workDir); + assertThatCode(op::execute).doesNotThrowAnyException(); + + var build = "build"; + op = op.workDir(build); + assertThat(op.workDir()).as("as string").isEqualTo(new File(build)); + assertThatCode(op::execute).doesNotThrowAnyException(); + + op = op.workDir(workDir.toPath()); + assertThat(op.workDir()).as("as path").isEqualTo(workDir); assertThatCode(op::execute).doesNotThrowAnyException(); }