Added opton to add a List via the command method
This commit is contained in:
parent
9843cfeb6b
commit
193c791408
6 changed files with 44 additions and 8 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -53,3 +53,6 @@ atlassian-ide-plugin.xml
|
|||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Local Properties
|
||||
local.properties
|
8
.idea/misc.xml
generated
8
.idea/misc.xml
generated
|
@ -7,9 +7,15 @@
|
|||
<component name="PDMPlugin">
|
||||
<option name="customRuleSets">
|
||||
<list>
|
||||
<option value="K:\java\semver\config\pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/config/pmd.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="options">
|
||||
<map>
|
||||
<entry key="Statistics URL" value="" />
|
||||
<entry key="Target JDK" value="17" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
|
|
10
README.md
10
README.md
|
@ -29,9 +29,15 @@ constitute a failure.
|
|||
```java
|
||||
@BuildCommand
|
||||
public void startServer() throws Exception {
|
||||
final List<String> cmds;
|
||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
cmds = List.of("cmd", "/c", "stop.bat");
|
||||
} else {
|
||||
cmds = List.of("./stop.sh");
|
||||
}
|
||||
new ExecOperation()
|
||||
.fromProject(this)
|
||||
.command("cmd", "/c", "stop.bat")
|
||||
.command(cmds)
|
||||
.fail(ExecFail.STDERR)
|
||||
.execute();
|
||||
}
|
||||
|
@ -61,7 +67,7 @@ public void startServer() throws Exception {
|
|||
new ExecOperation()
|
||||
.fromProject(this)
|
||||
.command("touch", "foo.txt")
|
||||
.workDir("/tmp")
|
||||
.workDir(System.getProperty("java.io.tmpdir"))
|
||||
.execute();
|
||||
}
|
||||
```
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
</properties>
|
||||
</rule>
|
||||
|
||||
|
||||
<!-- CODE STYLE -->
|
||||
<rule ref="category/java/codestyle.xml">
|
||||
<exclude name="AtLeastOneConstructor"/>
|
||||
|
|
|
@ -54,6 +54,16 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the command and arguments to be executed.
|
||||
*
|
||||
* @see #command(String...)
|
||||
*/
|
||||
public ExecOperation command(List<String> args) {
|
||||
args_.addAll(args);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the command.
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@ import rife.bld.WebProject;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
@ -30,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
|||
|
||||
class ExecOperationTest {
|
||||
private static final String FOO = "foo";
|
||||
private static final String HELLO = "Hello";
|
||||
|
||||
@Test
|
||||
void testAll() {
|
||||
|
@ -55,6 +57,16 @@ class ExecOperationTest {
|
|||
assertThat(tmpFile).exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCommandList() {
|
||||
assertThatCode(() ->
|
||||
new ExecOperation()
|
||||
.fromProject(new BaseProject())
|
||||
.command(List.of("logger", "-s", HELLO))
|
||||
.fail(ExecFail.STDERR)
|
||||
.execute()).message().startsWith("STDERR -> ").endsWith(HELLO);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testException() {
|
||||
assertThatCode(() ->
|
||||
|
@ -100,9 +112,9 @@ class ExecOperationTest {
|
|||
assertThatCode(() ->
|
||||
new ExecOperation()
|
||||
.fromProject(new BaseProject())
|
||||
.command("logger", "-s", "Hello")
|
||||
.command("logger", "-s", HELLO)
|
||||
.fail(ExecFail.STDERR)
|
||||
.execute()).message().startsWith("STDERR -> ").endsWith("Hello");
|
||||
.execute()).message().startsWith("STDERR -> ").endsWith(HELLO);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -110,7 +122,7 @@ class ExecOperationTest {
|
|||
assertThatCode(() ->
|
||||
new ExecOperation()
|
||||
.fromProject(new BaseProject())
|
||||
.command("echo", "Hello")
|
||||
.command("echo", HELLO)
|
||||
.fail(ExecFail.STDOUT)
|
||||
.execute()).message().isEqualTo("STDOUT -> Hello");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue