diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c0f022b63..2b9aea59a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -190,6 +190,7 @@ stephan Stephen Chin Steve Cohen Steve Loughran +Steve Morin Steven E. Newton Takashi Okamoto Thomas Butz diff --git a/WHATSNEW b/WHATSNEW index d780b227e..0a897b3b3 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -65,6 +65,9 @@ Other changes: * Added revision and userid attributes to documentation. +* Added a new "failall" value for the onerror attribute of . + Bugzilla report 31685. + Changes from Ant 1.6.2 to current Ant 1.6 CVS version ===================================================== diff --git a/docs/manual/CoreTasks/typedef.html b/docs/manual/CoreTasks/typedef.html index 4433e7438..a618031ce 100644 --- a/docs/manual/CoreTasks/typedef.html +++ b/docs/manual/CoreTasks/typedef.html @@ -116,9 +116,13 @@ onerror The action to take if there was a failure in defining the type. The values are fail - cause a build exception, report, - output a warning, but continue, ignore, do nothing. The default - is fail. + output a warning, but continue, ignore, do nothing. (introduced in ant1.6) + An additional value is failall - 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 fail. No diff --git a/src/etc/testcases/taskdefs/typedef.xml b/src/etc/testcases/taskdefs/typedef.xml index eeec7eb09..7ad10f4a4 100644 --- a/src/etc/testcases/taskdefs/typedef.xml +++ b/src/etc/testcases/taskdefs/typedef.xml @@ -53,4 +53,16 @@ onerror="ignore"/> hi - \ No newline at end of file + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Definer.java b/src/main/org/apache/tools/ant/taskdefs/Definer.java index e2272514e..18d695a37 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Definer.java +++ b/src/main/org/apache/tools/ant/taskdefs/Definer.java @@ -73,7 +73,7 @@ public abstract class Definer extends DefBase { */ 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 @@ public abstract class Definer extends DefBase { * @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 @@ public abstract class Definer extends DefBase { } 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/**/ resourceToURLs(ClassLoader classLoader) { @@ -271,10 +288,20 @@ public abstract class Definer extends DefBase { 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 @@ public abstract class Definer extends DefBase { } } catch (BuildException ex) { switch (onError) { + case OnError.FAIL_ALL: case OnError.FAIL: throw ex; case OnError.REPORT: diff --git a/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java b/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java index cc62dcf96..b3c54ae65 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java @@ -73,4 +73,16 @@ public class TypedefTest extends BuildFileTest { 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 "); + } }