ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Bolin <bolinf...@gmail.com>
Subject parameterizing the "error" attribute of an exec task
Date Sun, 28 Feb 2010 18:45:38 GMT
I am creating a macrodef that calls <exec>. I want to make it possible to
parameterize the "error" attribute by doing something like:

  <macrodef name="closure-compile-with-error">
    <attribute name="outputfile" />
    <attribute name="compilationlevel" default="SIMPLE_OPTIMIZATIONS" />
    <attribute name="outputmode" default="compiled" />
    <attribute name="failonerror" default="true" />
    <attribute name="error" default="" />
    <element name="extraflags" optional="yes" />
    <element name="extrapaths" optional="yes" />
    <sequential>
      <exec executable="python"
            failonerror="@{failonerror}"
            error="@{error}"
            logError="true">
        <arg value="${calcdeps.py}" />
        <arg line='--output_file="@{outputfile}"' />
        <extrapaths />
        <arg line='-p "${closure-library.dir}"' />
        <arg line="-o @{outputmode}" />
        <arg line='-c "${closure-compiler.jar}"' />
        <arg line='-f "--compilation_level=@{compilationlevel}"' />
        <extraflags />
      </exec>
    </sequential>
  </macrodef>

The problem is that by defining an optional attribute:

    <attribute name="error" default="" />

I have to give it a default value, which in this case becomes empty string.
If the caller of <closure-compiler-with-error> does not want to specify
"error", then <exec> ends up trying to write stderr to the current
directory, which fails because it is a directory and not a file. Ideally,
the default value would be "/dev/null" or something like that, but I also
want this to work on Windows.

It seems that this is a more general problem where I only want to include
certain options if they are specified. As you can see, I created
<extraflags> and <extrapaths> to handle that problem in general, but I do
not believe I can do something similar for <exec>, can I?

Thank you,
Michael

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message