Compare commits

...

3 commits

8 changed files with 49 additions and 28 deletions

View file

@ -2,12 +2,12 @@
<library name="bld"> <library name="bld">
<CLASSES> <CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.0.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" /> <root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.0-sources.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1-sources.jar!/" />
</SOURCES> </SOURCES>
<excluded> <excluded>
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" /> <root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />

View file

@ -9,7 +9,7 @@
], ],
"java.configuration.updateBuildConfiguration": "automatic", "java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [ "java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-1.9.0.jar", "${HOME}/.bld/dist/bld-1.9.1.jar",
"lib/**/*.jar" "lib/**/*.jar"
] ]
} }

View file

@ -2,7 +2,7 @@
[![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![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) [![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) [![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) [![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) [![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 ```java
@BuildCommand @BuildCommand

Binary file not shown.

View file

@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true 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.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation= bld.downloadLocation=
bld.sourceDirectories= bld.sourceDirectories=
bld.version=1.9.0 bld.version=1.9.1

View file

@ -35,7 +35,7 @@ public class ExecOperationBuild extends Project {
public ExecOperationBuild() { public ExecOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "ExecOperation"; name = "ExecOperation";
version = version(1, 0, 0); version = version(1, 0, 1, "SNAPSHOT");
javaRelease = 17; javaRelease = 17;
@ -44,7 +44,7 @@ public class ExecOperationBuild extends Project {
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES); repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
scope(compile) scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 0))); .include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1)));
scope(test) scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2))) .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.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))

View file

@ -24,6 +24,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -39,8 +40,8 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
private final List<String> args_ = new ArrayList<>(); private final List<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;
private String workDir_; private File workDir_;
/** /**
* Configures the command and arguments to be executed. * Configures the command and arguments to be executed.
@ -81,11 +82,11 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
LOGGER.severe("A project must be specified."); LOGGER.severe("A project must be specified.");
} }
final File workDir; final File workDir = Objects.requireNonNullElseGet(workDir_,
if (workDir_ == null || workDir_.isBlank()) { () -> new File(project_.workDirectory().getAbsolutePath()));
workDir = new File(project_.workDirectory().getAbsolutePath());
} else { if (LOGGER.isLoggable(Level.INFO)) {
workDir = new File(workDir_); LOGGER.info("Working directory: " + workDir.getAbsolutePath());
} }
if (workDir.isDirectory()) { if (workDir.isDirectory()) {
@ -99,21 +100,21 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
} }
var proc = pb.start(); var proc = pb.start();
var err = proc.waitFor(timeout, TimeUnit.SECONDS); var err = proc.waitFor(timeout_, TimeUnit.SECONDS);
if (!err) { if (!err) {
proc.destroy(); proc.destroy();
throw new IOException("The command timed out."); throw new IOException("The command timed out.");
} else if (proc.exitValue() != 0 && failOnExit_) { } 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 { } 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.
* <p> * <p>
* Default is {@code TRUE} * Default is {@code TRUE}
* *
@ -143,18 +144,28 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
* @return this operation instance * @return this operation instance
*/ */
public ExecOperation timeout(int timeout) { public ExecOperation timeout(int timeout) {
this.timeout = timeout; timeout_ = timeout;
return this; 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 * @param dir the directory path
* @return this operation instance * @return this operation instance
*/ */
public ExecOperation workDir(String dir) { public ExecOperation workDir(String dir) {
workDir_ = dir; return workDir(new File(dir));
return this;
} }
} }

View file

@ -53,12 +53,12 @@ class ExecOperationTest {
} }
@Test @Test
void testExitStatus() { void testExitValue() {
assertThatCode(() -> assertThatCode(() ->
new ExecOperation() new ExecOperation()
.fromProject(new BaseProject()) .fromProject(new BaseProject())
.command(List.of("cat", FOO)) .command(List.of("cat", FOO))
.execute()).message().contains("exit status"); .execute()).message().contains("exit value/status");
} }
@Test @Test
@ -83,11 +83,21 @@ class ExecOperationTest {
@Test @Test
void testWorkDir() { 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(() -> assertThatCode(() ->
new ExecOperation() new ExecOperation()
.fromProject(new BaseProject()) .fromProject(new BaseProject())
.command("echo") .command("echo")
.workDir(FOO) .workDir(FOO)
.execute()).message().startsWith("Invalid work directory: ").endsWith(FOO); .execute()).message().startsWith("Invalid working directory: ").endsWith(FOO);
} }
} }