Class JBangOperation
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionargs()Retrieves the live collection of arguments to be passed to the script.Sets the arguments to be used in thescript.args(Collection<String> args) Sets the arguments to be used in thescript.env()Returns the environment variables.Adds an environment variable.Adds environment variables.voidexecute()Performs the operationexitOnFailure(boolean exitOnFailure) Configures whether the operation should exit upon a JBang execution failure.fromProject(BaseProject project) Configures a JBang operation from aBaseProject.inheritIO(boolean inheritIO) Configures whether the child process should inherit the I/O streams of the current JVM.static booleanisAix()Determines if the current operating system is AIX.static booleanisCygwin()Determines if the current operating system is Cygwin.booleanChecks whether the operation is configured to exit upon a JBang execution failure.static booleanDetermines if the current operating system is FreeBSD.booleanReturns whether the child process inherits the I/O streams of the current JVM.static booleanisLinux()Determines if the operating system is Linux.static booleanisMacOS()Determines if the current operating system is macOS.static booleanisMinGw()Determines if the current operating system is MinGW.static booleanDetermines if the current operating system is OpenVMS.static booleanDetermines if the current operating system is Solaris.static booleanDetermines if the current operating system is Windows.Retrieves the live collection of arguments to be used when running the script.Sets one or more arguments to be used when running the script.jBangArgs(Collection<String> args) Sets the arguments to be used when running thescriptRetrieves the JBang home directory.Sets the JBang home directory.Sets the JBang home directory.Sets the JBang home directory.outputConsumer(Consumer<String> outputConsumer) Sets a consumer to receive output lines when not inheriting I/O.voidreset()Resets the script-related state of the operation to its default values.script()Retrieves the script that has been set for execution.Sets the script to be executed.longtimeout()Retrieves the timeout for JBang execution in seconds.timeout(long seconds) Sets the timeout for JBang execution in seconds.workDir()Retrieves the working directory.Provides the working directory if it differs from the project's directory.Provides the working directory if it differs from the project's directory.Provides the working directory if it differs from the project's directory.Methods inherited from class rife.bld.operations.AbstractOperation
executeOnce, executeOnce, silent, silent
-
Constructor Details
-
JBangOperation
public JBangOperation()
-
-
Method Details
-
execute
Performs the operation- Specified by:
executein classAbstractOperation<JBangOperation>- Throws:
Exception- if an error occursExitStatusException- if workDir is null or invalid, JBang execution fails or times out
-
isAix
public static boolean isAix()Determines if the current operating system is AIX.- Returns:
trueif the operating system is identified as AIX,falseotherwise- See Also:
-
SystemTools.isAix()
-
isCygwin
public static boolean isCygwin()Determines if the current operating system is Cygwin.- Returns:
trueif the operating system is identified as Cygwin,falseotherwise- See Also:
-
SystemTools.isCygwin()
-
isFreeBsd
public static boolean isFreeBsd()Determines if the current operating system is FreeBSD.- Returns:
trueif the operating system is FreeBSD,falseotherwise- See Also:
-
SystemTools.isFreeBsd()
-
isLinux
public static boolean isLinux()Determines if the operating system is Linux.- Returns:
trueif the operating system is Linux,falseotherwise- See Also:
-
SystemTools.isLinux()
-
isMacOS
public static boolean isMacOS()Determines if the current operating system is macOS.- Returns:
trueif the OS is macOS,falseotherwise- See Also:
-
SystemTools.isMacOS()
-
isMinGw
public static boolean isMinGw()Determines if the current operating system is MinGW.- Returns:
trueif the operating system is identified as MinGW,falseotherwise- See Also:
-
SystemTools.isMinGw()
-
isOpenVms
public static boolean isOpenVms()Determines if the current operating system is OpenVMS.- Returns:
trueif the operating system is OpenVMS,falseotherwise- See Also:
-
SystemTools.isOpenVms()
-
isSolaris
public static boolean isSolaris()Determines if the current operating system is Solaris.- Returns:
trueif the operating system is Solaris,falseotherwise- See Also:
-
SystemTools.isSolaris()
-
isWindows
public static boolean isWindows()Determines if the current operating system is Windows.- Returns:
trueif the operating system is Windows,falseotherwise- See Also:
-
SystemTools.isWindows()
-
args
Sets the arguments to be used in thescript.- Parameters:
args- the arguments to use in the script- Returns:
- this operation instance
- Throws:
IllegalArgumentException- if theargselements arenullor emptyNullPointerException- if theargscollection isnull
-
args
Sets the arguments to be used in thescript.- Parameters:
args- the arguments to use in the script- Returns:
- this operation instance
- Throws:
IllegalArgumentException- if theargselements arenullor emptyNullPointerException- if theargscollection isnull
-
args
Retrieves the live collection of arguments to be passed to the script.The returned list is the operation's internal list. Callers may add to it directly; this is intentional by design (builder pattern).
- Returns:
- the mutable list of script arguments
-
env
Adds an environment variable.These variables are merged with the current process environment. Existing variables with the same name are overridden.
- Parameters:
name- the variable name, must not be nullvalue- the variable value, must not be null- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifnameis empty or nullNullPointerException- ifvalueis null- See Also:
-
env
Adds environment variables.These variables are merged with the current process environment. Existing variables with the same name are overridden.
- Parameters:
vars- the map of environment variables, must not be null and must not contain null keys or values- Returns:
- this operation instance
- Throws:
NullPointerException- ifvarsis null, or ifvarscontains a null key or value- See Also:
-
env
Returns the environment variables.The returned map is mutable and can be modified directly before calling
execute().- Returns:
- the mutable environment variables map, never null
-
exitOnFailure
Configures whether the operation should exit upon a JBang execution failure.Default value is
true- Parameters:
exitOnFailure-trueif the operation should exit on failure,falseotherwise- Returns:
- this operation instance
-
fromProject
Configures a JBang operation from aBaseProject.Sets the following from the project:
- Parameters:
project- the project to configure the operation from- Returns:
- this operation instance
- Throws:
NullPointerException- if theprojectisnull
-
inheritIO
Configures whether the child process should inherit the I/O streams of the current JVM.When
true, the child process uses the same stdin, stdout, and stderr as the current Java process. This enables interactive commands, preserves ANSI colors, and allows progress bars to display correctly. Output is not captured by the logger and cannot be asserted in tests.When
false, stdout and stderr are merged and captured through the logger. This makes output testable and keeps it in the build log, but breaks interactive prompts and ANSI formatting.Default is
TRUE- Parameters:
inheritIO-trueto inherit I/O,falseto capture output- Returns:
- this operation instance
-
isExitOnFailure
public boolean isExitOnFailure()Checks whether the operation is configured to exit upon a JBang execution failure.Default value is
true- Returns:
trueif the operation is set to exit on failure,falseotherwise.
-
isInheritIO
public boolean isInheritIO()Returns whether the child process inherits the I/O streams of the current JVM.- Returns:
trueif I/O is inherited (default),falseifstderris redirected tostdout- See Also:
-
jBangArgs
Sets the arguments to be used when running thescript- Parameters:
args- the arguments to use when running the script- Returns:
- this operation instance
- Throws:
IllegalArgumentException- if theargselements arenullor emptyNullPointerException- if theargscollection isnull
-
jBangArgs
Sets one or more arguments to be used when running the script.- Parameters:
args- the arguments to use when running the script- Returns:
- this operation instance
- Throws:
IllegalArgumentException- if theargselements arenullor emptyNullPointerException- if theargscollection isnull
-
jBangArgs
Retrieves the live collection of arguments to be used when running the script.The returned list is the operation's internal list. Callers may add to it directly; this is intentional by design (builder pattern).
- Returns:
- the mutable list of JBang arguments
-
jBangHome
Sets the JBang home directory.- Parameters:
jBangHome- the JBang home directory- Returns:
- this operation instance
- Throws:
NullPointerException- ifjBangHomeis nullIllegalArgumentException- ifjBangHomeis empty
-
jBangHome
Sets the JBang home directory.- Parameters:
jBangHome- the JBang home directory- Returns:
- this operation instance
- Throws:
NullPointerException- ifjBangHomeis null
-
jBangHome
Sets the JBang home directory.- Parameters:
jBangHome- the JBang home directory- Returns:
- this operation instance
- Throws:
NullPointerException- ifjBangHomeis null
-
jBangHome
Retrieves the JBang home directory.- Returns:
- the JBang home directory
-
outputConsumer
Sets a consumer to receive output lines when not inheriting I/O.Only called when
isInheritIO()isfalse. Default logs at INFO level.- Parameters:
outputConsumer- the output consumer, must not be null- Returns:
- this operation instance
- Throws:
NullPointerException- if outputConsumer is null
-
reset
public void reset()Resets the script-related state of the operation to its default values.Specifically, this method:
- Clears all
script arguments - Clears all
environment variables - Clears all
JBang arguments - Resets the
exit on failure flagtotrue - Clears the assigned
script
The following are intentionally preserved across resets, as they are typically set once via
fromProjectand shared across multiple script executions:workDir,jBangHome,timeout,inheritIO, and theoutputConsumer. - Clears all
-
script
Sets the script to be executed.- Parameters:
script- the script to execute- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifscriptis null or emptyNullPointerException- ifscriptis null
-
script
Retrieves the script that has been set for execution.- Returns:
- the script to be executed or
null
-
timeout
Sets the timeout for JBang execution in seconds.If the process does not complete within the specified timeout, it will be terminated and the operation will fail. If set to any negative value, the process will wait indefinitely. Passing
0is not allowed; use a negative value to indicate no timeout.Default is
600seconds (10 minutes)- Parameters:
seconds- the timeout in seconds (positive); use a negative value for no timeout- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifsecondsis0- Since:
- 1.2
-
timeout
public long timeout()Retrieves the timeout for JBang execution in seconds.A positive value is the timeout duration in seconds. A negative value indicates no timeout (wait indefinitely).
0is not a valid state; the setter disallows it.- Returns:
- the timeout in seconds (positive), or a negative value if no timeout is set
- Since:
- 1.2
-
workDir
Retrieves the working directory.- Returns:
- the directory
-
workDir
Provides the working directory if it differs from the project's directory.- Parameters:
dir- the directory- Returns:
- this operation instance
- Throws:
NullPointerException- ifdiris null
-
workDir
Provides the working directory if it differs from the project's directory.- Parameters:
dir- the directory- Returns:
- this operation instance
- Throws:
NullPointerException- ifdiris null
-
workDir
Provides the working directory if it differs from the project's directory.- Parameters:
dir- the directory path- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifdiris emptyNullPointerException- ifdiris null
-