Search in sources :

Example 6 with EnvironmentVariables

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"));
}
Also used : EnvironmentVariables(com.oracle.bedrock.runtime.options.EnvironmentVariables) Platform(com.oracle.bedrock.runtime.Platform) Properties(java.util.Properties) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 7 with EnvironmentVariables

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"));
}
Also used : EnvironmentVariables(com.oracle.bedrock.runtime.options.EnvironmentVariables) Platform(com.oracle.bedrock.runtime.Platform) Properties(java.util.Properties) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 8 with EnvironmentVariables

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"));
}
Also used : EnvironmentVariables(com.oracle.bedrock.runtime.options.EnvironmentVariables) Platform(com.oracle.bedrock.runtime.Platform) Properties(java.util.Properties) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 9 with EnvironmentVariables

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"));
}
Also used : EnvironmentVariables(com.oracle.bedrock.runtime.options.EnvironmentVariables) Docker(com.oracle.bedrock.runtime.docker.Docker) Properties(java.util.Properties) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 10 with EnvironmentVariables

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;
}
Also used : Table(com.oracle.bedrock.table.Table) EnvironmentVariables(com.oracle.bedrock.runtime.options.EnvironmentVariables) Properties(java.util.Properties)

Aggregations

EnvironmentVariables (com.oracle.bedrock.runtime.options.EnvironmentVariables)10 Properties (java.util.Properties)9 OptionsByType (com.oracle.bedrock.OptionsByType)8 Platform (com.oracle.bedrock.runtime.Platform)5 Arguments (com.oracle.bedrock.runtime.options.Arguments)4 Test (org.junit.Test)4 Table (com.oracle.bedrock.table.Table)3 File (java.io.File)3 LaunchLogging (com.oracle.bedrock.options.LaunchLogging)2 DisplayName (com.oracle.bedrock.runtime.options.DisplayName)2 ErrorStreamRedirection (com.oracle.bedrock.runtime.options.ErrorStreamRedirection)2 Executable (com.oracle.bedrock.runtime.options.Executable)2 WorkingDirectory (com.oracle.bedrock.runtime.options.WorkingDirectory)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Option (com.oracle.bedrock.Option)1 PermanentlyUnavailableException (com.oracle.bedrock.deferred.PermanentlyUnavailableException)1 TemporarilyUnavailableException (com.oracle.bedrock.deferred.TemporarilyUnavailableException)1 ExpressionEvaluator (com.oracle.bedrock.lang.ExpressionEvaluator)1