Package org.sikuli.script.runners
Class AbstractScriptRunner
- java.lang.Object
-
- org.sikuli.script.runners.AbstractScriptRunner
-
- All Implemented Interfaces:
IScriptRunner
- Direct Known Subclasses:
AbstractLocalFileScriptRunner,InvalidRunner,NetworkRunner,ProcessRunner,ServerRunner,SikulixRunner
public abstract class AbstractScriptRunner extends Object implements IScriptRunner
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.sikuli.script.support.IScriptRunner
IScriptRunner.EffectiveRunner, IScriptRunner.Options
-
-
Constructor Summary
Constructors Constructor Description AbstractScriptRunner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Aborts the current running script.protected voidadjustBundlePath(String script, IScriptRunner.Options options)booleancanHandle(String identifier)Checks if this runner can handle the given identifier.booleancanHandleFileEnding(String identifier)voidclose()Is executed before Sikuli closes.protected voiddoAbort()Interrupts the worker thread.protected voiddoClose()protected intdoEvalScript(String script, IScriptRunner.Options options)protected voiddoInit(String[] args)protected booleandoRedirect(PrintStream stdout, PrintStream stderr)protected voiddoRunLines(String lines, IScriptRunner.Options options)protected intdoRunScript(String scriptfile, String[] scriptArgs, IScriptRunner.Options options)intevalScript(String script, IScriptRunner.Options maybeOptions)Evaluates the Script.voidexecAfter(String[] stmts)add statements to be run after script has endedvoidexecBefore(String[] stmts)add statements to be run after SCRIPT_HEADER, but before script is executedStringgetDefaultExtension()convenience: return the first defined extension (default)IScriptRunner.EffectiveRunnergetEffectiveRunner(String script)Needed in the IDE to detect the runner when file or folder is openedString[]getFileEndings()Usually the same as getExtensions() but with the leading dot.booleanhasExtension(String ending)checks whether this ScriptRunner supports the given file extensionvoidinit(String[] args)Can be used to initialize the ScriptRunner.booleanisAborted()Checks if the currently running script has been aborted.booleanisAbortSupported()Checks if abort is supported by this script runner implementation.booleanisReady()booleanisRunning()booleanisSupported()Checks if the current platform supports this runner.protected voidlog(int level, String message, Object... args)voidredirect(PrintStream stdout, PrintStream stderr)Redirects the runner's STDIO to the given PrintStream.voidreset()Resets this runner.protected voidresetBundlePath(String script, IScriptRunner.Options options)voidrunLines(String lines, IScriptRunner.Options maybeOptions)Run the given script lines.intrunScript(String script, String[] scriptArgs, IScriptRunner.Options maybeOptions)Executes the Script.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.sikuli.script.support.IScriptRunner
getExtensions, getName, getType
-
-
-
-
Method Detail
-
init
public final void init(String[] args) throws SikuliXception
Description copied from interface:IScriptRunnerCan be used to initialize the ScriptRunner. This method is called at the beginning of program execution. The given parameters can be used to parse any ScriptRunner specific custom options.- Specified by:
initin interfaceIScriptRunner- Parameters:
args- All arguments that were passed to the main-method- Throws:
SikuliXception
-
isReady
public final boolean isReady()
-
isSupported
public boolean isSupported()
Description copied from interface:IScriptRunnerChecks if the current platform supports this runner.- Specified by:
isSupportedin interfaceIScriptRunner- Returns:
- true if platform supports this runner, false otherwise
-
hasExtension
public final boolean hasExtension(String ending)
Description copied from interface:IScriptRunnerchecks whether this ScriptRunner supports the given file extension- Specified by:
hasExtensionin interfaceIScriptRunner- Returns:
- true if the runner has the given extension, false otherwise
-
getDefaultExtension
public String getDefaultExtension()
Description copied from interface:IScriptRunnerconvenience: return the first defined extension (default)- Specified by:
getDefaultExtensionin interfaceIScriptRunner- Returns:
- default extension
-
canHandle
public boolean canHandle(String identifier)
Description copied from interface:IScriptRunnerChecks if this runner can handle the given identifier.- Specified by:
canHandlein interfaceIScriptRunner- Parameters:
identifier- Can be Runner name, type or one of its supported extensions Can also be script code prefixed with the runnerName (e.g. JavaScript*console.log("hello"))- Returns:
- true if the runner can handle the identifier, false otherwise
-
redirect
public final void redirect(PrintStream stdout, PrintStream stderr)
Description copied from interface:IScriptRunnerRedirects the runner's STDIO to the given PrintStream.Subsequent calls to this function override the previously set streams.
If one of the parameters is set to null, STDIO redirection is reset to System.out and System.err.
- Specified by:
redirectin interfaceIScriptRunner- Parameters:
stdout- PrintStream for STDOUTstderr- PrintStream for STDERR
-
doRedirect
protected boolean doRedirect(PrintStream stdout, PrintStream stderr)
-
runScript
public final int runScript(String script, String[] scriptArgs, IScriptRunner.Options maybeOptions)
Description copied from interface:IScriptRunnerExecutes the Script.- Specified by:
runScriptin interfaceIScriptRunner- Parameters:
script- Identifier pointing to the script. This can either by a file path or an URI, depending on the runner implementationscriptArgs- Arguments to be passed directly to the script with --argsmaybeOptions- Implementation specific options.- Returns:
- exitcode for the script execution
-
getEffectiveRunner
public IScriptRunner.EffectiveRunner getEffectiveRunner(String script)
Description copied from interface:IScriptRunnerNeeded in the IDE to detect the runner when file or folder is opened- Specified by:
getEffectiveRunnerin interfaceIScriptRunner- Returns:
- array: EffectiveRunner object
-
doRunScript
protected int doRunScript(String scriptfile, String[] scriptArgs, IScriptRunner.Options options)
-
evalScript
public final int evalScript(String script, IScriptRunner.Options maybeOptions)
Description copied from interface:IScriptRunnerEvaluates the Script.- Specified by:
evalScriptin interfaceIScriptRunner- Parameters:
script- Script contentmaybeOptions- Implementation specific options.- Returns:
- exitcode for the script execution
-
doEvalScript
protected int doEvalScript(String script, IScriptRunner.Options options)
-
runLines
public final void runLines(String lines, IScriptRunner.Options maybeOptions)
Description copied from interface:IScriptRunnerRun the given script lines. The implementation might perform some optimizations on the code (e.g. fix indentation) before executing it.- Specified by:
runLinesin interfaceIScriptRunner- Parameters:
lines- Code do executemaybeOptions- Implementation specific options.
-
doRunLines
protected void doRunLines(String lines, IScriptRunner.Options options)
-
close
public final void close()
Description copied from interface:IScriptRunnerIs executed before Sikuli closes. Can be used to cleanup the ScriptRunner- Specified by:
closein interfaceIScriptRunner
-
doClose
protected void doClose()
-
reset
public final void reset()
Description copied from interface:IScriptRunnerResets this runner.The runner gets closed and initialized again using init.
- Specified by:
resetin interfaceIScriptRunner
-
execBefore
public void execBefore(String[] stmts)
Description copied from interface:IScriptRunneradd statements to be run after SCRIPT_HEADER, but before script is executed- Specified by:
execBeforein interfaceIScriptRunner- Parameters:
stmts- string array of statements (null resets the statement buffer)
-
execAfter
public void execAfter(String[] stmts)
Description copied from interface:IScriptRunneradd statements to be run after script has ended- Specified by:
execAfterin interfaceIScriptRunner- Parameters:
stmts- string array of statements (null resets the statement buffer)
-
isRunning
public final boolean isRunning()
- Specified by:
isRunningin interfaceIScriptRunner- Returns:
- true if the runner is currently executing a script, false otherwise
-
isAbortSupported
public boolean isAbortSupported()
Description copied from interface:IScriptRunnerChecks if abort is supported by this script runner implementation.- Specified by:
isAbortSupportedin interfaceIScriptRunner- Returns:
- true is abort is supported, false otherwise
-
abort
public final void abort()
Description copied from interface:IScriptRunnerAborts the current running script.Not all runners can be aborted, please check abort support using isAbortSupported().
- Specified by:
abortin interfaceIScriptRunner
-
doAbort
protected void doAbort()
Interrupts the worker thread. Can be overridden by Runner implementations if an interrupt is not needed.
-
isAborted
public final boolean isAborted()
Description copied from interface:IScriptRunnerChecks if the currently running script has been aborted.- Specified by:
isAbortedin interfaceIScriptRunner- Returns:
- true if the currently running script has been aborted, false otherwise.
-
canHandleFileEnding
public final boolean canHandleFileEnding(String identifier)
-
getFileEndings
public String[] getFileEndings()
Description copied from interface:IScriptRunnerUsually the same as getExtensions() but with the leading dot.Some files (e.g. $py.class) might have a somewhat unusual but very specific file ending.
- Specified by:
getFileEndingsin interfaceIScriptRunner- Returns:
- An Array containing the supported line endings
-
adjustBundlePath
protected void adjustBundlePath(String script, IScriptRunner.Options options)
-
resetBundlePath
protected void resetBundlePath(String script, IScriptRunner.Options options)
-
-