Class JBossModulesCommandBuilder

java.lang.Object
org.wildfly.core.launcher.JBossModulesCommandBuilder
All Implemented Interfaces:
CommandBuilder
Direct Known Subclasses:
DomainCommandBuilder, StandaloneCommandBuilder

public class JBossModulesCommandBuilder extends Object implements CommandBuilder
Builds a list of commands used to launch JBoss Modules module.

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

Author:
James R. Perkins
  • Constructor Details

    • JBossModulesCommandBuilder

      protected JBossModulesCommandBuilder(Path wildflyHome, String moduleName)
      Creates a command builder for a launching JBoss Modules module.

      Note the wildflyHome and javaHome are not validated using the constructor. The static of(Path, String) is preferred.

      Parameters:
      wildflyHome - the path to WildFly, cannot be null
      moduleName - the name of the entry module, cannot be null
  • Method Details

    • of

      public static JBossModulesCommandBuilder of(Path wildflyHome, String moduleName)
      Creates a command builder for a launching JBoss Modules module.
      Parameters:
      wildflyHome - the path to the WildFly home directory, cannot be null
      moduleName - the name of the entry module, cannot be null
      Returns:
      a new builder
    • of

      public static JBossModulesCommandBuilder of(String wildflyHome, String moduleName)
      Creates a command builder for a launching JBoss Modules module.
      Parameters:
      wildflyHome - the path to the WildFly home directory, cannot be null
      moduleName - the name of the entry module, cannot be null
      Returns:
      a new builder
    • setUseSecurityManager

      public JBossModulesCommandBuilder setUseSecurityManager(boolean useSecMgr)
      Sets whether or not the security manager option, -secmgr, should be used.
      Parameters:
      useSecMgr - true to use the a security manager, otherwise false
      Returns:
      the builder
    • useSecurityManager

      public boolean useSecurityManager()
      Indicates whether or no a security manager should be used for the server launched.
      Returns:
      true if a security manager should be used, otherwise false
    • addModuleDir

      public JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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
    • addServerArgument

      public JBossModulesCommandBuilder addServerArgument(String arg)
      Adds an argument to be passed to the server ignore the argument if null.
      Parameters:
      arg - the argument to pass
      Returns:
      the builder
    • addServerArguments

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

      public JBossModulesCommandBuilder addServerArguments(Iterable<String> args)
      Adds the arguments to the collection of arguments that will be passed to the server ignoring any null arguments.
      Parameters:
      args - the arguments to add
      Returns:
      the builder
    • getWildFlyHome

      public Path getWildFlyHome()
      Returns the home directory used.
      Returns:
      the home directory
    • 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
    • getModulesJarName

      public String getModulesJarName()
      Returns the normalized path to the jboss-modules.jar for launching the server.
      Returns:
      the path to jboss-modules.jar
    • getServerArguments

      public List<String> getServerArguments()
      A collection of server command line arguments.
      Returns:
      the server arguments
    • addJavaOption

      public JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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
    • addModuleOption

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

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

      Parameters:
      arg - the argument to add
      Returns:
      the builder
    • addModuleOptions

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

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

      Parameters:
      args - the argument to add
      Returns:
      the builder
    • addModuleOptions

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

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

      Parameters:
      args - the argument to add
      Returns:
      the builder
    • setModuleOptions

      public JBossModulesCommandBuilder 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 addModuleDirs(String...) to add a module directory.

      Parameters:
      args - the argument to use
      Returns:
      the builder
    • setModuleOptions

      public JBossModulesCommandBuilder 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 addModuleDirs(Iterable) to add a module directory.

      Parameters:
      args - the argument to use
      Returns:
      the builder
    • setJavaHome

      public JBossModulesCommandBuilder 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 JBossModulesCommandBuilder 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
    • setModulesLockless

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

      public JBossModulesCommandBuilder setModulesMetrics(boolean b)
      Set to true to gather metrics for JBoss Modules.
      Parameters:
      b - true to gather metrics for JBoss Modules.
      Returns:
      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
      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
    • setSingleServerArg

      protected void setSingleServerArg(String key, String value)
    • addServerArg

      protected void addServerArg(String key, String value)
    • getServerArg

      protected String getServerArg(String key)
      Returns the first argument from the server arguments.
      Parameters:
      key - the key to the argument
      Returns:
      the first argument or null