From 77d7463b0c3d11adbe7530686fd3e95b976bce56 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 21 Jun 2024 00:00:23 -0700 Subject: [PATCH 1/4] Bumped PMD extension to version 1.0.1 --- lib/bld/bld-wrapper.jar | Bin 27319 -> 27319 bytes lib/bld/bld-wrapper.properties | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index ffdaf71a2b7a43e762ee9f7e68ef77a690ee56a4..ef31ff4f272c6cff6ffe4300434dc77205a94216 100644 GIT binary patch delta 131 zcmdmfm2vx3M&1B#W)=|!4h{~6puQ6mdFz;g)W$v~V-UT0vvD^QnBi!~t_Nm#r<`X5 wGi1{Y!BUe0GweYElP705gXx69e;#vM+x;)DP00T=ow*UYD diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index cab667f..b07a9cc 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,8 +1,8 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true -bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.9 -bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5 -bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.downloadLocation= +bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5 +bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.0.1 +bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.sourceDirectories= bld.version=1.9.1 From e601ffab91989c85f6c8a6de962ab03f32b1e3be Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 21 Jun 2024 00:01:08 -0700 Subject: [PATCH 2/4] Bumped AssertJ to version 3.26.0 --- src/bld/java/rife/bld/extension/ExecOperationBuild.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld/java/rife/bld/extension/ExecOperationBuild.java b/src/bld/java/rife/bld/extension/ExecOperationBuild.java index 46e4875..d141cb7 100644 --- a/src/bld/java/rife/bld/extension/ExecOperationBuild.java +++ b/src/bld/java/rife/bld/extension/ExecOperationBuild.java @@ -48,7 +48,7 @@ public class ExecOperationBuild extends Project { scope(test) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2))) - .include(dependency("org.assertj", "assertj-core", version(3, 25, 3))); + .include(dependency("org.assertj", "assertj-core", version(3, 26, 0))); javadocOperation() .javadocOptions() From 35287d7d6d261b76f29c89879deafc8ff102e111 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 21 Jun 2024 00:08:04 -0700 Subject: [PATCH 3/4] Use a Collection instead of a List to hold the command and arguments --- .../java/rife/bld/extension/ExecOperation.java | 14 ++++++++++++-- .../java/rife/bld/extension/ExecOperationTest.java | 14 ++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/rife/bld/extension/ExecOperation.java b/src/main/java/rife/bld/extension/ExecOperation.java index af192d0..3989ead 100644 --- a/src/main/java/rife/bld/extension/ExecOperation.java +++ b/src/main/java/rife/bld/extension/ExecOperation.java @@ -37,7 +37,7 @@ import java.util.logging.Logger; */ public class ExecOperation extends AbstractOperation { private static final Logger LOGGER = Logger.getLogger(ExecOperation.class.getName()); - private final List args_ = new ArrayList<>(); + private final Collection args_ = new ArrayList<>(); private boolean failOnExit_ = true; private BaseProject project_; private int timeout_ = 30; @@ -61,6 +61,16 @@ public class ExecOperation extends AbstractOperation { return this; } + /** + * Returns the command and arguments to be executed. + * + * @return the command and arguments + */ + public Collection command() { + return args_; + } + + /** * Configures the command and arguments to be executed. * @@ -92,7 +102,7 @@ public class ExecOperation extends AbstractOperation { 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)) { diff --git a/src/test/java/rife/bld/extension/ExecOperationTest.java b/src/test/java/rife/bld/extension/ExecOperationTest.java index d070e15..5d819b3 100644 --- a/src/test/java/rife/bld/extension/ExecOperationTest.java +++ b/src/test/java/rife/bld/extension/ExecOperationTest.java @@ -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 From 6e8d3c2cd6283e98448c9e0290399be0baf9428e Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 21 Jun 2024 00:13:25 -0700 Subject: [PATCH 4/4] Added public methods to directly access configuration options --- .../rife/bld/extension/ExecOperation.java | 27 ++++++++++ .../rife/bld/extension/ExecOperationTest.java | 54 ++++++++++++------- 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/src/main/java/rife/bld/extension/ExecOperation.java b/src/main/java/rife/bld/extension/ExecOperation.java index 3989ead..aa035c5 100644 --- a/src/main/java/rife/bld/extension/ExecOperation.java +++ b/src/main/java/rife/bld/extension/ExecOperation.java @@ -147,6 +147,15 @@ public class ExecOperation extends AbstractOperation { return this; } + /** + * Returns whether the operation should fail if the command exit value/status is not 0. + * + * @return {@code true} or {@code false} + */ + public boolean isFailOnExit() { + return failOnExit_; + } + /** * Configure the command timeout. * @@ -158,6 +167,15 @@ public class ExecOperation extends AbstractOperation { return this; } + /** + * Returns the command timeout. + * + * @return the timeout + */ + public int timeout() { + return timeout_; + } + /** * Configures the working directory. * @@ -178,4 +196,13 @@ public class ExecOperation extends AbstractOperation { public ExecOperation workDir(String dir) { return workDir(new File(dir)); } + + /** + * Returns the working directory. + * + * @return the directory + */ + public File workDir() { + return workDir_; + } } diff --git a/src/test/java/rife/bld/extension/ExecOperationTest.java b/src/test/java/rife/bld/extension/ExecOperationTest.java index 5d819b3..ee1c06e 100644 --- a/src/test/java/rife/bld/extension/ExecOperationTest.java +++ b/src/test/java/rife/bld/extension/ExecOperationTest.java @@ -19,6 +19,7 @@ package rife.bld.extension; import org.junit.jupiter.api.Test; import rife.bld.BaseProject; import rife.bld.Project; +import rife.bld.WebProject; import java.io.File; import java.util.List; @@ -57,32 +58,49 @@ class ExecOperationTest { @Test void testFailOnExit() { - assertThatCode(() -> - new ExecOperation() - .fromProject(new BaseProject()) - .command(List.of("cat", FOO)) - .failOnExit(false) - .execute()).doesNotThrowAnyException(); + var op = new ExecOperation() + .fromProject(new BaseProject()) + .command(List.of("cat", FOO)) + .failOnExit(false); + assertThat(op.isFailOnExit()).isFalse(); + assertThatCode(op::execute).doesNotThrowAnyException(); + + op.failOnExit(true); + assertThat(op.isFailOnExit()).isTrue(); } @Test void testTimeout() { - assertThatCode(() -> - new ExecOperation() - .fromProject(new BaseProject()) - .timeout(5) - .command(List.of("sleep", "10")) - .execute()).message().contains("timed out"); + var op = new ExecOperation() + .fromProject(new BaseProject()) + .timeout(5) + .command(List.of("sleep", "10")); + assertThat(op.timeout()).isEqualTo(5); + assertThatCode(op::execute).message().contains("timed out"); + } + + @Test + void testTouch() 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(); } @Test void testWorkDir() { - assertThatCode(() -> - new ExecOperation() - .fromProject(new BaseProject()) - .command("echo", FOO) - .workDir(new File(System.getProperty("java.io.tmpdir"))) - .execute()).doesNotThrowAnyException(); + var workDir = new File(System.getProperty("java.io.tmpdir")); + var op = new ExecOperation() + .fromProject(new BaseProject()) + .command("echo", FOO) + .workDir(workDir); + assertThat(op.workDir()).isEqualTo(workDir); + assertThatCode(op::execute).doesNotThrowAnyException(); } @Test