You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Kruszewski Marek <ma...@dialogika.de> on 2008/01/27 22:14:10 UTC

How to set a property to the modification time of a file

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


Re: How to set a property to the modification time of a file

Posted by "Scot P. Floess" <fl...@mindspring.com>.
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


Re: How to set a property to the modification time of a file

Posted by Dale Anson <da...@grafidog.com>.
See the FileUtils task in the Antelope project:

http://antelope.tigris.org/nonav/docs/manual/bk03ch12.html

Hope this helps,

Dale


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

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