use of com.oracle.bedrock.runtime.options.EnvironmentVariables in project oracle-bedrock by coherence-community.
the class CommonCommandTests method shouldSetEnvironmentVariablesFromEnvironmentables.
@Test
public void shouldSetEnvironmentVariablesFromEnvironmentables() throws Exception {
Platform platform = mock(Platform.class);
OptionsByType options = OptionsByType.empty();
C command = newInstance();
EnvironmentVariables vars = EnvironmentVariables.custom().with(EnvironmentVariable.of("foo", "foo-value")).with(EnvironmentVariable.of("bar", "bar-value"));
CLI copy = command.withEnvironment(vars);
assertThat(copy, is(notNullValue()));
assertThat(copy, is(instanceOf(command.getClass())));
assertThat(copy.getCommands(), is(command.getCommands()));
assertThat(copy.getArguments(), is(command.getArguments()));
assertThat(copy.getFlags(), is(command.getFlags()));
copy.onLaunching(platform, options);
EnvironmentVariables variables = options.get(EnvironmentVariables.class);
assertThat(variables, is(notNullValue()));
Properties properties = variables.realize(platform);
assertThat(properties, is(notNullValue()));
assertThat(properties.get("foo"), is("foo-value"));
assertThat(properties.get("bar"), is("bar-value"));
}
use of com.oracle.bedrock.runtime.options.EnvironmentVariables in project oracle-bedrock by coherence-community.
the class CommonCommandTests method shouldSetEnvironmentVariables.
@Test
public void shouldSetEnvironmentVariables() throws Exception {
Platform platform = mock(Platform.class);
OptionsByType options = OptionsByType.empty();
C command = newInstance();
CLI copy = command.withEnvironment(EnvironmentVariable.of("foo", "foo-value"), EnvironmentVariable.of("bar", "bar-value"));
assertThat(copy, is(notNullValue()));
assertThat(copy, is(instanceOf(command.getClass())));
assertThat(copy.getCommands(), is(command.getCommands()));
assertThat(copy.getArguments(), is(command.getArguments()));
assertThat(copy.getFlags(), is(command.getFlags()));
copy.onLaunching(platform, options);
EnvironmentVariables variables = options.get(EnvironmentVariables.class);
assertThat(variables, is(notNullValue()));
Properties properties = variables.realize(platform);
assertThat(properties, is(notNullValue()));
assertThat(properties.get("foo"), is("foo-value"));
assertThat(properties.get("bar"), is("bar-value"));
}
use of com.oracle.bedrock.runtime.options.EnvironmentVariables in project oracle-bedrock by coherence-community.
the class CommonCommandTests method shouldSetEnvironmentVariableFromNameAndValue.
@Test
public void shouldSetEnvironmentVariableFromNameAndValue() throws Exception {
Platform platform = mock(Platform.class);
OptionsByType options = OptionsByType.empty();
C command = newInstance();
CLI copy = command.withEnvironment("foo-var", "foo-value");
assertThat(copy, is(notNullValue()));
assertThat(copy, is(instanceOf(command.getClass())));
assertThat(copy.getCommands(), is(command.getCommands()));
assertThat(copy.getArguments(), is(command.getArguments()));
assertThat(copy.getFlags(), is(command.getFlags()));
copy.onLaunching(platform, options);
EnvironmentVariables variables = options.get(EnvironmentVariables.class);
assertThat(variables, is(notNullValue()));
Properties properties = variables.realize(platform);
assertThat(properties, is(notNullValue()));
assertThat(properties.get("foo-var"), is("foo-value"));
}
use of com.oracle.bedrock.runtime.options.EnvironmentVariables in project oracle-bedrock by coherence-community.
the class AbstractDockerCommandTest method shouldAddEnvironmentVariablesOnFinalize.
@Test
public void shouldAddEnvironmentVariablesOnFinalize() throws Exception {
Docker docker = Docker.auto().withEnvironmentVariables(EnvironmentVariable.of("foo", "foo1"), EnvironmentVariable.of("bar", "bar1"));
OptionsByType optionsByType = OptionsByType.of(docker);
AbstractDockerCommand command = new CommandStub("foo");
command.onLaunch(LocalPlatform.get(), optionsByType);
EnvironmentVariables env = optionsByType.get(EnvironmentVariables.class);
Properties vars = env.realize(LocalPlatform.get());
assertThat(vars.get("foo"), is("foo1"));
assertThat(vars.get("bar"), is("bar1"));
}
use of com.oracle.bedrock.runtime.options.EnvironmentVariables in project oracle-bedrock by coherence-community.
the class AbstractRemoteApplicationLauncher method getEnvironmentVariables.
@Override
public Properties getEnvironmentVariables(Platform platform, OptionsByType optionsByType) {
Table diagnosticsTable = optionsByType.get(Table.class);
EnvironmentVariables environmentVariables = optionsByType.getOrSetDefault(EnvironmentVariables.class, EnvironmentVariables.of(EnvironmentVariables.Source.TargetPlatform));
Properties variables = new Properties();
switch(environmentVariables.getSource()) {
case Custom:
if (diagnosticsTable != null) {
diagnosticsTable.addRow("Environment Variables", "(cleared)");
}
break;
case ThisApplication:
variables.putAll(System.getenv());
if (diagnosticsTable != null) {
diagnosticsTable.addRow("Environment Variables", "(based on parent process)");
}
break;
case TargetPlatform:
if (diagnosticsTable != null) {
diagnosticsTable.addRow("Environment Variables", "(based on platform defaults)");
}
break;
}
// add the optionally defined environment variables
variables.putAll(environmentVariables.realize(platform, optionsByType.asArray()));
if (variables.size() > 0 && diagnosticsTable != null) {
Table table = Tabularize.tabularize(variables);
diagnosticsTable.addRow("", table.toString());
}
return variables;
}
Aggregations