Class AbstractScriptRunner

    • Constructor Detail

      • AbstractScriptRunner

        public AbstractScriptRunner()
    • Method Detail

      • log

        protected void log​(int level,
                           String message,
                           Object... args)
      • init

        public final void init​(String[] args)
                        throws SikuliXception
        Description copied from interface: IScriptRunner
        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.
        Specified by:
        init in interface IScriptRunner
        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: IScriptRunner
        Checks if the current platform supports this runner.
        Specified by:
        isSupported in interface IScriptRunner
        Returns:
        true if platform supports this runner, false otherwise
      • hasExtension

        public final boolean hasExtension​(String ending)
        Description copied from interface: IScriptRunner
        checks whether this ScriptRunner supports the given file extension
        Specified by:
        hasExtension in interface IScriptRunner
        Returns:
        true if the runner has the given extension, false otherwise
      • getDefaultExtension

        public String getDefaultExtension()
        Description copied from interface: IScriptRunner
        convenience: return the first defined extension (default)
        Specified by:
        getDefaultExtension in interface IScriptRunner
        Returns:
        default extension
      • canHandle

        public boolean canHandle​(String identifier)
        Description copied from interface: IScriptRunner
        Checks if this runner can handle the given identifier.
        Specified by:
        canHandle in interface IScriptRunner
        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: IScriptRunner
        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.

        Specified by:
        redirect in interface IScriptRunner
        Parameters:
        stdout - PrintStream for STDOUT
        stderr - PrintStream for STDERR
      • runScript

        public final int runScript​(String script,
                                   String[] scriptArgs,
                                   IScriptRunner.Options maybeOptions)
        Description copied from interface: IScriptRunner
        Executes the Script.
        Specified by:
        runScript in interface IScriptRunner
        Parameters:
        script - Identifier pointing to the script. This can either by a file path or an URI, depending on the runner implementation
        scriptArgs - Arguments to be passed directly to the script with --args
        maybeOptions - Implementation specific options.
        Returns:
        exitcode for the script execution
      • evalScript

        public final int evalScript​(String script,
                                    IScriptRunner.Options maybeOptions)
        Description copied from interface: IScriptRunner
        Evaluates the Script.
        Specified by:
        evalScript in interface IScriptRunner
        Parameters:
        script - Script content
        maybeOptions - Implementation specific options.
        Returns:
        exitcode for the script execution
      • runLines

        public final void runLines​(String lines,
                                   IScriptRunner.Options maybeOptions)
        Description copied from interface: IScriptRunner
        Run the given script lines. The implementation might perform some optimizations on the code (e.g. fix indentation) before executing it.
        Specified by:
        runLines in interface IScriptRunner
        Parameters:
        lines - Code do execute
        maybeOptions - Implementation specific options.
      • close

        public final void close()
        Description copied from interface: IScriptRunner
        Is executed before Sikuli closes. Can be used to cleanup the ScriptRunner
        Specified by:
        close in interface IScriptRunner
      • doClose

        protected void doClose()
      • reset

        public final void reset()
        Description copied from interface: IScriptRunner
        Resets this runner.

        The runner gets closed and initialized again using init.

        Specified by:
        reset in interface IScriptRunner
      • execBefore

        public void execBefore​(String[] stmts)
        Description copied from interface: IScriptRunner
        add statements to be run after SCRIPT_HEADER, but before script is executed
        Specified by:
        execBefore in interface IScriptRunner
        Parameters:
        stmts - string array of statements (null resets the statement buffer)
      • execAfter

        public void execAfter​(String[] stmts)
        Description copied from interface: IScriptRunner
        add statements to be run after script has ended
        Specified by:
        execAfter in interface IScriptRunner
        Parameters:
        stmts - string array of statements (null resets the statement buffer)
      • isRunning

        public final boolean isRunning()
        Specified by:
        isRunning in interface IScriptRunner
        Returns:
        true if the runner is currently executing a script, false otherwise
      • isAbortSupported

        public boolean isAbortSupported()
        Description copied from interface: IScriptRunner
        Checks if abort is supported by this script runner implementation.
        Specified by:
        isAbortSupported in interface IScriptRunner
        Returns:
        true is abort is supported, false otherwise
      • abort

        public final void abort()
        Description copied from interface: IScriptRunner
        Aborts the current running script.

        Not all runners can be aborted, please check abort support using isAbortSupported().

        Specified by:
        abort in interface IScriptRunner
      • 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: IScriptRunner
        Checks if the currently running script has been aborted.
        Specified by:
        isAborted in interface IScriptRunner
        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: IScriptRunner
        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.

        Specified by:
        getFileEndings in interface IScriptRunner
        Returns:
        An Array containing the supported line endings