Package org.scijava.script
Interface ScriptService
-
- All Superinterfaces:
Comparable<Prioritized>,Contextual,Disposable,HasPluginInfo,Identifiable,Initializable,Locatable,Logged,Prioritized,PTService<ScriptLanguage>,RichPlugin,SciJavaPlugin,SciJavaService,Service,SingletonService<ScriptLanguage>,Versioned
- All Known Implementing Classes:
DefaultScriptService
public interface ScriptService extends SingletonService<ScriptLanguage>, SciJavaService
Interface for service that works with scripts. This service discovers available scripts, and provides convenience methods to interact with them.- Author:
- Johannes Schindelin, Curtis Rueden
-
-
Field Summary
Fields Modifier and Type Field Description static StringSCRIPTS_PATH_PROPERTYSystem property for overriding the list of directories to scan for scripts.static StringSCRIPTS_RESOURCE_DIRBase directory for discovering scripts, including within classpath resources as well as beneath the application base directory.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidaddAlias(Class<?> type)TODOvoidaddAlias(String alias, Class<?> type)TODOvoidaddScriptDirectory(File scriptDirectory)Adds a base directory to scan for scripts.voidaddScriptDirectory(File scriptDirectory, MenuPath menuPrefix)Adds a base directory to scan for scripts, placing discovered scripts beneath the given menu path prefix.default booleancanHandleFile(File file)TODOdefault booleancanHandleFile(String fileName)TODOMap<String,Class<?>>getAliases()TODOScriptLanguageIndexgetIndex()Gets the index of available scripting languages.default ScriptLanguagegetLanguageByExtension(String extension)Gets the scripting language that handles the given file extension.default ScriptLanguagegetLanguageByName(String name)Gets the scripting language with the given name.default List<ScriptLanguage>getLanguages()Gets the available scripting languages.MenuPathgetMenuPrefix(File scriptDirectory)Gets the menu path prefix for the given script directory, or null if none.default Class<ScriptLanguage>getPluginType()Gets the type of plugins managed by this service.ScriptInfogetScript(File scriptFile)Gets the cachedScriptInfometadata for the script at the given file, creating it if it does not already exist.List<File>getScriptDirectories()Gets the base directories to scan for scripts.Collection<ScriptInfo>getScripts()Gets all available scripts.Class<?>lookupClass(String typeName)TODOvoidremoveScriptDirectory(File scriptDirectory)Removes a base directory to scan for scripts.Future<ScriptModule>run(File file, boolean process, Object... inputs)Executes the script in the given file.Future<ScriptModule>run(File file, boolean process, Map<String,Object> inputMap)Executes the script in the given file.default Future<ScriptModule>run(String path, Reader reader, boolean process, Object... inputs)Executes the given script.default Future<ScriptModule>run(String path, Reader reader, boolean process, Map<String,Object> inputMap)Executes the given script.default Future<ScriptModule>run(String path, String script, boolean process, Object... inputs)Executes the given script.default Future<ScriptModule>run(String path, String script, boolean process, Map<String,Object> inputMap)Executes the given script.Future<ScriptModule>run(ScriptInfo info, boolean process, Object... inputs)Executes the given script.Future<ScriptModule>run(ScriptInfo info, boolean process, Map<String,Object> inputMap)Executes the given script.-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
Methods inherited from interface org.scijava.Disposable
dispose
-
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
-
Methods inherited from interface org.scijava.Locatable
getLocation
-
Methods inherited from interface org.scijava.Prioritized
compareTo, getPriority, setPriority
-
Methods inherited from interface org.scijava.plugin.PTService
getPlugins, getPluginService, pluginService
-
Methods inherited from interface org.scijava.plugin.RichPlugin
getIdentifier, log
-
Methods inherited from interface org.scijava.service.Service
registerEventHandlers
-
Methods inherited from interface org.scijava.plugin.SingletonService
create, filterInstances, getInstance, getInstances, initialize, objectService
-
Methods inherited from interface org.scijava.Versioned
getVersion
-
-
-
-
Field Detail
-
SCRIPTS_PATH_PROPERTY
static final String SCRIPTS_PATH_PROPERTY
System property for overriding the list of directories to scan for scripts.- See Also:
getScriptDirectories(), Constant Field Values
-
SCRIPTS_RESOURCE_DIR
static final String SCRIPTS_RESOURCE_DIR
Base directory for discovering scripts, including within classpath resources as well as beneath the application base directory.- See Also:
- Constant Field Values
-
-
Method Detail
-
getIndex
ScriptLanguageIndex getIndex()
Gets the index of available scripting languages.
-
getLanguages
default List<ScriptLanguage> getLanguages()
Gets the available scripting languages.This method does the same thing as
SingletonService.getInstances().
-
getLanguageByExtension
default ScriptLanguage getLanguageByExtension(String extension)
Gets the scripting language that handles the given file extension.
-
getLanguageByName
default ScriptLanguage getLanguageByName(String name)
Gets the scripting language with the given name.
-
getScriptDirectories
List<File> getScriptDirectories()
Gets the base directories to scan for scripts.
-
getMenuPrefix
MenuPath getMenuPrefix(File scriptDirectory)
Gets the menu path prefix for the given script directory, or null if none.
-
addScriptDirectory
void addScriptDirectory(File scriptDirectory)
Adds a base directory to scan for scripts.
-
addScriptDirectory
void addScriptDirectory(File scriptDirectory, MenuPath menuPrefix)
Adds a base directory to scan for scripts, placing discovered scripts beneath the given menu path prefix.
-
removeScriptDirectory
void removeScriptDirectory(File scriptDirectory)
Removes a base directory to scan for scripts.
-
getScripts
Collection<ScriptInfo> getScripts()
Gets all available scripts.
-
getScript
ScriptInfo getScript(File scriptFile)
Gets the cachedScriptInfometadata for the script at the given file, creating it if it does not already exist.
-
run
Future<ScriptModule> run(File file, boolean process, Object... inputs) throws FileNotFoundException, ScriptException
Executes the script in the given file.- Parameters:
file- File containing the script to execute.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the plugin, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.- Throws:
FileNotFoundExceptionScriptException
-
run
Future<ScriptModule> run(File file, boolean process, Map<String,Object> inputMap) throws FileNotFoundException, ScriptException
Executes the script in the given file.- Parameters:
file- File containing the script to execute.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputMap- Table of input parameter values, with keys matching the plugin's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.- Throws:
FileNotFoundExceptionScriptException
-
run
default Future<ScriptModule> run(String path, String script, boolean process, Object... inputs)
Executes the given script.- Parameters:
path- Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.script- The script itself to execute.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the plugin, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
default Future<ScriptModule> run(String path, String script, boolean process, Map<String,Object> inputMap)
Executes the given script.- Parameters:
path- Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.script- The script itself to execute.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputMap- Table of input parameter values, with keys matching the plugin's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
default Future<ScriptModule> run(String path, Reader reader, boolean process, Object... inputs)
Executes the given script.- Parameters:
path- Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.reader- A stream providing the script contents.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the plugin, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
default Future<ScriptModule> run(String path, Reader reader, boolean process, Map<String,Object> inputMap)
Executes the given script.- Parameters:
path- Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.reader- A stream providing the script contents.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputMap- Table of input parameter values, with keys matching the plugin's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
Future<ScriptModule> run(ScriptInfo info, boolean process, Object... inputs)
Executes the given script.- Parameters:
info- The script to instantiate and run.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputs- List of input parameter names and values. The expected order is in pairs: an input name followed by its value, for each desired input to populate. Leaving some inputs unpopulated is allowed. Passing the name of an input that is not valid for the plugin, or passing a value of a type incompatible with the associated input parameter, will issue an error and ignore that name/value pair.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
run
Future<ScriptModule> run(ScriptInfo info, boolean process, Map<String,Object> inputMap)
Executes the given script.- Parameters:
info- The script to instantiate and run.process- If true, executes the script with pre- and postprocessing steps from all availablePreprocessorPlugins andPostprocessorPlugins in the plugin index; if false, executes the script with no pre- or postprocessing.inputMap- Table of input parameter values, with keys matching the plugin's input parameter names. Passing a value of a type incompatible with the associated input parameter will issue an error and ignore that value.- Returns:
Futureof the module instance being executed. CallingFuture.get()will block until execution is complete.
-
canHandleFile
default boolean canHandleFile(File file)
TODO
-
canHandleFile
default boolean canHandleFile(String fileName)
TODO
-
addAlias
default void addAlias(Class<?> type)
TODO
-
lookupClass
Class<?> lookupClass(String typeName) throws ScriptException
TODO- Throws:
ScriptException
-
getPluginType
default Class<ScriptLanguage> getPluginType()
Description copied from interface:PTServiceGets the type of plugins managed by this service.- Specified by:
getPluginTypein interfacePTService<ScriptLanguage>
-
-