Java Mailing List Archive

http://www.ant-tasks.com/

Home » Ant Users List »

parameterizing the "error" attribute of an exec task

Michael Bolin

2010-02-28


Author LoginPost Reply
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="@(protected)}"
       error="@(protected)}"
       logError="true">
    <arg value="${calcdeps.py}" />
    <arg line='--output_file="@(protected)}"' />
    <extrapaths />
    <arg line='-p "${closure-library.dir}"' />
    <arg line="-o @{outputmode}" />
    <arg line='-c "${closure-compiler.jar}"' />
    <arg line='-f "--compilation_level=@(protected)}"' />
    <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
©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.