Class AbstractScriptEngine

java.lang.Object
org.eclipse.core.runtime.PlatformObject
org.eclipse.core.internal.jobs.InternalJob
org.eclipse.core.runtime.jobs.Job
org.eclipse.ease.AbstractScriptEngine
All Implemented Interfaces:
Comparable, org.eclipse.core.runtime.IAdaptable, IScriptEngine
Direct Known Subclasses:
AbstractReplScriptEngine, ArchiveEngine, JVMCompiledScriptEngine, TestSuiteScriptEngine

public abstract class AbstractScriptEngine
extends org.eclipse.core.runtime.jobs.Job
implements IScriptEngine
Base implementation for a script engine. Handles Job implementation of script engine, adding script code for execution, module loading support and a basic online help system.
  • Constructor Details

    • AbstractScriptEngine

      public AbstractScriptEngine​(String name)
      Constructor. Sets the name for the underlying job.
      Parameters:
      name - name of script engine job
  • Method Details

    • getCurrentScriptEngine

      public static IScriptEngine getCurrentScriptEngine()
      Get the current script engine. Works only if executed from the script engine thread.
      Returns:
      script engine or null
    • getDescription

      public EngineDescription getDescription()
      Description copied from interface: IScriptEngine
      Get engine description for current engine.
      Specified by:
      getDescription in interface IScriptEngine
      Returns:
      engine description
    • execute

      public final ScriptResult execute​(Object content)
      Description copied from interface: IScriptEngine
      Execute script code. The code provided will be scheduled and executed as soon as all previously scheduled code is executed. If content is a Reader object, or a File special treatment is done, otherwise the toString() method is used to extract script code. This is a non-blocking call.
      Specified by:
      execute in interface IScriptEngine
      Parameters:
      content - content to be executed.
      Returns:
      execution result
    • inject

      public Object inject​(Object content, boolean uiThread) throws ExecutionException
      Description copied from interface: IScriptEngine
      Inject script code and execute synchronously. Code passed to this method will be invoked immediately. It might interrupt a currently running execution requested asynchronously.
      Specified by:
      inject in interface IScriptEngine
      Parameters:
      content - content to be executed.
      uiThread - execute code in UI thread
      Returns:
      execution result
      Throws:
      ExecutionException - when code execution failed
    • terminate

      public void terminate()
      Description copied from interface: IScriptEngine
      Terminate this interpreter. Addresses a request to terminate current script execution. When the request will be handled is implementation specific.
      Specified by:
      terminate in interface IScriptEngine
    • checkForCancellation

      public void checkForCancellation()
      Check engine for cancellation request and terminate if indicated by the monitor.
    • isFinished

      public boolean isFinished()
      Description copied from interface: IScriptEngine
      Verify that engine was started and terminated.
      Specified by:
      isFinished in interface IScriptEngine
      Returns:
      true when engine ran and terminated
    • joinEngine

      public void joinEngine() throws InterruptedException
      Description copied from interface: IScriptEngine
      Join engine execution thread. Waits for engine termination.
      Specified by:
      joinEngine in interface IScriptEngine
      Throws:
      InterruptedException - when join command got interrupted
    • joinEngine

      public void joinEngine​(long timeout) throws InterruptedException
      Description copied from interface: IScriptEngine
      Join engine execution thread. Waits for engine execution up to timeout milliseconds.
      Specified by:
      joinEngine in interface IScriptEngine
      Parameters:
      timeout - command timeout in milliseconds
      Throws:
      InterruptedException - when join command got interrupted
    • getMonitor

      public org.eclipse.core.runtime.IProgressMonitor getMonitor()
      Description copied from interface: IScriptEngine
      Get the monitor of the current running engine. The monitor is only valid while the script engine is running.
      Specified by:
      getMonitor in interface IScriptEngine
      Returns:
      current monitor or null
    • setCloseStreamsOnTerminate

      public void setCloseStreamsOnTerminate​(boolean closeStreams)
      Description copied from interface: IScriptEngine
      Set marker to automatically close I/O streams when engine is terminated.
      Specified by:
      setCloseStreamsOnTerminate in interface IScriptEngine
      Parameters:
      closeStreams - true to close streams
    • getOutputStream

      public PrintStream getOutputStream()
      Specified by:
      getOutputStream in interface IScriptEngine
    • setOutputStream

      public void setOutputStream​(OutputStream outputStream)
      Description copied from interface: IScriptEngine
      Set the default output stream for the interpreter.
      Specified by:
      setOutputStream in interface IScriptEngine
      Parameters:
      outputStream - default output stream
    • getInputStream

      public InputStream getInputStream()
      Specified by:
      getInputStream in interface IScriptEngine
    • setInputStream

      public void setInputStream​(InputStream inputStream)
      Description copied from interface: IScriptEngine
      Set the default input stream for the interpreter.
      Specified by:
      setInputStream in interface IScriptEngine
      Parameters:
      inputStream - default input stream
    • getErrorStream

      public PrintStream getErrorStream()
      Specified by:
      getErrorStream in interface IScriptEngine
    • setErrorStream

      public void setErrorStream​(OutputStream errorStream)
      Description copied from interface: IScriptEngine
      Set the default error stream for the interpreter.
      Specified by:
      setErrorStream in interface IScriptEngine
      Parameters:
      errorStream - default error stream
    • addExecutionListener

      public void addExecutionListener​(IExecutionListener listener)
      Specified by:
      addExecutionListener in interface IScriptEngine
    • removeExecutionListener

      public void removeExecutionListener​(IExecutionListener listener)
      Specified by:
      removeExecutionListener in interface IScriptEngine
    • getStackTrace

      public ScriptStackTrace getStackTrace()
    • getExecutedFile

      public Object getExecutedFile()
      Description copied from interface: IScriptEngine
      Get the currently executed file instance.
      Specified by:
      getExecutedFile in interface IScriptEngine
      Returns:
      currently executed file
    • setExecutionRootFile

      public void setExecutionRootFile​(Object executionRootFile)
    • setEngineDescription

      public void setEngineDescription​(EngineDescription description)
    • setVariable

      public void setVariable​(String name, Object content)
      Description copied from interface: IScriptEngine
      Set a variable in the script engine. This variable will be stored in the global script scope
      Specified by:
      setVariable in interface IScriptEngine
      Parameters:
      name - variable name
      content - variable content
    • getVariable

      public Object getVariable​(String name)
      Description copied from interface: IScriptEngine
      Get a script variable. Retrieve a variable from the global script scope.
      Specified by:
      getVariable in interface IScriptEngine
      Parameters:
      name - variable name
      Returns:
      variable content or null
    • hasVariable

      public boolean hasVariable​(String name)
      Description copied from interface: IScriptEngine
      Check if a variable exists within the scope of the engine. As a variable content may be null, IScriptEngine.getVariable(String) might not be sufficient to query.
      Specified by:
      hasVariable in interface IScriptEngine
      Parameters:
      name - variable name
      Returns:
      true when variable exists
    • getVariables

      public Map<String,​Object> getVariables()
      Description copied from interface: IScriptEngine
      Get all variables from the scope.
      Specified by:
      getVariables in interface IScriptEngine
      Returns:
      map of variables
    • extractArguments

      public static final String[] extractArguments​(String arguments)
      Split a string with comma separated arguments.
      Parameters:
      arguments - comma separated arguments
      Returns:
      trimmed list of arguments
    • addSecurityCheck

      public void addSecurityCheck​(ISecurityCheck.ActionType type, ISecurityCheck check)
      Description copied from interface: IScriptEngine
      Add a dedicated security check for a certain script action. If the check was already registered for this action, no further check will be added.
      Specified by:
      addSecurityCheck in interface IScriptEngine
      Parameters:
      type - action type to add check for
      check - check to register
    • removeSecurityCheck

      public void removeSecurityCheck​(ISecurityCheck check)
      Description copied from interface: IScriptEngine
      Remove registered security check for all actions. If the check was not registered at all nothing will happen.
      Specified by:
      removeSecurityCheck in interface IScriptEngine
      Parameters:
      check - check to be removed
    • setLaunch

      public void setLaunch​(org.eclipse.debug.core.ILaunch launch)
    • getLaunch

      public org.eclipse.debug.core.ILaunch getLaunch()
      Description copied from interface: IScriptEngine
      Get the launch that was used to create this engine.
      Specified by:
      getLaunch in interface IScriptEngine
      Returns:
      launch or null in case this engine was created without launch configuration