Class Task

java.lang.Object
net.javasauce.ss.util.task.Task
Direct Known Subclasses:
AbstractGitTask, BarrierTask, CopyTask, DecompileTask, DetectChangesTask, DiscordReportTask, DownloadTask, GenerateComparisonsTask, GenerateGradleProjectTask, GenerateRootProjectTask, PrepareToolTask, RemapperTask, SetupGitRepoTask, SetupJdkTask, UnzipTask

public abstract class Task extends Object
A task is some operation that executes on a given executor. Tasks can declare inputs and outputs. Outputs of one task may be used as inputs to another task.

Tasks automatically declare dependencies between each-other by consuming their outputs as inputs, or deriving their own output from another tasks output. Note: Task dependencies are collected when a dependent task is scheduled for execution.

Tasks may declare themselves as cacheable, using a selection of their inputs and outputs as the cache value, if the cache value matches the previous run, it will not be re-run. Note: It's important to ensure your outputs are included in the cache, otherwise your task may not re-run when it's missing.

Tasks may declare 'inner' tasks via declareCompositeTask(net.javasauce.ss.util.task.Task), these tasks copy any explicit dependencies their outer has/will have, and are marked as explicit dependencies of their outer.

Created by covers1624 on 6/24/25.

  • Constructor Details

    • Task

      public Task(String name, Executor executor)
      Parameters:
      name - The name for this task, used for logging.
      executor - The executor to run this task on. If you don't know what to provide you can use ForkJoinPool.commonPool(), for the built-in executor. Providing your task a specific executor can be used to create execution groups, for example, using a single-thread executor can ensure only one instance of your task is executed at a time.
  • Method Details

    • runTasks

      public static void runTasks(Task... tasks)
      Schedule the given tasks and wait for them to complete.
      Parameters:
      tasks - The tasks to run.
    • runTasks

      public static void runTasks(Iterable<? extends Task> tasks)
      Schedule the given tasks and wait for them to complete.
      Parameters:
      tasks - The tasks to run.
    • withCaching

      protected final void withCaching(TaskOutput<Path> cacheNextTo, Consumer<TaskCacheBuilder> cons)
      Enable caching for your task.
      Parameters:
      cacheNextTo - The output to store the cache file next to.
      cons - The function to configure the cache with your cache inputs/outputs.
    • withCaching

      protected final void withCaching(TaskOutput<Path> cacheNextTo, String cacheSuffix, Consumer<TaskCacheBuilder> configure)
      Enable caching for your task.
      Parameters:
      cacheNextTo - The output to store the cache file next to.
      cacheSuffix - A suffix on the cache name, this can be used to distinguish between .sha1 files. // TODO perhaps we change the suffix to always be '_task.sha1'
      configure - The function to configure the cache with your cache inputs/outputs.
    • input

      protected final <T> TaskInput<T> input(String name)
      Create a new input for your task. You must set a value before the task executes.
      Parameters:
      name - The name for your input. Used in logging/errors.
      Returns:
      A new input for your task, a value must be set.
    • input

      protected final <T> TaskInput<T> input(String name, T _default)
      Create a new input for your task, with the provided initial value.
      Parameters:
      name - The name for your input. Used in logging/errors.
      Returns:
      A new input for your task.
    • optionalInput

      protected final <T> TaskInput<Optional<T>> optionalInput(String name)
      Create a new optional input for your task. The default value is set to empty.
      Parameters:
      name - The name for your input. Used in logging/errors.
      Returns:
      A new input for your task.
    • inputCollection

      protected final <T> TaskInput.Collection<T> inputCollection(String name)
      Create a new collection input for your task. The default value is set to an empty list.
      Parameters:
      name - The name for your input. Used in logging/errors.
      Returns:
      A new input for your task.
    • output

      protected final <T> TaskOutput<T> output(String name)
      Create a new output for your task. You must set a value before executing the task.
      Parameters:
      name - The name for your output. Used in logging/errors.
      Returns:
      A new output for your task.
    • computedOutput

      protected final <T> TaskOutput<T> computedOutput(String name)
      Create a new output for your task. You must set a value for this output before your task finishes executing.
      Parameters:
      name - The name for your output. Used in logging/errors.
      Returns:
      A new output for your task.
    • dependsOn

      public void dependsOn(Task... tasks)
      Mark this task as requiring the provided tasks, without declaring any IO dependencies.
      Parameters:
      tasks - The tasks to depend on.
    • dependsOn

      public void dependsOn(Iterable<Task> tasks)
      Mark this task as requiring the provided tasks, without declaring any IO dependencies.
      Parameters:
      tasks - The tasks to depend on.
    • declareCompositeTask

      protected void declareCompositeTask(Task task)
      Declare the given task execute before this task.

      The given task will copy all explicit dependencies of this task, however, will not automatically copy any implicit dependencies handed through IO variables. The given task will need to either derive its own inputs from the inputs of the outer, or copy the outers inputs.

    • getFuture

      public final CompletableFuture<Task> getFuture()
      Resolve this tasks dependencies and return a future for the execution of this task.
      Returns:
      The future.
    • execute

      protected abstract void execute() throws Throwable
      Called to execute your task actions.
      Throws:
      Throwable
    • getName

      public final String getName()