Browse Source

Set default permissions appropriate to fail the builds when failonerror is

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-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
1de5995d90
4 changed files with 39 additions and 2 deletions
  1. +6
    -1
      docs/manual/CoreTasks/java.html
  2. +16
    -0
      src/etc/testcases/taskdefs/java.xml
  3. +8
    -1
      src/main/org/apache/tools/ant/taskdefs/Java.java
  4. +9
    -0
      src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java

+ 6
- 1
docs/manual/CoreTasks/java.html View File

@@ -88,7 +88,7 @@ JVM.
<tr>
<td valign="top">failonerror</td>
<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>
</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
been revoked) the System.exit() call will be intercepted
and treated like indicated in <i>failonerror</i>.</p>
<p><a name="failonerror"/>
If you specify <code>failonerror=&quot;true&quot;</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>



+ 16
- 0
src/etc/testcases/taskdefs/java.xml View File

@@ -139,7 +139,23 @@
<echo message="exitcode = ${exitcode}"/>
</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">
<java classname="${spawnapp}" fork="true" spawn="true" classpath="${tests-classpath.value}">


+ 8
- 1
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -97,7 +97,7 @@ public class Java extends Task {
private Long timeout = null;
private Redirector redirector = new Redirector(this);
private String resultProperty;
private Permissions perm;
private Permissions perm = null;
private boolean spawn = false;
private boolean incompatibleWithSpawn = false;
@@ -108,6 +108,7 @@ public class Java extends Task {
*/
public void execute() throws BuildException {
File savedDir = dir;
Permissions savedPermissions = perm;

int err = -1;
try {
@@ -122,6 +123,7 @@ public class Java extends Task {
maybeSetResultPropertyValue(err);
} finally {
dir = savedDir;
perm = savedPermissions;
}
}

@@ -179,6 +181,11 @@ public class Java extends Task {
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(),
Project.MSG_VERBOSE);
}


+ 9
- 0
src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java View File

@@ -196,6 +196,15 @@ public class JavaTest extends BuildFileTest {
assertEquals("-1",project.getProperty("exitcode"));
}

public void testRunFailWithFailOnError() {
expectBuildExceptionContaining("testRunFailWithFailOnError",
"non zero return code",
"Java returned:");
}

public void testRunSuccessWithFailOnError() {
executeTarget("testRunSuccessWithFailOnError");
}
public void testSpawn() {
FileUtils fileutils = FileUtils.newFileUtils();
File logFile = fileutils.createTempFile("spawn","log", project.getBaseDir());


Loading…
Cancel
Save