mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-24 15:57:11 -07:00
Improvement to environment API for process operation.
This commit is contained in:
parent
9362a60c52
commit
4b6cac6ace
3 changed files with 32 additions and 10 deletions
|
@ -170,6 +170,19 @@ public abstract class AbstractProcessOperation<T extends AbstractProcessOperatio
|
|||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an environment variable to use for the operation.
|
||||
*
|
||||
* @param name the name of the environment variable
|
||||
* @param value the value of the environment variable
|
||||
* @return this operation instance
|
||||
* @since 2.2.1
|
||||
*/
|
||||
public T environment(String name, String value) {
|
||||
environment_.put(name, value);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides environment variable entries to use for the operation.
|
||||
*
|
||||
|
|
|
@ -40,6 +40,7 @@ public class TestJUnitOperation {
|
|||
void testPopulation()
|
||||
throws Exception {
|
||||
var environment = Map.of("env1", "val1", "env2", "val2", "env3", "val3");
|
||||
var environment_full = Map.of("env1", "val1", "env2", "val2", "env3", "val3", "env4", "val4");
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var java_tool = "javatool";
|
||||
|
@ -57,6 +58,7 @@ public class TestJUnitOperation {
|
|||
operation1
|
||||
.workDirectory(work_directory)
|
||||
.environment(environment)
|
||||
.environment("env4", "val4")
|
||||
.javaTool(java_tool)
|
||||
.javaOptions(List.of(test_java_option1, test_java_option2))
|
||||
.testToolOptions(List.of(test_tool_option1, test_tool_option2))
|
||||
|
@ -66,7 +68,7 @@ public class TestJUnitOperation {
|
|||
.errorProcessor(test_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation1.workDirectory());
|
||||
assertEquals(environment, operation1.environment());
|
||||
assertEquals(environment_full, operation1.environment());
|
||||
assertEquals(java_tool, operation1.javaTool());
|
||||
assertTrue(operation1.javaOptions().contains(test_java_option1));
|
||||
assertTrue(operation1.javaOptions().contains(test_java_option2));
|
||||
|
@ -81,6 +83,7 @@ public class TestJUnitOperation {
|
|||
var operation2 = new JUnitOperation();
|
||||
operation2.workDirectory(work_directory);
|
||||
operation2.environment(environment);
|
||||
operation2.environment("env4", "val4");
|
||||
operation2.javaTool(java_tool);
|
||||
operation2.javaOptions().add(test_java_option1);
|
||||
operation2.javaOptions().add(test_java_option2);
|
||||
|
@ -93,7 +96,7 @@ public class TestJUnitOperation {
|
|||
operation2.errorProcessor(test_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation2.workDirectory());
|
||||
assertEquals(environment, operation2.environment());
|
||||
assertEquals(environment_full, operation2.environment());
|
||||
assertEquals(java_tool, operation2.javaTool());
|
||||
assertTrue(operation2.javaOptions().contains(test_java_option1));
|
||||
assertTrue(operation2.javaOptions().contains(test_java_option2));
|
||||
|
@ -131,7 +134,7 @@ public class TestJUnitOperation {
|
|||
public class Source1 {
|
||||
public final String name_;
|
||||
public Source1() {
|
||||
name_ = System.getenv("execute_name");
|
||||
name_ = System.getenv("execute_name") + System.getenv("execute_number");
|
||||
}
|
||||
|
||||
public static void main(String[] arguments)
|
||||
|
@ -163,7 +166,8 @@ public class TestJUnitOperation {
|
|||
|
||||
var output = new StringBuilder();
|
||||
var test_operation = new JUnitOperation()
|
||||
.environment(Map.of("execute_name", "source1"))
|
||||
.environment(Map.of("execute_name", "source"))
|
||||
.environment("execute_number", "1")
|
||||
.mainClass("Source2")
|
||||
.classpath(List.of(build_main.getAbsolutePath(), build_test.getAbsolutePath()))
|
||||
.outputProcessor(s -> {
|
||||
|
|
|
@ -41,6 +41,7 @@ public class TestRunOperation {
|
|||
void testPopulation()
|
||||
throws Exception {
|
||||
var environment = Map.of("env1", "val1", "env2", "val2", "env3", "val3");
|
||||
var environment_full = Map.of("env1", "val1", "env2", "val2", "env3", "val3", "env4", "val4");
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var java_tool = "javatool";
|
||||
|
@ -59,6 +60,7 @@ public class TestRunOperation {
|
|||
operation1
|
||||
.workDirectory(work_directory)
|
||||
.environment(environment)
|
||||
.environment("env4", "val4")
|
||||
.javaTool(java_tool)
|
||||
.javaOptions(List.of(run_java_option1, run_java_option2))
|
||||
.classpath(List.of(run_classpath1, run_classpath2))
|
||||
|
@ -69,7 +71,7 @@ public class TestRunOperation {
|
|||
.errorProcessor(run_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation1.workDirectory());
|
||||
assertEquals(environment, operation1.environment());
|
||||
assertEquals(environment_full, operation1.environment());
|
||||
assertEquals(java_tool, operation1.javaTool());
|
||||
assertTrue(operation1.javaOptions().contains(run_java_option1));
|
||||
assertTrue(operation1.javaOptions().contains(run_java_option2));
|
||||
|
@ -85,6 +87,7 @@ public class TestRunOperation {
|
|||
var operation2 = new RunOperation();
|
||||
operation2.workDirectory(work_directory);
|
||||
operation2.environment(environment);
|
||||
operation2.environment("env4", "val4");
|
||||
operation2.javaTool(java_tool);
|
||||
operation2.javaOptions().add(run_java_option1);
|
||||
operation2.javaOptions().add(run_java_option2);
|
||||
|
@ -98,7 +101,7 @@ public class TestRunOperation {
|
|||
operation2.errorProcessor(run_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation2.workDirectory());
|
||||
assertEquals(environment, operation2.environment());
|
||||
assertEquals(environment_full, operation2.environment());
|
||||
assertEquals(java_tool, operation2.javaTool());
|
||||
assertTrue(operation2.javaOptions().contains(run_java_option1));
|
||||
assertTrue(operation2.javaOptions().contains(run_java_option2));
|
||||
|
@ -136,7 +139,7 @@ public class TestRunOperation {
|
|||
public class Source1 {
|
||||
public final String name_;
|
||||
public Source1() {
|
||||
name_ = System.getenv("execute_name");
|
||||
name_ = System.getenv("execute_name") + System.getenv("execute_number");
|
||||
}
|
||||
|
||||
public static void main(String[] arguments)
|
||||
|
@ -156,7 +159,8 @@ public class TestRunOperation {
|
|||
|
||||
var output = new StringBuilder();
|
||||
var run_operation = new RunOperation()
|
||||
.environment(Map.of("execute_name", "source1"))
|
||||
.environment(Map.of("execute_name", "source"))
|
||||
.environment("execute_number", "1")
|
||||
.mainClass("Source1")
|
||||
.classpath(List.of(build_main.getAbsolutePath()))
|
||||
.outputProcessor(s -> {
|
||||
|
@ -187,7 +191,7 @@ public class TestRunOperation {
|
|||
public class Source1 {
|
||||
public final String name_;
|
||||
public Source1() {
|
||||
name_ = System.getenv("execute_name");
|
||||
name_ = System.getenv("execute_name") + System.getenv("execute_number");
|
||||
}
|
||||
|
||||
public static void main(String[] arguments)
|
||||
|
@ -222,7 +226,8 @@ public class TestRunOperation {
|
|||
|
||||
var output = new StringBuilder();
|
||||
var run_operation = new RunOperation()
|
||||
.environment(Map.of("execute_name", "source1"))
|
||||
.environment(Map.of("execute_name", "source"))
|
||||
.environment("execute_number", "1")
|
||||
.module("pkg")
|
||||
.modulePath(new File(destination_dir, destination_name).getAbsolutePath())
|
||||
.outputProcessor(s -> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue