public interface ObjectFactory
An instance of the factory can be injected into a task, plugin or other object by annotating a public constructor or property getter method with javax.inject.Inject
.
It is also available via Project.getObjects()
.
Modifier and Type | Method | Description |
---|---|---|
DirectoryProperty |
directoryProperty() |
Creates a new
DirectoryProperty that uses the project directory to resolve relative paths, if required. |
<T> NamedDomainObjectContainer<T> |
domainObjectContainer(Class<T> elementType) |
Creates a new
NamedDomainObjectContainer for managing named objects of the specified type. |
<T> NamedDomainObjectContainer<T> |
domainObjectContainer(Class<T> elementType,
NamedDomainObjectFactory<T> factory) |
Creates a new
NamedDomainObjectContainer for managing named objects of the specified type. |
<T> DomainObjectSet<T> |
domainObjectSet(Class<T> elementType) |
Creates a new
DomainObjectSet for managing objects of the specified type. |
ConfigurableFileCollection |
fileCollection() |
Creates a new
ConfigurableFileCollection . |
RegularFileProperty |
fileProperty() |
Creates a new
RegularFileProperty that uses the project directory to resolve relative paths, if required. |
ConfigurableFileTree |
fileTree() |
Creates a new
ConfigurableFileTree . |
<T> ListProperty<T> |
listProperty(Class<T> elementType) |
|
<K,V> |
mapProperty(Class<K> keyType,
Class<V> valueType) |
|
<T extends Named> |
named(Class<T> type,
String name) |
Creates a simple immutable
Named object of the given type and name. |
<T> NamedDomainObjectList<T> |
namedDomainObjectList(Class<T> elementType) |
Creates a new
NamedDomainObjectList for managing named objects of the specified type. |
<T> NamedDomainObjectSet<T> |
namedDomainObjectSet(Class<T> elementType) |
Creates a new
NamedDomainObjectSet for managing named objects of the specified type. |
<T> T |
newInstance(Class<? extends T> type,
Object... parameters) |
Create a new instance of T, using
parameters as the construction parameters. |
<T> ExtensiblePolymorphicDomainObjectContainer<T> |
polymorphicDomainObjectContainer(Class<T> elementType) |
Creates a new
ExtensiblePolymorphicDomainObjectContainer for managing named objects of the specified type. |
<T> Property<T> |
property(Class<T> valueType) |
Creates a
Property implementation to hold values of the given type. |
<T> SetProperty<T> |
setProperty(Class<T> elementType) |
|
SourceDirectorySet |
sourceDirectorySet(String name,
String displayName) |
Creates a
SourceDirectorySet . |
<T extends Named> T named(Class<T> type, String name) throws ObjectInstantiationException
Named
object of the given type and name.
The given type can be an interface that extends Named
or an abstract class that 'implements' Named
. An abstract class, if provided:
Named.getName()
and should define this method as abstract. Any implementation will be overridden.An interface, if provided, must not define or inherit any other methods.
Objects created using this method are not decorated or extensible.
ObjectInstantiationException
- On failure to create the new instance.<T> T newInstance(Class<? extends T> type, Object... parameters) throws ObjectInstantiationException
parameters
as the construction parameters.
The type must be non-final, and can be a class, abstract class or interface.
Objects created using this method are decorated and extensible, meaning that they have DSL support mixed in and can be extended using the `extensions` property, similar to the Project
object.
An @Inject annotation is required on any constructor that accepts parameters because JSR-330 semantics for dependency injection are used. In addition to those parameters provided as an argument to this method, the following services are also available for injection:
ObjectInstantiationException
- On failure to create the new instance.SourceDirectorySet sourceDirectorySet(String name, String displayName)
SourceDirectorySet
.name
- A short name for the set.displayName
- A human consumable display name for the set.ConfigurableFileCollection fileCollection()
ConfigurableFileCollection
. The collection is initially empty.ConfigurableFileTree fileTree()
ConfigurableFileTree
. The tree will have no base dir specified.<T> NamedDomainObjectContainer<T> domainObjectContainer(Class<T> elementType)
Creates a new NamedDomainObjectContainer
for managing named objects of the specified type.
The specified element type must have a public constructor which takes the name as a String parameter. The type must be non-final and a class or abstract class.
Interfaces are supported if they declare a read-only name
property of type String, and are otherwise empty or consist entirely of managed properties.
All objects MUST expose their name as a bean property called "name". The name must be constant for the life of the object.
The objects created by the container are decorated and extensible, and have services available for injection. See newInstance(Class, Object...)
for more details.
T
- The type of objects for the container to contain.elementType
- The type of objects for the container to contain.<T> NamedDomainObjectContainer<T> domainObjectContainer(Class<T> elementType, NamedDomainObjectFactory<T> factory)
Creates a new NamedDomainObjectContainer
for managing named objects of the specified type. The given factory is used to create object instances.
All objects MUST expose their name as a bean property named "name". The name must be constant for the life of the object.
T
- The type of objects for the container to contain.elementType
- The type of objects for the container to contain.factory
- The factory to use to create object instances.<T> ExtensiblePolymorphicDomainObjectContainer<T> polymorphicDomainObjectContainer(Class<T> elementType)
Creates a new ExtensiblePolymorphicDomainObjectContainer
for managing named objects of the specified type.
The returned container will not have any factories or bindings registered.
T
- The type of objects for the container to contain.elementType
- The type of objects for the container to contain.<T> DomainObjectSet<T> domainObjectSet(Class<T> elementType)
DomainObjectSet
for managing objects of the specified type.T
- The type of objects for the domain object set to contain.elementType
- The type of objects for the domain object set to contain.<T> NamedDomainObjectSet<T> namedDomainObjectSet(Class<T> elementType)
NamedDomainObjectSet
for managing named objects of the specified type.
All objects MUST expose their name as a bean property called "name". The name must be constant for the life of the object.
T
- The type of objects for the domain object set to contain.elementType
- The type of objects for the domain object set to contain.<T> NamedDomainObjectList<T> namedDomainObjectList(Class<T> elementType)
NamedDomainObjectList
for managing named objects of the specified type.
All objects MUST expose their name as a bean property called "name". The name must be constant for the life of the object.
T
- The type of objects for the domain object set to contain.elementType
- The type of objects for the domain object set to contain.<T> Property<T> property(Class<T> valueType)
Property
implementation to hold values of the given type. The property has no initial value.
For certain types, there are more specialized property factory methods available:
List
properties, you should use listProperty(Class)
.Set
properties, you should use setProperty(Class)
.Map
properties, you should use mapProperty(Class, Class)
.Directory
properties, you should use directoryProperty()
.RegularFile
properties, you should use fileProperty()
.valueType
- The type of the property.<T> ListProperty<T> listProperty(Class<T> elementType)
ListProperty
implementation to hold a List
of the given element type T
. The property has an empty list as its initial value.
The implementation will return immutable List
values from its query methods.
T
- The type of element.elementType
- The type of element.<T> SetProperty<T> setProperty(Class<T> elementType)
SetProperty
implementation to hold a Set
of the given element type T
. The property has an empty set as its initial value.
The implementation will return immutable Set
values from its query methods.
T
- The type of element.elementType
- The type of element.<K,V> MapProperty<K,V> mapProperty(Class<K> keyType, Class<V> valueType)
MapProperty
implementation to hold a Map
of the given key type K
and value type V
. The property has an empty map as its initial value.
The implementation will return immutable Map
values from its query methods.
K
- the type of key.V
- the type of value.keyType
- the type of key.valueType
- the type of value.DirectoryProperty directoryProperty()
DirectoryProperty
that uses the project directory to resolve relative paths, if required. The property has no initial value.RegularFileProperty fileProperty()
RegularFileProperty
that uses the project directory to resolve relative paths, if required. The property has no initial value.