Package org.apache.groovy.plugin
Class GroovyRunnerRegistry
- java.lang.Object
-
- org.apache.groovy.plugin.GroovyRunnerRegistry
-
- All Implemented Interfaces:
Iterable<GroovyRunner>
,Map<String,GroovyRunner>
public class GroovyRunnerRegistry extends Object implements Map<String,GroovyRunner>, Iterable<GroovyRunner>
Registry of services that implement theGroovyRunner
interface.This registry makes use of the
ServiceLoader
facility. The preferred method for registering newGroovyRunner
providers is to place them in a provider-configuration file in the resource directoryMETA-INF/services
. The preferred method for accessing the registered runners is by making use of theIterable
interface using an enhanced for-loop.For compatibility with previous versions, this registry implements the
Map
interface. Allnull
keys and values will be ignored and no exception thrown, except where noted.By default the registry contains runners that are capable of running
JUnit 3
andJUnit 4
test classes if those libraries are available to the class loader.- Since:
- 2.5.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears all registered runners from the registry and resets the registry so that it contains only the default set of runners.boolean
containsKey(Object key)
Returnstrue
if a runner was registered with the specified key.boolean
containsValue(Object runner)
Returnstrue
if registry contains the given runner instance.Set<Map.Entry<String,GroovyRunner>>
entrySet()
Returns a set of entries for registered runners.GroovyRunner
get(Object key)
Returns the registered runner for the specified key.static GroovyRunnerRegistry
getInstance()
Returns a reference to the one and only registry instance.boolean
isEmpty()
Returnstrue
if the registry contains no runners, elsefalse
.Iterator<GroovyRunner>
iterator()
Returns an iterator for all runners that are registered.Set<String>
keySet()
Set of all keys associated with registered runners.void
load(ClassLoader classLoader)
LoadsGroovyRunner
instances using theServiceLoader
facility.GroovyRunner
put(String key, GroovyRunner runner)
Registers a runner with the specified key.void
putAll(Map<? extends String,? extends GroovyRunner> m)
Adds all entries from the given Map to the registry.GroovyRunner
remove(Object key)
Removes a registered runner from the registry.int
size()
Returns the number of registered runners.String
toString()
Collection<GroovyRunner>
values()
Returns a collection of all registered runners.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
getInstance
public static GroovyRunnerRegistry getInstance()
Returns a reference to the one and only registry instance.- Returns:
- registry instance
-
load
public void load(ClassLoader classLoader)
LoadsGroovyRunner
instances using theServiceLoader
facility.- Parameters:
classLoader
- used to locate provider-configuration files and classes
-
iterator
public Iterator<GroovyRunner> iterator()
Returns an iterator for all runners that are registered. The returned iterator is a snapshot of the registry at the time the iterator is created. This iterator does not support removal.- Specified by:
iterator
in interfaceIterable<GroovyRunner>
- Returns:
- iterator for all registered runners
-
size
public int size()
Returns the number of registered runners.- Specified by:
size
in interfaceMap<String,GroovyRunner>
- Returns:
- number of registered runners
-
isEmpty
public boolean isEmpty()
Returnstrue
if the registry contains no runners, elsefalse
.- Specified by:
isEmpty
in interfaceMap<String,GroovyRunner>
- Returns:
true
if no runners are registered
-
containsKey
public boolean containsKey(Object key)
Returnstrue
if a runner was registered with the specified key.- Specified by:
containsKey
in interfaceMap<String,GroovyRunner>
- Parameters:
key
- for the registered runner- Returns:
true
if a runner was registered with given key
-
containsValue
public boolean containsValue(Object runner)
Returnstrue
if registry contains the given runner instance.- Specified by:
containsValue
in interfaceMap<String,GroovyRunner>
- Parameters:
runner
- instance of a GroovyRunner- Returns:
true
if the given runner is registered
-
get
public GroovyRunner get(Object key)
Returns the registered runner for the specified key.- Specified by:
get
in interfaceMap<String,GroovyRunner>
- Parameters:
key
- used to lookup the runner- Returns:
- the runner registered with the given key
-
put
public GroovyRunner put(String key, GroovyRunner runner)
Registers a runner with the specified key.- Specified by:
put
in interfaceMap<String,GroovyRunner>
- Parameters:
key
- to associate with the runnerrunner
- the runner to register- Returns:
- the previously registered runner for the given key,
if no runner was previously registered for the key
then
null
-
remove
public GroovyRunner remove(Object key)
Removes a registered runner from the registry.- Specified by:
remove
in interfaceMap<String,GroovyRunner>
- Parameters:
key
- of the runner to remove- Returns:
- the runner instance that was removed, if no runner
instance was removed then
null
-
putAll
public void putAll(Map<? extends String,? extends GroovyRunner> m)
Adds all entries from the given Map to the registry. Any entries in the provided Map that contain anull
key or value will be ignored.- Specified by:
putAll
in interfaceMap<String,GroovyRunner>
- Parameters:
m
- entries to add to the registry- Throws:
NullPointerException
- if the given Map isnull
-
clear
public void clear()
Clears all registered runners from the registry and resets the registry so that it contains only the default set of runners.- Specified by:
clear
in interfaceMap<String,GroovyRunner>
-
keySet
public Set<String> keySet()
Set of all keys associated with registered runners. This is a snapshot of the registry and any subsequent registry changes will not be reflected in the set.- Specified by:
keySet
in interfaceMap<String,GroovyRunner>
- Returns:
- an unmodifiable set of keys for registered runners
-
values
public Collection<GroovyRunner> values()
Returns a collection of all registered runners. This is a snapshot of the registry and any subsequent registry changes will not be reflected in the collection.- Specified by:
values
in interfaceMap<String,GroovyRunner>
- Returns:
- an unmodifiable collection of registered runner instances
-
entrySet
public Set<Map.Entry<String,GroovyRunner>> entrySet()
Returns a set of entries for registered runners. This is a snapshot of the registry and any subsequent registry changes will not be reflected in the set.- Specified by:
entrySet
in interfaceMap<String,GroovyRunner>
- Returns:
- an unmodifiable set of registered runner entries
-
-