public class AntTask
extends org.apache.tools.ant.Task
Implements the following features:
To use this task, add this to your ANT build script:
<taskdef
classpath="path/to/zz-patch-x.y.z-jar-with-dependencies.jar"
resource="antlib.xml"
/>
Modifier and Type | Class and Description |
---|---|
static class |
AntTask.AddElement
Configures an "add" operation, i.e. an entry that is added to an archive.
|
static class |
AntTask.Element_path
A predicate that determines whether a path is applicable by matching it with a glob.
|
static class |
AntTask.Element_path2
A glob that implements renaming of a path.
|
static class |
AntTask.PatchElement
Configures a patch, i.e. the transformation of contents by applying a "DIFF document" to the input.
|
static class |
AntTask.SubstituteElement
Configures a substitution, i.e. the transformation of contents by finding pattern matches and replacing them
with a replacement string.
|
static class |
AntTask.TextElement |
Constructor and Description |
---|
AntTask() |
Modifier and Type | Method and Description |
---|---|
void |
addConfigured(org.apache.tools.ant.types.ResourceCollection value)
Adds another set of resources (
<fileset> , <path> , ...) that will be patched. |
void |
addConfiguredAdd(AntTask.AddElement element)
Configures that an entry be added to all archives that match the path pattern.
|
void |
addConfiguredPatch(AntTask.PatchElement element)
Configures a transformation by applying a DIFF document.
|
void |
addConfiguredRemove(AntTask.Element_path element)
Configures that files/entries that match the
name be deleted/removed. |
void |
addConfiguredRename(AntTask.Element_path2 element)
Configures that files/entries that match the
name be renamed. |
void |
addConfiguredSubstitute(AntTask.SubstituteElement element)
Configures that lines that match the
AntTask.SubstituteElement.setRegex(String) within files/entries that match
the AntTask.Element_path.setPath(String) glob pattern be replaced with the AntTask.SubstituteElement.setReplacement(String) string. |
void |
addConfiguredUpdate(AntTask.Element_path element)
Configures that the contents of files/entries that match the
name glob pattern be replaced with the
contents of the given "update file". |
void |
execute() |
void |
setFile(File file)
Configures a file to be transformed; either in-place, or, iff
tofile=... or todir=... is
configured, out-of-place. |
void |
setKeepOriginals(boolean value)
Whether to keep backup copies of files/entries that are modified or removed, renamed to
". |
void |
setLookInto(String value)
Look into compressed and archive contents if the format and the path match the given glob.
|
void |
setMode(de.unkrig.commons.file.filetransformation.FileTransformer.Mode mode)
Configures how the files are processed.
|
void |
setTodir(File existingDir)
Configures the directory for the output file created from
file=... and/or the resource collection
subelements. |
void |
setTofile(File file)
Configures the output file for the input file specified through
file=... . |
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
public void setMode(de.unkrig.commons.file.filetransformation.FileTransformer.Mode mode)
TRANSFORM
CHECK
CHECK_AND_TRANSFORM
public void setKeepOriginals(boolean value)
".
file-name.orig"
.public void setFile(File file)
tofile=...
or todir=...
is
configured, out-of-place.public void setTofile(File file)
file=...
. The default is to patch the
input file in-place.public void setTodir(File existingDir)
file=...
and/or the resource collection
subelements.public void setLookInto(String value)
Supported archive formats are: [cpio, zip, dump, jar, tar, ar, arj, 7z].
Supported compression formats are: [snappy-raw, bzip2, gz, snappy-framed, pack200, xz, z, lzma].
The default is too look into any recognized archive or compressed contents.
Example:
lookInto="zip:**,tar:**,gz:**"
public void addConfigured(org.apache.tools.ant.types.ResourceCollection value)
<fileset>
, <path>
, ...) that will be patched.public void addConfiguredUpdate(AntTask.Element_path element)
name
glob pattern be replaced with the
contents of the given "update file".public void addConfiguredSubstitute(AntTask.SubstituteElement element) throws de.unkrig.commons.text.parser.ParseException
AntTask.SubstituteElement.setRegex(String)
within files/entries that match
the AntTask.Element_path.setPath(String)
glob pattern be replaced with the AntTask.SubstituteElement.setReplacement(String)
string.
Alternatively, the regex and the replacement can be configured with AntTask.SubstituteElement.addConfiguredRegex(AntTask.TextElement)
and AntTask.SubstituteElement.addConfiguredReplacement(AntTask.TextElement)
subelements; one advantage of subelements is
that they can contain <![CDATA[...]]>
sections where you don't have to SGML-escape special characters.
You are not limited to line-wise pattern matching, but be careful with using greedy quantifiers, because these may require that the entire contents of each file needs to be loaded into memory.
de.unkrig.commons.text.parser.ParseException
public void addConfiguredPatch(AntTask.PatchElement element) throws IOException, de.unkrig.commons.text.StringStream.UnexpectedElementException
A DIFF document generally contains differentials for one or more files. Each differential comprises a sequence of "hunks". Traditional format, context format and unified format are supported.
If the DIFF document describes more than on differential, then all but the first differential are ignored. The file name information in the differential is also ignored.
de.unkrig.commons.text.StringStream.UnexpectedElementException
- The patch file does not contain a valid DIFF documentIOException
public void addConfiguredRemove(AntTask.Element_path element)
name
be deleted/removed.public void addConfiguredRename(AntTask.Element_path2 element)
name
be renamed.public void addConfiguredAdd(AntTask.AddElement element)
public void execute() throws org.apache.tools.ant.BuildException
execute
in class org.apache.tools.ant.Task
org.apache.tools.ant.BuildException
Copyright © 2022 Arno Unkrig. All rights reserved.