public abstract class TransformationSet
extends java.lang.Object
TransformationSet transforms source files by applying templates loaded from template
files. The result is written to output files.
Source and template files can be specified either as paths to files or directories, or as a
path to a directory with a configuration closure, which operates on a PatternFilterable.
Relative paths are resolved relative to the project directory.
The output file for a transformation can be specified in several ways:
setOutputFile(Object).
If the transformation set contains several transformations, the effect of specifying a single
output file is implementation specific.setOutputDir(Object). The name of the output file will be the same as the name of
the transformation's source file.Closure applied to the source and template file
paths of the transformation. The Closure either returns an object specifying the output
file of the transformation or null if there should be no explicit output file. In the former case
the returned object is resolved with Project::file().
It is possible to pass parameters to the transformations. This is done by calling
parameter(String, Object).
Example of a configuration closure for a transformation set:
{
source 'src.xml'
sources ('srcDir')
{
include '*.xml'
}
templates 'a.xsl', 'rsrc/b.xsl'
templates ('templatesDir')
{
exclude 'common.xsl'
}
outputDir = 'dst'
outputMapping {
s, t ->
if (s.name.startsWith('xyz'))
'dst/' + s.name + '-' + t.name
else
null
}
parameters(
'stringParam': 'value',
'intParam': 17
)
}
| Modifier and Type | Field and Description |
|---|---|
protected org.gradle.api.Project |
fProject |
| Modifier | Constructor and Description |
|---|---|
protected |
TransformationSet(org.gradle.api.Project pProject)
Create a new
TransformationSet. |
| Modifier and Type | Method and Description |
|---|---|
TransformationSet |
configure(groovy.lang.Closure<?> pClosure)
Configure this transformation set through a
Closure. |
protected abstract Transformer |
createTransformer(java.lang.ClassLoader pClassLoader)
Create the
Transformer instance associated with this transformer set. |
void |
dynamicOutputDirectory(java.lang.Object pDirectoryPath)
Specify a directory where the transformations are known to generate dynamic output.
|
java.io.File |
getConfigurationFile()
Get the file to configure the underlying transformer with before executing the
transformations.
|
org.gradle.api.file.FileCollection |
getDynamicOutputDirectories()
Get the directories specified as dynamic output directory.
|
java.util.List<java.io.File> |
getMappedOutputFiles()
Get the output file specifications produced by applying all output mappings to the pairs of
source and template files.
|
java.io.File |
getOutputDir() |
java.io.File |
getOutputFile() |
java.util.Map<java.lang.String,java.lang.Object> |
getParameters()
Get the parameters specified for the transformations.
|
org.gradle.api.file.FileCollection |
getSourceFiles()
Get the source files that each template file will be applied to.
|
org.gradle.api.file.FileCollection |
getTemplateFiles()
Get the template files that will be applied to each source.
|
void |
outputMapping(groovy.lang.Closure<?> pClosure)
Add a closure that maps a source file and a template file to an output file.
|
void |
parameter(java.lang.String pName,
java.lang.Object pValue)
Add a parameter that will be passed to each template when it is applied to a source file.
|
void |
parameters(java.util.Map<java.lang.String,java.lang.Object> pParameters)
Add parameters that will be passed to each template when it is applied to a source file.
|
void |
setConfigurationFile(java.lang.Object pFile) |
void |
setOutputDir(java.lang.Object pDirectoryPath)
Specify a directory to create output files in for transformations that don't have an explicit
output mapping.
|
void |
setOutputFile(java.lang.Object pFilePath)
Specify a single file to write all output to for transformations that don't have an explicit
output mapping.
|
void |
source(java.lang.Object pPath)
Add a source file or directory to the transformation set.
|
void |
sources(java.lang.Object... pPaths)
Add multiple source files and/or directories to the transformation set.
|
void |
sources(java.lang.Object pDirectoryPath,
groovy.lang.Closure<?> pConfigClosure)
Add a source file directory to the transformation set and specify which of its files to
include and/or exclude through a
Closure. |
void |
template(java.lang.Object pPath)
Add a template file or directory to the transformation set.
|
void |
templates(java.lang.Object... pPaths)
Add multiple template files to the transformation set.
|
void |
templates(java.lang.Object pDirectoryPath,
groovy.lang.Closure<?> pConfigClosure)
Add a template file directory to the transformation set and specify which of its files to
include and/or exclude through a
Closure. |
int |
transform(java.lang.ClassLoader pTransformerClassLoader)
Execute all transformations in this set.
|
protected TransformationSet(org.gradle.api.Project pProject)
TransformationSet.pProject - The project to resolve file paths with.java.lang.NullPointerException - if pProject is null.@InputFile @Optional public java.io.File getConfigurationFile()
public void setConfigurationFile(java.lang.Object pFile)
@InputFiles public org.gradle.api.file.FileCollection getSourceFiles()
@InputFiles public org.gradle.api.file.FileCollection getTemplateFiles()
@OutputFile @Optional public java.io.File getOutputFile()
@OutputDirectory @Optional public java.io.File getOutputDir()
@OutputFiles public java.util.List<java.io.File> getMappedOutputFiles()
This property is read-only and intended to be used by the Gradle up-to-date check.
@OutputDirectories public org.gradle.api.file.FileCollection getDynamicOutputDirectories()
@Input public java.util.Map<java.lang.String,java.lang.Object> getParameters()
public void source(java.lang.Object pPath)
pPath - An object that resolves to a file or directory. See the documentation of
org.gradle.api.Project::file() for the possible types that can be
resolved.java.lang.NullPointerException - if pPath is null.public void sources(java.lang.Object... pPaths)
pPaths - An array of objects that resolve to files and/or directories. See the
documentation of org.gradle.api.Project::files() for the possible
types that can be resolved.java.lang.NullPointerException - if pPaths is null.public void sources(java.lang.Object pDirectoryPath,
groovy.lang.Closure<?> pConfigClosure)
Closure.pDirectoryPath - An object that resolves to a directory. See the documentation of
org.gradle.api.Project::file() for the possible types that
can be resolved.pConfigClosure - A closure that configures a PatternFilterable.java.lang.NullPointerException - if any of the parameters is null.public void template(java.lang.Object pPath)
pPath - An object that resolves to a file or directory. See the documentation of
org.gradle.api.Project::file() for the possible types that can be
resolved.java.lang.NullPointerException - if pPath is null.public void templates(java.lang.Object... pPaths)
pPaths - An array of objects that resolve to files and/or directories. See the
documentation of org.gradle.api.Project::files() for the possible
types that can be resolved.java.lang.NullPointerException - if pPaths is null.public void templates(java.lang.Object pDirectoryPath,
groovy.lang.Closure<?> pConfigClosure)
Closure.pDirectoryPath - An object that resolves to a directory. See the documentation of
org.gradle.api.Project::file() for the possible types that
can be resolved.pConfigClosure - A closure that configures a PatternFilterable.java.lang.NullPointerException - if any of the parameters is null.public void setOutputFile(java.lang.Object pFilePath)
pFilePath - An object that resolves to a file. See the documentation of
org.gradle.api.Project::file() for the possible types that can be
resolved. Null means no output file.public void setOutputDir(java.lang.Object pDirectoryPath)
pDirectoryPath - An object that resolves to a directory. See the documentation of
org.gradle.api.Project::file() for the possible types that
can be resolved. Null means no output directory.public void outputMapping(groovy.lang.Closure<?> pClosure)
pClosure - The mapping closure.java.lang.NullPointerException - if pClosure is null.public void parameter(java.lang.String pName,
java.lang.Object pValue)
pName - The parameter's name.pValue - The parameter's value.java.lang.NullPointerException - if pName is null.public void parameters(java.util.Map<java.lang.String,java.lang.Object> pParameters)
pParameters - The parameters to add.java.lang.NullPointerException - if pParameters is null.public void dynamicOutputDirectory(java.lang.Object pDirectoryPath)
pDirectoryPath - An object that resolves to a directory. See the documentation of
org.gradle.api.Project::file() for the possible types that
can be resolved.java.lang.NullPointerException - if pDirectoryPath is null.public TransformationSet configure(groovy.lang.Closure<?> pClosure)
Closure.pClosure - The configuration closure.public int transform(java.lang.ClassLoader pTransformerClassLoader)
pTransformerClassLoader - The class loader to load Transformer implementations
with.protected abstract Transformer createTransformer(java.lang.ClassLoader pClassLoader) throws java.lang.ReflectiveOperationException
Transformer instance associated with this transformer set.pClassLoader - The class loader with which to load the Transformer
implementation class.Transformer instance, never null.java.lang.ReflectiveOperationException - if the Transformer implementation class isn't
available or cannot be instantiated.