Ant-contrib.unkrig.de

From unkrig.de
Revision as of 22:43, 20 November 2013 by Aunkrig (talk | contribs) (→‎Tasks)
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

<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="FTP upload of update site" (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="User ID"/> (zero or more)
Displays the given text.
<text property="ftp.userid" defaultvalue="www.unkrig.de"/> (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="Use passive FTP" property="ftp.passive" defaultvalue="true"/> (zero or more)
A checkbox with a label. On return, the named property is set to 'true' iff the box is checked. Iff 'defaultvalue="true"' is given, then the checkbox is pre-selected.
<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>).

<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.

<setAuthenticator>

This task configures the authentication for all following URLConnections, e.g. those created by <urlConnection>. 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

<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 URLConnection; see the JAVADOC for 'java.net.URLConnection'.
httpChunkLength="...", httpContentLength="..., httpFollowRedirects="...", httpFollowRedirects2="...", httpRequestMethod="..." (all optional)
Various pararmeters that apply iff the URLConnection is an HttpURLConnection. 'httpFollowRedirects2' implements an enhanced redirect processing which, specifically, allows for redirection between different protocol, e.g. from HTTP to HTTPS and vice versa.
Subelements
<url context="..." protocol="..." host="..." port="..." userInfo="..." path="..." query="..." ref="..." /> (zero or one)
An alternative to the 'url="..."' attribute; configures the URL by its components. Missing components default to 'http://localhost/'. Relative URL can be specified by using the 'ref="..."' attribute or the '<context context="..." protocol="..." host="..." port="..." userInfo="..." path="..." query="..." ref="..." />' subelement.
<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. That data is either (A) written to the named 'file="..."', or (B) parsed as configured by the '<jsonAsProperties name="...">' subelement (see <jsonProperty>), or (C) written to STDOUT, if neither 'file="..."' nor '<jsonAsProperties name="...">' are configured.

<setCookieHandler>

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

Attributes
enable="..." (optional)
Whether to enable or disable cookie handling. The default is 'true'. Cookie handling is disabled by default.

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".