FileDocCategorySizeDatePackage
Tstamp.javaAPI DocApache Ant 1.7012029Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

Tstamp

public class Tstamp extends org.apache.tools.ant.Task
Sets properties to the current time, or offsets from the current time. The default properties are TSTAMP, DSTAMP and TODAY;
since
Ant 1.1
ant.task
category="utility"

Fields Summary
private Vector
customFormats
private String
prefix
Constructors Summary
Methods Summary
public org.apache.tools.ant.taskdefs.Tstamp$CustomFormatcreateFormat()
create a custom format with the current prefix.

return
a ready to fill-in format

        CustomFormat cts = new CustomFormat();
        customFormats.addElement(cts);
        return cts;
    
public voidexecute()
create the timestamps. Custom ones are done before the standard ones, to get their retaliation in early.

throws
BuildException on error.

        try {
            Date d = new Date();

            Enumeration i = customFormats.elements();
            while (i.hasMoreElements()) {
                CustomFormat cts = (CustomFormat) i.nextElement();
                cts.execute(getProject(), d, getLocation());
            }

            SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd");
            setProperty("DSTAMP", dstamp.format(d));

            SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm");
            setProperty("TSTAMP", tstamp.format(d));

            SimpleDateFormat today
                = new SimpleDateFormat ("MMMM d yyyy", Locale.US);
            setProperty("TODAY", today.format(d));

        } catch (Exception e) {
            throw new BuildException(e);
        }
    
public voidsetPrefix(java.lang.String prefix)
Set a prefix for the properties. If the prefix does not end with a "." one is automatically added.

param
prefix the prefix to use.
since
Ant 1.5


                                     
        
        this.prefix = prefix;
        if (!this.prefix.endsWith(".")) {
            this.prefix += ".";
        }
    
private voidsetProperty(java.lang.String name, java.lang.String value)
helper that encapsulates prefix logic and property setting policy (i.e. we use setNewProperty instead of setProperty).

        getProject().setNewProperty(prefix + name, value);