Class PlatformModule

All Implemented Interfaces:
IScriptModule

public class PlatformModule extends ScriptingModule
Provides global platform functions like preferences, event bus or the command framework.
  • Field Details

  • Constructor Details

    • PlatformModule

      public PlatformModule()
  • Method Details

    • adapt

      public Object adapt(Object source, Class<?> target)
      Adapt object to target type. Try to get an adapter for an object.
      Parameters:
      source - object to adapt
      target - target class to adapt to
      Returns:
      adapted object or null
    • getService

      public Object getService(Class<?> type)
      Get a platform service.
      Parameters:
      type - service type
      Returns:
      service instance or null
    • executeCommand

      public void executeCommand(String commandId, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Map<String,String> parameters) throws org.eclipse.core.commands.ExecutionException, org.eclipse.core.commands.common.NotDefinedException, org.eclipse.core.commands.NotEnabledException, org.eclipse.core.commands.NotHandledException
      Execute a command from the command framework. As we have no UI available, we do not pass a control to the command. Hence HandlerUtil.getActive... commands will very likely fail.
      Parameters:
      commandId - full id of the command to execute
      parameters - command parameters
      Throws:
      org.eclipse.core.commands.ExecutionException - If the handler has problems executing this command.
      org.eclipse.core.commands.common.NotDefinedException - If the command you are trying to execute is not defined.
      org.eclipse.core.commands.NotEnabledException - If the command you are trying to execute is not enabled.
      org.eclipse.core.commands.NotHandledException - If there is no handler.
    • getSystemProperty

      public String getSystemProperty(String key)
      Get a system property or environment value. First we try to look up a system property. If not found we query the environment for the key.
      Parameters:
      key - key to query
      Returns:
      system property/environment variable for key
    • runProcess

      public Process runProcess(String name, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String[] args, @ScriptParameter(defaultValue="system.out") String output, @ScriptParameter(defaultValue="system.err") String error) throws IOException
      Run an external process. The process is started in the background and a Process object is returned. Query the result for finished state, output and error streams of the executed process. Output and error streams need to be consumed, otherwise the running process may stall (or even die) in case that the buffers are full. Setting parameters output and error to null will automatically discard the produced data.
      Parameters:
      name - program to run (with full path if necessary)
      args - program arguments
      output - output file location to redirect output to.
      • "system.out": use the default output of the application
      • null: discard output
      • "keep": do nothing, let the script deal with it
      • any other: file location to redirect to. Accepts absolute file paths and workspace urls (see )
      error - error stream to redirect output to.
      • "system.err": use the default output of the application
      • null: discard output
      • "keep": do nothing, let the script deal with it
      • any other: file location to redirect to. Accepts absolute file paths and workspace urls (see )
      Returns:
      process object to track process execution
      Throws:
      IOException - if an I/O error occurs
    • readPreferences

      public Object readPreferences(String node, String key, @ScriptParameter(defaultValue="") Object defaultValue)
      Read a preferences value. The defaultValue is optional, but contains type information if used. Provide instances of Boolean, Integer, Double, Float, Long, byte[], or String to get the appropriate return value of same type.
      Parameters:
      node - node to read from
      key - key name to read from
      defaultValue - default value to use, if value is not set
      Returns:
      preference value or null
    • writePreferences

      public void writePreferences(String node, String key, Object value) throws org.osgi.service.prefs.BackingStoreException
      Set a preferences value. Valid types for value are: Boolean, Integer, Double, Float, Long, byte[], and String.
      Parameters:
      node - node to write to
      key - key to store to
      value - value to store
      Throws:
      org.osgi.service.prefs.BackingStoreException - when preferences cannot be persisted
    • postEvent

      public void postEvent(String topic, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object data, @ScriptParameter(defaultValue="0") long delay)
      Post an event on the event broker. If delay is set, the event will be posted after the given amount of time asynchronously. In any case this method returns immediately.
      Parameters:
      topic - topic to post
      data - topic data
      delay - delay to post this even in [ms]
    • waitForEvent

      public org.osgi.service.event.Event waitForEvent(String topic, @ScriptParameter(defaultValue="0") long timeout) throws InterruptedException
      Wait for a given event on the event bus.
      Parameters:
      topic - topic to subscribe for
      timeout - maximum time to wait for event in [ms]. Use 0 to wait without timeout.
      Returns:
      posted event or null in case of a timeout
      Throws:
      InterruptedException - when the script thread gets interrupted