Ant-contrib.unkrig.de

From unkrig.de
Jump to navigation Jump to search

Abstract

Some contributions to APACHE ANT, e.g. the <swingDialog> task which significantly enhances ANT's <input> task.

Tasks

<follow>

Waits until a file grows.

The name refers to the 'follow mode' of the LESS utility (or the 'follow' option of the TAIL command), which does more or less the same.

Attributes
file="..." (mandatory)
The file to monitor.
outputFile="..." (optional)
Write the additional data to the named file.
stdout="true" (optional)
Write the additional data to STDOUT.
stderr="true" (optional)
Write the additional data to STDERR.
encoding="..." (optional)
If a <filterchain> is configured, then the data from the file is DECODED with this encoding, then fed through the <filterchain>, and then ENCODED again. Defaults to the system default encoding.
periodTime="..." (optional)
The period in milliseconds to check the file's size. The default is 500.
timeout="..." (optional)
The time (in seconds) when to give up if the file size does not change. The default is 300 (5 minutes); a value of '0' indicates to wait indefinitely.
failOnTimeout="false" (optional)
Whether the execution of the current target should fail or not if the file size does not change. The default is to fail on timeout.
Subelements
<filterchain>
If given, then the data that is added to the file is fed through this <filterchain>, and the task will complete only when the <filterchain> produces some output. This is useful to check if a specific line of text was appended to the file.

<jsonProperty>

Parses a JSON document into a set of properties, in analogy with the standard ANT <xmlproperty> task.

Attributes
file="..." (mandatory)
The file from which to read the JSON document.
encoding="..." (optional)
The encoding of the JSON document. The default is 'UTF-8'.
name="..." (mandatory)
The prefix of the names of the properties to set.

<nslookup>

Resolves a host name or IP address.

Attributes
host="..." (mandatory)
Either a machine name, such as "java.sun.com", or a textual representation of its IP address. For host specified in literal IPv6 address, either the form defined in RFC 2732 or the literal IPv6 address format defined in RFC 2373 is accepted. IPv6 scoped addresses are also supported.
addressProperty="..." (optional)
The IP address of the host is determined and stored in the given property.
addressesProperty="..." (optional)
The IP addresses of the host are determined, based on the configured name service on the system, and stored in the given property, separated by commas.
hostName="..." (optional)
Performs a reverse name lookup, based on the system configured name lookup service, and the result is stored in the given property.
canonicalHostName="..." (optional)
Performs a reverse name lookup, based on the system configured name lookup service, and the result is stored in the given property.
failOnError="false"
Whether or not the execution of the current target should fail if the host name or address cannot resolved. The default is "true".

<setAuthenticator>

This task configures the authentication for all following java.net.URLConnections, e.g. those created by the <urlConnection> task. It does this by matching a request against the configured <credentials> subelements and using password authentication as configured by the first matching <credentials> element.

Subelements
<credentials requestingHost="localhost" requestingSite="127\.0\.0\.1" requestingPort="80" requestingProtocol="http" requestingPrompt="The Realm" requestingScheme="http" requestingUrl="http://acme\.com" requestorType="SERVER-or-PROXY" userName="..." password="..." /> (zero or more)
If the request matches all the requesting... and requestor... attributes (all of which are regular expressions), then
  • If both userName="..." and password="..." are given, then these determine the PasswordAuthentication
  • If none of userName="..." and password="..." are given, then the user is prompted to enter the user name and password
  • If only one of userName="..." and password="..." is given, then it is displayed to the user, and the user is prompted to enter the other

<setCookieHandler>

Enables or disables cookie handling for Java's java.net.HttpURLConnection, including the <urlConnection> task.

Attributes
enable="false"
Whether to enable or disable cookie handling. The default is true. Initially, cookie handling is disabled.

<swingDialog>

Pops up a highly configurable dialog and invites the user to fill in form fields.

This task will fail iff the CANCEL button is pressed or the dialog is closed, except if <ifCancelTask>'s (or <ifClosedTask>'s, respectively) are configured.

Swing-dialog.png

Attributes
title="..." (optional)
The text to be displayed in the title bar of the dialog.
optionType="..." (optional)
DEFAULT (an 'OK' button), YES_NO, YES_NO_CANCEL, OK_CANCEL (the default): Determines which buttons are displayed in the dialog.
messageType="..." (optional)
ERROR, INFORMATION, WARNING, QUESTION, PLAIN (the default): If not set to PLAIN, then a respective icon is displayed in the dialog.
property="..." (optional)
The named property will be set to YES, NO, CANCEL, OK or CLOSED when the task completes.
Subelements
<label text="..." /> (zero or more)
Displays the given text.
<text property="..." defaultValue="..." /> (zero or more)
A one-line text input field with an (optional) default value. On return, the named property is set to the text of the field. Iff secure="true" is given, then characters entered into the field are not echoed.
<checkbox text="..." property="..." preselected="true" /> (zero or more)
A checkbox with a label. On return, the named property is set to true iff the box is checked.
<list selectionMode="SINGLE SINGLE_INTERVAL MULTIPLE_INTERVAL" values="..." defaultValues="..." delimiters="..." property="..." /> (zero or more)
A list for selection of zero, one or more values as configured by values="..." and delimiters="...". On completion, the named property="..." is set from the selected values, concatenated with the first of the delimiter="..." characters. The default delimiter is ",".
<ifYes>, <ifNo>, <ifCancel>, <ifOk>, <ifClosed> (at most one of each)
These can have task subelements, which are executed iff the respective dialog button is pressed (<ifYes>, <ifNo>, <ifCancel>, <ifOk>) or the dialog is closed (<ifClosed>).

