I have a macrodef to wrap the <ant> task, just so I can execute it
conditionally. The conditional check is done inside a script. When the
script creates an <ant> task and executes it, the <java> tasks that
have "fork" set to "no" don't get the stdout set properly, so the
output always comes on to console, even though an outputproperty is
set. Here is a sample build file (called t.xml) and a sample Java
program (called Hello.java) to be executed from the build file:
----------cut here---------
<?xml version="1.0" encoding="UTF-8" ?>
<project basedir="." name="scriptant">
<macrodef name="myant">
<attribute name="antfile"/>
<attribute name="target"/>
<attribute name="inheritAll" default="true"/>
<sequential>
<script language="beanshell"><![CDATA[
if (project.getProperty("patch.extant.suppress") == null ||
!project.getProperty("patch.extant.suppress").equals("false")) {
ant = project.createTask("ant");
ant.setAntfile("@{antfile}");
ant.setTarget("@{target}");
inheritAll = "@{inheritAll}".equals("true");
ant.setInheritAll(inheritAll);
ant.execute();
}
]]></script>
</sequential>
</macrodef>
<target name="testexec">
<exec executable="sh.exe" outputproperty="execoutput">
<arg value="-c"/>
<arg value="echo hello"/>
</exec>
<fail>
<condition>
<not>
<equals arg1="${execoutput}" arg2="hello"/>
</not>
</condition>
</fail>
<echo message="output=${execoutput}"/>
</target>
<target name="testjava">
<java classname="Hello" fork="no" outputproperty="javaoutput">
<classpath>
<pathelement location="."/>
</classpath>
</java>
<fail>
<condition>
<not>
<equals arg1="${javaoutput}" arg2="hello"/>
</not>
</condition>
</fail>
<echo message="output=${javaoutput}"/>
</target>
<target name="testmyant">
<myant antfile="t.xml" target="testexec"/>
<myant antfile="t.xml" target="testjava"/>
</target>
</project>
----------cut here---------
----------cut here---------
public class Hello
{
public static void main(String[] args)
{
System.out.println("hello");
}
}
----------cut here---------
Compile the program and execute the "testmyant" target, you can see
that the output comes through the script's stdout. If you directly
execute "testjava" target, it works as expected. I don't know if this
is specific to beanshell, but it should be the responsibility of java
task to make sure the stdout is set correctly, so isn't this a bug?
As a workaround I am replacing the <script> task with the ant-contrib
<if> task, but I really wanted to avoid using the ant-contrib by using
<script> as a generic solution whenever I cross the limits of ant.
<macrodef name="myant">
<attribute name="antfile"/>
<attribute name="target"/>
<attribute name="inheritAll" default="true"/>
<sequential>
<if>
<not>
<isset property="patch.extant.suppress"/>
</not>
<then>
<ant antfile="@{antfile}" target="@{target}"
inheritAll="@{inheritAll}"/>
</then>
</if>
</sequential>
</macrodef>
Thank you,
Hari
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]