/** * Constructs an {@link AbstractRemoteApplicationBuilder} for a specified * {@link RemotePlatform}. * * @param platform the {@link RemotePlatform} */ public AbstractRemoteApplicationBuilder(RemotePlatform platform) { super(platform); // by default there are no custom remote environment variables remoteEnvironmentVariablesBuilder = new PropertiesBuilder(); }
/** * Creates a new {@link Properties} instance containing name, value pairs * defined by the {@link PropertiesBuilder}. * <p> * If a property with in the {@link PropertiesBuilder} is defined as an * {@link Iterator}, the next value from the said {@link Iterator} is used * as a value for the property. * * @return a new {@link Properties} instance as defined by the {@link PropertiesBuilder} */ public Properties realize() { return realize(null); }
/** * Sets the specified environment variable to the specified value. * * @param name the name of the environment variable * @param value the value of the environment variable * * @return the {@link ApplicationSchema} (so that we can perform method chaining) */ @SuppressWarnings("unchecked") public S setEnvironmentVariable(String name, Object value) { m_propertiesBuilder.setProperty(name, value); return (S) this; }
/** * Optionally sets the specified named property to have the specified value. * * @param name the name of the property * @param value the value of the property * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used */ public PropertiesBuilder setPropertyIfAbsent(String name, Object value) { if (containsProperty(name)) { return this; } else { return setProperty(name, value); } }
properties.putAll(overrides.realize()); for (String name : getPropertyNames()) Object value = getProperty(name);
/** * A helper method to instantiate a new {@link ContainerClassLoader} * using the current platform class path and system properties. * * @param applicationName the name of the application * * @return a {@link ContainerClassLoader} for the application * * @throws Exception if some exception occurs */ public static ContainerClassLoader newInstance(String applicationName) throws Exception { PropertiesBuilder builder = PropertiesBuilder.fromCurrentNonStandardSystemProperties(); return newInstance(applicationName, ClassPath.ofSystem(), builder.realize(), System.getProperties(), Container.getAvailablePorts(), false, Container.PIPE_BUFFER_SIZE_BYTES); }
Properties systemProperties = schema.getSystemPropertiesBuilder().realize(); Properties environmentVariables = PropertiesBuilder.fromCurrentEnvironmentVariables().realize();
/** * Sets the specified named default property to have the specified value. * * @param name the name of the property * @param defaultValue the default value of the property * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used */ @Deprecated public PropertiesBuilder setDefaultProperty(String name, Object defaultValue) { if (containsProperty(name)) { properties.get(name).setDefaultValue(defaultValue); } else { properties.put(name, new Property(name, null, defaultValue)); } return this; }
/** * Adds the properties defined by the {@link PropertiesBuilder} to this {@link JavaApplicationSchema}. * * @param systemProperties The system {@link PropertiesBuilder} * @return the {@link JavaApplicationSchema} */ @SuppressWarnings("unchecked") public S setSystemProperties(PropertiesBuilder systemProperties) { m_systemPropertiesBuilder.addProperties(systemProperties); return (S) this; }
/** * Determines if a {@link JavaApplication} will run in a "headless" mode. * * @return the {@link JavaApplicationSchema} * * @see JavaApplication#JAVA_AWT_HEADLESS */ public boolean isHeadless() { Object value = m_systemPropertiesBuilder.getProperty(JAVA_AWT_HEADLESS); return value instanceof Boolean && ((Boolean) value); } }
/** * Clears the currently registered environment variables from the * {@link ApplicationBuilder}. * * @return the {@link ApplicationSchema} (so that we can perform method chaining) */ @SuppressWarnings("unchecked") public S clearEnvironmentVariables() { m_propertiesBuilder.clear(); return (S) this; }
/** * Constructs a {@link PropertiesBuilder} based on the properties defined * in another {@link PropertiesBuilder}. * * @param propertiesBuilder the {@link PropertiesBuilder} on which to base * the new {@link PropertiesBuilder} */ public PropertiesBuilder(PropertiesBuilder propertiesBuilder) { this(); for (String name : propertiesBuilder.getPropertyNames()) { this.properties.put(name, new Property(propertiesBuilder.properties.get(name))); } }
/** * Optionally sets the specified named property to use an {@link Iterator} * (to provide successive requests for the property with values from the said * {@link Iterator} when the {@link PropertiesBuilder} is realized) * * @param name the name of the property * @param iterator an {@link Iterator} that will provide successive property * values for the property when the {@link PropertiesBuilder} * is realized * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used. */ public PropertiesBuilder setPropertyIfAbsent(String name, Iterator<?> iterator) { if (containsProperty(name)) { return this; } else { return setProperty(name, iterator); } }
/** * Sets the specified named property to have the specified value. * * @param name the name of the property * @param value the value of the property * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used */ public PropertiesBuilder setProperty(String name, Object value) { if (containsProperty(name)) { properties.get(name).setValue(value); } else { properties.put(name, new Property(name, value, null)); } return this; }
/** * Adds/Overrides the current environment variables with those specified by * the {@link PropertiesBuilder}. * * @param environmentVariablesBuilder the environment variables to * add/override on the {@link ApplicationBuilder} * * @return the {@link ApplicationSchema} (so that we can perform method chaining) */ @SuppressWarnings("unchecked") public S setEnvironmentVariables(PropertiesBuilder environmentVariablesBuilder) { m_propertiesBuilder.addProperties(environmentVariablesBuilder); return (S) this; }
/** * A helper to construct a {@link PropertiesBuilder} based on the * operating system environment variables defined for the * currently executing process. * * @return a {@link PropertiesBuilder} */ public static PropertiesBuilder fromCurrentEnvironmentVariables() { return new PropertiesBuilder(System.getenv()); }
/** * Sets the specified system property. * * @param name The name of the system property * @param value The value for the system property * @return the {@link JavaApplicationSchema} */ @SuppressWarnings("unchecked") public S setSystemProperty(String name, Object value) { m_systemPropertiesBuilder.setProperty(name, value); return (S) this; }
@Override public Properties getRemoteEnvironmentVariables() { EnvironmentVariables environmentVariables = options.get(EnvironmentVariables.class, EnvironmentVariables .of(EnvironmentVariables.Source.TargetPlatform)); Properties variables = new Properties(); switch (environmentVariables.getSource()) { case Custom : break; case ThisApplication : variables.putAll(System.getenv()); break; case TargetPlatform : break; } // add the optionally defined environment variables variables.putAll(environmentVariables.getBuilder().realize()); return variables; }
/** * Sets the specified named default property to use an {@link Iterator} to * provide successive property values when the {@link PropertiesBuilder} is realized. * * @param name the name of the property * @param defaultIterator the default {@link Iterator} that will provide * successive property values for the property when * the {@link PropertiesBuilder} is realized * * @return the {@link PropertiesBuilder} to which the property was added so * that further chained method calls, like to other * <code>setProperty(...)</code> methods on this class may be used */ @Deprecated public PropertiesBuilder setDefaultProperty(String name, Iterator<?> defaultIterator) { if (containsProperty(name)) { properties.get(name).setDefaultValue(defaultIterator); } else { properties.put(name, new Property(name, null, defaultIterator)); } return this; }
/** * Constructs an {@link AbstractApplicationSchema}. * * @param executableName the name of the executable for the {@link Application}s * produced from this {@link ApplicationSchema} */ public AbstractApplicationSchema(String executableName) { m_executableName = executableName; m_propertiesBuilder = new PropertiesBuilder(); m_applicationArguments = new ArrayList<String>(); m_isErrorStreamRedirected = false; m_isDiagnosticsEnabled = false; m_defaultTimeout = 1; m_defaultTimeoutUnits = TimeUnit.MINUTES; m_isEnvironmentInherited = true; m_lifecycleInterceptors = new LinkedList<LifecycleEventInterceptor<A>>(); }