Class StandaloneCommandBuilder

java.lang.Object
org.wildfly.core.launcher.JBossModulesCommandBuilder
org.wildfly.core.launcher.StandaloneCommandBuilder
All Implemented Interfaces:
CommandBuilder

public class StandaloneCommandBuilder extends JBossModulesCommandBuilder implements CommandBuilder
Builds a list of commands used to launch a standalone instance of WildFly.

This builder is not thread safe and the same instance should not be used in multiple threads.

Author:
James R. Perkins
  • Method Details

    • of

      public static StandaloneCommandBuilder of(Path wildflyHome)
      Creates a command builder for a standalone instance of WildFly.
      Parameters:
      wildflyHome - the path to the WildFly home directory
      Returns:
      a new builder
    • of

      public static StandaloneCommandBuilder of(String wildflyHome)
      Creates a command builder for a standalone instance of WildFly.
      Parameters:
      wildflyHome - the path to the WildFly home directory
      Returns:
      a new builder
    • addJavaOption

      public StandaloneCommandBuilder addJavaOption(String jvmArg)
      Adds a JVM argument to the command ignoring null arguments.
      Overrides:
      addJavaOption in class JBossModulesCommandBuilder
      Parameters:
      jvmArg - the JVM argument to add
      Returns:
      the builder
    • addJavaOptions

      public StandaloneCommandBuilder addJavaOptions(String... javaOpts)
      Adds the array of JVM arguments to the command.
      Overrides:
      addJavaOptions in class JBossModulesCommandBuilder
      Parameters:
      javaOpts - the array of JVM arguments to add, null arguments are ignored
      Returns:
      the builder
    • addJavaOptions

      public StandaloneCommandBuilder addJavaOptions(Iterable<String> javaOpts)
      Adds the collection of JVM arguments to the command.
      Overrides:
      addJavaOptions in class JBossModulesCommandBuilder
      Parameters:
      javaOpts - the collection of JVM arguments to add, null arguments are ignored
      Returns:
      the builder
    • setJavaOptions

      public StandaloneCommandBuilder setJavaOptions(Iterable<String> javaOpts)
      Sets the JVM arguments to use. This overrides any default JVM arguments that would normally be added and ignores null values in the collection.

      If the collection is null the JVM arguments will be cleared and no new arguments will be added.

      Overrides:
      setJavaOptions in class JBossModulesCommandBuilder
      Parameters:
      javaOpts - the JVM arguments to use
      Returns:
      the builder
    • setJavaOptions

      public StandaloneCommandBuilder setJavaOptions(String... javaOpts)
      Sets the JVM arguments to use. This overrides any default JVM arguments that would normally be added and ignores null values in the array.

      If the array is null the JVM arguments will be cleared and no new arguments will be added.

      Overrides:
      setJavaOptions in class JBossModulesCommandBuilder
      Parameters:
      javaOpts - the JVM arguments to use
      Returns:
      the builder
    • getJavaOptions

      public List<String> getJavaOptions()
      Returns the JVM arguments.
      Overrides:
      getJavaOptions in class JBossModulesCommandBuilder
      Returns:
      the JVM arguments
    • addModuleOption

      public StandaloneCommandBuilder addModuleOption(String arg)
      Adds an option which will be passed to JBoss Modules.

      Note that -mp or --modulepath is not supported. Use JBossModulesCommandBuilder.addModuleDir(String) to add a module directory.

      Overrides:
      addModuleOption in class JBossModulesCommandBuilder
      Parameters:
      arg - the argument to add
      Returns:
      the builder
    • addModuleOptions

      public StandaloneCommandBuilder addModuleOptions(String... args)
      Adds the options which will be passed to JBoss Modules.

      Note that -mp or --modulepath is not supported. Use JBossModulesCommandBuilder.addModuleDirs(String...) to add a module directory.

      Overrides:
      addModuleOptions in class JBossModulesCommandBuilder
      Parameters:
      args - the argument to add
      Returns:
      the builder
    • addModuleOptions

      public StandaloneCommandBuilder addModuleOptions(Iterable<String> args)
      Adds the options which will be passed to JBoss Modules.

      Note that -mp or --modulepath is not supported. Use JBossModulesCommandBuilder.addModuleDirs(Iterable) to add a module directory.

      Overrides:
      addModuleOptions in class JBossModulesCommandBuilder
      Parameters:
      args - the argument to add
      Returns:
      the builder
    • setModuleOptions

      public StandaloneCommandBuilder setModuleOptions(String... args)
      Clears the current module options and adds the options which will be passed to JBoss Modules.

      Note that -mp or --modulepath is not supported. Use JBossModulesCommandBuilder.addModuleDirs(String...) to add a module directory.

      Overrides:
      setModuleOptions in class JBossModulesCommandBuilder
      Parameters:
      args - the argument to use
      Returns:
      the builder
    • setModuleOptions

      public StandaloneCommandBuilder setModuleOptions(Iterable<String> args)
      Clears the current module options and adds the options which will be passed to JBoss Modules.

      Note that -mp or --modulepath is not supported. Use JBossModulesCommandBuilder.addModuleDirs(Iterable) to add a module directory.

      Overrides:
      setModuleOptions in class JBossModulesCommandBuilder
      Parameters:
      args - the argument to use
      Returns:
      the builder
    • setDebug

      public StandaloneCommandBuilder setDebug()
      Sets the debug argument for the JVM with a default port of 8787.
      Returns:
      the builder
    • setDebug

      public StandaloneCommandBuilder setDebug(int port)
      Sets the debug argument for the JVM.
      Parameters:
      port - the port to listen on
      Returns:
      the builder
    • setDebug

      public StandaloneCommandBuilder setDebug(boolean suspend, int port)
      Sets the debug JPDA remote socket debugging argument.
      Parameters:
      suspend - true to suspend otherwise false
      port - the port to listen on
      Returns:
      the builder
    • setBaseDirectory

      public StandaloneCommandBuilder setBaseDirectory(String baseDir)
      Sets the base directory to use.

      The default is $JBOSS_HOME/standalone.

      Parameters:
      baseDir - the base directory or null to resolve the base directory
      Returns:
      the builder
    • setBaseDirectory

      public StandaloneCommandBuilder setBaseDirectory(Path baseDir)
      Sets the base directory to use.

      The default is $JBOSS_HOME/standalone.

      Parameters:
      baseDir - the base directory or null to resolve the base directory
      Returns:
      the builder
    • setJavaHome

      public StandaloneCommandBuilder setJavaHome(String javaHome)
      Sets the Java home where the Java executable can be found.
      Overrides:
      setJavaHome in class JBossModulesCommandBuilder
      Parameters:
      javaHome - the Java home or null to use te system property java.home
      Returns:
      the builder
    • setJavaHome

      public StandaloneCommandBuilder setJavaHome(Path javaHome)
      Sets the Java home where the Java executable can be found.
      Overrides:
      setJavaHome in class JBossModulesCommandBuilder
      Parameters:
      javaHome - the Java home or null to use te system property java.home
      Returns:
      the builder
    • setModulesLockless

      public StandaloneCommandBuilder setModulesLockless(boolean b)
      Set to true to use JBoss Modules lockless mode.
      Overrides:
      setModulesLockless in class JBossModulesCommandBuilder
      Parameters:
      b - true to use lockless mode
      Returns:
      the builder
    • setModulesMetrics

      public StandaloneCommandBuilder setModulesMetrics(boolean b)
      Set to true to gather metrics for JBoss Modules.
      Overrides:
      setModulesMetrics in class JBossModulesCommandBuilder
      Parameters:
      b - true to gather metrics for JBoss Modules.
      Returns:
      this builder
    • setServerConfiguration

      public StandaloneCommandBuilder setServerConfiguration(String configFile)
      Sets the configuration file for the server. The file must be in the configuration directory. A value of null will remove the configuration file.

      This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

      Parameters:
      configFile - the configuration file name or null to remove the configuration file
      Returns:
      the builder
    • getServerConfiguration

      public String getServerConfiguration()
      Returns the configuration file set or null if one was not set.
      Returns:
      the configuration file set or null if not set
    • setServerReadOnlyConfiguration

      public StandaloneCommandBuilder setServerReadOnlyConfiguration(String configFile)
      Sets the configuration file for the server. The file must be in the configuration directory. A value of null will remove the configuration file.

      This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

      Parameters:
      configFile - the configuration file name or null to remove the configuration file
      Returns:
      the builder
    • getReadOnlyServerConfiguration

      public String getReadOnlyServerConfiguration()
      Returns the configuration file set or null if one was not set.
      Returns:
      the configuration file set or null if not set
    • addSecurityProperty

      public StandaloneCommandBuilder addSecurityProperty(String key)
      Adds a security property to be passed to the server with a null value.
      Parameters:
      key - the property key
      Returns:
      the builder
    • addSecurityProperty

      public StandaloneCommandBuilder addSecurityProperty(String key, String value)
      Adds a security property to be passed to the server.
      Parameters:
      key - the property key
      value - the property value
      Returns:
      the builder
    • addSecurityProperties

      public StandaloneCommandBuilder addSecurityProperties(Map<String,String> properties)
      Adds all the security properties to be passed to the server.
      Parameters:
      properties - a map of the properties to add, null values are allowed in the map
      Returns:
      the builder
    • setGitRepository

      public StandaloneCommandBuilder setGitRepository(String gitRepository, String gitBranch, String gitAuthentication)
      Configures the git repository for the standalone server.
      Parameters:
      gitRepository - the git repository to clone to get the server configuration from
      gitBranch - the branch to use to get the server configuration
      gitAuthentication - the Elytron configuration file for managing git credentials
      Returns:
      the builder
    • setYamlFiles

      public StandaloneCommandBuilder setYamlFiles(Collection<Path> yamlFiles)
      Adds the YAML configuration file argument with the given YAML configuration files.
      Parameters:
      yamlFiles - the files to add
      Returns:
      the builder
    • setYamlFiles

      public StandaloneCommandBuilder setYamlFiles(Path... yamlFiles)
      Adds the YAML configuration file argument with the given YAML configuration files.
      Parameters:
      yamlFiles - the files to add
      Returns:
      the builder
    • setStability

      public StandaloneCommandBuilder setStability(String stability)
      Sets the stability level of the domain controller process.
      Parameters:
      stability - a stability level
      Returns:
      a reference to this builder
    • buildArguments

      public List<String> buildArguments()
      Description copied from interface: CommandBuilder
      A list of command arguments required to launch WildFly instance.

      These are the arguments the follow a java executable command.

      Specified by:
      buildArguments in interface CommandBuilder
      Overrides:
      buildArguments in class JBossModulesCommandBuilder
      Returns:
      the list of arguments required to launch WildFly
    • getJavaHome

      public Path getJavaHome()
      Returns the Java home directory where the java executable command can be found.

      If the directory was not set the system property value, java.home, should be used.

      Returns:
      the path to the Java home directory
    • getBaseDirectory

      public Path getBaseDirectory()
      Returns the base directory for the server.

      Example: For standalone the base directory would be $JBOSS_HOME/standalone.

      Returns:
      the base directory
    • getThis

      protected StandaloneCommandBuilder getThis()
      Returns the concrete builder.
      Returns:
      the concrete builder
    • setUseSecurityManager

      public StandaloneCommandBuilder setUseSecurityManager(boolean useSecMgr)
      Description copied from class: JBossModulesCommandBuilder
      Sets whether or not the security manager option, -secmgr, should be used.
      Overrides:
      setUseSecurityManager in class JBossModulesCommandBuilder
      Parameters:
      useSecMgr - true to use the a security manager, otherwise false
      Returns:
      the builder
    • addModuleDir

      public StandaloneCommandBuilder addModuleDir(String moduleDir)
      Description copied from class: JBossModulesCommandBuilder
      Adds a directory to the collection of module paths.
      Overrides:
      addModuleDir in class JBossModulesCommandBuilder
      Parameters:
      moduleDir - the module directory to add
      Returns:
      the builder
    • addModuleDirs

      public StandaloneCommandBuilder addModuleDirs(String... moduleDirs)
      Description copied from class: JBossModulesCommandBuilder
      Adds all the module directories to the collection of module paths.
      Overrides:
      addModuleDirs in class JBossModulesCommandBuilder
      Parameters:
      moduleDirs - an array of module paths to add
      Returns:
      the builder
    • addModuleDirs

      public StandaloneCommandBuilder addModuleDirs(Iterable<String> moduleDirs)
      Description copied from class: JBossModulesCommandBuilder
      Adds all the module directories to the collection of module paths.
      Overrides:
      addModuleDirs in class JBossModulesCommandBuilder
      Parameters:
      moduleDirs - a collection of module paths to add
      Returns:
      the builder
    • setModuleDirs

      public StandaloneCommandBuilder setModuleDirs(Iterable<String> moduleDirs)
      Description copied from class: JBossModulesCommandBuilder
      Replaces any previously set module directories with the collection of module directories.

      The default module directory will NOT be used if this method is invoked.

      Overrides:
      setModuleDirs in class JBossModulesCommandBuilder
      Parameters:
      moduleDirs - the collection of module directories to use
      Returns:
      the builder
    • setModuleDirs

      public StandaloneCommandBuilder setModuleDirs(String... moduleDirs)
      Description copied from class: JBossModulesCommandBuilder
      Replaces any previously set module directories with the array of module directories.

      The default module directory will NOT be used if this method is invoked.

      Overrides:
      setModuleDirs in class JBossModulesCommandBuilder
      Parameters:
      moduleDirs - the array of module directories to use
      Returns:
      the builder
    • getLogDirectory

      public Path getLogDirectory()
      Returns the log directory for the server.
      Returns:
      the log directory
    • setLogDirectory

      public StandaloneCommandBuilder setLogDirectory(String path)
      Sets the log directory to be used for log files.

      If set to null, the default, the log directory will be resolved.

      Parameters:
      path - the path to the log directory or null to have the log directory resolved
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the directory is not a valid directory
    • setLogDirectory

      public StandaloneCommandBuilder setLogDirectory(Path path)
      Sets the log directory to be used for log files.

      If set to null, the default, the log directory will be resolved.

      Parameters:
      path - the path to the log directory or null to have the log directory resolved
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the directory is not a valid directory
    • getConfigurationDirectory

      public Path getConfigurationDirectory()
      Returns the configuration directory for the server.
      Returns:
      the configuration directory
    • setConfigurationDirectory

      public StandaloneCommandBuilder setConfigurationDirectory(String path)
      Sets the configuration directory to be used for configuration files.

      If set to null, the default, the configuration directory will be resolved.

      Parameters:
      path - the path to the configuration directory or null to have the configuration directory resolved
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the directory is not a valid directory
    • setConfigurationDirectory

      public StandaloneCommandBuilder setConfigurationDirectory(Path path)
      Sets the configuration directory to be used for configuration files.

      If set to null, the default, the configuration directory will be resolved.

      Parameters:
      path - the path to the configuration directory or null to have the configuration directory resolved
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the directory is not a valid directory
    • addServerArgument

      public StandaloneCommandBuilder addServerArgument(String arg)
      Description copied from class: JBossModulesCommandBuilder
      Adds an argument to be passed to the server ignore the argument if null.
      Overrides:
      addServerArgument in class JBossModulesCommandBuilder
      Parameters:
      arg - the argument to pass
      Returns:
      the builder
    • addServerArguments

      public StandaloneCommandBuilder addServerArguments(String... args)
      Description copied from class: JBossModulesCommandBuilder
      Adds the arguments to the collection of arguments that will be passed to the server ignoring any null arguments.
      Overrides:
      addServerArguments in class JBossModulesCommandBuilder
      Parameters:
      args - the arguments to add
      Returns:
      the builder
    • addServerArguments

      public StandaloneCommandBuilder addServerArguments(Iterable<String> args)
      Description copied from class: JBossModulesCommandBuilder
      Adds the arguments to the collection of arguments that will be passed to the server ignoring any null arguments.
      Overrides:
      addServerArguments in class JBossModulesCommandBuilder
      Parameters:
      args - the arguments to add
      Returns:
      the builder
    • setAdminOnly

      public StandaloneCommandBuilder setAdminOnly()
      Sets the server argument --admin-only.
      Returns:
      the builder
    • setStartSuspended

      public StandaloneCommandBuilder setStartSuspended()
      Sets the server argument --start-mode=suspend.
      Returns:
      the builder
    • setBindAddressHint

      public StandaloneCommandBuilder setBindAddressHint(String address)
      Sets the system property jboss.bind.address to the address given.

      This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

      Note: This option only works if the standard system property has not been removed from the interface. If the system property was removed the address provided has no effect.

      Parameters:
      address - the address to set the bind address to
      Returns:
      the builder
    • setBindAddressHint

      public StandaloneCommandBuilder setBindAddressHint(String interfaceName, String address)
      Sets the system property jboss.bind.address.$INTERFACE to the address given where $INTERFACE is the interfaceName parameter. For example in the default configuration passing management for the interfaceName parameter would result in the system property jboss.bind.address.management being set to the address provided.

      This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

      Note: This option only works if the standard system property has not been removed from the interface. If the system property was removed the address provided has no effect.

      Parameters:
      interfaceName - the name of the interface of the binding address
      address - the address to bind the management interface to
      Returns:
      the builder
    • setMulticastAddressHint

      public StandaloneCommandBuilder setMulticastAddressHint(String address)
      Sets the system property jboss.default.multicast.address to the address given.

      This will override any previous value set via JBossModulesCommandBuilder.addServerArgument(String).

      Note: This option only works if the standard system property has not been removed from the interface. If the system property was removed the address provided has no effect.

      Parameters:
      address - the address to set the multicast system property to
      Returns:
      the builder
    • addPropertiesFile

      public StandaloneCommandBuilder addPropertiesFile(String file)
      Adds a properties file to be passed to the server. Note that the file must exist.
      Parameters:
      file - the file to add
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the file does not exist or is not a regular file
    • addPropertiesFile

      public StandaloneCommandBuilder addPropertiesFile(Path file)
      Adds a properties file to be passed to the server. Note that the file must exist.
      Parameters:
      file - the file to add
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the file does not exist or is not a regular file
    • setPropertiesFile

      public StandaloneCommandBuilder setPropertiesFile(String file)
      Sets the properties file to use for the server or null to remove the file. Note that the file must exist.

      This will override any previous values set.

      Parameters:
      file - the properties file to use or null
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the file does not exist or is not a regular file
    • setPropertiesFile

      public StandaloneCommandBuilder setPropertiesFile(Path file)
      Sets the properties file to use for the server or null to remove the file. Note that the file must exist.

      This will override any previous values set.

      Parameters:
      file - the properties file to use or null
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the file does not exist or is not a regular file
    • getLoggingPropertiesArgument

      protected String getLoggingPropertiesArgument(String fileName)
      Returns the command line argument that specifies the logging configuration.
      Parameters:
      fileName - the name of the configuration file
      Returns:
      the command line argument
    • getBootLogArgument

      protected String getBootLogArgument(String fileName)
      Returns the command line argument that specifies the path the log file that should be used.

      This is generally only used on the initial boot of the server in standalone. The server will rewrite the configuration file with hard-coded values.

      Parameters:
      fileName - the name of the file
      Returns:
      the command line argument
    • normalizePath

      protected Path normalizePath(String path)
      Resolves the path to the path relative to the WildFly home directory.
      Parameters:
      path - the name of the relative path
      Returns:
      the normalized path
    • normalizePath

      protected Path normalizePath(Path parent, String path)
      Resolves the path relative to the parent and normalizes it.
      Parameters:
      parent - the parent path
      path - the path
      Returns:
      the normalized path
    • addSystemPropertyArg

      protected static void addSystemPropertyArg(List<String> cmd, String key, Object value)