Class ScriptExecutor
- All Implemented Interfaces:
Renamable, RequiredResourceSupport, ResourceProvider
A provider of execution results from invoking a script
executed by a configurable interpreter.
The provider generates resources in response to requests for
ExecResult whose name matches this
provider's name.
-
The working directory is the project directory.
-
The provider retrieves all resources added by
required(Stream). While the provider itself does not process these resources, it is assumed that they are processed by the script and therefore need to be available. -
The provider invokes the function configured with
output(Function)and collects all resources. If the generated resources exist and no resource fromrequiredis newer than the generated resources found, the provider returns a result that indicates successful invocation. The date of the result is set to the newest date from the generated resources and the (existing) resources are attached. -
Else, the provider executes the script, calls the function set with
output(Function)again and adds the result to theExecResultthat it returns.
The generated resources can also be provided directly (i.e. not as part
of an ExecResult) in response to a configurable resource request, see
provideResources(ResourceRequest, Function).
The provider also uses the function set with output(Function) to determine
the resources to be removed when it is invoked with a request for
Cleanliness.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd the given arguments as arguments of the script.Add the strings from the stream as arguments of the script, seeargs(String...).protected <T extends Resource>
Collection<T> doProvide(ResourceRequest<T> request) Invoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.interpreter(Path interpreter) Sets the path to the interpreter that is to be invoked.interpreterFlags(String... flags) Adds the given flags to the interpreter invocation.Set the new name.Sets the function used to determine the resources generated by this provider.project()Returns the project that this provider belongs to.provideResources(ResourceRequest<?> proto, Function<Project, Stream<Resource>> resources) Provide the generated resources directly in response to a requests like the given prototype request.Convenience method that adds aFileResourceto the required resources.Convenience method that adds aFileTreeto the required resources.Required.Sets the script to be executed.scriptArgumentFlag(String flag) Sets the flag that precedes a script passed to the interpreter on the command line.scriptFile(Path script) Sets the script file to be executed.toString()To string.Methods inherited from class AbstractProvider
context, name, of, rename, vavrStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceProvider
context, name, of, resources
-
Constructor Details
-
ScriptExecutor
Initializes a new script executor.- Parameters:
project- the project
-
-
Method Details
-
project
-
name
-
interpreter
Sets the path to the interpreter that is to be invoked.- Parameters:
interpreter- the interpreter- Returns:
- the script executor
-
interpreterFlags
Adds the given flags to the interpreter invocation.- Parameters:
flags- the flags- Returns:
- the script executor
-
scriptFile
Sets the script file to be executed.- Parameters:
script- the script- Returns:
- the script executor
-
scriptArgumentFlag
Sets the flag that precedes a script passed to the interpreter on the command line. Defaults to "-c".- Parameters:
flag- the flag- Returns:
- the script executor
-
script
Sets the script to be executed.- Parameters:
script- the script- Returns:
- the script executor
-
args
Add the given arguments as arguments of the script. Note that the absolute path of the script or, when usingscript(String), this provider's name is automatically added as the first argument, before the arguments specified by this method.- Parameters:
args- the arguments- Returns:
- the script executor
-
args
Add the strings from the stream as arguments of the script, seeargs(String...).- Parameters:
args- the args- Returns:
- the script executor
-
required
Required.- Specified by:
requiredin interfaceRequiredResourceSupport- Parameters:
resources- the resources- Returns:
- the script executor
-
required
Description copied from interface:RequiredResourceSupportConvenience method that adds aFileTreeto the required resources. Ifrootis relative, it is resolved against the project's directory.- Specified by:
requiredin interfaceRequiredResourceSupport- Parameters:
root- the rootpattern- the pattern- Returns:
- the provider
-
required
Description copied from interface:RequiredResourceSupportConvenience method that adds aFileResourceto the required resources. Ifpathis relative, it is resolved against the project's directory.- Specified by:
requiredin interfaceRequiredResourceSupport- Parameters:
file- the file- Returns:
- the provider
-
output
Sets the function used to determine the resources generated by this provider. The function is evaluated both for incremental up-to-date checks, for determining the resources returned after script execution, and for determining the resources to be cleaned.- Parameters:
resources- the function that provides the results as resources- Returns:
- the script executor
-
provideResources
public ScriptExecutor provideResources(ResourceRequest<?> proto, Function<Project, Stream<Resource>> resources) Provide the generated resources directly in response to a requests like the given prototype request. Invoking this method implies a call tooutput(Function)withresources.- Parameters:
proto- defines the kind of request that the script executor should respond to with the generated resourcesresources- the function that provides the results as resources- Returns:
- the script executor
-
doProvide
Description copied from class:AbstractProviderInvoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.- Specified by:
doProvidein classAbstractProvider- Type Parameters:
T- the generic type- Parameters:
request- the request for resources- Returns:
- the stream
-
toString
To string.- Overrides:
toStringin classAbstractProvider- Returns:
- the string
-