ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject Problem with <macrodef> + <script language="javascript"> on Windo ws
Date Mon, 08 Mar 2004 21:59:26 GMT
I thought the following would work:

    <!-- Gets the last modified date/time for a given file -->
    <macrodef name="last-modified">
      <attribute name="property" />
      <attribute name="file" />
      <sequential>
        <script language="javascript">
          file = project.resolveFile("@{file}");
          project.setNewProperty("@{property}", file.lastModified());
        </script>
      </sequential>
    </macrodef>

But it doesn't on Windows when used from within another <macrodef>:

    <macrodef name="update-module-help">
      <attribute name="name" />
      <sequential>
        <property name="@{name}.dest"
                  location="${helpzips}/com_lgc_@{name}_help.zip" />

        <!-- Get the timestamp BEFORE <get> -->
        <last-modified property="@{name}.ttprev" file="${@{name}.dest}" />

        <!-- Possibly get a new updated help ZIP file -->
        <get
src="${help.server}/@{name}_help/latest/com_lgc_@{name}_help.zip"
             dest="${helpzips}/com_lgc_@{name}_help.zip"
             usetimestamp="true"/>

        <!-- Get the timestamp AFTER <get> -->
        <last-modified property="@{name}.ttnext" file="${@{name}.dest}" />

        <echo>@{name}.dest   = ${@{name}.dest}</echo>
        <echo>@{name}.ttprev = ${@{name}.ttprev}</echo>
        <echo>@{name}.ttnext = ${@{name}.ttnext}</echo>

        <!-- Unzip only if the local help ZIP file changed -->
        <if>
          <not>
            <equals arg1="${@{name}.ttprev}" arg2="${@{name}.ttnext}" />
          </not>
          <then>
            <unzip src="${helpzips}/com_lgc_@{name}_help.zip"
                   dest="${SetupImage}/Help" />
          </then>
          <else>
            <echo>Not modified - so not unzipped</echo>
          </else>
        </if>
      </sequential>
    </macrodef>

In the <last-modified> macro, when called from the other macro,
the file attribute has lost of its back-slashes '\'...

The attribute string somehow is interpreted, and all back-slashes
are meant to be escape characters, which are thus removed!

Very weird!!!

I could turn around the issue, thankfully, be using an intermediate
property. Not very pretty, and pollutes the caller's property-namespace,
but at least it works! Here's the turn around:

    <!-- Gets the last modified date/time for a given file -->
    <macrodef name="last-modified">
      <attribute name="property" />
      <attribute name="file" />
      <sequential>
        <property name="@{property}.file" location="@{file}" />
        <script language="javascript">
          filename = project.getProperty("@{property}.file");
          file = project.resolveFile(filename);
          project.setNewProperty("@{property}", file.lastModified());
        </script>
      </sequential>
    </macrodef>

If that hadn't worked, I would have had to go with a Java tasks. --DD

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


Mime
View raw message