Class CliCommandBuilder

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

public class CliCommandBuilder extends Object implements CommandBuilder
Builds a list of commands to create a new process for a CLI instance.

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

Author:
James R. Perkins
  • Method Details

    • asModularLauncher

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

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

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

      public static CliCommandBuilder of(String wildflyHome)
      Creates a command builder for a modular CLI instance.
      Parameters:
      wildflyHome - the path to the WildFly home directory
      Returns:
      a new builder
    • asJarLauncher

      public static CliCommandBuilder asJarLauncher(Path wildflyHome)
      Creates a command builder for a non-modular CLI instance launched from wildflyHome/bin/client/jboss-client.jar.
      Parameters:
      wildflyHome - the path to the WildFly home directory
      Returns:
      a new builder
    • asJarLauncher

      public static CliCommandBuilder asJarLauncher(String wildflyHome)
      Creates a command builder for a non-modular CLI instance launched from wildflyHome/bin/client/jboss-client.jar.
      Parameters:
      wildflyHome - the path to the WildFly home directory
      Returns:
      a new builder
    • setConnection

      public CliCommandBuilder setConnection(String controller)
      Sets the hostname and port to connect to.

      This sets both the --connect and --controller arguments.

      Parameters:
      controller - the controller argument to use
      Returns:
      the builder
    • setConnection

      public CliCommandBuilder setConnection(String hostname, int port)
      Sets the hostname and port to connect to.

      This sets both the --connect and --controller arguments.

      Parameters:
      hostname - the host name
      port - the port
      Returns:
      the builder
    • setConnection

      public CliCommandBuilder setConnection(String protocol, String hostname, int port)
      Sets the protocol, hostname and port to connect to.

      This sets both the --connect and --controller arguments.

      Parameters:
      protocol - the protocol to use
      hostname - the host name
      port - the port
      Returns:
      the builder
    • setController

      public CliCommandBuilder setController(String controller)
      Sets the hostname and port to connect to.
      Parameters:
      controller - the controller argument to use
      Returns:
      the builder
    • setController

      public CliCommandBuilder setController(String hostname, int port)
      Sets the hostname and port to connect to.
      Parameters:
      hostname - the host name
      port - the port
      Returns:
      the builder
    • setController

      public CliCommandBuilder setController(String protocol, String hostname, int port)
      Sets the protocol, hostname and port to connect to.
      Parameters:
      protocol - the protocol to use
      hostname - the host name
      port - the port
      Returns:
      the builder
    • setUser

      public CliCommandBuilder setUser(String user)
      Sets the user to use when establishing a connection.
      Parameters:
      user - the user to use
      Returns:
      the builder
    • setPassword

      public CliCommandBuilder setPassword(String password)
      Sets the password to use when establishing a connection.
      Parameters:
      password - the password to use
      Returns:
      the builder
    • setScriptFile

      public CliCommandBuilder setScriptFile(String path)
      Sets the path to the script file to execute.
      Parameters:
      path - the path to the script file to execute
      Returns:
      the builder
    • setScriptFile

      public CliCommandBuilder setScriptFile(Path path)
      Sets the path to the script file to execute.
      Parameters:
      path - the path to the script file to execute
      Returns:
      the builder
    • setCommand

      public CliCommandBuilder setCommand(String command)
      Sets the command to execute.
      Parameters:
      command - the command to execute
      Returns:
      the builder
    • setCommands

      public CliCommandBuilder setCommands(String... commands)
      Sets the commands to execute.
      Parameters:
      commands - the commands to execute
      Returns:
      the builder
    • setCommands

      public CliCommandBuilder setCommands(Iterable<String> commands)
      Sets the commands to execute.
      Parameters:
      commands - the commands to execute
      Returns:
      the builder
    • setTimeout

      public CliCommandBuilder setTimeout(int timeout)
      Sets the timeout used when connecting to the server.
      Parameters:
      timeout - the time out to use
      Returns:
      the builder
    • setUseGui

      public CliCommandBuilder setUseGui()
      Sets the command argument to use the GUI CLI client.
      Returns:
      the builder
    • addJavaOption

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

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

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

      public CliCommandBuilder 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.

      Parameters:
      javaOpts - the JVM arguments to use
      Returns:
      the builder
    • setJavaOptions

      public CliCommandBuilder 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.

      Parameters:
      javaOpts - the JVM arguments to use
      Returns:
      the builder
    • getJavaOptions

      public List<String> getJavaOptions()
      Returns the JVM arguments.
      Returns:
      the JVM arguments
    • addCliArgument

      public CliCommandBuilder addCliArgument(String arg)
      Adds an argument to be passed to the CLI command ignore the argument if null.
      Parameters:
      arg - the argument to pass
      Returns:
      the builder
    • addCliArguments

      public CliCommandBuilder addCliArguments(String... args)
      Adds the arguments to the collection of arguments that will be passed to the CLI command ignoring any null arguments.
      Parameters:
      args - the arguments to add
      Returns:
      the builder
    • addCliArguments

      public CliCommandBuilder addCliArguments(Iterable<String> args)
      Adds the arguments to the collection of arguments that will be passed to the CLI command ignoring any null arguments.
      Parameters:
      args - the arguments to add
      Returns:
      the builder
    • addModuleDir

      public CliCommandBuilder addModuleDir(String moduleDir)
      Adds a directory to the collection of module paths.
      Parameters:
      moduleDir - the module directory to add
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if the path is null
    • addModuleDirs

      public CliCommandBuilder addModuleDirs(String... moduleDirs)
      Adds all the module directories to the collection of module paths.
      Parameters:
      moduleDirs - an array of module paths to add
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if any of the module paths are invalid or null
    • addModuleDirs

      public CliCommandBuilder addModuleDirs(Iterable<String> moduleDirs)
      Adds all the module directories to the collection of module paths.
      Parameters:
      moduleDirs - a collection of module paths to add
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if any of the module paths are invalid or null
    • setModuleDirs

      public CliCommandBuilder setModuleDirs(Iterable<String> moduleDirs)
      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.

      Parameters:
      moduleDirs - the collection of module directories to use
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if any of the module paths are invalid or null
    • setModuleDirs

      public CliCommandBuilder setModuleDirs(String... moduleDirs)
      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.

      Parameters:
      moduleDirs - the array of module directories to use
      Returns:
      the builder
      Throws:
      IllegalArgumentException - if any of the module paths are invalid or null
    • getModulePaths

      public String getModulePaths()
      Returns the modules paths used on the command line.
      Returns:
      the paths separated by the path separator
    • setJavaHome

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

      public CliCommandBuilder setJavaHome(Path javaHome)
      Sets the Java home where the Java executable can be found.
      Parameters:
      javaHome - the Java home or null to use te system property java.home
      Returns:
      the builder
    • 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
    • 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
      Returns:
      the list of arguments required to launch WildFly
    • build

      public List<String> build()
      Description copied from interface: CommandBuilder
      A list of commands, including a java executable, required to launch WildFly instance.
      Specified by:
      build in interface CommandBuilder
      Returns:
      the list of arguments required to launch WildFly