Search in sources :

Example 96 with OptionsByType

use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.

the class Platform method getPlatform.

@Override
default Platform getPlatform(Option... options) {
    OptionsByType platformOptions = OptionsByType.of(options);
    PlatformPredicate predicate = platformOptions.get(PlatformPredicate.class);
    return predicate.test(this) ? this : null;
}
Also used : PlatformPredicate(com.oracle.bedrock.runtime.options.PlatformPredicate) OptionsByType(com.oracle.bedrock.OptionsByType)

Example 97 with OptionsByType

use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.

the class RemoteEvents method add.

/**
 * Internally adds a {@link RemoteEventListener} to this {@link RemoteEvents} option
 *
 * @param listener       the {@link RemoteEventListener} to add
 * @param optionsByType  the {@link OptionsByType} for the {@link RemoteEventListener}
 */
private void add(RemoteEventListener listener, OptionsByType optionsByType) {
    StreamName streamName = optionsByType.get(StreamName.class);
    HashMap<RemoteEventListener, OptionsByType> streamEventListeners = eventListeners.computeIfAbsent(streamName, name -> new HashMap<>());
    streamEventListeners.put(listener, optionsByType);
}
Also used : StreamName(com.oracle.bedrock.runtime.concurrent.options.StreamName) OptionsByType(com.oracle.bedrock.OptionsByType) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener)

Example 98 with OptionsByType

use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.

the class WorkingDirectory method temporaryDirectory.

public static WorkingDirectory temporaryDirectory() {
    ContextSensitiveDirectoryName name = new ContextSensitiveDirectoryName() {

        @Override
        public Object resolve(Platform platform, OptionsByType optionsByType) {
            DisplayName displayName = optionsByType.get(DisplayName.class);
            PlatformSeparators separators = optionsByType.get(PlatformSeparators.class);
            String sanitizedDisplayName = separators.asSanitizedFileName(displayName.resolve(optionsByType));
            Calendar now = Calendar.getInstance();
            String temporaryDirectoryName = String.format("%1$s-%2$tY%2$tm%2$td-%2$tH%2$tM%2$tS-%2$tL", sanitizedDisplayName, now);
            TemporaryDirectory defaultTemp = TemporaryDirectory.at(separators.getFileSeparator() + "tmp");
            TemporaryDirectory temporaryDirectory = optionsByType.getOrDefault(TemporaryDirectory.class, defaultTemp);
            return new File(temporaryDirectory.get().toFile(), temporaryDirectoryName);
        }
    };
    return new WorkingDirectory(name);
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) Calendar(java.util.Calendar) OptionsByType(com.oracle.bedrock.OptionsByType) File(java.io.File)

Example 99 with OptionsByType

use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.

the class WorkingDirectory method subDirectoryOf.

/**
 * Create a {@link WorkingDirectory} where the working directory for
 * the application will be a sub directory of the specified parent directory.
 *
 * @param parent  the parent directory of the working directory
 *
 * @return  a {@link WorkingDirectory} where the working directory for
 *          the application will be a sub directory of the specified
 *          parent directory
 */
public static WorkingDirectory subDirectoryOf(final File parent) {
    ContextSensitiveDirectoryName name = new ContextSensitiveDirectoryName() {

        @Override
        public Object resolve(Platform platform, OptionsByType optionsByType) {
            DisplayName displayName = optionsByType.get(DisplayName.class);
            PlatformSeparators separators = optionsByType.get(PlatformSeparators.class);
            String sanitizedDisplayName = separators.asSanitizedFileName(displayName.resolve(optionsByType));
            File parentFile = (parent != null) ? parent : new File(System.getProperty("user.dir"));
            return new File(parentFile, sanitizedDisplayName);
        }
    };
    return new WorkingDirectory(name);
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) OptionsByType(com.oracle.bedrock.OptionsByType) File(java.io.File)

Example 100 with OptionsByType

use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.

the class ProfilesTest method shouldReturnCreateProfiles.

/**
 * Ensure that we can load and instantiate Profiles.
 */
@Test
public void shouldReturnCreateProfiles() {
    System.setProperty("bedrock.profile.example", "hello");
    OptionsByType optionsByType = Profiles.getProfiles();
    assertThat(optionsByType, is(not(nullValue())));
    assertThat(optionsByType.asArray().length, is(1));
    ExampleProfile profile = optionsByType.get(ExampleProfile.class);
    assertThat(profile, is(not(nullValue())));
    assertThat(profile.getParameters(), is("hello"));
    System.getProperties().remove("bedrock.profile.example");
}
Also used : OptionsByType(com.oracle.bedrock.OptionsByType) ExampleProfile(com.oracle.bedrock.example.ExampleProfile) Test(org.junit.Test)

Aggregations

OptionsByType (com.oracle.bedrock.OptionsByType)171 Test (org.junit.Test)102 Platform (com.oracle.bedrock.runtime.Platform)56 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)30 Arguments (com.oracle.bedrock.runtime.options.Arguments)25 MetaClass (com.oracle.bedrock.runtime.MetaClass)24 Properties (java.util.Properties)19 File (java.io.File)18 Application (com.oracle.bedrock.runtime.Application)13 Option (com.oracle.bedrock.Option)12 DeployedArtifacts (com.oracle.bedrock.runtime.remote.DeployedArtifacts)10 DeploymentArtifact (com.oracle.bedrock.runtime.remote.DeploymentArtifact)10 EnvironmentVariables (com.oracle.bedrock.runtime.options.EnvironmentVariables)9 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)9 Session (com.jcraft.jsch.Session)8 Timeout (com.oracle.bedrock.options.Timeout)8 DisplayName (com.oracle.bedrock.runtime.options.DisplayName)8 SimpleJUnitTestRun (com.oracle.bedrock.testsupport.junit.SimpleJUnitTestRun)8 ArrayList (java.util.ArrayList)8 AbstractRemoteTest (com.oracle.bedrock.runtime.remote.AbstractRemoteTest)7