true (and fork false) and no other permissions were set. Suggestion of Steve Loughran. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275153 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -88,7 +88,7 @@ JVM. | |||||
| <tr> | <tr> | ||||
| <td valign="top">failonerror</td> | <td valign="top">failonerror</td> | ||||
| <td valign="top">Stop the buildprocess if the command exits with a | <td valign="top">Stop the buildprocess if the command exits with a | ||||
| returncode other than 0. Default is "false"</td> | |||||
| returncode other than 0. Default is "false"(see <a href="#failonerror">note</a>)</td> | |||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| @@ -220,6 +220,11 @@ see <a href="../CoreTypes/permissions.html">permissions</a></p> | |||||
| <p>When the permission RuntimePermission exitVM has not been granted (or has | <p>When the permission RuntimePermission exitVM has not been granted (or has | ||||
| been revoked) the System.exit() call will be intercepted | been revoked) the System.exit() call will be intercepted | ||||
| and treated like indicated in <i>failonerror</i>.</p> | and treated like indicated in <i>failonerror</i>.</p> | ||||
| <p><a name="failonerror"/> | |||||
| If you specify <code>failonerror="true"</code> and you do not specify permissions, | |||||
| a set of default permissions will be added to your java invocation making sure that | |||||
| a non zero return code will lead to a <code>BuildException</code>. | |||||
| </p> | |||||
| <p>Settings will be ignored if fork is enabled.</p> | <p>Settings will be ignored if fork is enabled.</p> | ||||
| @@ -139,7 +139,23 @@ | |||||
| <echo message="exitcode = ${exitcode}"/> | <echo message="exitcode = ${exitcode}"/> | ||||
| </target> | </target> | ||||
| <target name="testRunFailWithFailOnError"> | |||||
| <java classname="${app}" | |||||
| classpath="${tests-classpath.value}" | |||||
| failonerror="true" | |||||
| > | |||||
| <arg value="2"/> | |||||
| </java> | |||||
| </target> | |||||
| <target name="testRunSuccessWithFailOnError"> | |||||
| <java classname="${app}" | |||||
| classpath="${tests-classpath.value}" | |||||
| failonerror="true" | |||||
| > | |||||
| <arg value="0"/> | |||||
| </java> | |||||
| </target> | |||||
| <target name="testSpawn"> | <target name="testSpawn"> | ||||
| <java classname="${spawnapp}" fork="true" spawn="true" classpath="${tests-classpath.value}"> | <java classname="${spawnapp}" fork="true" spawn="true" classpath="${tests-classpath.value}"> | ||||
| @@ -97,7 +97,7 @@ public class Java extends Task { | |||||
| private Long timeout = null; | private Long timeout = null; | ||||
| private Redirector redirector = new Redirector(this); | private Redirector redirector = new Redirector(this); | ||||
| private String resultProperty; | private String resultProperty; | ||||
| private Permissions perm; | |||||
| private Permissions perm = null; | |||||
| private boolean spawn = false; | private boolean spawn = false; | ||||
| private boolean incompatibleWithSpawn = false; | private boolean incompatibleWithSpawn = false; | ||||
| @@ -108,6 +108,7 @@ public class Java extends Task { | |||||
| */ | */ | ||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| File savedDir = dir; | File savedDir = dir; | ||||
| Permissions savedPermissions = perm; | |||||
| int err = -1; | int err = -1; | ||||
| try { | try { | ||||
| @@ -122,6 +123,7 @@ public class Java extends Task { | |||||
| maybeSetResultPropertyValue(err); | maybeSetResultPropertyValue(err); | ||||
| } finally { | } finally { | ||||
| dir = savedDir; | dir = savedDir; | ||||
| perm = savedPermissions; | |||||
| } | } | ||||
| } | } | ||||
| @@ -179,6 +181,11 @@ public class Java extends Task { | |||||
| Project.MSG_WARN); | Project.MSG_WARN); | ||||
| } | } | ||||
| if (perm == null && failOnError == true) { | |||||
| perm = new Permissions(); | |||||
| log("running " + this.cmdl.getClassname() | |||||
| + " with default permissions (exit forbidden)", Project.MSG_VERBOSE); | |||||
| } | |||||
| log("Running in same VM " + cmdl.describeJavaCommand(), | log("Running in same VM " + cmdl.describeJavaCommand(), | ||||
| Project.MSG_VERBOSE); | Project.MSG_VERBOSE); | ||||
| } | } | ||||
| @@ -196,6 +196,15 @@ public class JavaTest extends BuildFileTest { | |||||
| assertEquals("-1",project.getProperty("exitcode")); | assertEquals("-1",project.getProperty("exitcode")); | ||||
| } | } | ||||
| public void testRunFailWithFailOnError() { | |||||
| expectBuildExceptionContaining("testRunFailWithFailOnError", | |||||
| "non zero return code", | |||||
| "Java returned:"); | |||||
| } | |||||
| public void testRunSuccessWithFailOnError() { | |||||
| executeTarget("testRunSuccessWithFailOnError"); | |||||
| } | |||||
| public void testSpawn() { | public void testSpawn() { | ||||
| FileUtils fileutils = FileUtils.newFileUtils(); | FileUtils fileutils = FileUtils.newFileUtils(); | ||||
| File logFile = fileutils.createTempFile("spawn","log", project.getBaseDir()); | File logFile = fileutils.createTempFile("spawn","log", project.getBaseDir()); | ||||