Browse Source

add failall value for onerror attribute of <typedef>

PR: 31685
Obtained from: 	steve morin


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276950 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
7228bef97c
6 changed files with 78 additions and 18 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +6
    -2
      docs/manual/CoreTasks/typedef.html
  4. +13
    -1
      src/etc/testcases/taskdefs/typedef.xml
  5. +43
    -15
      src/main/org/apache/tools/ant/taskdefs/Definer.java
  6. +12
    -0
      src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java

+ 1
- 0
CONTRIBUTORS View File

@@ -190,6 +190,7 @@ stephan
Stephen Chin Stephen Chin
Steve Cohen Steve Cohen
Steve Loughran Steve Loughran
Steve Morin
Steven E. Newton Steven E. Newton
Takashi Okamoto Takashi Okamoto
Thomas Butz Thomas Butz


+ 3
- 0
WHATSNEW View File

@@ -65,6 +65,9 @@ Other changes:


* Added revision and userid attributes to <pvcs> documentation. * 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 Changes from Ant 1.6.2 to current Ant 1.6 CVS version
===================================================== =====================================================




+ 6
- 2
docs/manual/CoreTasks/typedef.html View File

@@ -116,9 +116,13 @@
<td valign="top">onerror</td> <td valign="top">onerror</td>
<td valign="top">The action to take if there was a failure in defining the <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>, 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) (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>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
</tr> </tr>


+ 13
- 1
src/etc/testcases/taskdefs/typedef.xml View File

@@ -53,4 +53,16 @@
onerror="ignore"/> onerror="ignore"/>
<mytask>hi</mytask> <mytask>hi</mytask>
</target> </target>
</project>
<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>

+ 43
- 15
src/main/org/apache/tools/ant/taskdefs/Definer.java View File

@@ -73,7 +73,7 @@ public abstract class Definer extends DefBase {
*/ */
public static class OnError extends EnumeratedAttribute { public static class OnError extends EnumeratedAttribute {
/** Enumerated values */ /** 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 * Constructor
*/ */
@@ -94,7 +94,7 @@ public abstract class Definer extends DefBase {
* @return an array of the allowed values for this attribute. * @return an array of the allowed values for this attribute.
*/ */
public String[] getValues() { 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() { private URL fileToURL() {
String message = null;
if (!(file.exists())) { 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 { try {
return file.toURL();
if (message == null) {
return file.toURL();
}
} catch (Exception ex) { } 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) { private Enumeration/*<URL>*/ resourceToURLs(ClassLoader classLoader) {
@@ -271,10 +288,20 @@ public abstract class Definer extends DefBase {
e, getLocation()); e, getLocation());
} }
if (!ret.hasMoreElements()) { 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; return ret;
@@ -488,6 +515,7 @@ public abstract class Definer extends DefBase {
} }
} catch (BuildException ex) { } catch (BuildException ex) {
switch (onError) { switch (onError) {
case OnError.FAIL_ALL:
case OnError.FAIL: case OnError.FAIL:
throw ex; throw ex;
case OnError.REPORT: case OnError.REPORT:


+ 12
- 0
src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java View File

@@ -73,4 +73,16 @@ public class TypedefTest extends BuildFileTest {
public void testDoubleNotPresent() { public void testDoubleNotPresent() {
expectLogContaining("double-notpresent", "hi"); 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 ");
}
} }

Loading…
Cancel
Save