Package org.eclipse.ease
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.
-
Field Summary
Fields inherited from class org.eclipse.core.runtime.jobs.Job
ASYNC_FINISH, BUILD, DECORATE, INTERACTIVE, LONG, NONE, RUNNING, SHORT, SLEEPING, WAITING
Fields inherited from interface org.eclipse.ease.IScriptEngine
TRACE_SCRIPT_ENGINE
-
Constructor Summary
Constructors Constructor Description AbstractScriptEngine(String name)
Constructor. -
Method Summary
Modifier and Type Method Description void
addExecutionListener(IExecutionListener listener)
void
addSecurityCheck(ISecurityCheck.ActionType type, ISecurityCheck check)
Add a dedicated security check for a certain script action.ScriptResult
execute(Object content)
Execute script code.static IScriptEngine
getCurrentScriptEngine()
Get the current script engine.EngineDescription
getDescription()
Get engine description for current engine.PrintStream
getErrorStream()
Object
getExecutedFile()
Get the currently executed file instance.InputStream
getInputStream()
org.eclipse.debug.core.ILaunch
getLaunch()
Get the launch that was used to create this engine.org.eclipse.core.runtime.IProgressMonitor
getMonitor()
Get the monitor of the current running engine.PrintStream
getOutputStream()
ScriptStackTrace
getStackTrace()
Object
getVariable(String name)
Get a script variable.Map<String,Object>
getVariables()
Get all variables from the scope.boolean
hasVariable(String name)
Check if a variable exists within the scope of the engine.Object
inject(Object content, boolean uiThread)
Inject script code and execute synchronously.boolean
isFinished()
Verify that engine was started and terminated.void
joinEngine()
Join engine execution thread.void
joinEngine(long timeout)
Join engine execution thread.void
removeExecutionListener(IExecutionListener listener)
void
setCloseStreamsOnTerminate(boolean closeStreams)
Set marker to automatically close I/O streams when engine is terminated.void
setEngineDescription(EngineDescription description)
void
setErrorStream(OutputStream errorStream)
Set the default error stream for the interpreter.void
setExecutionRootFile(Object executionRootFile)
void
setInputStream(InputStream inputStream)
Set the default input stream for the interpreter.void
setLaunch(org.eclipse.debug.core.ILaunch launch)
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()
Terminate this interpreter.Methods inherited from class org.eclipse.core.runtime.jobs.Job
addJobChangeListener, belongsTo, cancel, create, create, createSystem, createSystem, done, getJobGroup, getJobManager, getName, getPriority, getProperty, getResult, getRule, getState, getThread, isBlocking, isSystem, isUser, join, join, removeJobChangeListener, schedule, schedule, setJobGroup, setName, setPriority, setProgressGroup, setProperty, setRule, setSystem, setThread, setUser, shouldRun, shouldSchedule, sleep, toString, wakeUp, wakeUp, yieldRule
Methods inherited from class org.eclipse.core.internal.jobs.InternalJob
compareTo
Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapter
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.ease.IScriptEngine
getName, registerJar, schedule, terminateCurrent
-
Constructor Details
-
AbstractScriptEngine
Constructor. Sets the name for the underlying job.- Parameters:
name
- name of script engine job
-
-
Method Details
-
getCurrentScriptEngine
Get the current script engine. Works only if executed from the script engine thread.- Returns:
- script engine or
null
-
getDescription
Description copied from interface:IScriptEngine
Get engine description for current engine.- Specified by:
getDescription
in interfaceIScriptEngine
- Returns:
- engine description
-
execute
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 aReader
object, or aFile
special treatment is done, otherwise the toString() method is used to extract script code. This is a non-blocking call.- Specified by:
execute
in interfaceIScriptEngine
- Parameters:
content
- content to be executed.- Returns:
- execution result
-
inject
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 interfaceIScriptEngine
- 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 interfaceIScriptEngine
-
isFinished
public boolean isFinished()Description copied from interface:IScriptEngine
Verify that engine was started and terminated.- Specified by:
isFinished
in interfaceIScriptEngine
- Returns:
true
when engine ran and terminated
-
joinEngine
Description copied from interface:IScriptEngine
Join engine execution thread. Waits for engine termination.- Specified by:
joinEngine
in interfaceIScriptEngine
- Throws:
InterruptedException
- when join command got interrupted
-
joinEngine
Description copied from interface:IScriptEngine
Join engine execution thread. Waits for engine execution up to timeout milliseconds.- Specified by:
joinEngine
in interfaceIScriptEngine
- 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 interfaceIScriptEngine
- 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 interfaceIScriptEngine
- Parameters:
closeStreams
-true
to close streams
-
getOutputStream
- Specified by:
getOutputStream
in interfaceIScriptEngine
-
setOutputStream
Description copied from interface:IScriptEngine
Set the default output stream for the interpreter.- Specified by:
setOutputStream
in interfaceIScriptEngine
- Parameters:
outputStream
- default output stream
-
getInputStream
- Specified by:
getInputStream
in interfaceIScriptEngine
-
setInputStream
Description copied from interface:IScriptEngine
Set the default input stream for the interpreter.- Specified by:
setInputStream
in interfaceIScriptEngine
- Parameters:
inputStream
- default input stream
-
getErrorStream
- Specified by:
getErrorStream
in interfaceIScriptEngine
-
setErrorStream
Description copied from interface:IScriptEngine
Set the default error stream for the interpreter.- Specified by:
setErrorStream
in interfaceIScriptEngine
- Parameters:
errorStream
- default error stream
-
addExecutionListener
- Specified by:
addExecutionListener
in interfaceIScriptEngine
-
removeExecutionListener
- Specified by:
removeExecutionListener
in interfaceIScriptEngine
-
getStackTrace
-
getExecutedFile
Description copied from interface:IScriptEngine
Get the currently executed file instance.- Specified by:
getExecutedFile
in interfaceIScriptEngine
- Returns:
- currently executed file
-
setExecutionRootFile
-
setEngineDescription
-
setVariable
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 interfaceIScriptEngine
- Parameters:
name
- variable namecontent
- variable content
-
getVariable
Description copied from interface:IScriptEngine
Get a script variable. Retrieve a variable from the global script scope.- Specified by:
getVariable
in interfaceIScriptEngine
- Parameters:
name
- variable name- Returns:
- variable content or
null
-
hasVariable
Description copied from interface:IScriptEngine
Check if a variable exists within the scope of the engine. As a variable content may benull
,IScriptEngine.getVariable(String)
might not be sufficient to query.- Specified by:
hasVariable
in interfaceIScriptEngine
- Parameters:
name
- variable name- Returns:
true
when variable exists
-
getVariables
Description copied from interface:IScriptEngine
Get all variables from the scope.- Specified by:
getVariables
in interfaceIScriptEngine
- Returns:
- map of variables
-
addSecurityCheck
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 interfaceIScriptEngine
- Parameters:
type
- action type to add check forcheck
- check to register
-
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 interfaceIScriptEngine
- Returns:
- launch or
null
in case this engine was created without launch configuration
-