public class ScriptBuilder extends Object
Modifier and Type | Field and Description |
---|---|
private Map<String,String> |
bgProcesses |
private String |
logFolder |
private int |
nextBgPid |
private StringBuilder |
script |
Constructor and Description |
---|
ScriptBuilder()
Create a new script builder using the working folder
for log and progress information.
|
ScriptBuilder(String logFolder)
Create a new script builder for a generic script.
|
Modifier and Type | Method and Description |
---|---|
String |
bkgr(String... cmds)
Adds a batch of commands that are executed in the background.
|
String |
bkgr(String cmd)
Adds a command that is executed in the background.
|
void |
cmd(String cmd)
Run a command.
|
void |
comment(String comment)
Adds a comment to the script.
|
void |
echo(String text)
Echo the given text to stdout
|
int |
length()
Get the current length of the script.
|
void |
newLine()
Adds an empty line.
|
void |
progress(int progress,
String status)
Update the progress file.
|
void |
time(String comment)
Append the current time (hour:minute:second) and comment into the 'time.log' file in the
log folder.
|
String |
toString()
Get the generated script.
|
void |
waitForProcess(String pid)
Wait for the given process to end.
|
private final StringBuilder script
private final String logFolder
private int nextBgPid
public ScriptBuilder()
public ScriptBuilder(String logFolder)
logFolder
- Path to a folder to use for outputting
log and progress information. If null, the folder set
by ${WD} is used (=working directory for jobs executed by
the Open Grid cluster).public void comment(String comment)
comment
- The comment (must not contain any new lines)public void newLine()
public void time(String comment)
public void progress(int progress, String status)
progress
- The progress (in percent)status
- The status messagepublic void cmd(String cmd)
public void echo(String text)
public String bkgr(String cmd)
waitForProcess(String)
to add a wait statement that also catches the
exit code of the background task.public String bkgr(String... cmds)
waitForProcess(String)
to add
a wait statement that also catches the exit code of the background task.public void waitForProcess(String pid)
pid
- The process id variable name returned by bkgr(String)
.IllegalArgumentException
- If the pid is unknownpublic int length()
public String toString()
toString
in class Object
IllegalStateException
- If waitForProcess(String)
hasn't
been called for all commands started in the background (bkgr(String)
or bkgr(String...)
)