@NotThreadSafe public interface

CommandBuilderSupport

com.atlassian.bitbucket.scm.CommandBuilderSupport<B extends com.atlassian.bitbucket.scm.CommandBuilderSupport<B>>
Known Indirect Subclasses

Class Overview

Provides a unifying abstraction for common functionality expected to be provided by both free-form CommandBuilders and, for those plugins which choose to provide them, type-safe builders.

Summary

Public Methods
@Nonnull <T> Command<T> build(CommandOutputHandler<T> outputHandler)
Builds a Command which, when executed, will provide output to the provided outputHandler for processing.
@Nonnull B clearEnvironment()
Clears any environment variables which have been set.
@Nonnull B defaultExitHandler()
Applies the default CommandExitHandler.
@Nonnull B defaultWorkingDirectory()
Applies the default working directory, which is the working directory for the current Java process.
@Nonnull B environment(String name, String value)
Adds an environment variable with the specified name and value.
@Nonnull B exitHandler(CommandExitHandler value)
Sets the CommandExitHandler which should be invoked after the command exits.
@Nonnull B workingDirectory(String value)
Sets the working directory which should be used when the command is run.
@Nonnull B workingDirectory(File value)
Sets the working directory which should be used when the command is run.

Public Methods

@Nonnull public Command<T> build (CommandOutputHandler<T> outputHandler)

Builds a Command which, when executed, will provide output to the provided outputHandler for processing.

Parameters
outputHandler the handler to receive and process output from the command as it executes
Returns
  • the built command
Throws
NullPointerException if the provided outputHandler is null

@Nonnull public B clearEnvironment ()

Clears any environment variables which have been set.

Returns
  • this

@Nonnull public B defaultExitHandler ()

Applies the default CommandExitHandler. The default exit handler used is based on the builder in play; each builder is free to define its own default exit handler.

Note: If no explicit exit handler is set, the default will be applied automatically when the command is built; it is not possible to build a command without an exit handler.

Returns
  • this

@Nonnull public B defaultWorkingDirectory ()

Applies the default working directory, which is the working directory for the current Java process. This may be useful for commands that create directories, such as SCM clone commands.

Returns
  • this

@Nonnull public B environment (String name, String value)

Adds an environment variable with the specified name and value. Both parameters are required, and an exception will be thrown if either is not provided.

Parameters
name the name of the environment variable to set
value the value to set for the environment variable
Returns
  • this
Throws
IllegalArgumentException if name or value is empty or blank
NullPointerException if name or value is null

@Nonnull public B exitHandler (CommandExitHandler value)

Sets the CommandExitHandler which should be invoked after the command exits. This handler receives:

  • the exit code from the process
  • any Throwable thrown during processing
  • any output the process wrote to its error stream
Whether the command executes successfully or fails in some way (either in the command itself or in processing performed by handlers attached to the command), the exit handler is guaranteed to be invoked.

Parameters
value the handler which should be invoked when the command exits
Returns
  • this
Throws
NullPointerException if the provided value is null

@Nonnull public B workingDirectory (String value)

Sets the working directory which should be used when the command is run. Paths provided here should be absolute, to ensure the command runs in the correct directory.

Parameters
value the absolute path to the desired working directory
Returns
  • this
Throws
IllegalArgumentException if value references a nonexistent path, or a file
NullPointerException if the provided value is null

@Nonnull public B workingDirectory (File value)

Sets the working directory which should be used when the command is run.

Parameters
value the desired working directory
Returns
  • this
Throws
IllegalArgumentException if value references a nonexistent path, or a file
NullPointerException if the provided value is null