Class PlatformModule

java.lang.Object
org.eclipse.ease.modules.platform.PlatformModule

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

  • Constructor Details

    • PlatformModule

      public PlatformModule()
  • Method Details

    • adapt

      public static 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 static Object getService​(Class<?> type)
      Get a platform service.
      Parameters:
      type - service type
      Returns:
      service instance or null
    • executeCommand

      public static 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 static 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 static 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
      • "keep": do nothing, let the script deal with it
      • any other: absolute file location to redirect to
      error - error stream to redirect output to.
      • "system.err": use the default output of the application
      • "keep": do nothing, let the script deal with it
      • any other: absolute file location to redirect to
      Returns:
      process object to track process execution
      Throws:
      IOException - if an I/O error occurs
    • readPreferences

      public static 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 static void writePreferences​(String node, String key, Object value)
      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
    • postEvent

      public static 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 static 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