Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically retrieve returncode from ant-task
    primarykey
    data
    text
    <p>Had a problem with retrieving returncode programmatically...following files. (did cut out some company-specific things). I got 2 files, one general file with a java-task in it and a specific file, which defines sime properties and a ant-task. </p> <p>How can i get the build.rc in my executing java-test? The echo-message at the end of the file delivers the actual return-code, but the p.getProperty("build.rc") returns null. </p> <p><strong>specific.build.xml</strong> </p> <pre><code>&lt;project basedir="../../../.." name="run-joblauncher"&gt; &lt;property name="prop1" value="valProp1" /&gt; &lt;ant antfile="./dev/script/general.xml" dir="${basedir}" target="RUN-MYCLASS" inheritAll="true"/&gt; &lt;/project&gt; </code></pre> <p><strong>general.xml</strong></p> <pre><code>&lt;project basedir="../../../.." default="RUN-MYCLASS" name="run-specifictest"&gt; &lt;target name="RUN-MYCLASS"&gt; &lt;property name="returnCode" value="99"/&gt; &lt;target name="RUN-MYCLASS"&gt; &lt;java classname="my.company.class" fork="true" resultproperty="build.rc" failonerror="false"&gt; &lt;arg value="${workdir}"/&gt; &lt;classpath&gt; &lt;pathelement path="${java.class.path}"/&gt; &lt;/classpath&gt; &lt;/java&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p><strong>myJunitTest.java</strong></p> <pre><code>public class TestAntScripts extends TestCase { public void testMyAnt() throws IOException { File dir = new File("pathToSpecific.xml"); Project p = null; try { File buildFile = new File(buildFileName); p = new Project(); DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); consoleLogger.setMessageOutputLevel(Project.MSG_INFO); p.addBuildListener(consoleLogger); p.addBuildListener(new CustomBuildListener(this)); p.fireBuildStarted(); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, buildFile); p.fireBuildFinished(null); } catch (BuildException e) { p.fireBuildFinished(e); e.printStackTrace(); System.err.println("AntRunner for buildfile " + buildFileName + " failed with Exception "); } String rc = p.getProperty("returnCode"); assertEquals(0, Integer.parseInt(rc)); } public void taskFinished(String buildRc) { assertEquals(0, buildRc); } } </code></pre> <p><strong>EDIT:</strong> </p> <p>how's the approach to assign a value to a already defined property? defined a var returnCode outside the java-target and try to assign the value like <code>&lt;var name="returnCode" value="${build.rc}"/&gt;</code> inside the target. not runnin'..</p> <p><strong>EDIT2:</strong> added a custom BuildListener and grabbing the build.rc over there. </p> <pre><code> @Override public void targetFinished(BuildEvent event) { if (event.getTarget().getName().trim().equalsIgnoreCase("RUN-MYCLASS")) { String buildRc = event.getTarget().getProject().getProperty("build.rc"); tester.taskFinished(buildRc, jobname); } </code></pre> <p>tester is my JUnit-Test, which will be set in Constructor.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload