Class PlatformModule
java.lang.Object
org.eclipse.ease.modules.AbstractScriptModule
org.eclipse.ease.modules.platform.ScriptingModule
org.eclipse.ease.modules.platform.PlatformModule
- All Implemented Interfaces:
IScriptModule
Provides global platform functions like preferences, event bus or the command framework.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdapt object to target type.void
executeCommand
(String commandId, Map<String, String> parameters) Execute a command from the command framework.getService
(Class<?> type) Get a platform service.getSystemProperty
(String key) Get a system property or environment value.void
Post an event on the event broker.readPreferences
(String node, String key, Object defaultValue) Read a preferences value.runProcess
(String name, String[] args, String output, String error) Run an external process.org.osgi.service.event.Event
waitForEvent
(String topic, long timeout) Wait for a given event on the event bus.void
writePreferences
(String node, String key, Object value) Set a preferences value.Methods inherited from class org.eclipse.ease.modules.platform.ScriptingModule
createScriptEngine, executeSync, extractArguments, fork, getSharedObject, join, listScriptEngines, notify, notifyAll, setSharedObject, wait
Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule
initialize
-
Field Details
-
MODULE_ID
Module identifier.- See Also:
-
-
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 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 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 aProcess
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 tonull
will 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
- 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 fromkey
- key name to read fromdefaultValue
- 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 tokey
- key to store tovalue
- 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 postdata
- topic datadelay
- 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 fortimeout
- 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
-