From 2a2c81994a5a08ffdc4cce1c62855fd5e3549100 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 5 Apr 2024 12:55:44 -0700 Subject: [PATCH 1/3] A File can now also be used to specify the working dir --- .../rife/bld/extension/ExecOperation.java | 41 ++++++++++++------- .../rife/bld/extension/ExecOperationTest.java | 16 ++++++-- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/main/java/rife/bld/extension/ExecOperation.java b/src/main/java/rife/bld/extension/ExecOperation.java index f07d740..af192d0 100644 --- a/src/main/java/rife/bld/extension/ExecOperation.java +++ b/src/main/java/rife/bld/extension/ExecOperation.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -39,8 +40,8 @@ public class ExecOperation extends AbstractOperation { private final List args_ = new ArrayList<>(); private boolean failOnExit_ = true; private BaseProject project_; - private int timeout = 30; - private String workDir_; + private int timeout_ = 30; + private File workDir_; /** * Configures the command and arguments to be executed. @@ -81,11 +82,11 @@ public class ExecOperation extends AbstractOperation { LOGGER.severe("A project must be specified."); } - final File workDir; - if (workDir_ == null || workDir_.isBlank()) { - workDir = new File(project_.workDirectory().getAbsolutePath()); - } else { - workDir = new File(workDir_); + final File workDir = Objects.requireNonNullElseGet(workDir_, + () -> new File(project_.workDirectory().getAbsolutePath())); + + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.info("Working directory: " + workDir.getAbsolutePath()); } if (workDir.isDirectory()) { @@ -99,21 +100,21 @@ public class ExecOperation extends AbstractOperation { } var proc = pb.start(); - var err = proc.waitFor(timeout, TimeUnit.SECONDS); + var err = proc.waitFor(timeout_, TimeUnit.SECONDS); if (!err) { proc.destroy(); throw new IOException("The command timed out."); } else if (proc.exitValue() != 0 && failOnExit_) { - throw new IOException("The command exit status is: " + proc.exitValue()); + throw new IOException("The command exit value/status is: " + proc.exitValue()); } } else { - throw new IOException("Invalid work directory: " + workDir); + throw new IOException("Invalid working directory: " + workDir); } } /** - * Configures whether the operation should fail if the command exit status is not 0. + * Configures whether the operation should fail if the command exit value/status is not 0. *

* Default is {@code TRUE} * @@ -143,18 +144,28 @@ public class ExecOperation extends AbstractOperation { * @return this operation instance */ public ExecOperation timeout(int timeout) { - this.timeout = timeout; + timeout_ = timeout; return this; } /** - * Configures the work directory. + * Configures the working directory. + * + * @param dir the directory + * @return this operation instance + */ + public ExecOperation workDir(File dir) { + workDir_ = dir; + return this; + } + + /** + * Configures the working directory. * * @param dir the directory path * @return this operation instance */ public ExecOperation workDir(String dir) { - workDir_ = dir; - return this; + return workDir(new File(dir)); } } diff --git a/src/test/java/rife/bld/extension/ExecOperationTest.java b/src/test/java/rife/bld/extension/ExecOperationTest.java index e0b584c..d070e15 100644 --- a/src/test/java/rife/bld/extension/ExecOperationTest.java +++ b/src/test/java/rife/bld/extension/ExecOperationTest.java @@ -53,12 +53,12 @@ class ExecOperationTest { } @Test - void testExitStatus() { + void testExitValue() { assertThatCode(() -> new ExecOperation() .fromProject(new BaseProject()) .command(List.of("cat", FOO)) - .execute()).message().contains("exit status"); + .execute()).message().contains("exit value/status"); } @Test @@ -83,11 +83,21 @@ class ExecOperationTest { @Test void testWorkDir() { + assertThatCode(() -> + new ExecOperation() + .fromProject(new BaseProject()) + .command("echo", FOO) + .workDir(new File(System.getProperty("java.io.tmpdir"))) + .execute()).doesNotThrowAnyException(); + } + + @Test + void testWorkDirInvalid() { assertThatCode(() -> new ExecOperation() .fromProject(new BaseProject()) .command("echo") .workDir(FOO) - .execute()).message().startsWith("Invalid work directory: ").endsWith(FOO); + .execute()).message().startsWith("Invalid working directory: ").endsWith(FOO); } } From d5882eca8447de2bd55c0db678f72533b8f3f3d1 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 9 May 2024 21:11:50 -0700 Subject: [PATCH 2/3] Bumped bld to version 1.9.1 --- .idea/libraries/bld.xml | 4 ++-- .vscode/settings.json | 2 +- README.md | 6 +++--- lib/bld/bld-wrapper.jar | Bin 27319 -> 27319 bytes lib/bld/bld-wrapper.properties | 2 +- .../bld/extension/ExecOperationBuild.java | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.idea/libraries/bld.xml b/.idea/libraries/bld.xml index 59ffe59..48e8fd5 100644 --- a/.idea/libraries/bld.xml +++ b/.idea/libraries/bld.xml @@ -2,12 +2,12 @@ - + - + diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e8368e..d136e4d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,7 @@ ], "java.configuration.updateBuildConfiguration": "automatic", "java.project.referencedLibraries": [ - "${HOME}/.bld/dist/bld-1.9.0.jar", + "${HOME}/.bld/dist/bld-1.9.1.jar", "lib/**/*.jar" ] } diff --git a/README.md b/README.md index c707871..9b2a9a1 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) -[![bld](https://img.shields.io/badge/1.9.0-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) +[![bld](https://img.shields.io/badge/1.9.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) [![Release](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/releases/com/uwyn/rife2/bld-exec/maven-metadata.xml?color=blue)](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-exec) [![Snapshot](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/snapshots/com/uwyn/rife2/bld-exec/maven-metadata.xml?label=snapshot)](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-exec) [![GitHub CI](https://github.com/rife2/bld-exec/actions/workflows/bld.yml/badge.svg)](https://github.com/rife2/bld-exec/actions/workflows/bld.yml) @@ -21,9 +21,9 @@ public void startServer() throws Exception { } ``` -## Exit Status +## Exit Value -Use the `failOnExit` function to specify whether a command non-zero exit status constitutes a failure. +Use the `failOnExit` function to specify whether a command non-zero exit value (status) constitutes a failure. ```java @BuildCommand diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index 82762f1dd24fca63ea5add2e5d08292f16e8a107..ffdaf71a2b7a43e762ee9f7e68ef77a690ee56a4 100644 GIT binary patch delta 166 zcmdmfm2vx3M&1B#W)=|!4h{~6FWrkL^42i}sf~R~#vpq0X5(%qFvHP|T@TFgPC3sA zX2_-)f~6)0W+*DMFa&tBbLeNj&1Pp{U| Date: Thu, 9 May 2024 21:12:06 -0700 Subject: [PATCH 3/3] Bumped PMD extension to version 0.9.9 --- lib/bld/bld-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index f882472..cab667f 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,6 +1,6 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true -bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.8 +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=