Class ProcessConfig.Builder

java.lang.Object
cloud.opencode.base.core.process.ProcessConfig.Builder
Enclosing class:
ProcessConfig

public static final class ProcessConfig.Builder extends Object
Builder for ProcessConfig. ProcessConfig 的构建器。
Since:
JDK 25, opencode-base-core V1.0.3
Author:
Leon Soo www.LeonSoo.com
  • Method Details

    • command

      public ProcessConfig.Builder command(String... command)
      Sets the command and arguments. 设置命令和参数。
      Parameters:
      command - the command and arguments - 命令和参数
      Returns:
      this builder - 此构建器
    • command

      public ProcessConfig.Builder command(List<String> command)
      Sets the command and arguments. 设置命令和参数。
      Parameters:
      command - the command list - 命令列表
      Returns:
      this builder - 此构建器
    • workingDirectory

      public ProcessConfig.Builder workingDirectory(Path dir)
      Sets the working directory for the process. 设置进程的工作目录。
      Parameters:
      dir - the working directory, or null to inherit - 工作目录,或 null 以继承
      Returns:
      this builder - 此构建器
    • environment

      public ProcessConfig.Builder environment(String key, String value)
      Adds a single environment variable. 添加单个环境变量。

      Security Warning | 安全警告: Do not pass untrusted input as environment variable names or values. Dangerous variables like LD_PRELOAD, PATH, or DYLD_INSERT_LIBRARIES can lead to code execution.

      安全警告: 切勿将不可信输入作为环境变量名或值传入。 LD_PRELOADPATH 等危险变量可导致代码执行。

      Parameters:
      key - the variable name - 变量名
      value - the variable value - 变量值
      Returns:
      this builder - 此构建器
    • environment

      public ProcessConfig.Builder environment(Map<String,String> env)
      Adds multiple environment variables. 添加多个环境变量。
      Parameters:
      env - the environment variables - 环境变量
      Returns:
      this builder - 此构建器
    • timeout

      public ProcessConfig.Builder timeout(Duration timeout)
      Sets the execution timeout. 设置执行超时时间。
      Parameters:
      timeout - the timeout duration, or null for no timeout - 超时时间,或 null 表示无超时
      Returns:
      this builder - 此构建器
    • timeout

      public ProcessConfig.Builder timeout(long amount, TimeUnit unit)
      Sets the execution timeout. 设置执行超时时间。
      Parameters:
      amount - the timeout amount - 超时数量
      unit - the time unit - 时间单位
      Returns:
      this builder - 此构建器
    • redirectErrorStream

      public ProcessConfig.Builder redirectErrorStream(boolean redirect)
      Sets whether stderr should be merged into stdout. 设置是否将 stderr 合并到 stdout。
      Parameters:
      redirect - true to merge stderr into stdout - 若为 true 则合并 stderr 到 stdout
      Returns:
      this builder - 此构建器
    • stdoutFile

      public ProcessConfig.Builder stdoutFile(Path file)
      Redirects stdout to a file. 将 stdout 重定向到文件。
      Parameters:
      file - the target file, or null for in-memory capture - 目标文件,或 null 以在内存中捕获
      Returns:
      this builder - 此构建器
    • stderrFile

      public ProcessConfig.Builder stderrFile(Path file)
      Redirects stderr to a file. 将 stderr 重定向到文件。
      Parameters:
      file - the target file, or null for in-memory capture - 目标文件,或 null 以在内存中捕获
      Returns:
      this builder - 此构建器
    • inheritIO

      public ProcessConfig.Builder inheritIO(boolean inherit)
      Sets whether the process should inherit the parent's IO streams. 设置进程是否继承父进程的 IO 流。

      When enabled, stdout/stderr will not be captured in memory.

      启用后,stdout/stderr 将不会在内存中捕获。

      Parameters:
      inherit - true to inherit IO - 若为 true 则继承 IO
      Returns:
      this builder - 此构建器
    • build

      public ProcessConfig build()
      Builds the ProcessConfig. 构建 ProcessConfig
      Returns:
      a new immutable ProcessConfig - 新的不可变 ProcessConfig
      Throws:
      IllegalArgumentException - if command is empty - 若命令为空