ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scot P. Floess" <flo...@mindspring.com>
Subject Re: How to set a property to the modification time of a file
Date Mon, 28 Jan 2008 02:23:36 GMT
Marek:

I just quickly looked through the Ant docs to see if something jumped 
out - I didn't readily see anything.

However, perhaps you could use beanshell or some other scripting 
technique?  For example,

    <scriptdef
        name        = "compute-file-modification-date"
        language    = "beanshell"
        description = "Store the file modification date in @{property}."
        uri         = "http://keros.sourceforge.net/keros-environment" >

        <classpath>
            <path  refid = "keros.LIB_PATH_REF"/>
        </classpath>

        <attribute  name = "file"/>
        <attribute  name = "property"/>
        <attribute  name = "format"/>

        <![CDATA[
            java.io.File file = new java.io.File ( attributes.get ( 
"file" ) );

            java.lang.String fileValue;

            if ( file.exists () )
            {
                String format = attributes.get ( "format" );

                java.text.SimpleDateFormat simpleDateFormat;

                if ( format != null )
                {
                    simpleDateFormat = new java.text.SimpleDateFormat ( 
format );
                }
                else
                {
                    simpleDateFormat = new java.text.SimpleDateFormat ();
                }

                fileValue = simpleDateFormat.format ( new java.util.Date 
( file.lastModified () ) );
            }
            else
            {
                fileValue = "";
            }

            project.setProperty ( attributes.get ( "property" ), 
fileValue );
        ]]>
    </scriptdef>

Sorry, your posting got me to thinking...so I am adding this 
functionality to my open source project :)

Kruszewski Marek wrote:
> How to set in an ant-task a property to the modification time of a file?
>
> - Marek
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>   

-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate   http://sourceforge.net/projects/jplate
Chief Architect JavaPIM  http://sourceforge.net/projects/javapim

Architect Keros          http://sourceforge.net/projects/keros


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message