Tutorial :Capturing Ant task output



Question:

Is it possible to capture the warnings that Javadoc prints when run via the javadoc Ant task? I don't see an output attribute such as the one in the task. There seem to be warnings that Checkstyle just isn't catching and it'd be nice to snag that output in a file.

Seems strange this wouldn't be capturable, hopefully I'm missing something obvious.

~*~*~*~ EDIT (answer below) ~*~*~*~

It would appear the Ant <record> task is exactly what I was looking for. See the Ant docs.

<target name="generate.docs">      <record name="javadoc.log" action="start"/>      <javadoc ... />      <record name="javadoc.log" action="stop"/>  <target/>  


Solution:1

It looks like this is possible using the <exec> tag (reference here)... it would probably be a royal pain, but it might be possible to exec the javadoc executable and reconstruct the command arguments necessary to generate the javadoc. As a great big honking strike against, though, it appears that only uses your natural shell redirect, so building on both Win32 and Linux would require some special-case mojo.

It may be worth it to write your own task to do the job; either the <redirect> tag as Roboprog has mentioned above, or extending the Javadoc task...


Solution:2

I assume the previous redirection answer was down voted due to unstated requirement to do this every time via the build.xml script commands.

Yep. The feature does not seem to be there in the task. A better question might be: Is there a task / tag in Ant that will redirect ALL output from ANY nested tags? Such a task/tag would save System.out and/or System.err, set them to create or append to a file, then restore them at the end of the block.

Something like:

<redirect file='foo.txt' append='true'>    <anytag you='want' />  </redirect>  


Solution:3

You can execute javadoc as a Java class with the com.sun.tools.javadoc.Main class, calling the execute method (it is in the tools.jar included in the JDK), so you could wrap a java class that you call from the Ant java task, which allows redirection of output. you will have to reconstruct the javadoc command line arguments yourself, instead of having the niceties of the Ant task, but it should work.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »