Package org.sikuli.script.support
Interface IScriptRunner
-
- All Known Implementing Classes:
AbstractLocalFileScriptRunner,AbstractScriptRunner,AppleScriptRunner,InvalidRunner,JarExeRunner,JarRunner,JRubyRunner,JythonRunner,NetworkRunner,PowershellRunner,ProcessRunner,PythonRunner,RobotRunner,ServerRunner,SikulixRunner,SilkulixGitTestRunner,SKLRunner,TextRunner,ZipRunner
public interface IScriptRunnerInterface for ScriptRunners like Jython.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classIScriptRunner.EffectiveRunnerstatic classIScriptRunner.OptionsSpecial options to pass to the runner.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidabort()Aborts the current running script.booleancanHandle(String identifier)Checks if this runner can handle the given identifier.voidclose()Is executed before Sikuli closes.intevalScript(String script, IScriptRunner.Options options)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[]getExtensions()returns the list of possible script file extensions, first is the defaultString[]getFileEndings()Usually the same as getExtensions() but with the leading dot.StringgetName()Gets the name of the ScriptRunner.StringgetType()return the type of script this handler can execute.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.booleanisRunning()booleanisSupported()Checks if the current platform supports this runner.voidredirect(PrintStream stdout, PrintStream stderr)Redirects the runner's STDIO to the given PrintStream.voidreset()Resets this runner.voidrunLines(String lines, IScriptRunner.Options options)Run the given script lines.intrunScript(String scriptFile, String[] scriptArgs, IScriptRunner.Options options)Executes the Script.
-
-
-
Method Detail
-
init
void init(String[] args) throws SikuliXception
Can 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.- Parameters:
args- All arguments that were passed to the main-method- Throws:
SikuliXception
-
runScript
int runScript(String scriptFile, String[] scriptArgs, IScriptRunner.Options options)
Executes the Script.- Parameters:
scriptFile- 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 --argsoptions- Implementation specific options.- Returns:
- exitcode for the script execution
-
evalScript
int evalScript(String script, IScriptRunner.Options options)
Evaluates the Script.- Parameters:
script- Script contentoptions- Implementation specific options.- Returns:
- exitcode for the script execution
-
runLines
void runLines(String lines, IScriptRunner.Options options)
Run the given script lines. The implementation might perform some optimizations on the code (e.g. fix indentation) before executing it.- Parameters:
lines- Code do executeoptions- Implementation specific options.
-
isSupported
boolean isSupported()
Checks if the current platform supports this runner.- Returns:
- true if platform supports this runner, false otherwise
-
getName
String getName()
Gets the name of the ScriptRunner. Should be unique. This value is needed to distinguish between different ScriptRunners.- Returns:
- Name to identify the ScriptRunner or null if not available
-
getExtensions
String[] getExtensions()
returns the list of possible script file extensions, first is the default- Returns:
- array of strings
-
getDefaultExtension
String getDefaultExtension()
convenience: return the first defined extension (default)- Returns:
- default extension
-
getType
String getType()
return the type of script this handler can execute.- Returns:
-
hasExtension
boolean hasExtension(String ending)
checks whether this ScriptRunner supports the given file extension- Returns:
- true if the runner has the given extension, false otherwise
-
close
void close()
Is executed before Sikuli closes. Can be used to cleanup the ScriptRunner
-
execBefore
void execBefore(String[] stmts)
add statements to be run after SCRIPT_HEADER, but before script is executed- Parameters:
stmts- string array of statements (null resets the statement buffer)
-
execAfter
void execAfter(String[] stmts)
add statements to be run after script has ended- Parameters:
stmts- string array of statements (null resets the statement buffer)
-
canHandle
boolean canHandle(String identifier)
Checks if this runner can handle the given identifier.- 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
-
getEffectiveRunner
IScriptRunner.EffectiveRunner getEffectiveRunner(String script)
Needed in the IDE to detect the runner when file or folder is opened- Parameters:
script-- Returns:
- array: EffectiveRunner object
-
redirect
void redirect(PrintStream stdout, PrintStream stderr)
Redirects 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.
- Parameters:
stdout- PrintStream for STDOUTstderr- PrintStream for STDERR
-
reset
void reset()
Resets this runner.The runner gets closed and initialized again using init.
-
isRunning
boolean isRunning()
- Returns:
- true if the runner is currently executing a script, false otherwise
-
abort
void abort()
Aborts the current running script.Not all runners can be aborted, please check abort support using isAbortSupported().
-
isAborted
boolean isAborted()
Checks if the currently running script has been aborted.- Returns:
- true if the currently running script has been aborted, false otherwise.
-
isAbortSupported
boolean isAbortSupported()
Checks if abort is supported by this script runner implementation.- Returns:
- true is abort is supported, false otherwise
-
getFileEndings
String[] getFileEndings()
Usually 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.
- Returns:
- An Array containing the supported line endings
-
-