Interface ProviderFactory
-
@NonExtensible public interface ProviderFactory
A factory for creating instances ofProvider
.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 viaProject.getProviders()
andSettings.getProviders()
.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends Credentials>
Provider<T>credentials(java.lang.Class<T> credentialsType, java.lang.String identity)
Creates aProvider
for the givenCredentials
type.<T extends Credentials>
Provider<T>credentials(java.lang.Class<T> credentialsType, Provider<java.lang.String> identity)
Creates aProvider
for the givenCredentials
type.Provider<java.lang.String>
environmentVariable(java.lang.String variableName)
Creates aProvider
whose value is fetched from the environment variable with the given name.Provider<java.lang.String>
environmentVariable(Provider<java.lang.String> variableName)
Creates aProvider
whose value is fetched from the environment variable with the given name.Provider<java.util.Map<java.lang.String,java.lang.String>>
environmentVariablesPrefixedBy(java.lang.String variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the environment variables with the names starting with the given prefix.Provider<java.util.Map<java.lang.String,java.lang.String>>
environmentVariablesPrefixedBy(Provider<java.lang.String> variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the environment variables with the names starting with the given prefix.ExecOutput
exec(Action<? super ExecSpec> action)
Allows lazy access to the output of the external process.FileContents
fileContents(RegularFile file)
Allows lazy access to the contents of the given file.FileContents
fileContents(Provider<RegularFile> file)
Allows lazy access to the contents of the given file.Provider<java.util.Map<java.lang.String,java.lang.String>>
gradlePropertiesPrefixedBy(java.lang.String variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the Gradle properties with the names starting with the given prefix.Provider<java.util.Map<java.lang.String,java.lang.String>>
gradlePropertiesPrefixedBy(Provider<java.lang.String> variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the Gradle properties with the names starting with the given prefix.Provider<java.lang.String>
gradleProperty(java.lang.String propertyName)
Creates aProvider
whose value is fetched from the Gradle property of the given name.Provider<java.lang.String>
gradleProperty(Provider<java.lang.String> propertyName)
Creates aProvider
whose value is fetched from the Gradle property of the given name.ExecOutput
javaexec(Action<? super JavaExecSpec> action)
Allows lazy access to the output of the external java process.<T,P extends ValueSourceParameters>
Provider<T>of(java.lang.Class<? extends ValueSource<T,P>> valueSourceType, Action<? super ValueSourceSpec<P>> configuration)
Creates aProvider
whose value is obtained from the givenValueSource
.<T> Provider<T>
provider(java.util.concurrent.Callable<? extends @Nullable T> value)
Creates aProvider
whose value is calculated using the givenCallable
.Provider<java.util.Map<java.lang.String,java.lang.String>>
systemPropertiesPrefixedBy(java.lang.String variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the system properties with the names starting with the given prefix.Provider<java.util.Map<java.lang.String,java.lang.String>>
systemPropertiesPrefixedBy(Provider<java.lang.String> variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the system properties with the names starting with the given prefix.Provider<java.lang.String>
systemProperty(java.lang.String propertyName)
Creates aProvider
whose value is fetched from system properties using the given property name.Provider<java.lang.String>
systemProperty(Provider<java.lang.String> propertyName)
Creates aProvider
whose value is fetched from system properties using the given property name.<A,B,R>
Provider<R>zip(Provider<A> first, Provider<B> second, java.util.function.BiFunction<? super A,? super B,? extends R> combiner)
Returns a provider which value will be computed by combining a provider value with another provider value using the supplied combiner function.
-
-
-
Method Detail
-
provider
<T> Provider<T> provider(java.util.concurrent.Callable<? extends @Nullable T> value)
Creates aProvider
whose value is calculated using the givenCallable
.The provider is live and will call the
Callable
each time its value is queried. TheCallable
may returnnull
, in which case the provider is considered to have no value.- Parameters:
value
- Thejava.util.concurrent.Callable
use to calculate the value.- Returns:
- The provider. Never returns null.
-
environmentVariable
Provider<java.lang.String> environmentVariable(java.lang.String variableName)
Creates aProvider
whose value is fetched from the environment variable with the given name.- Parameters:
variableName
- The name of the environment variable.- Returns:
- The provider. Never returns null.
- Since:
- 6.1
-
environmentVariable
Provider<java.lang.String> environmentVariable(Provider<java.lang.String> variableName)
Creates aProvider
whose value is fetched from the environment variable with the given name.- Parameters:
variableName
- The provider for the name of the environment variable; when the given provider has no value, the returned provider has no value.- Returns:
- The provider. Never returns null.
- Since:
- 6.1
-
environmentVariablesPrefixedBy
Provider<java.util.Map<java.lang.String,java.lang.String>> environmentVariablesPrefixedBy(java.lang.String variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the environment variables with the names starting with the given prefix. The prefix comparison is case-sensitive. The returned map is immutable.- Parameters:
variableNamePrefix
- The prefix of the environment variable names- Returns:
- The provider. Never returns null.
- Since:
- 7.5
-
environmentVariablesPrefixedBy
Provider<java.util.Map<java.lang.String,java.lang.String>> environmentVariablesPrefixedBy(Provider<java.lang.String> variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the environment variables with the names starting with the given prefix. The prefix comparison is case-sensitive. The returned map is immutable.- Parameters:
variableNamePrefix
- The prefix of the environment variable names- Returns:
- The provider. Never returns null.
- Since:
- 7.5
-
systemProperty
Provider<java.lang.String> systemProperty(java.lang.String propertyName)
Creates aProvider
whose value is fetched from system properties using the given property name.- Parameters:
propertyName
- the name of the system property- Returns:
- the provider for the system property, never returns null
- Since:
- 6.1
-
systemProperty
Provider<java.lang.String> systemProperty(Provider<java.lang.String> propertyName)
Creates aProvider
whose value is fetched from system properties using the given property name.- Parameters:
propertyName
- the name of the system property- Returns:
- the provider for the system property, never returns null
- Since:
- 6.1
-
systemPropertiesPrefixedBy
Provider<java.util.Map<java.lang.String,java.lang.String>> systemPropertiesPrefixedBy(java.lang.String variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the system properties with the names starting with the given prefix. The prefix comparison is case-sensitive. The returned map is immutable.- Parameters:
variableNamePrefix
- The prefix of the system property names- Returns:
- The provider. Never returns null.
- Since:
- 7.5
-
systemPropertiesPrefixedBy
Provider<java.util.Map<java.lang.String,java.lang.String>> systemPropertiesPrefixedBy(Provider<java.lang.String> variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the system properties with the names starting with the given prefix. The prefix comparison is case-sensitive. The returned map is immutable.- Parameters:
variableNamePrefix
- The prefix of the system property names- Returns:
- The provider. Never returns null.
- Since:
- 7.5
-
gradleProperty
Provider<java.lang.String> gradleProperty(java.lang.String propertyName)
Creates aProvider
whose value is fetched from the Gradle property of the given name.- Parameters:
propertyName
- the name of the Gradle property- Returns:
- the provider for the Gradle property, never returns null
- Since:
- 6.2
-
gradleProperty
Provider<java.lang.String> gradleProperty(Provider<java.lang.String> propertyName)
Creates aProvider
whose value is fetched from the Gradle property of the given name.- Parameters:
propertyName
- the name of the Gradle property- Returns:
- the provider for the Gradle property, never returns null
- Since:
- 6.2
-
gradlePropertiesPrefixedBy
Provider<java.util.Map<java.lang.String,java.lang.String>> gradlePropertiesPrefixedBy(java.lang.String variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the Gradle properties with the names starting with the given prefix. The prefix comparison is case-sensitive. The returned map is immutable.- Parameters:
variableNamePrefix
- The prefix of the Gradle property names- Returns:
- The provider. Never returns null.
- Since:
- 8.0
-
gradlePropertiesPrefixedBy
Provider<java.util.Map<java.lang.String,java.lang.String>> gradlePropertiesPrefixedBy(Provider<java.lang.String> variableNamePrefix)
Creates aProvider
whose value is a name-to-value map of the Gradle properties with the names starting with the given prefix. The prefix comparison is case-sensitive. The returned map is immutable.- Parameters:
variableNamePrefix
- The prefix of the Gradle property names- Returns:
- The provider. Never returns null.
- Since:
- 8.0
-
fileContents
FileContents fileContents(RegularFile file)
Allows lazy access to the contents of the given file.When the file contents are read at configuration time the file is automatically considered as an input to the configuration model.
- Parameters:
file
- the file whose contents to read.- Returns:
- an interface that allows lazy access to the contents of the given file.
- Since:
- 6.1
- See Also:
FileContents.getAsText()
,FileContents.getAsBytes()
-
fileContents
FileContents fileContents(Provider<RegularFile> file)
Allows lazy access to the contents of the given file.When the file contents are read at configuration time the file is automatically considered as an input to the configuration model.
- Parameters:
file
- provider of the file whose contents to read.- Returns:
- an interface that allows lazy access to the contents of the given file.
- Since:
- 6.1
- See Also:
FileContents.getAsText()
,FileContents.getAsBytes()
-
exec
ExecOutput exec(Action<? super ExecSpec> action)
Allows lazy access to the output of the external process.When the process output is read at configuration time it is considered as an input to the configuration model. Consequent builds will re-execute the process to obtain the output and check if the cached model is still up-to-date.
The process input and output streams cannot be configured.
For more sophisticated use cases, like handling execution exceptions, supplying input streams or processing the output in a streaming way, use
ValueSource
.- Parameters:
action
- the configuration of the external process with the output stream pre-configured.- Returns:
- an interface that allows lazy access to the process' output.
- Since:
- 7.5
-
javaexec
ExecOutput javaexec(Action<? super JavaExecSpec> action)
Allows lazy access to the output of the external java process.When the process output is read at configuration time it is considered as an input to the configuration model. Consequent builds will re-execute the process to obtain the output and check if the cached model is still up-to-date.
The process input and output streams cannot be configured.
For more sophisticated use cases, like handling execution exceptions, supplying input streams or processing the output in a streaming way, use
ValueSource
.- Parameters:
action
- the configuration of the external process with the output stream pre-configured.- Returns:
- an interface that allows lazy access to the process' output.
- Since:
- 7.5
-
of
<T,P extends ValueSourceParameters> Provider<T> of(java.lang.Class<? extends ValueSource<T,P>> valueSourceType, Action<? super ValueSourceSpec<P>> configuration)
Creates aProvider
whose value is obtained from the givenValueSource
.- Parameters:
valueSourceType
- the type of theValueSource
configuration
- action to configure the parameters to the givenValueSource
- Returns:
- the provider, never returns null
- Since:
- 6.1
-
credentials
<T extends Credentials> Provider<T> credentials(java.lang.Class<T> credentialsType, java.lang.String identity)
Creates aProvider
for the givenCredentials
type.The provider returned by this method should be attached to a task's input property. This way, the presence of credentials will be validated before any of the tasks are executed if and only if the task with credentials property is to be executed.
Values for the requested Credentials type will be sourced from the project's properties using the pattern "identity" + credentials field. For example,
PasswordCredentials
provider with identity "myService" will look for properties named "myServiceUsername" and "myServicePassword".The following credential types are currently supported:
- Parameters:
credentialsType
- type of credentials to be provided.identity
- identity to be associated with the credentials.- Returns:
- The provider. Never returns null.
- Since:
- 6.6
-
credentials
<T extends Credentials> Provider<T> credentials(java.lang.Class<T> credentialsType, Provider<java.lang.String> identity)
Creates aProvider
for the givenCredentials
type.The provider returned by this method should be attached to a task's input property. This way, the presence of credentials will be validated before any of the tasks are executed if and only if the task with credentials property is to be executed.
Values for the requested Credentials type will be sourced from the project's properties using the pattern "identity" + credentials field. For example,
PasswordCredentials
provider with identity "myService" will look for properties named "myServiceUsername" and "myServicePassword".The following credential types are currently supported:
- Parameters:
credentialsType
- type of credentials to be provided.identity
- a provider returning the identity to be associated with the credentials.- Returns:
- The provider. Never returns null.
- Since:
- 6.6
-
zip
<A,B,R> Provider<R> zip(Provider<A> first, Provider<B> second, java.util.function.BiFunction<? super A,? super B,? extends R> combiner)
Returns a provider which value will be computed by combining a provider value with another provider value using the supplied combiner function.The resulting provider will be live, so that each time it is queried, it queries both supplied providers and applies the combiner to the results. Whenever any of the providers has no value, the new provider will also have no value and the combiner will not be called.
If the supplied providers represents a task or the output of a task, the resulting provider will carry the dependency information.
- Type Parameters:
A
- the type of the first providerB
- the type of the second providerR
- the type of the result of the combiner- Parameters:
first
- the first provider to combine withsecond
- the second provider to combine withcombiner
- the combiner of values. May returnnull
, in which case the provider will have no value.- Returns:
- a combined provider
- Since:
- 6.6
-
-