<urlConnection>

Connects to a resource and writes data to it and/or reads data from it.

Attributes
url="...", allowUserInteraction="...", connectTimeout="...", readTimeout="..." defaultUseCaches="...", ifModifiedSince="...", useCaches="..." (all optional)
The various parameters of the java.net.URLConnection.
httpChunkLength="...", httpContentLength="...", httpFollowRedirects="true", httpRequestMethod="..." (all optional)
Various pararmeters that apply iff the URLConnection is an java.net.HttpURLConnection.
httpFollowRedirects2="true" (optional)
Implements an enhanced redirect processing which, specifically, allows for redirection between different protocols, e.g. from HTTP to HTTPS and vice versa.
Subelements
<url> (zero or one)
An alternative to the url="..." attribute described above; configures the URL by its components.
Attributes
context="..." (optional)
The 'base URL' for a relative URL (an alternative for the <context> element described below).
protocol="..." (optional)
The 'protocol' component of the URL; defaults to http.
host="..." (optional)
The 'host' component of the URL; defaults to localhost.
port="..." (optional)
The 'port' component of the URL.
userInfo="..." (optional)
The 'userinfo' component of the URL, like user [ ':' password ].
path="..." (optional)
The 'path' component of the URL; defaults to /.
query="..." (optional)
The 'query' component of the URL, is appended to the URL with '?'.
ref="..." (optional)
The 'ref' component of the URL, is appended to the URL with '#'.
Sub-subelements
<formField name="..." value="..."> (zero or more)
Are combined with the query="..." attribute to pose the URL's query string.
<context> (zero or one)
The 'base URL' for a relative URL (an alternative for the context="..." attribute described above); attributes and subelements are identical with the <url> element.
<requestProperty name="..." value="..." /> (zero or more)
Adds one property to the request; for HTTP connections these are mapped to request headers.
<output value="..." encoding="..." file="..." /> (zero or one)
If given, then data is written to the resource. That data is obtained from (A) the value="..." and encoding="..." attributes, (B) the named file="...", (C) one or more <multipartFormData name="..." fileName="..." value="..." file="..." /> subelements, or (D) one or more <applicationXWwwFormUrlencoded name="..." value="..." /> subelements.
<input file="..." /> (zero or one)
If given, then data is read from the resource and written to the named file="...".
<input><jsonAsProperties name="..." /></input> (zero or one)
If given, then data is read from the resource and parsed as a JSON document (see <jsonProperty>).
<input /> (zero or one)
If given, then data is read from the resource and written to STDOUT.

Resource Collections

<resourceCollectionDelta>

Selects the subset of resources that was added, deleted or modified since the last check.

Attributes
stateFile="..."
Where to store state information. If this file is deleted, then all resources appear as 'added'. The default is '$HOME/.resource-collection.delta.properties'.
added="true"
Whether the files that were ADDED to the resource collection subelement since the last invocation should be returned.
deleted="true"
Whether the files that were DELETED from the resource collection subelement since the last invocation should be returned.
modified="true"
Whether the files in the resource collection subelement that were MODIFIED since the last invocation should be returned.
Subelements
Resource collection (<fileset>, ...)
The resources to monitor.

Filter Readers

<progress>

Prints dots (".") to STDERR as data is read through it. This implements a kind of 'progress monitoring' for slow tasks that read some data.

Attributes
bytesPerTick="..."
That many bytes must be processed before another dot is printed. The default is '1024'.
exponential="false"
If true, then the initial dot printing frequency will degrade so that no more than 80 dots will ever be printed. The default is true.

Download and installation

The JAR file can be downloaded from http://ant-contrib.unkrig.de/download/.

To make the contributions available in your ANT scripts, write

<taskdef resource="de/unkrig/antcontrib/ant.xml" classpath="lib/de.unkrig.ant-contrib.jar" />

, or, if you put the JAR file on ANT's default classpath, just

<taskdef resource="de/unkrig/antcontrib/ant.xml" />

Source code

The source code is available in the SUBVERSION repository. The repository URL is

https://svn.code.sf.net/p/loggifier/code

License

ANT-CONTRIB is published under the "New BSD License".