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
Modifier and Type Method Description voidabort()Aborts the current running script.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.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, waitMethods inherited from interface org.sikuli.script.support.IScriptRunner
getExtensions, getName, getType
-
Constructor Details
-
AbstractScriptRunner
public AbstractScriptRunner()
-
-
Method Details
-
log
-
init
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
-
doInit
- Throws:
Exception
-
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
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
Description copied from interface:IScriptRunnerconvenience: return the first defined extension (default)- Specified by:
getDefaultExtensionin interfaceIScriptRunner- Returns:
- default extension
-
canHandle
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
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
-
runScript
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
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
-
evalScript
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
-
runLines
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
-
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
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
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
-
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
-