Compare commits

..

No commits in common. "6e8d3c2cd6283e98448c9e0290399be0baf9428e" and "906969525efaab799e2623cd1cadf0a5936a0920" have entirely different histories.

5 changed files with 33 additions and 82 deletions

Binary file not shown.

View file

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

View file

@ -48,7 +48,7 @@ public class ExecOperationBuild extends Project {
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)))
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0))); .include(dependency("org.assertj", "assertj-core", version(3, 25, 3)));
javadocOperation() javadocOperation()
.javadocOptions() .javadocOptions()

View file

@ -37,7 +37,7 @@ import java.util.logging.Logger;
*/ */
public class ExecOperation extends AbstractOperation<ExecOperation> { public class ExecOperation extends AbstractOperation<ExecOperation> {
private static final Logger LOGGER = Logger.getLogger(ExecOperation.class.getName()); private static final Logger LOGGER = Logger.getLogger(ExecOperation.class.getName());
private final Collection<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;
@ -61,16 +61,6 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
return this; return this;
} }
/**
* Returns the command and arguments to be executed.
*
* @return the command and arguments
*/
public Collection<String> command() {
return args_;
}
/** /**
* Configures the command and arguments to be executed. * Configures the command and arguments to be executed.
* *
@ -102,7 +92,7 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
if (workDir.isDirectory()) { if (workDir.isDirectory()) {
var pb = new ProcessBuilder(); var pb = new ProcessBuilder();
pb.inheritIO(); pb.inheritIO();
pb.command(args_.stream().toList()); pb.command(args_);
pb.directory(workDir); pb.directory(workDir);
if (LOGGER.isLoggable(Level.INFO)) { if (LOGGER.isLoggable(Level.INFO)) {
@ -147,15 +137,6 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
return this; 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. * Configure the command timeout.
* *
@ -167,15 +148,6 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
return this; return this;
} }
/**
* Returns the command timeout.
*
* @return the timeout
*/
public int timeout() {
return timeout_;
}
/** /**
* Configures the working directory. * Configures the working directory.
* *
@ -196,13 +168,4 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
public ExecOperation workDir(String dir) { public ExecOperation workDir(String dir) {
return workDir(new File(dir)); return workDir(new File(dir));
} }
/**
* Returns the working directory.
*
* @return the directory
*/
public File workDir() {
return workDir_;
}
} }

View file

@ -19,7 +19,6 @@ package rife.bld.extension;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import rife.bld.BaseProject; import rife.bld.BaseProject;
import rife.bld.Project; import rife.bld.Project;
import rife.bld.WebProject;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@ -32,10 +31,16 @@ class ExecOperationTest {
private static final String FOO = "foo"; private static final String FOO = "foo";
@Test @Test
void testCommand() { void testCat() throws Exception {
var op = new ExecOperation().fromProject(new WebProject()) var tmpFile = new File("hello.tmp");
.command(FOO, "bar"); tmpFile.deleteOnExit();
assertThat(op.command()).isEqualTo(List.of(FOO, "bar")); new ExecOperation()
.fromProject(new Project())
.timeout(10)
.command("touch", tmpFile.getName())
.execute();
assertThat(tmpFile).exists();
} }
@Test @Test
@ -58,49 +63,32 @@ class ExecOperationTest {
@Test @Test
void testFailOnExit() { void testFailOnExit() {
var op = new ExecOperation() assertThatCode(() ->
.fromProject(new BaseProject()) new ExecOperation()
.command(List.of("cat", FOO)) .fromProject(new BaseProject())
.failOnExit(false); .command(List.of("cat", FOO))
assertThat(op.isFailOnExit()).isFalse(); .failOnExit(false)
assertThatCode(op::execute).doesNotThrowAnyException(); .execute()).doesNotThrowAnyException();
op.failOnExit(true);
assertThat(op.isFailOnExit()).isTrue();
} }
@Test @Test
void testTimeout() { void testTimeout() {
var op = new ExecOperation() assertThatCode(() ->
.fromProject(new BaseProject()) new ExecOperation()
.timeout(5) .fromProject(new BaseProject())
.command(List.of("sleep", "10")); .timeout(5)
assertThat(op.timeout()).isEqualTo(5); .command(List.of("sleep", "10"))
assertThatCode(op::execute).message().contains("timed out"); .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 @Test
void testWorkDir() { void testWorkDir() {
var workDir = new File(System.getProperty("java.io.tmpdir")); assertThatCode(() ->
var op = new ExecOperation() new ExecOperation()
.fromProject(new BaseProject()) .fromProject(new BaseProject())
.command("echo", FOO) .command("echo", FOO)
.workDir(workDir); .workDir(new File(System.getProperty("java.io.tmpdir")))
assertThat(op.workDir()).isEqualTo(workDir); .execute()).doesNotThrowAnyException();
assertThatCode(op::execute).doesNotThrowAnyException();
} }
@Test @Test