with FailOnError = "true" PR: 22533 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275162 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"<!--(see <a href="#failonerror">note)--></a></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,13 +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"/> | <p><a name="failonerror"/> | ||||
If you specify <code>failonerror="true"</code> and you do not specify permissions, | 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 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>. | a non zero return code will lead to a <code>BuildException</code>. | ||||
</p> | </p> | ||||
--> | |||||
<p>Settings will be ignored if fork is enabled.</p> | <p>Settings will be ignored if fork is enabled.</p> | ||||
<p><em>since Ant 1.6</em>.</p> | <p><em>since Ant 1.6</em>.</p> | ||||
@@ -180,13 +180,11 @@ public class Java extends Task { | |||||
log("bootclasspath ignored when same JVM is used.", | log("bootclasspath ignored when same JVM is used.", | ||||
Project.MSG_WARN); | Project.MSG_WARN); | ||||
} | } | ||||
/* | |||||
if (perm == null && failOnError == true) { | if (perm == null && failOnError == true) { | ||||
perm = new Permissions(); | |||||
perm = new Permissions(true); | |||||
log("running " + this.cmdl.getClassname() | log("running " + this.cmdl.getClassname() | ||||
+ " with default permissions (exit forbidden)", Project.MSG_VERBOSE); | + " 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); | ||||
} | } | ||||
@@ -86,8 +86,24 @@ public class Permissions { | |||||
private java.security.Permissions granted = null; | private java.security.Permissions granted = null; | ||||
private SecurityManager origSm = null; | private SecurityManager origSm = null; | ||||
private boolean active = false; | private boolean active = false; | ||||
/** | |||||
private boolean delegateToOldSM = false; | |||||
/** | |||||
* default constructor | |||||
*/ | |||||
public Permissions() { | |||||
} | |||||
/** | |||||
* create a new set of permissions | |||||
* @param delegateToOldSM if <code>true</code> the old security manager | |||||
* will be used if the permission has not been explicitly granted or revoked | |||||
* in this instance | |||||
* if false, it behaves like the default constructor | |||||
*/ | |||||
public Permissions(boolean delegateToOldSM) { | |||||
this.delegateToOldSM = delegateToOldSM; | |||||
} | |||||
/** | |||||
* Adds a permission to be granted. | * Adds a permission to be granted. | ||||
* @param perm The Permissions.Permission to be granted. | * @param perm The Permissions.Permission to be granted. | ||||
*/ | */ | ||||
@@ -194,20 +210,43 @@ public class Permissions { | |||||
* The central point in checking permissions. | * The central point in checking permissions. | ||||
* Overridden from java.lang.SecurityManager | * Overridden from java.lang.SecurityManager | ||||
* | * | ||||
* @parem perm The permission requested. | |||||
* @param perm The permission requested. | |||||
*/ | */ | ||||
public void checkPermission(java.security.Permission perm) { | public void checkPermission(java.security.Permission perm) { | ||||
if (active) { | if (active) { | ||||
if (!granted.implies(perm)) { | |||||
throw new SecurityException("Permission " + perm +" was not granted."); | |||||
} | |||||
for (Iterator i = revokedPermissions.listIterator(); i.hasNext();) { | |||||
if (((Permissions.Permission)i.next()).matches(perm)) { | |||||
throw new SecurityException("Permission " + perm +" was revoked."); | |||||
if (delegateToOldSM && !perm.getName().equals("exitVM")) { | |||||
boolean permOK = false; | |||||
if (granted.implies(perm)) { | |||||
permOK = true; | |||||
} | } | ||||
checkRevoked(perm); | |||||
/* | |||||
if the permission was not explicitly granted or revoked | |||||
the original security manager will do its work | |||||
*/ | |||||
if (!permOK && origSm != null) { | |||||
origSm.checkPermission(perm); | |||||
} | |||||
} else { | |||||
if (!granted.implies(perm)) { | |||||
throw new SecurityException("Permission " + perm + " was not granted."); | |||||
} | |||||
checkRevoked(perm); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* throws an exception if this permission is revoked | |||||
* @param perm the permission being checked | |||||
*/ | |||||
private void checkRevoked(java.security.Permission perm) { | |||||
for (Iterator i = revokedPermissions.listIterator(); i.hasNext();) { | |||||
if (((Permissions.Permission)i.next()).matches(perm)) { | |||||
throw new SecurityException("Permission " + perm + " was revoked."); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
/** Represents a permission. */ | /** Represents a permission. */ | ||||
@@ -279,7 +318,7 @@ public class Permissions { | |||||
if (name != null) { | if (name != null) { | ||||
if (name.endsWith("*")) { | if (name.endsWith("*")) { | ||||
if (!perm.getName().startsWith(name.substring(0,name.length()-1))) { | |||||
if (!perm.getName().startsWith(name.substring(0, name.length() - 1))) { | |||||
return false; | return false; | ||||
} | } | ||||
} else { | } else { | ||||
@@ -304,7 +343,7 @@ public class Permissions { | |||||
/** | /** | ||||
* Parses the actions into a set of separate strings. | * Parses the actions into a set of separate strings. | ||||
* @param action The actions to be parsed. | |||||
* @param actions The actions to be parsed. | |||||
*/ | */ | ||||
private Set parseActions(String actions) { | private Set parseActions(String actions) { | ||||
Set result = new HashSet(); | Set result = new HashSet(); | ||||
@@ -317,9 +356,12 @@ public class Permissions { | |||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
/** | |||||
* get a string description of the permissions | |||||
* @return string description of the permissions | |||||
*/ | |||||
public String toString() { | public String toString() { | ||||
return ("Permission: " + className + " (\""+name+"\", \""+actions+"\")"); | |||||
return ("Permission: " + className + " (\"" + name + "\", \"" + actions + "\")"); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -195,7 +195,7 @@ public class JavaTest extends BuildFileTest { | |||||
executeTarget("testResultPropertyNonZeroNoFork"); | executeTarget("testResultPropertyNonZeroNoFork"); | ||||
assertEquals("-1",project.getProperty("exitcode")); | assertEquals("-1",project.getProperty("exitcode")); | ||||
} | } | ||||
/* | |||||
public void testRunFailWithFailOnError() { | public void testRunFailWithFailOnError() { | ||||
expectBuildExceptionContaining("testRunFailWithFailOnError", | expectBuildExceptionContaining("testRunFailWithFailOnError", | ||||
"non zero return code", | "non zero return code", | ||||
@@ -205,7 +205,7 @@ public class JavaTest extends BuildFileTest { | |||||
public void testRunSuccessWithFailOnError() { | public void testRunSuccessWithFailOnError() { | ||||
executeTarget("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()); | ||||