antoine 2003/09/01 05:45:07 Modified: docs/manual/CoreTasks java.html src/main/org/apache/tools/ant/taskdefs Java.java src/testcases/org/apache/tools/ant/taskdefs JavaTest.java src/main/org/apache/tools/ant/types Permissions.java Log: Use again Permissions to catch non zero exit statuses when using the Java task with FailOnError = "true" PR: 22533 Revision Changes Path 1.24 +1 -3 ant/docs/manual/CoreTasks/java.html Index: java.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/java.html,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- java.html 29 Aug 2003 13:05:06 -0000 1.23 +++ java.html 1 Sep 2003 12:45:06 -0000 1.24 @@ -88,7 +88,7 @@ <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"<!--(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> </tr> <tr> @@ -220,13 +220,11 @@ <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="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><em>since Ant 1.6</em>.</p> 1.73 +1 -3 ant/src/main/org/apache/tools/ant/taskdefs/Java.java Index: Java.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- Java.java 29 Aug 2003 13:05:06 -0000 1.72 +++ Java.java 1 Sep 2003 12:45:07 -0000 1.73 @@ -180,13 +180,11 @@ log("bootclasspath ignored when same JVM is used.", Project.MSG_WARN); } - /* if (perm == null && failOnError == true) { - perm = new Permissions(); + perm = new Permissions(true); log("running " + this.cmdl.getClassname() + " with default permissions (exit forbidden)", Project.MSG_VERBOSE); } - */ log("Running in same VM " + cmdl.describeJavaCommand(), Project.MSG_VERBOSE); } 1.17 +2 -2 ant/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java Index: JavaTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/JavaTest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- JavaTest.java 29 Aug 2003 13:05:06 -0000 1.16 +++ JavaTest.java 1 Sep 2003 12:45:07 -0000 1.17 @@ -195,7 +195,7 @@ executeTarget("testResultPropertyNonZeroNoFork"); assertEquals("-1",project.getProperty("exitcode")); } - /* + public void testRunFailWithFailOnError() { expectBuildExceptionContaining("testRunFailWithFailOnError", "non zero return code", @@ -205,7 +205,7 @@ public void testRunSuccessWithFailOnError() { executeTarget("testRunSuccessWithFailOnError"); } - */ + public void testSpawn() { FileUtils fileutils = FileUtils.newFileUtils(); File logFile = fileutils.createTempFile("spawn","log", project.getBaseDir()); 1.3 +55 -13 ant/src/main/org/apache/tools/ant/types/Permissions.java Index: Permissions.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Permissions.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Permissions.java 29 Aug 2003 11:10:58 -0000 1.2 +++ Permissions.java 1 Sep 2003 12:45:07 -0000 1.3 @@ -86,8 +86,24 @@ private java.security.Permissions granted = null; private SecurityManager origSm = null; 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. * @param perm The Permissions.Permission to be granted. */ @@ -194,20 +210,43 @@ * The central point in checking permissions. * Overridden from java.lang.SecurityManager * - * @parem perm The permission requested. + * @param perm The permission requested. */ public void checkPermission(java.security.Permission perm) { 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. */ @@ -279,7 +318,7 @@ if (name != null) { 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; } } else { @@ -304,7 +343,7 @@ /** * 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) { Set result = new HashSet(); @@ -317,9 +356,12 @@ } return result; } - + /** + * get a string description of the permissions + * @return string description of the permissions + */ public String toString() { - return ("Permission: " + className + " (\""+name+"\", \""+actions+"\")"); + return ("Permission: " + className + " (\"" + name + "\", \"" + actions + "\")"); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]