Class ProcessUnit.ProcessUnitBuilder

java.lang.Object
de.iip_ecosphere.platform.configuration.maven.ProcessUnit.ProcessUnitBuilder
Enclosing class:
ProcessUnit

public static class ProcessUnit.ProcessUnitBuilder extends Object
Creates process units.
Author:
Holger Eichelberger, SSE
  • Field Details

    • description

      private String description
    • args

      private List<String> args
    • home

      private File home
    • logger

      private de.iip_ecosphere.platform.tools.maven.python.Logger logger
    • timeout

      private long timeout
    • logFile

      private File logFile
    • checkRegEx

      private List<Pattern> checkRegEx
    • listener

    • notifyByLogMatch

      private boolean notifyByLogMatch
    • conjunctLogMatches

      private boolean conjunctLogMatches
    • argAggregate

      private String argAggregate
    • argAggregateStart

      private String argAggregateStart
    • argAggregateEnd

      private String argAggregateEnd
    • err2In

      private boolean err2In
    • nodejsHome

      private String nodejsHome
  • Constructor Details

    • ProcessUnitBuilder

      public ProcessUnitBuilder(String description, de.iip_ecosphere.platform.tools.maven.python.Logger logger)
      Creates a process builder instance.
      Parameters:
      description - the description of the unit
      logger - the logger, may be null then a StandardLogger is used
  • Method Details

    • logTo

      public ProcessUnit.ProcessUnitBuilder logTo(File logFile)
      Sets the logging to a given file.
      Parameters:
      logFile - the file to log to
      Returns:
      this (builder style)
    • addCheckRegEx

      public ProcessUnit.ProcessUnitBuilder addCheckRegEx(Pattern regEx)
      Adds a checking regular expression on the logging.
      Parameters:
      regEx - the regular expression
      Returns:
      this (builder style)
    • setRegExConjunction

      public ProcessUnit.ProcessUnitBuilder setRegExConjunction(boolean conjunct)
      Sets the log regEx aggregation mode, either conjunction or disjunction.
      Parameters:
      conjunct - if true the default, all regular expressions must match, if false only one
      Returns:
      this (builder style)
    • setHome

      public ProcessUnit.ProcessUnitBuilder setHome(File home)
      Sets the process home directory.
      Parameters:
      home - the home directory
      Returns:
      this (builder style)
    • redirectErr2In

      public ProcessUnit.ProcessUnitBuilder redirectErr2In()
      Redirects the process error stream so that it appears as input stream.
      Returns:
      this (builder style)
    • addMavenCommand

      public ProcessUnit.ProcessUnitBuilder addMavenCommand()
      Adds the maven command (shall be used for arguments).
      Returns:
      this (builder style)
    • getMavenPath

      private String getMavenPath()
      Returns the maven path.
      Returns:
      the maven path
    • prependPath

      private String prependPath(String path, String cmd)
      Prepends path before cmd as file system path.
      Parameters:
      path - the path, may be empty/null (ignored)
      cmd - the command
      Returns:
      the composed path (if not ignored) and command separated by a file separator
    • setNodeJsHome

      public ProcessUnit.ProcessUnitBuilder setNodeJsHome(String home)
      Changes the nodejs home/bin directory, i.e., the directory where the bin files are located, which is usually in Windows the home directory, in linux the bin sub-directory.
      Parameters:
      home - the home directory, ignored if null or empty
      Returns:
      this for chaining
    • getNodeJsPath

      private String getNodeJsPath()
      Returns the path for NodeJS.
      Returns:
      the path, may be empty for unknown
    • addShellScriptCommand

      public ProcessUnit.ProcessUnitBuilder addShellScriptCommand(String scriptName)
      Adds a shell command (shall be used for arguments). Prefixes a command processor for windows and a "./" for the others.
      Parameters:
      scriptName - the script name without extension (adding "bat" for windows and "sh" else)
      Returns:
      this (builder style)
      See Also:
    • addShellScriptCommand

      public ProcessUnit.ProcessUnitBuilder addShellScriptCommand(String scriptName, String extension)
      Adds a shell script command (shall be used for arguments). Prefixes a command processor for windows and a "./" for the others.
      Parameters:
      scriptName - the script name without extension
      extension - the extension (may be empty, start with "." or just be the extension)
      Returns:
      this (builder style)
      See Also:
    • enableArgumentAggregation

      private void enableArgumentAggregation()
      Enables argument aggregation if needed, i.e., some command lines require complex arguments to be aggregated into a single argument. If no aggregation is needed, arguments are added directly to args.
    • appendByAggregation

      private boolean appendByAggregation(String arg)
      Appends an argument by aggregation if enabled through enableArgumentAggregation().
      Parameters:
      arg - the argument(s)
      Returns:
      true if arg was not processed, false if arg was processed and does not need further aggregation
    • addArgumentOrScriptCommand

      public ProcessUnit.ProcessUnitBuilder addArgumentOrScriptCommand(String cmd)
      Adds cmd as a script (also if in ProcessUnit.SCRIPT_NAMES) or as argument.
      Parameters:
      cmd - the script name
      Returns:
      this (builder style)
      See Also:
    • addArgumentOrScriptCommand

      public ProcessUnit.ProcessUnitBuilder addArgumentOrScriptCommand(boolean cmdAsScript, String cmd)
      Adds cmd as a script (also if in ProcessUnit.SCRIPT_NAMES) or as argument.
      Parameters:
      cmdAsScript - is cmd is a script command
      cmd - the script name
      Returns:
      this (builder style)
    • addArgument

      public ProcessUnit.ProcessUnitBuilder addArgument(boolean enable, Object argument)
      Adds a conditional command line argument.
      Parameters:
      enable - the condition result
      argument - the argument
      Returns:
      this (builder style)
    • addArgument

      public ProcessUnit.ProcessUnitBuilder addArgument(Object argument)
      Adds a command line argument.
      Parameters:
      argument - the argument
      Returns:
      this (builder style)
    • addArguments

      public ProcessUnit.ProcessUnitBuilder addArguments(List<String> arguments)
      Adds command line arguments.
      Parameters:
      arguments - the arguments (may be null, ignored)
      Returns:
      this (builder style)
    • addArguments

      public ProcessUnit.ProcessUnitBuilder addArguments(String... arguments)
      Adds command line arguments.
      Parameters:
      arguments - the arguments
      Returns:
      this (builder style)
    • setTimeout

      public ProcessUnit.ProcessUnitBuilder setTimeout(long timeout)
      Sets the lifetime/timeout of the process.
      Parameters:
      timeout - the timeout in milliseconds, default is 0, ignored if not positive
      Returns:
      this (builder style)
    • setNotifyListenerByLogMatch

      public ProcessUnit.ProcessUnitBuilder setNotifyListenerByLogMatch(boolean notifyByLogMatch)
      Sets whether the process listener shall be informed on a complete log regEx match, terminating the process if there is no listener.
      Parameters:
      notifyByLogMatch - notify the listener by a complete log match or not (default is true)
      Returns:
      this (builder style)
    • setListener

      Sets a termination listener.
      Parameters:
      listener - the listener, may be null for none
      Returns:
      this (builder style)
    • build4Mvn

      public ProcessUnit build4Mvn() throws org.apache.maven.plugin.MojoExecutionException
      Builds the process.
      Returns:
      the process unit
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if creating the process fails
    • build

      public ProcessUnit build() throws IOException
      Builds the process.
      Returns:
      the process unit
      Throws:
      IOException - if creating the process fails