Package org.scijava.script
Class DefaultScriptService
- java.lang.Object
-
- org.scijava.AbstractContextual
-
- org.scijava.plugin.AbstractRichPlugin
-
- org.scijava.service.AbstractService
-
- org.scijava.plugin.AbstractPTService<PT>
-
- org.scijava.plugin.AbstractSingletonService<ScriptLanguage>
-
- org.scijava.script.DefaultScriptService
-
- All Implemented Interfaces:
Comparable<Prioritized>,Contextual,Disposable,Identifiable,Initializable,Locatable,Logged,HasPluginInfo,PTService<ScriptLanguage>,RichPlugin,SciJavaPlugin,SingletonService<ScriptLanguage>,Prioritized,ScriptService,SciJavaService,Service,Versioned
public class DefaultScriptService extends AbstractSingletonService<ScriptLanguage> implements ScriptService
Default service for working with scripts.- Author:
- Johannes Schindelin, Curtis Rueden
-
-
Field Summary
-
Fields inherited from interface org.scijava.script.ScriptService
SCRIPTS_PATH_PROPERTY, SCRIPTS_RESOURCE_DIR
-
-
Constructor Summary
Constructors Constructor Description DefaultScriptService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAlias(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.Map<String,Class<?>>getAliases()TODOScriptLanguageIndexgetIndex()Gets the index of available scripting languages.MenuPathgetMenuPrefix(File scriptDirectory)Gets the menu path prefix for the given script directory, or null if none.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.voidinitialize()Performs any needed initialization when the service is first loaded.Class<?>lookupClass(String alias)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.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 class org.scijava.plugin.AbstractSingletonService
getInstance, getInstances, objectService, onEvent, onEvent
-
Methods inherited from class org.scijava.plugin.AbstractPTService
pluginService
-
Methods inherited from class org.scijava.service.AbstractService
getContext, setContext, toString
-
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
getInfo, getPriority, setInfo, setPriority
-
Methods inherited from class org.scijava.AbstractContextual
context
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
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.script.ScriptService
addAlias, canHandleFile, canHandleFile, getLanguageByExtension, getLanguageByName, getLanguages, getPluginType, run, run, run, run
-
Methods inherited from interface org.scijava.service.Service
registerEventHandlers
-
Methods inherited from interface org.scijava.plugin.SingletonService
create, filterInstances, getInstance, getInstances, objectService
-
Methods inherited from interface org.scijava.Versioned
getVersion
-
-
-
-
Method Detail
-
getIndex
public ScriptLanguageIndex getIndex()
Description copied from interface:ScriptServiceGets the index of available scripting languages.- Specified by:
getIndexin interfaceScriptService
-
getScriptDirectories
public List<File> getScriptDirectories()
Description copied from interface:ScriptServiceGets the base directories to scan for scripts.- Specified by:
getScriptDirectoriesin interfaceScriptService
-
getMenuPrefix
public MenuPath getMenuPrefix(File scriptDirectory)
Description copied from interface:ScriptServiceGets the menu path prefix for the given script directory, or null if none.- Specified by:
getMenuPrefixin interfaceScriptService
-
addScriptDirectory
public void addScriptDirectory(File scriptDirectory)
Description copied from interface:ScriptServiceAdds a base directory to scan for scripts.- Specified by:
addScriptDirectoryin interfaceScriptService
-
addScriptDirectory
public void addScriptDirectory(File scriptDirectory, MenuPath menuPrefix)
Description copied from interface:ScriptServiceAdds a base directory to scan for scripts, placing discovered scripts beneath the given menu path prefix.- Specified by:
addScriptDirectoryin interfaceScriptService
-
removeScriptDirectory
public void removeScriptDirectory(File scriptDirectory)
Description copied from interface:ScriptServiceRemoves a base directory to scan for scripts.- Specified by:
removeScriptDirectoryin interfaceScriptService
-
getScripts
public Collection<ScriptInfo> getScripts()
Description copied from interface:ScriptServiceGets all available scripts.- Specified by:
getScriptsin interfaceScriptService
-
getScript
public ScriptInfo getScript(File scriptFile)
Description copied from interface:ScriptServiceGets the cachedScriptInfometadata for the script at the given file, creating it if it does not already exist.- Specified by:
getScriptin interfaceScriptService
-
run
public Future<ScriptModule> run(File file, boolean process, Object... inputs)
Description copied from interface:ScriptServiceExecutes the script in the given file.- Specified by:
runin interfaceScriptService- 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.
-
run
public Future<ScriptModule> run(File file, boolean process, Map<String,Object> inputMap)
Description copied from interface:ScriptServiceExecutes the script in the given file.- Specified by:
runin interfaceScriptService- 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.
-
run
public Future<ScriptModule> run(ScriptInfo info, boolean process, Object... inputs)
Description copied from interface:ScriptServiceExecutes the given script.- Specified by:
runin interfaceScriptService- 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
public Future<ScriptModule> run(ScriptInfo info, boolean process, Map<String,Object> inputMap)
Description copied from interface:ScriptServiceExecutes the given script.- Specified by:
runin interfaceScriptService- 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.
-
addAlias
public void addAlias(String alias, Class<?> type)
Description copied from interface:ScriptServiceTODO- Specified by:
addAliasin interfaceScriptService
-
getAliases
public Map<String,Class<?>> getAliases()
Description copied from interface:ScriptServiceTODO- Specified by:
getAliasesin interfaceScriptService
-
lookupClass
public Class<?> lookupClass(String alias) throws ScriptException
Description copied from interface:ScriptServiceTODO- Specified by:
lookupClassin interfaceScriptService- Throws:
ScriptException
-
initialize
public void initialize()
Description copied from interface:ServicePerforms any needed initialization when the service is first loaded.NB: This method is not intended to be called directly. It is called by the service framework itself (specifically by the
ServiceHelper) when initializing the service. It should not be called a second time.- Specified by:
initializein interfaceInitializable- Specified by:
initializein interfaceService- Specified by:
initializein interfaceSingletonService<ScriptLanguage>
-
-