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 Summary
-
Constructor Summary
Constructors Constructor Description PlatformModule() -
Method Summary
Modifier and Type Method Description static Objectadapt(Object source, Class<?> target)Adapt object to target type.static voidexecuteCommand(String commandId, Map<String,String> parameters)Execute a command from the command framework.static ObjectgetService(Class<?> type)Get a platform service.static StringgetSystemProperty(String key)Get a system property or environment value.static voidpostEvent(String topic, Object data, long delay)Post an event on the event broker.static ObjectreadPreferences(String node, String key, Object defaultValue)Read a preferences value.static ProcessrunProcess(String name, String[] args, String output, String error)Run an external process.static org.osgi.service.event.EventwaitForEvent(String topic, long timeout)Wait for a given event on the event bus.static voidwritePreferences(String node, String key, Object value)Set a preferences value.
-
Field Details
-
MODULE_ID
Module identifier.- See Also:
- Constant Field Values
-
-
Constructor Details
-
PlatformModule
public PlatformModule()
-
-
Method Details
-
adapt
Adapt object to target type. Try to get an adapter for an object.- Parameters:
source- object to adapttarget- target class to adapt to- Returns:
- adapted object or
null
-
getService
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.NotHandledExceptionExecute 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 executeparameters- 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
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 IOExceptionRun an external process. The process is started in the background and aProcessobject 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 tonullwill automatically discard the produced data.- Parameters:
name- program to run (with full path if necessary)args- program argumentsoutput- 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 fromkey- key name to read fromdefaultValue- default value to use, if value is not set- Returns:
- preference value or
null
-
writePreferences
Set a preferences value. Valid types for value are: Boolean, Integer, Double, Float, Long, byte[], and String.- Parameters:
node- node to write tokey- key to store tovalue- 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 postdata- topic datadelay- delay to post this even in [ms]
-
waitForEvent
public static org.osgi.service.event.Event waitForEvent(String topic, @ScriptParameter(defaultValue="0") long timeout) throws InterruptedExceptionWait for a given event on the event bus.- Parameters:
topic- topic to subscribe fortimeout- maximum time to wait for event in [ms]. Use 0 to wait without timeout.- Returns:
- posted event or
nullin case of a timeout - Throws:
InterruptedException- when the script thread gets interrupted
-