saker.build Documentation TaskDoc JavaDoc Packages
public class TaskUtils
Utility class for task related functionality.
Methods
public static String
Chooses a default target name based on a collection of target names.
public static NavigableMap<SakerPath, SakerFile>
Collects the file references from the given file deltas associated with the given tag.
public static NavigableMap<SakerPath, SakerFile>
Same as collectFilesForTag(TaskFileDeltas, Object), but collect the files for multiple tags.
public static TaskFactory<?>
createTask(ExecutionContext context, TaskName taskname, String repositoryid)
Looks up a task factory for the given name and optional repository identifier.
public static void
initParametersOfTask(TaskContext taskcontext, Object taskobj, Map<String, ? extends TaskIdentifier> parameters)
Initializes the parameter fields of the given task object for the given parameter map.
public static void
initParametersOfTask(TaskContext taskcontext, Object taskobj, Map<String, ? extends TaskIdentifier> parameters, TaskResultResolver taskresultresolver)
Initializes the parameter fields of the given task object for the given parameter map.
public static void
Prints a formatted exception view and omits transitive task execution failures.
Chooses a default target name based on a collection of target names.

This method can be used to determine a target to build when the user didn't specify an explicit target name when referencing a build script.

The algorithm is as follows:

  1. If the names is empty, null is returned.
  2. If the size of the names is 1, the single element is returned.
  3. If the names contain "build", then "build" is returned.
  4. Else null is returned.
namesThe names to select a default target from.
The determined default target name or null if failed.
NullPointerExceptionIf names is null.
Collects the file references from the given file deltas associated with the given tag.

This method will examine the file change deltas and collect the paths and files from them.

deltasThe file deltas.
tagThe tag to collect the files for.
The files present in deltas mapped to their paths. Values might be null, if FileChangeDelta.getFile() returns null.
NullPointerExceptionIf the deltas are null.
Same as collectFilesForTag(TaskFileDeltas, Object), but collect the files for multiple tags.
deltasThe file deltas.
tagsThe tags to collect the files for.
The files present in deltas mapped to their paths. Values might be null, if FileChangeDelta.getFile() returns null.
NullPointerExceptionIf any of the arguments are null.
public static TaskFactory<?> createTask(ExecutionContext context, TaskName taskname, String repositoryid) throws TaskNotFoundException
Looks up a task factory for the given name and optional repository identifier.

The method uses the currently loaded repositories and tries to find a task factory by the given name.

An optional repository identifier can be specified to explicitly try to only load from the repository that bears that identifier.

When calling this from a task execution, use TaskLookupExecutionProperty to ensure proper incremental operation.

contextThe execution context.
tasknameThe task name to look up.
repositoryidThe repository identifier to search, or null if all loaded repositories should be used.
The found task factory.
TaskNotFoundExceptionIf the task was not found. View the suppressed and cause exceptions for more information.
public static void initParametersOfTask(TaskContext taskcontext, Object taskobj, Map<String, ? extends TaskIdentifier> parameters) throws TaskParameterException
Initializes the parameter fields of the given task object for the given parameter map.

This method uses the provided task context to resolve the parameter values. Same as calling initParametersOfTask(TaskContext, Object, Map<String, ? extends TaskIdentifier>, TaskResultResolver) with the task context as resolver:

 initParametersOfTask(taskcontext, taskobj, parameters, taskcontext);
 
taskcontextThe task context.
taskobjThe object to assign the fields to. This is usually the task that is being called.
parametersThe parameters of the task to assign the fields.
TaskParameterExceptionIn case of error.
public static void initParametersOfTask(TaskContext taskcontext, Object taskobj, Map<String, ? extends TaskIdentifier> parameters, TaskResultResolver taskresultresolver) throws TaskParameterException
Initializes the parameter fields of the given task object for the given parameter map.

This method uses SakerInput and DataContext annotations to assign converted values to the annotated fields.

For each annotated field, the method will look up a corresponding parameter value in the provided parameters map. If a task identifier is found for any of the parameter names for the field, it will be requested from the specified task result resolver using TaskResultResolver.getTaskResult(TaskIdentifier). The return value of the task will be assigned to the annotated field, using the conversion rules from DataConverterUtils.convert(TaskResultResolver, Object, Field).

The method specially handles any fields which have the type of Optional. In that case, if there was no parameter for the given name, it will be null. Otherwise, an Optional is created for it with the value converted to the generic argument of the declared Optional. (I.e. if the field is null, the parameter is not present, if it is an Optional that doesn't have a value present, then the value for it was null.)

Callers can reify the task resolution implementation by passing a custom implementation of TaskResultResolver as argument.

taskcontextThe task context.
taskobjThe object to assign the fields to. This is usually the task that is being called.
parametersThe parameters of the task to assign the fields.
taskresultresolverThe task result resolver to look up the results of the parameter values.
TaskParameterExceptionIn case of error.
public static void printTaskExceptionsOmitTransitive(ExceptionView exceptionview, PrintStream ps, SakerPath workingdir, ExceptionFormat format) throws NullPointerException
Prints a formatted exception view and omits transitive task execution failures.

This method is intended for displaying the exceptions caused by build execution failure.

The method will omit printing exceptions which are caused by other task execution failure exceptions. This helps reducing the clutter that is caused by cascaded task failures.

If a task throws a TaskExecutionFailedException during its Task.run(TaskContext) method call, then it will be omitted from the display, as it only adds noise to the output. The task exception that transitively caused the failure will not be omitted, as that is a root failure.

Exceptions that are caused by execution deadlock (TaskExecutionDeadlockedException) are also omitted accordingly.

If the method sees that all exceptions would be omitted, it will fall back to printing all exceptions.

The method expects the argument exception view to represent a MultiTaskExecutionFailedException directly thrown by the build execution.

exceptionviewThe exception view.
psThe output stream.
workingdirThe path to relativize script trace element paths, or null to don't relativize.
formatThe exception format to apply when printing each individual exception.
NullPointerExceptionIf the exception, exception format, or output stream arguments are null.