Class ToolExecBase<P extends EnhancedProblems>

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
org.gradle.api.internal.ConventionTask
org.gradle.api.tasks.JavaExec
net.minecraftforge.gradleutils.shared.ToolExecBase<P>
Type Parameters:
P - The type of enhanced problems, used for common problems reporting with illegal task arguments
All Implemented Interfaces:
Comparable<Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.IConventionAware, org.gradle.api.internal.TaskInternal, Named, ExtensionAware, Task, BaseExecSpec, JavaExecSpec, JavaForkOptions, ProcessForkOptions, Configurable<Task>

public abstract class ToolExecBase<P extends EnhancedProblems> extends JavaExec
This tool execution task is a template on top of JavaExec to make executing tools much easier and more consistent between plugins.
See Also:
Implementation Requirements:
Implementing plugins should make a shared subclass named ToolExec which all other tool executing tasks should extend from.
  • Field Details

    • defaultToolDir

      protected final DirectoryProperty defaultToolDir
      The default tool directory (usage is not required).
  • Constructor Details

    • ToolExecBase

      protected ToolExecBase(Class<P> problemsType, Tool tool)
      Creates a new task instance using the given types and tool information.
      Parameters:
      problemsType - The type of problems to use for this task (accessible via getProblems())
      tool - The tool to use for this task
      Implementation Requirements:
      The implementing subclass must make their constructor public, annotated with Inject, and have only a single parameter for Tool, passing in static plugin and problems types to this base constructor. The types must also be manually specified in the class declaration when overriding this class. The best practice is to make a single ToolExec class for the implementing plugin to use, which other tasks can extend off of.
  • Method Details

    • getAdditionalArgs

      @Input @Optional public ListProperty<String> getAdditionalArgs()
      Additional arguments to use when invoking the tool. Use in configuration instead of args(java.lang.String, java.lang.Iterable<? extends java.io.File>).
      Returns:
      The list property for the additional arguments
    • getProjectLayout

      @Inject protected abstract ProjectLayout getProjectLayout()
      The project layout provided by Gradle services.
      Returns:
      The project layout
      See Also:
    • getProblems

      @Internal protected final P getProblems()
      The enhanced problems instance to use for this task.
      Returns:
      The enhanced problems
    • addArguments

      @MustBeInvokedByOverriders protected void addArguments()
      This method should be overridden by subclasses to add arguments to this task via JavaExec.args(java.lang.Object...). To preserve arguments added by superclasses, this method must be invoked by overriders.
    • exec

      public void exec()
      Overrides:
      exec in class JavaExec
      Implementation Note:
      Not invoking this method from an overriding method will result in the tool never being executed and addArguments() never being run.
    • args

      protected final void args(String arg, Iterable<? extends File> files)
      Adds each file to the arguments preceded by the given argument. Designed to work well with JOpt Simple.
      Parameters:
      arg - The flag to use for each file
      files - The files to add
    • args

      protected final void args(String arg, FileSystemLocationProperty<? extends FileSystemLocation> fileProvider)
      Adds the given argument followed by the given file location to the arguments.
      Parameters:
      arg - The flag to use
      fileProvider - The file to add
    • args

      protected final void args(String arg, Provider<?> provider)
      Adds the given argument followed by the given object (may be a file location) to the arguments.
      Parameters:
      arg - The flag to use
      provider - The object (or file) to add
    • argOnlyIf

      protected final void argOnlyIf(String arg, Provider<Boolean> onlyIf)
      Adds the given argument if and only if the given boolean property is present and true.
      Parameters:
      arg - The argument to add
      onlyIf - The provider to test
    • argOnlyIf

      protected final void argOnlyIf(String arg, Spec<? super ToolExecBase<?>> onlyIf)
      Adds the given argument if and only if the given spec, using this task, is satisfied.
      Parameters:
      arg - The argument to add
      onlyIf - The spec to test