Package org.eclipse.ease
Interface IScriptEngine
- All Known Subinterfaces:
IDebugEngine
,IPythonDebugEngine
,IReplEngine
- All Known Implementing Classes:
AbstractReplScriptEngine
,AbstractScriptEngine
,ArchiveEngine
,JVMCompiledScriptEngine
,JythonScriptEngine
,NashornScriptEngine
,Py4jDebuggerEngine
,Py4jScriptEngine
,RhinoScriptEngine
,TestSuiteScriptEngine
public interface IScriptEngine
Interface for a script engine. A script engine is capable of interpreting script code at runtime. Script engines shall be derived from
Thread
and
therefore run separately from other code. An engine shall be started by calling schedule()
.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final boolean
Trace enablement for script engines. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExecutionListener
(IExecutionListener listener) void
addSecurityCheck
(ISecurityCheck.ActionType type, ISecurityCheck check) Add a dedicated security check for a certain script action.Execute script code.Get engine description for current engine.Get the currently executed file instance.org.eclipse.debug.core.ILaunch
Get the launch that was used to create this engine.getName()
Get the engine name.getVariable
(String name) Get a script variable.Get all variables from the scope.boolean
hasVariable
(String name) Check if a variable exists within the scope of the engine.Inject script code and execute synchronously.boolean
Verify that engine was started and terminated.void
Join engine execution thread.void
joinEngine
(long timeout) Join engine execution thread.void
registerJar
(URL url) Register a jar file and add it to the classpath.void
removeExecutionListener
(IExecutionListener listener) void
schedule()
Schedule script execution.void
setCloseStreamsOnTerminate
(boolean closeStreams) Set marker to automatically close I/O streams when engine is terminated.void
setErrorStream
(OutputStream errorStream) Set the default error stream for the interpreter.void
setInputStream
(InputStream inputStream) Set the default input stream for the interpreter.void
setOutputStream
(OutputStream outputStream) Set the default output stream for the interpreter.void
setVariable
(String name, Object content) Set a variable in the script engine.void
Terminate this interpreter.void
Stops the currently executed piece of code.
-
Field Details
-
TRACE_SCRIPT_ENGINE
static final boolean TRACE_SCRIPT_ENGINETrace enablement for script engines.
-
-
Method Details
-
execute
Execute script code. The code provided will be scheduled and executed as soon as all previously scheduled code is executed. If content is aReader
object, or aFile
special treatment is done, otherwise the toString() method is used to extract script code. This is a non-blocking call.- Parameters:
content
- content to be executed.- Returns:
- execution result
-
inject
Inject script code and execute synchronously. Code passed to this method will be invoked immediately. It might interrupt a currently running execution requested asynchronously.- Parameters:
content
- content to be executed.uiThread
- execute code in UI thread- Returns:
- execution result
- Throws:
ExecutionException
- when code execution failed
-
getExecutedFile
Object getExecutedFile()Get the currently executed file instance.- Returns:
- currently executed file
-
setOutputStream
Set the default output stream for the interpreter.- Parameters:
outputStream
- default output stream
-
setErrorStream
Set the default error stream for the interpreter.- Parameters:
errorStream
- default error stream
-
setInputStream
Set the default input stream for the interpreter.- Parameters:
inputStream
- default input stream
-
getOutputStream
PrintStream getOutputStream() -
getErrorStream
PrintStream getErrorStream() -
getInputStream
InputStream getInputStream() -
setCloseStreamsOnTerminate
void setCloseStreamsOnTerminate(boolean closeStreams) Set marker to automatically close I/O streams when engine is terminated.- Parameters:
closeStreams
-true
to close streams
-
schedule
void schedule()Schedule script execution. This will start the script engine that either waits for input or immediate starts execution of previously scheduled input. -
terminate
void terminate()Terminate this interpreter. Addresses a request to terminate current script execution. When the request will be handled is implementation specific. -
terminateCurrent
void terminateCurrent()Stops the currently executed piece of code. Will continue to execute the next scheduled piece of code. -
addExecutionListener
-
removeExecutionListener
-
getName
String getName()Get the engine name.- Returns:
- engine name
-
setVariable
Set a variable in the script engine. This variable will be stored in the global script scope- Parameters:
name
- variable namecontent
- variable content
-
getVariable
Get a script variable. Retrieve a variable from the global script scope.- Parameters:
name
- variable name- Returns:
- variable content or
null
-
hasVariable
Check if a variable exists within the scope of the engine. As a variable content may benull
,getVariable(String)
might not be sufficient to query.- Parameters:
name
- variable name- Returns:
true
when variable exists
-
getDescription
EngineDescription getDescription()Get engine description for current engine.- Returns:
- engine description
-
getVariables
Get all variables from the scope.- Returns:
- map of variables
-
registerJar
Register a jar file and add it to the classpath. After registering, classes within the jar file shall be usable within the script.- Parameters:
url
- url to load jar file from
-
joinEngine
Join engine execution thread. Waits for engine execution up to timeout milliseconds.- Parameters:
timeout
- command timeout in milliseconds- Throws:
InterruptedException
- when join command got interrupted
-
joinEngine
Join engine execution thread. Waits for engine termination.- Throws:
InterruptedException
- when join command got interrupted
-
isFinished
boolean isFinished()Verify that engine was started and terminated.- Returns:
true
when engine ran and terminated
-
addSecurityCheck
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.- Parameters:
type
- action type to add check forcheck
- check to register
-
getLaunch
org.eclipse.debug.core.ILaunch getLaunch()Get the launch that was used to create this engine.- Returns:
- launch or
null
in case this engine was created without launch configuration
-