Class ScriptingModule

java.lang.Object
org.eclipse.ease.modules.AbstractScriptModule
org.eclipse.ease.modules.platform.ScriptingModule
All Implemented Interfaces:
IScriptModule

public class ScriptingModule
extends AbstractScriptModule
Commands to launch additional script engines.
  • Field Details

  • Constructor Details

    • ScriptingModule

      public ScriptingModule()
  • Method Details

    • 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
    • createScriptEngine

      public static IScriptEngine createScriptEngine​(String identifier)
      Create a new script engine instance.
      Parameters:
      identifier - engine ID, literal engine name or accepted file extension
      Returns:
      script engine instance (not started) or null
    • listScriptEngines

      public static String[] listScriptEngines()
      Retrieve a list of available script engines.
      Returns:
      array of engine IDs
    • fork

      public ScriptResult fork​(Object resource, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String arguments, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String engineIdOrExtension)
      Fork a new script engine and execute provided resource.
      Parameters:
      resource - resource to execute (path, URI or file instance)
      arguments - optional script arguments delimited by commas ','. When the string arguments contains commas ',', or for arguments that are not string, the caller may set a shared object with and pass the key here. The callee can then retrieve it with the method.
      engineIdOrExtension - engine ID to be used or a file extension to look for engines (eg: js)
      Returns:
      execution result
    • join

      public static boolean join​(IScriptEngine engine, @ScriptParameter(defaultValue="0") long timeout)
      Wait for a script engine to shut down. If timeout is set to 0 this method will wait endlessly.
      Parameters:
      engine - script engine to wait for
      timeout - time to wait for shutdown [ms]
      Returns:
      true when engine is shut down
    • executeSync

      public Object executeSync​(Object monitor, Object code) throws ExecutionException
      Run a code fragment in a synchronized block. Executes code within a synchronized block on the monitor object. The code object might be a String, File, IFile or any other object that can be adapted to IScriptable.
      Parameters:
      monitor - monitor to synchronize on
      code - code to run.
      Returns:
      execution result of executed code
      Throws:
      ExecutionException - when execution of code fails
    • wait

      public static void wait​(Object monitor, @ScriptParameter(defaultValue="0") long timeout) throws InterruptedException
      Causes the current thread to wait until either another thread invokes the Object.notify() method or the Object.notifyAll() method for this object, or a specified amount of time has elapsed. Calls the java method monitor.wait(timeout).
      Parameters:
      monitor - monitor to wait for
      timeout - max timeout (0 does not time out)
      Throws:
      InterruptedException - when wait gets interrupted
    • notify

      public static void notify​(Object monitor)
      Wakes up a single thread that is waiting on the monitor. Calls the java method monitor.notify().
      Parameters:
      monitor - monitor to notify
    • notifyAll

      public static void notifyAll​(Object monitor)
      Wakes up all threads that are waiting on the monitor. Calls the java method monitor.notifyAll().
      Parameters:
      monitor - monitor to notify
    • setSharedObject

      public void setSharedObject​(String key, Object object, @ScriptParameter(defaultValue="false") boolean permanent, @ScriptParameter(defaultValue="false") boolean writable) throws IllegalAccessException
      Add an object to the shared object store. The shared object store allows to share java instances between several script engines. By default objects are stored until the script engine providing it is terminated. This helps to avoid polluting the java heap. When permanent is set to true , this object will be stored forever.
      Parameters:
      key - key to store the object
      object - instance to store
      permanent - flag indicating permanent storage
      writable - flag indicating that any engine may write this value
      Throws:
      IllegalAccessException - when scriptEngine is not the owner of the shared object
    • getSharedObject

      public Object getSharedObject​(String key)
      Get an object from the shared object store.
      Parameters:
      key - key to retrieve object for
      Returns:
      shared object or null