Search in sources :

Example 1 with ClassPathModifier

use of com.oracle.bedrock.runtime.java.ClassPathModifier in project oracle-bedrock by coherence-community.

the class RemoteJavaApplicationLauncher method getCommandLineArguments.

@Override
public List<String> getCommandLineArguments(Platform platform, OptionsByType optionsByType) {
    ArrayList<String> arguments = new ArrayList<>();
    // ----- establish Bedrock specific system properties -----
    Table systemPropertiesTable = new Table();
    systemPropertiesTable.getOptions().add(Table.orderByColumn(0));
    systemPropertiesTable.getOptions().add(Cell.Separator.of(""));
    // establish the URI for this (the parent) process
    String parentURI = "//${local.address}:" + remoteChannel.getPort();
    ExpressionEvaluator evaluator = new ExpressionEvaluator(optionsByType);
    String parentUriString = evaluator.evaluate(parentURI, String.class);
    arguments.add("-D" + Settings.PARENT_URI + "=" + parentUriString);
    systemPropertiesTable.addRow(Settings.PARENT_URI, parentUriString);
    // add Orphanable configuration
    Orphanable orphanable = optionsByType.get(Orphanable.class);
    arguments.add("-D" + Settings.ORPHANABLE + "=" + orphanable.isOrphanable());
    systemPropertiesTable.addRow(Settings.ORPHANABLE, Boolean.toString(orphanable.isOrphanable()));
    // ----- establish the remote application class path -----
    // set the remote classpath (it must be quoted to prevent wildcard expansion)
    arguments.add("-cp");
    ClassPathModifier modifier = optionsByType.getOrSetDefault(ClassPathModifier.class, ClassPathModifier.none());
    String classPath = modifier.applyQuotes(remoteClassPath.toString(optionsByType.asArray()));
    arguments.add(classPath);
    Table diagnosticsTable = optionsByType.get(Table.class);
    if (diagnosticsTable != null) {
        Table classPathTable = remoteClassPath.getTable();
        classPathTable.getOptions().add(Cell.Separator.of(""));
        diagnosticsTable.addRow("Class Path", classPathTable.toString());
    }
    for (JvmOption jvmOption : optionsByType.getInstancesOf(JvmOption.class)) {
        for (String value : jvmOption.resolve(optionsByType)) {
            arguments.add(value);
        }
    }
    // ----- establish the system properties for the java application -----
    systemProperties = optionsByType.get(SystemProperties.class).resolve(platform, optionsByType);
    for (String propertyName : systemProperties.stringPropertyNames()) {
        // (we don't want to have "parents" applications effect child applications
        if (propertyName.startsWith("bedrock.profile.") || !propertyName.startsWith("bedrock")) {
            // evaluate the property value
            String propertyValue = systemProperties.getProperty(propertyName);
            // build the actual system property command line argument
            StringBuilder propertyBuilder = new StringBuilder();
            propertyBuilder.append("-D");
            propertyBuilder.append(propertyName);
            if (!propertyValue.isEmpty()) {
                propertyValue = StringHelper.doubleQuoteIfNecessary(propertyValue);
                propertyBuilder.append("=");
                propertyBuilder.append(propertyValue);
                systemPropertiesTable.addRow(propertyName, propertyValue);
            }
            arguments.add(propertyBuilder.toString());
        }
    }
    for (String propertyName : System.getProperties().stringPropertyNames()) {
        if (propertyName.startsWith("bedrock.runtime.inherit.")) {
            // resolve the property value
            String propertyValue = System.getProperty(propertyName);
            propertyValue = evaluator.evaluate(propertyValue, String.class);
            arguments.add(propertyValue);
        }
    }
    if (diagnosticsTable != null) {
        diagnosticsTable.addRow("System Properties", systemPropertiesTable.toString());
    }
    // ----- establish the application command line to execute -----
    // use the launcher to launch the application
    // (we don't start the application directly itself)
    String applicationLauncherClassName = JavaApplicationRunner.class.getName();
    arguments.add(applicationLauncherClassName);
    // set the Java application class name we need to launch
    ClassName className = optionsByType.get(ClassName.class);
    if (className == null) {
        throw new IllegalArgumentException("Java Application ClassName not specified");
    }
    String applicationClassName = className.getName();
    arguments.add(applicationClassName);
    if (diagnosticsTable != null) {
        diagnosticsTable.addRow("Application Launcher", applicationLauncherClassName);
        diagnosticsTable.addRow("Application Class", applicationClassName);
    }
    // ----- included the java arguments to the command -----
    List<String> argList = optionsByType.get(Arguments.class).resolve(platform, optionsByType);
    // Set the actual arguments used back into the options
    optionsByType.add(Arguments.of(argList));
    for (String argument : argList) {
        arguments.add(argument);
    }
    return arguments;
}
Also used : Table(com.oracle.bedrock.table.Table) ArrayList(java.util.ArrayList) Arguments(com.oracle.bedrock.runtime.options.Arguments) ExpressionEvaluator(com.oracle.bedrock.lang.ExpressionEvaluator) Orphanable(com.oracle.bedrock.runtime.options.Orphanable) ClassName(com.oracle.bedrock.runtime.java.options.ClassName) ClassPathModifier(com.oracle.bedrock.runtime.java.ClassPathModifier) JvmOption(com.oracle.bedrock.runtime.java.options.JvmOption)

Aggregations

ExpressionEvaluator (com.oracle.bedrock.lang.ExpressionEvaluator)1 ClassPathModifier (com.oracle.bedrock.runtime.java.ClassPathModifier)1 ClassName (com.oracle.bedrock.runtime.java.options.ClassName)1 JvmOption (com.oracle.bedrock.runtime.java.options.JvmOption)1 Arguments (com.oracle.bedrock.runtime.options.Arguments)1 Orphanable (com.oracle.bedrock.runtime.options.Orphanable)1 Table (com.oracle.bedrock.table.Table)1 ArrayList (java.util.ArrayList)1