Package org.gradle.api.plugins
Interface ExtensionContainer
-
- All Known Subinterfaces:
Convention
public interface ExtensionContainer
Allows adding 'namespaced' DSL extensions to a target object.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> void
add(Class<T> publicType, String name, T extension)
Adds a new extension to this container.void
add(String name, Object extension)
Adds a new extension to this container.<T> void
add(TypeOf<T> publicType, String name, T extension)
Adds a new extension to this container.<T> void
configure(Class<T> type, Action<? super T> action)
Looks for the extension of the specified type and configures it with the supplied action.<T> void
configure(String name, Action<? super T> action)
Looks for the extension with the specified name and configures it with the supplied action.<T> void
configure(TypeOf<T> type, Action<? super T> action)
Looks for the extension of the specified type and configures it with the supplied action.<T> T
create(Class<T> publicType, String name, Class<? extends T> instanceType, Object... constructionArguments)
Creates and adds a new extension to this container.<T> T
create(String name, Class<T> type, Object... constructionArguments)
Creates and adds a new extension to this container.<T> T
create(TypeOf<T> publicType, String name, Class<? extends T> instanceType, Object... constructionArguments)
Creates and adds a new extension to this container.Object
findByName(String name)
Looks for the extension of a given name.<T> T
findByType(Class<T> type)
Looks for the extension of a given type (useful to avoid casting).<T> T
findByType(TypeOf<T> type)
Looks for the extension of a given type (useful to avoid casting).Object
getByName(String name)
Looks for the extension of a given name.<T> T
getByType(Class<T> type)
Looks for the extension of a given type (useful to avoid casting).<T> T
getByType(TypeOf<T> type)
Looks for the extension of a given type (useful to avoid casting).ExtraPropertiesExtension
getExtraProperties()
The extra properties extension in this extension container.Map<String,TypeOf<?>>
getSchema()
Provides access to all known extensions types.
-
-
-
Method Detail
-
add
@Incubating <T> void add(Class<T> publicType, String name, T extension)
Adds a new extension to this container. Adding an extension of name 'foo' will:- add 'foo' dynamic property
- add 'foo' dynamic method that accepts a closure that is a configuration script block
publicType
.- Parameters:
publicType
- The extension public typename
- The name for the extensionextension
- Any object implementingpublicType
- Throws:
IllegalArgumentException
- When an extension with the given name already exists.- Since:
- 3.5
-
add
@Incubating <T> void add(TypeOf<T> publicType, String name, T extension)
Adds a new extension to this container. Adding an extension of name 'foo' will:- add 'foo' dynamic property
- add 'foo' dynamic method that accepts a closure that is a configuration script block
publicType
.- Parameters:
publicType
- The extension public typename
- The name for the extensionextension
- Any object implementingpublicType
- Throws:
IllegalArgumentException
- When an extension with the given name already exists.- Since:
- 3.5
-
add
void add(String name, Object extension)
Adds a new extension to this container. Adding an extension of name 'foo' will:- add 'foo' dynamic property
- add 'foo' dynamic method that accepts a closure that is a configuration script block
extension.getClass()
unless the extension itself declares a preferred public type via theHasPublicType
protocol.- Parameters:
name
- The name for the extensionextension
- Any object- Throws:
IllegalArgumentException
- When an extension with the given name already exists
-
create
@Incubating <T> T create(Class<T> publicType, String name, Class<? extends T> instanceType, Object... constructionArguments)
Creates and adds a new extension to this container. A new instance of the giveninstanceType
will be created using the givenconstructionArguments
. The extension will be exposed aspublicType
. The new instance will have been dynamically madeExtensionAware
, which means that you can cast it toExtensionAware
.- Type Parameters:
T
- the extension public type- Parameters:
publicType
- The extension public typename
- The name for the extensioninstanceType
- The extension instance typeconstructionArguments
- The arguments to be used to construct the extension instance- Returns:
- The created instance
- Throws:
IllegalArgumentException
- When an extension with the given name already exists.- Since:
- 3.5
- See Also:
add(Class, String, Object)
-
create
@Incubating <T> T create(TypeOf<T> publicType, String name, Class<? extends T> instanceType, Object... constructionArguments)
Creates and adds a new extension to this container. A new instance of the giveninstanceType
will be created using the givenconstructionArguments
. The extension will be exposed aspublicType
. The new instance will have been dynamically madeExtensionAware
, which means that you can cast it toExtensionAware
.- Type Parameters:
T
- the extension public type- Parameters:
publicType
- The extension public typename
- The name for the extensioninstanceType
- The extension instance typeconstructionArguments
- The arguments to be used to construct the extension instance- Returns:
- The created instance
- Throws:
IllegalArgumentException
- When an extension with the given name already exists.- Since:
- 3.5
- See Also:
add(Class, String, Object)
-
create
<T> T create(String name, Class<T> type, Object... constructionArguments)
Creates and adds a new extension to this container. A new instance of the giventype
will be created using the givenconstructionArguments
. The extension will be exposed astype
unless the extension itself declares a preferred public type via theHasPublicType
protocol. The new instance will have been dynamically madeExtensionAware
, which means that you can cast it toExtensionAware
.- Parameters:
name
- The name for the extensiontype
- The type of the extensionconstructionArguments
- The arguments to be used to construct the extension instance- Returns:
- The created instance
- Throws:
IllegalArgumentException
- When an extension with the given name already exists.- See Also:
add(String, Object)
-
getSchema
@Incubating Map<String,TypeOf<?>> getSchema()
Provides access to all known extensions types.- Returns:
- A map of extensions public types, keyed by name
- Since:
- 3.5
-
getByType
<T> T getByType(Class<T> type) throws UnknownDomainObjectException
Looks for the extension of a given type (useful to avoid casting). If none found it will throw an exception.- Parameters:
type
- extension type- Returns:
- extension, never null
- Throws:
UnknownDomainObjectException
- When the given extension is not found.
-
getByType
@Incubating <T> T getByType(TypeOf<T> type) throws UnknownDomainObjectException
Looks for the extension of a given type (useful to avoid casting). If none found it will throw an exception.- Parameters:
type
- extension type- Returns:
- extension, never null
- Throws:
UnknownDomainObjectException
- When the given extension is not found.- Since:
- 3.5
-
findByType
@Nullable <T> T findByType(Class<T> type)
Looks for the extension of a given type (useful to avoid casting). If none found null is returned.- Parameters:
type
- extension type- Returns:
- extension or null
-
findByType
@Incubating @Nullable <T> T findByType(TypeOf<T> type)
Looks for the extension of a given type (useful to avoid casting). If none found null is returned.- Parameters:
type
- extension type- Returns:
- extension or null
- Since:
- 3.5
-
getByName
Object getByName(String name) throws UnknownDomainObjectException
Looks for the extension of a given name. If none found it will throw an exception.- Parameters:
name
- extension name- Returns:
- extension, never null
- Throws:
UnknownDomainObjectException
- When the given extension is not found.
-
findByName
@Nullable Object findByName(String name)
Looks for the extension of a given name. If none found null is returned.- Parameters:
name
- extension name- Returns:
- extension or null
-
configure
@Incubating <T> void configure(Class<T> type, Action<? super T> action)
Looks for the extension of the specified type and configures it with the supplied action.- Parameters:
type
- extension typeaction
- the configure action- Throws:
UnknownDomainObjectException
- if no extension is found.
-
configure
@Incubating <T> void configure(TypeOf<T> type, Action<? super T> action)
Looks for the extension of the specified type and configures it with the supplied action.- Parameters:
type
- extension typeaction
- the configure action- Throws:
UnknownDomainObjectException
- if no extension is found.- Since:
- 3.5
-
configure
@Incubating <T> void configure(String name, Action<? super T> action)
Looks for the extension with the specified name and configures it with the supplied action.- Parameters:
name
- extension nameaction
- the configure action- Throws:
UnknownDomainObjectException
- if no extension is found.- Since:
- 4.0
-
getExtraProperties
ExtraPropertiesExtension getExtraProperties()
The extra properties extension in this extension container. This extension is always present in the container, with the name “ext”.- Returns:
- The extra properties extension in this extension container.
-
-