java.lang.Object | |
↳ | com.atlassian.bitbucket.scm.AbstractCommandBuilder<B extends com.atlassian.bitbucket.scm.CommandBuilder<B>> |
Known Direct Subclasses
AbstractScmCommandBuilder<B extends ScmCommandBuilder<B>>
|
Provides a basic implementation of most CommandBuilder functionality, to simplify creating builders.
All CommandBuilder and CommandBuilderSupport methods are implemented except for the actual
build
method.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
arguments | Maintains an ordered list of arguments. | ||||||||||
binary | The binary to execute when the command is run. | ||||||||||
environment | Maintains a map of environment variables and their values. | ||||||||||
errorHandler | The CommandErrorHandler to receive and process the InputStream for reading data from the
command's error stream. |
||||||||||
exitHandler | The CommandExitHandler to be invoked when the command runs. | ||||||||||
i18nService | The I18nService , used to internationalise error messages for exceptions thrown during processing. |
||||||||||
inputHandler | The CommandInputHandler to receive and process the OutputStream for feeding data into the
command. |
||||||||||
workingDirectory | The working directory in which the command should be run. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
AbstractCommandBuilder and sets the I18nService to use for internationalising
error messages and the binary to execute. | |||||||||||
Constructs a new
AbstractCommandBuilder , sets the I18nService to use for internationalising
error messages and the binary to execute, and optionally sets the workingDirectory where it
should be executed. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Finds the index of the specified
anchor and inserts the provided argument immediately after it
in the arguments . | |||||||||||
Finds the index of the specified
anchor and inserts the provided argument directly before it in
the arguments . | |||||||||||
Clears the
arguments , but does not null or replace the list instance. | |||||||||||
Clears the
environment , but does not null or replace the map instance. | |||||||||||
Clears the
inputHandler , setting it to null . | |||||||||||
Indicates the default CommandErrorHandler should be applied when
build(CommandOutputHandler) is
called by setting the errorHandler to null . | |||||||||||
Indicates the default CommandExitHandler should be applied when
build(CommandOutputHandler) is
called by setting the exitHandler to null . | |||||||||||
Indicates the default working directory should be used when
build(CommandOutputHandler) is called by
setting the workingDirectory to null . | |||||||||||
Sets the provided
value as the errorHandler to use for processing the standard error stream
when the built command is executed. | |||||||||||
Sets the provided
value as the exitHandler to be called when the built command exits or is
canceled. | |||||||||||
Sets the provided
value as the inputHandler to use for providing data on the standard input
stream when the built command is executed. | |||||||||||
Finds the index of the specified
anchor and inserts the provided argument immediately after it
in the arguments . | |||||||||||
Finds the index of the specified
anchor and inserts the provided argument directly before it in
the arguments . | |||||||||||
Clears the environment variable of the provided
name if it has been set | |||||||||||
Puts the provided
value in the environment map with the specified name , after ensuring
both the name and value are not blank . | |||||||||||
Sets the provided
value as the workingDirectory to use when the built command is executed. | |||||||||||
Sets the provided
value as the workingDirectory to use when the built command is executed. | |||||||||||
Constructs a
File from the provided value and sets it as the
working directory to use when the built command is executed. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Ensures the provided
File is not null , exists and is a directory. | |||||||||||
Ensures the provided
File is null , or that it exists and is a directory. | |||||||||||
Ensures the provided value is not
null , empty or blank. | |||||||||||
Ensures the provided argument is not
null , empty or blank. | |||||||||||
Returns a reference to the current builder, typed correctly to appease Java generics.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
com.atlassian.bitbucket.scm.CommandBuilder
| |||||||||||
From interface
com.atlassian.bitbucket.scm.CommandBuilderSupport
|
Maintains an ordered list of arguments. LinkedList
is used to optimise insertion, since the argument
list is modified more than it is read.
Derived classes may add and remove arguments, but they may not replace the list reference.
The binary to execute when the command is run. This must be provided to the constructor, cannot be null
and may not be updated.
Note: When constructing the Command in build(CommandOutputHandler)
, the derived class may opt
to use an alternative, equivalent binary. For example, when using git, give a binary of "git" and a first
argument of "http-backend", the builder may opt to call git-http-backend
(from libexec/git-core
)
rather than git http-backend
.
Maintains a map of environment variables and their values.
Derived classes may add, replace and remove keys and their values, but they may not replace the map reference.
Note: Java's ProcessBuilder.environment
does not support null
keys or values. Derived
classes should validate entries before they are put into the map to ensure they do not violate that contract.
The CommandErrorHandler to receive and process the InputStream
for reading data from the
command's error stream. This field may be null
, but when it is implementations should apply a default
when building the Command. The default should be accumulate error stream output to provide to the
CommandExitHandler.
The CommandExitHandler to be invoked when the command runs. This field may be null
, but when it
is implementations should apply a default when building the Command.
The I18nService
, used to internationalise error messages for exceptions thrown during processing.
The CommandInputHandler to receive and process the OutputStream
for feeding data into the
command. Not all commands will support input, so this field may be null
.
The working directory in which the command should be run. Per the contract for ProcessBuilder.directory
,
this field may be null
to use the Java process's working directory.
Constructs a new AbstractCommandBuilder
and sets the I18nService
to use for internationalising
error messages and the binary
to execute.
i18nService | the I18nService for internationalising error messages |
---|---|
binary | the binary to execute |
IllegalArgumentException | if the provided binary is empty or blank |
---|---|
NullPointerException | if the provided i18nService or binary is null
|
Constructs a new AbstractCommandBuilder
, sets the I18nService
to use for internationalising
error messages and the binary
to execute, and optionally sets the workingDirectory
where it
should be executed.
i18nService | the I18nService for internationalising error messages |
---|---|
binary | the binary to execute |
workingDirectory | the working directory for the command, or null for the default |
IllegalArgumentException | if the provided binary is empty or blank, or if a working directory
is provided which does not exist or is not a directory |
---|---|
NullPointerException | if the provided i18nService or binary is null
|
Finds the index of the specified anchor
and inserts the provided argument
immediately after it
in the arguments
. If the anchor
is not found, the provided argument
is appended at the
end of the argument list.
anchor | the argument serving as the anchor for the new argument |
---|---|
argument | the argument to add immediately after the specified anchor |
IllegalArgumentException | if the provided anchor or argument is empty or blank |
---|---|
NullPointerException | if the provided anchor or argument is null
|
Inserts the provided argument
at the specified index
in the arguments
, after ensuring
it is not blank
.
index | the index at which the argument should be inserted |
---|---|
argument | the argument to insert at the specified index |
IllegalArgumentException | if the provided argument is empty or blank |
---|---|
IndexOutOfBoundsException | if the specified index is out of range for the argument list |
NullPointerException | if the provided argument is null
|
Finds the index of the specified anchor
and inserts the provided argument
directly before it in
the arguments
. If the anchor
is not found, the provided argument
is appended at the end
of the argument list.
anchor | the argument serving as the anchor for the new argument |
---|---|
argument | the argument to add immediately before the specified anchor |
IllegalArgumentException | if the provided anchor or argument is empty or blank |
---|---|
NullPointerException | if the provided anchor or argument is null
|
Clears the environment
, but does not null
or replace the map instance.
Indicates the default CommandErrorHandler should be applied when build(CommandOutputHandler)
is
called by setting the errorHandler
to null
.
Derived classes may override this to preemptively set the default error handler, or they may apply the default
in build(CommandOutputHandler)
when the errorHandler
field is null
. The latter is the
preferred approach, as it does not require code using the builder to call this method to trigger applying the
default handler.
Indicates the default CommandExitHandler should be applied when build(CommandOutputHandler)
is
called by setting the exitHandler
to null
.
Derived classes may override this to preemptively set the default exit handler, or they may apply the default
in build(CommandOutputHandler)
when the exitHandler
field is null
. The latter is the
preferred approach, as it does not require code using the builder to call this method to trigger applying the
default handler.
Indicates the default working directory should be used when build(CommandOutputHandler)
is called by
setting the workingDirectory
to null
. This is consistent with ProcessBuilder
.
Sets the provided value
as the errorHandler
to use for processing the standard error stream
when the built command is executed.
Note: As described on the CommandErrorHandler and CommandExitHandler interfaces, providing an
error handler will prevent the exit handler
from receiving any output
written to the standard error stream.
value | the handler to receive and process the command's error stream |
---|
NullPointerException | if the provided value is null
|
---|
Sets the provided value
as the exitHandler
to be called when the built command exits or is
canceled.
Note: As described on the CommandErrorHandler and CommandExitHandler interfaces, providing an
error handler
will prevent the exit handler from receiving any output
written to the standard error stream.
value | the handler which should be invoked when the command exits |
---|
NullPointerException | if the provided value is null
|
---|
Sets the provided value
as the inputHandler
to use for providing data on the standard input
stream when the built command is executed.
value | the handler to receive and process the command's input stream |
---|
NullPointerException | if the provided value is null
|
---|
Appends the provided argument
to the arguments
, after ensuring it is not null
.
Whitespace: Leading and trailing whitespace on the argument
is ignored, and the value is
used verbatim.
argument | the argument to append to the command |
---|
NullPointerException | if the provided argument is null |
---|
Finds the index of the specified anchor
and inserts the provided argument
immediately after it
in the arguments
. If the anchor
is not found, the provided argument
is appended at the
end of the argument list.
Whitespace: Leading and trailing whitespace on the anchor
or argument
is ignored,
and the values are used verbatim.
anchor | the argument serving as the anchor for the new argument |
---|---|
argument | the argument to add immediately after the specified anchor |
NullPointerException | if the provided anchor or argument is null |
---|
Inserts the provided argument
at the specified index
in the arguments
, after ensuring
it is not blank
.
Whitespace: Leading and trailing whitespace on the argument
is ignored, and the value is
used verbatim.
index | the index at which the argument should be inserted |
---|---|
argument | the argument to insert at the specified index |
IndexOutOfBoundsException | if the specified index is out of range for the argument list |
---|---|
NullPointerException | if the provided argument is null |
Finds the index of the specified anchor
and inserts the provided argument
directly before it in
the arguments
. If the anchor
is not found, the provided argument
is appended at the end
of the argument list.
Whitespace: Leading and trailing whitespace on the anchor
or argument
is ignored,
and the values are used verbatim.
anchor | the argument serving as the anchor for the new argument |
---|---|
argument | the argument to add immediately before the specified anchor |
NullPointerException | if the provided anchor or argument is null |
---|
Clears the environment variable of the provided name
if it has been set
name | the name of the environment variable to clear |
---|
Puts the provided value
in the environment
map with the specified name
, after ensuring
both the name
and value
are not blank
.
name | the name of the environment variable to set |
---|---|
value | the value to set for the environment variable |
IllegalArgumentException | if the provided name or value is empty or blank |
---|---|
NullPointerException | if the provided name or value is null |
Sets the provided value
as the workingDirectory
to use when the built command is executed.
value | the desired working directory |
---|
IllegalArgumentException | if the provided value does not exist, or does not reference a directory |
---|---|
NullPointerException | if the provided value is null
|
Sets the provided value
as the workingDirectory
to use when the built command is executed.
value | the desired working directory |
---|
IllegalArgumentException | if the provided value does not exist, or does not reference a directory |
---|---|
NullPointerException | if the provided value is null
|
Constructs a File
from the provided value
and sets it
as the
working directory to use when the built command is executed.
value | the absolute path to the desired working directory |
---|
IllegalArgumentException | if the provided value does not exist, or does not reference a directory |
---|---|
NullPointerException | if the provided value is null
|
Ensures the provided File
is not null
, exists and is a directory.
value | the File to validate |
---|
value
IllegalArgumentException | if the provided value does not exist, or does not reference a directory |
---|---|
NullPointerException | if the provided value is null
|
Ensures the provided File
is null
, or that it exists and is a directory.
value | the File to validate |
---|
value
, which may be null
IllegalArgumentException | if the provided value is not null but does not exist, or does
not reference a directory
|
---|
Ensures the provided value is not null
, empty or blank. The returned value is trimmed to remove
both leading and trailing whitespace.
value | the value to validate |
---|---|
name | the value's name, used in exception messages |
value
, trimmedIllegalArgumentException | if the provided value is empty or blank |
---|---|
NullPointerException | if the provided value is null |
Ensures the provided argument is not null
, empty or blank. The returned argument is trimmed to remove
both leading and trailing whitespace.
argument | the argument to validate |
---|
argument
, trimmedIllegalArgumentException | if the provided argument is empty or blank |
---|---|
NullPointerException | if the provided argument is null
|
Returns a reference to the current builder, typed correctly to appease Java generics.
Implementations of this method on derived builders are encouraged to use a covariant return type to return the
actual implementation class. For example:
public interface MyBuilder extends CommandBuilder<MyBuilder> {
//Implementation omitted
}
public class DefaultMyBuilder extends AbstractCommandBuilder<MyBuilder> implements MyBuilder {
//Implementation omitted
@Override
protected DefaultMyBuilder self() {
return this;
}
}
this
, in a derived class