All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gradle.api.plugins.ExtensionContainer Maven / Gradle / Ivy

There is a newer version: 8.6
Show newest version
/*
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.api.plugins;

import org.gradle.api.Action;
import org.gradle.api.UnknownDomainObjectException;
import org.gradle.api.reflect.TypeOf;
import org.gradle.internal.HasInternalProtocol;

import javax.annotation.Nullable;

/**
 * Allows adding 'namespaced' DSL extensions to a target object.
 */
@HasInternalProtocol
public interface ExtensionContainer {

    /**
     * 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 *
* * The extension will be exposed as {@code publicType}. * * @param publicType The extension public type * @param name The name for the extension * @param extension Any object implementing {@code publicType} * @throws IllegalArgumentException When an extension with the given name already exists. * @since 3.5 */ void add(Class 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 *
* * The extension will be exposed as {@code publicType}. * * @param publicType The extension public type * @param name The name for the extension * @param extension Any object implementing {@code publicType} * @throws IllegalArgumentException When an extension with the given name already exists. * @since 3.5 */ void add(TypeOf 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 *
* * The extension will be exposed as {@code extension.getClass()} unless the extension itself declares a preferred public type via the {@link org.gradle.api.reflect.HasPublicType} protocol. * * @param name The name for the extension * @param extension Any object * @throws IllegalArgumentException When an extension with the given name already exists */ void add(String name, Object extension); /** * Creates and adds a new extension to this container. * * A new instance of the given {@code instanceType} will be created using the given {@code constructionArguments}. * The extension will be exposed as {@code publicType}. * The new instance will have been dynamically made {@link ExtensionAware}, which means that you can cast it to {@link ExtensionAware}. * * @param the extension public type * @param publicType The extension public type * @param name The name for the extension * @param instanceType The extension instance type * @param constructionArguments The arguments to be used to construct the extension instance * @return The created instance * @throws IllegalArgumentException When an extension with the given name already exists. * @see #add(Class, String, Object) * @since 3.5 */ T create(Class publicType, String name, Class instanceType, Object... constructionArguments); /** * Creates and adds a new extension to this container. * * A new instance of the given {@code instanceType} will be created using the given {@code constructionArguments}. * The extension will be exposed as {@code publicType}. * The new instance will have been dynamically made {@link ExtensionAware}, which means that you can cast it to {@link ExtensionAware}. * * @param the extension public type * @param publicType The extension public type * @param name The name for the extension * @param instanceType The extension instance type * @param constructionArguments The arguments to be used to construct the extension instance * @return The created instance * @throws IllegalArgumentException When an extension with the given name already exists. * @see #add(Class, String, Object) * @since 3.5 */ T create(TypeOf publicType, String name, Class instanceType, Object... constructionArguments); /** * Creates and adds a new extension to this container. * * A new instance of the given {@code type} will be created using the given {@code constructionArguments}. * The extension will be exposed as {@code type} unless the extension itself declares a preferred public type via the {@link org.gradle.api.reflect.HasPublicType} protocol. * The new instance will have been dynamically made {@link ExtensionAware}, which means that you can cast it to {@link ExtensionAware}. * * @param name The name for the extension * @param type The type of the extension * @param constructionArguments The arguments to be used to construct the extension instance * @return The created instance * @throws IllegalArgumentException When an extension with the given name already exists. * @see #add(String, Object) */ T create(String name, Class type, Object... constructionArguments); /** * Provides access to the schema of all known extensions. * * @since 4.5 */ ExtensionsSchema getExtensionsSchema(); /** * Looks for the extension of a given type (useful to avoid casting). If none found it will throw an exception. * * @param type extension type * @return extension, never null * @throws UnknownDomainObjectException When the given extension is not found. */ T getByType(Class type) throws UnknownDomainObjectException; /** * Looks for the extension of a given type (useful to avoid casting). If none found it will throw an exception. * * @param type extension type * @return extension, never null * @throws UnknownDomainObjectException When the given extension is not found. * @since 3.5 */ T getByType(TypeOf type) throws UnknownDomainObjectException; /** * Looks for the extension of a given type (useful to avoid casting). If none found null is returned. * * @param type extension type * @return extension or null */ @Nullable T findByType(Class type); /** * Looks for the extension of a given type (useful to avoid casting). If none found null is returned. * * @param type extension type * @return extension or null * @since 3.5 */ @Nullable T findByType(TypeOf type); /** * Looks for the extension of a given name. If none found it will throw an exception. * * @param name extension name * @return extension, never null * @throws UnknownDomainObjectException When the given extension is not found. */ Object getByName(String name) throws UnknownDomainObjectException; /** * Looks for the extension of a given name. If none found null is returned. * * @param name extension name * @return extension or null */ @Nullable Object findByName(String name); /** * Looks for the extension of the specified type and configures it with the supplied action. * * @param type extension type * @param action the configure action * @throws UnknownDomainObjectException if no extension is found. */ void configure(Class type, Action action); /** * Looks for the extension of the specified type and configures it with the supplied action. * * @param type extension type * @param action the configure action * @throws UnknownDomainObjectException if no extension is found. * @since 3.5 */ void configure(TypeOf type, Action action); /** * Looks for the extension with the specified name and configures it with the supplied action. * * @param name extension name * @param action the configure action * @throws UnknownDomainObjectException if no extension is found. * @since 4.0 */ void configure(String name, Action action); /** * The extra properties extension in this extension container. * * This extension is always present in the container, with the name “ext”. * * @return The extra properties extension in this extension container. */ ExtraPropertiesExtension getExtraProperties(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy