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;
}
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);
}
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);
}
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);
}
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");
}
Aggregations