@Override public void onLaunching(Platform platform, OptionsByType optionsByType) { optionsByType.add(ClassName.of(JUnitTestRunner.class)); optionsByType.addIfAbsent(DisplayName.of("JUnit")); }
/** * Constructs a {@link Caching}. * * @param enabled is caching enabled? * @param options the {@link Option}s for {@link Caching} */ private Caching(boolean enabled, Option... options) { this.enabled = enabled; this.optionsByType = options == null || options.length == 0 ? OptionsByType.empty() : OptionsByType.of(options); }
optionsByType.addIfAbsent(ClassName.of(DEFAULT_CACHE_SERVER_CLASSNAME)); optionsByType.addIfAbsent(IPv4Preferred.yes()); optionsByType.add(Headless.enabled()); SystemProperties systemProperties = optionsByType.get(SystemProperties.class); optionsByType.add(systemProperties);
@Override public CompletableFuture<Void> raise(RemoteEvent event, Option... options) { if (isOpen()) { OptionsByType optionsByType = OptionsByType.of(options); StreamName streamName = optionsByType.get(StreamName.class); // by default we acknowledge when sent optionsByType.addIfAbsent(AcknowledgeWhen.SENT); EventOperation operation = new EventOperation(streamName, event, optionsByType); return sendOperation(operation, optionsByType); } else { throw new IllegalStateException("RemoteChannel is closed"); } }
@Override default DisplayName getDisplayName(OptionsByType optionsByType) { ClassName className = optionsByType.get(ClassName.class); if (className == null) { return optionsByType.get(DisplayName.class); } else { // determine the short class name of the class we're launching (as a possible default) String shortClassName = className.getName(); int lastDot = shortClassName.lastIndexOf("."); shortClassName = lastDot <= 0 ? shortClassName : shortClassName.substring(lastDot + 1); if (shortClassName.isEmpty()) { return optionsByType.get(DisplayName.class); } else { return optionsByType.getOrSetDefault(DisplayName.class, DisplayName.of(shortClassName)); } } } }
/** * Invokes the {@link RemoteCallable} in the {@link JavaApplication}, * waiting the default or provided {@link Timeout} for the result. * * @param callable the {@link RemoteCallable} * @param options the {@link Option}s * * @param <T> the type of the result * @return the value from the {@link RemoteCallable} */ default <T> T invoke(RemoteCallable<T> callable, Option... options) { // determine the timeout OptionsByType optionsByType = OptionsByType.of(options); Timeout timeout = optionsByType.getOrDefault(Timeout.class, getOptions().get(Timeout.class)); CompletableFuture<T> future = submit(callable, options); try { return future.get(timeout.to(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Launches a new {@link Application} based on the specified program executable / command * and provided {@link Option}s. * * @param executable the name of the executable / command to launch the application on the {@link Platform} * @param options the {@link Option}s for the {@link Application} * * @return an {@link Application} representing the launched application */ default Application launch(String executable, Option... options) { // add the program as a launch option OptionsByType optionsByType = OptionsByType.of(options).add(Executable.named(executable)); // launch as an Application.class return launch(Application.class, optionsByType.asArray()); }
@Override public Platform getPlatform(Option... options) { OptionsByType optionsByType = OptionsByType.of(options); PlatformPredicate predicate = optionsByType.getOrDefault(PlatformPredicate.class, PlatformPredicate.any()); Optional<Platform> platform = platforms.stream().filter(predicate).unordered().findFirst(); return platform.isPresent() ? platform.get() : null; } }
@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); } };
OptionsByType optionsByType) Table diagnosticsTable = optionsByType.get(Table.class); EnvironmentVariables environmentVariables = optionsByType.getOrSetDefault(EnvironmentVariables.class, EnvironmentVariables.of(EnvironmentVariables .Source.TargetPlatform)); variables.putAll(environmentVariables.realize(platform, optionsByType.asArray()));
@Override public CompletableFuture<Void> submit(RemoteRunnable runnable, Option... options) throws IllegalStateException { if (isOpen()) { OptionsByType optionsByType = OptionsByType.of(options); // by default we acknowledge when sent optionsByType.addIfAbsent(AcknowledgeWhen.SENT); RunnableOperation operation = new RunnableOperation(runnable, optionsByType); return sendOperation(operation, optionsByType); } else { throw new IllegalStateException("RemoteChannel is closed"); } }
@Override public HttpURLConnection openConnection(URL url, String userName, OptionsByType optionsByType) throws IOException { HttpAuthenticationType authType = optionsByType.getOrSetDefault(HttpAuthenticationType.class, HttpAuthenticationType.Basic); HttpProxy proxy = optionsByType.getOrSetDefault(HttpProxy.class, HttpProxy.none()); HttpURLConnection connection; switch (authType) { case Basic : String userPassword = userName + ":" + password; String encoding = Base64.getEncoder().encodeToString(userPassword.getBytes()); connection = proxy.openConnection(url); connection.setRequestProperty("Authorization", "Basic " + encoding); break; case NTLM : case Kerberos : default : throw new IllegalArgumentException("Unsupported HTTP authentication type " + authType); } return connection; } }
/** * The {@link Option}s to be used when closing the {@link Assembly}. * * @param options the {@link Option}s * * @return the {@link AbstractAssemblyResource} to permit fluent-style method calls * * @see Assembly#close(Option...) */ public R withClosingOptions(Option... options) { this.closingOptionsByType.addAll(options); return (R) this; } }
/** * Constructs an {@link ExpressionEvaluator} based on the specified {@link OptionsByType}. * * @param optionsByType the {@link OptionsByType} */ public ExpressionEvaluator(OptionsByType optionsByType) { this(optionsByType.get(Variables.class)); }
/** * Construct an {@link AbstractAssemblyBuilder}. */ public AbstractAssemblyBuilder() { characteristics = new LinkedList<>(); optionsByType = OptionsByType.empty(); }
@Override public Options addAll(OptionsByType options) { for (Option option : options.asArray()) { add(option); } return this; }
/** * Create a new {@link HttpDeployer}. * * @param options the {@link Option}s controlling this {@link HttpDeployer} */ public HttpDeployer(Option... options) { this.optionsByType = OptionsByType.of(options); }