peterreilly 2004/10/20 01:38:05 Modified: . WHATSNEW CONTRIBUTORS docs/manual/CoreTasks typedef.html src/etc/testcases/taskdefs typedef.xml src/main/org/apache/tools/ant/taskdefs Definer.java src/testcases/org/apache/tools/ant/taskdefs TypedefTest.java Log: add failall value for onerror attribute of <typedef> PR: 31685 Obtained from: steve morin Revision Changes Path 1.673 +3 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.672 retrieving revision 1.673 diff -u -r1.672 -r1.673 --- WHATSNEW 7 Oct 2004 16:25:03 -0000 1.672 +++ WHATSNEW 20 Oct 2004 08:38:04 -0000 1.673 @@ -65,6 +65,9 @@ * Added revision and userid attributes to <pvcs> documentation. +* Added a new "failall" value for the onerror attribute of <typedef>. + Bugzilla report 31685. + Changes from Ant 1.6.2 to current Ant 1.6 CVS version ===================================================== 1.34 +1 -0 ant/CONTRIBUTORS Index: CONTRIBUTORS =================================================================== RCS file: /home/cvs/ant/CONTRIBUTORS,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- CONTRIBUTORS 30 Sep 2004 09:24:28 -0000 1.33 +++ CONTRIBUTORS 20 Oct 2004 08:38:04 -0000 1.34 @@ -190,6 +190,7 @@ Stephen Chin Steve Cohen Steve Loughran +Steve Morin Steven E. Newton Takashi Okamoto Thomas Butz 1.17 +6 -2 ant/docs/manual/CoreTasks/typedef.html Index: typedef.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/typedef.html,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- typedef.html 6 Oct 2004 09:17:36 -0000 1.16 +++ typedef.html 20 Oct 2004 08:38:04 -0000 1.17 @@ -116,9 +116,13 @@ <td valign="top">onerror</td> <td valign="top">The action to take if there was a failure in defining the type. The values are <i>fail</i> - cause a build exception, <i>report</i>, - output a warning, but continue, <i>ignore</i>, do nothing. The default - is <i>fail</i>. + output a warning, but continue, <i>ignore</i>, do nothing. (introduced in ant1.6) + An additional value is <i>failall</i> - causes all behavior of fail but also + causes a build exception for the resource or file attribute + if the resource or file is not found. + (introduced in ant1.7) + The default is <i>fail</i>. </td> <td valign="top" align="center">No</td> </tr> 1.4 +13 -1 ant/src/etc/testcases/taskdefs/typedef.xml Index: typedef.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/typedef.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- typedef.xml 27 Nov 2003 09:07:44 -0000 1.3 +++ typedef.xml 20 Oct 2004 08:38:04 -0000 1.4 @@ -53,4 +53,16 @@ onerror="ignore"/> <mytask>hi</mytask> </target> -</project> \ No newline at end of file + + <target name="noresourcefailall"> + <typedef resource="somenotpresentfile.properties" onerror="failall"/> + </target> + + <target name="noresourcefail"> + <typedef resource="somenotpresentfile.properties" onerror="fail"/> + </target> + + <target name="noresourcenotfail"> + <typedef resource="somenotpresentfile.properties" /> + </target> +</project> 1.55 +43 -15 ant/src/main/org/apache/tools/ant/taskdefs/Definer.java Index: Definer.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- Definer.java 28 May 2004 15:23:26 -0000 1.54 +++ Definer.java 20 Oct 2004 08:38:04 -0000 1.55 @@ -73,7 +73,7 @@ */ public static class OnError extends EnumeratedAttribute { /** Enumerated values */ - public static final int FAIL = 0, REPORT = 1, IGNORE = 2; + public static final int FAIL = 0, REPORT = 1, IGNORE = 2, FAIL_ALL = 3; /** * Constructor */ @@ -94,7 +94,7 @@ * @return an array of the allowed values for this attribute. */ public String[] getValues() { - return new String[] {"fail", "report", "ignore"}; + return new String[] {"fail", "report", "ignore", "failall"}; } } @@ -244,21 +244,38 @@ } private URL fileToURL() { + String message = null; if (!(file.exists())) { - log("File " + file + " does not exist", Project.MSG_WARN); - return null; + message = "File " + file + " does not exist"; } - if (!(file.isFile())) { - log("File " + file + " is not a file", Project.MSG_WARN); - return null; + if (message == null && !(file.isFile())) { + message = "File " + file + " is not a file"; } try { - return file.toURL(); + if (message == null) { + return file.toURL(); + } } catch (Exception ex) { - log("File " + file + " cannot use as URL: " - + ex.toString(), Project.MSG_WARN); - return null; + message = + "File " + file + " cannot use as URL: " + + ex.toString(); + } + // Here if there is an error + switch (onError) { + case OnError.FAIL_ALL: + throw new BuildException(message); + case OnError.FAIL: + // Fall Through + case OnError.REPORT: + log(message, Project.MSG_WARN); + break; + case OnError.IGNORE: + // Fall Through + default: + // Ignore the problem + break; } + return null; } private Enumeration/*<URL>*/ resourceToURLs(ClassLoader classLoader) { @@ -271,10 +288,20 @@ e, getLocation()); } if (!ret.hasMoreElements()) { - if (onError != OnError.IGNORE) { - log("Could not load definitions from resource " - + resource + ". It could not be found.", - Project.MSG_WARN); + String message = "Could not load definitions from resource " + + resource + ". It could not be found."; + switch (onError) { + case OnError.FAIL_ALL: + throw new BuildException(message); + case OnError.FAIL: + case OnError.REPORT: + log(message, Project.MSG_WARN); + break; + case OnError.IGNORE: + // Fall Through + default: + // Ignore the problem + break; } } return ret; @@ -488,6 +515,7 @@ } } catch (BuildException ex) { switch (onError) { + case OnError.FAIL_ALL: case OnError.FAIL: throw ex; case OnError.REPORT: 1.12 +13 -1 ant/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java Index: TypedefTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- TypedefTest.java 9 Mar 2004 16:48:57 -0000 1.11 +++ TypedefTest.java 20 Oct 2004 08:38:05 -0000 1.12 @@ -73,4 +73,16 @@ public void testDoubleNotPresent() { expectLogContaining("double-notpresent", "hi"); } + + public void testNoResourceOnErrorFailAll(){ + this.expectBuildExceptionContaining("noresourcefailall","the requested resource does not exist","Could not load definitions from resource "); + } + + public void testNoResourceOnErrorFail(){ + expectLogContaining("noresourcefail","Could not load definitions from resource "); + } + + public void testNoResourceOnErrorNotFail(){ + expectLogContaining("noresourcenotfail","Could not load definitions from resource "); + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]