Skip to content

Commit

Permalink
Added command timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Apr 4, 2024
1 parent b1c8c49 commit 8b80ca1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.3
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.8
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.sourceDirectories=
Expand Down
7 changes: 4 additions & 3 deletions src/bld/java/rife/bld/extension/ExecOperationBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public class ExecOperationBuild extends Project {
public ExecOperationBuild() {
pkg = "rife.bld.extension";
name = "ExecOperation";
version = version(0, 9, 2);
version = version(0, 9, 3);

javaRelease = 17;

downloadSources = true;
autoDownloadPurge = true;
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);

repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 0)));
scope(test)
Expand Down Expand Up @@ -73,7 +74,7 @@ public ExecOperationBuild() {
.license(
new PublishLicense()
.name("The Apache License, Version 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0.txt")
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
)
.scm(
new PublishScm()
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/rife/bld/extension/ExecOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
private final List<String> args_ = new ArrayList<>();
private final Set<ExecFail> fail_ = new HashSet<>();
private BaseProject project_;
private int timeout = 30;
private String workDir_;

/**
Expand Down Expand Up @@ -98,7 +99,7 @@ public void execute() throws Exception {
}

var proc = pb.start();
var err = proc.waitFor(30, TimeUnit.SECONDS);
var err = proc.waitFor(timeout, TimeUnit.SECONDS);
var stdout = readStream(proc.getInputStream());
var stderr = readStream(proc.getErrorStream());

Expand Down Expand Up @@ -180,6 +181,17 @@ private List<String> readStream(InputStream stream) {
return lines;
}

/**
* Configure the command timeout.
*
* @param timeout The timeout in seconds
* @return this operation instance
*/
public ExecOperation timeout(int timeout) {
this.timeout = timeout;
return this;
}

/**
* Configures the working directory.
*
Expand Down
1 change: 1 addition & 0 deletions src/test/java/rife/bld/extension/ExecOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void testCat() throws Exception {
tmpFile.deleteOnExit();
new ExecOperation()
.fromProject(new Project())
.timeout(10)
.command("touch", tmpFile.getName())
.fail(ExecFail.NORMAL)
.execute();
Expand Down

0 comments on commit 8b80ca1

Please sign in to comment.