failonerror and errorproperty attributes for <nant> and <msbuild>, PR 40553
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/dotnet/trunk@448637 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/docs/msbuild.html b/docs/msbuild.html
index bdbd73e..9704fd5 100644
--- a/docs/msbuild.html
+++ b/docs/msbuild.html
@@ -54,6 +54,19 @@
Specify the framework to use.</td>
<td align="center">No.</td>
</tr>
+ <tr>
+ <td valign="top">failOnError</td>
+ <td valign="top">Stops the build if MSBuild returns with a code
+ indicating an error.</td>
+ <td align="center">No - defaults to true.</td>
+ </tr>
+ <tr>
+ <td valign="top">errorProperty</td>
+ <td valign="top">Name of the Ant property to set if MSBuild
+ indicated an error. Only useful if the failOnError attribute
+ is set to false.</td>
+ <td align="center">No.</td>
+ </tr>
</table>
<h3>Parameters specified as nested elements</h3>
diff --git a/docs/nant.html b/docs/nant.html
index 12b26d5..d4bd015 100644
--- a/docs/nant.html
+++ b/docs/nant.html
@@ -54,6 +54,19 @@
Specify the framework to use.</td>
<td align="center">No.</td>
</tr>
+ <tr>
+ <td valign="top">failOnError</td>
+ <td valign="top">Stops the build if NAnt returns with a code
+ indicating an error.</td>
+ <td align="center">No - defaults to true.</td>
+ </tr>
+ <tr>
+ <td valign="top">errorProperty</td>
+ <td valign="top">Name of the Ant property to set if NAnt
+ indicated an error. Only useful if the failOnError attribute
+ is set to false.</td>
+ <td align="center">No.</td>
+ </tr>
</table>
<h3>Parameters specified as nested elements</h3>
diff --git a/src/etc/testcases/msbuild.xml b/src/etc/testcases/msbuild.xml
index 650b514..3c60899 100644
--- a/src/etc/testcases/msbuild.xml
+++ b/src/etc/testcases/msbuild.xml
@@ -49,7 +49,7 @@
<target name="nested-task">
<property name="foo" value="bar"/>
- <dn:msbuild>
+ <dn:msbuild errorProperty="msbuild.failed">
<dn:build>
<Message Text="foo is ${foo}"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"/>
@@ -57,4 +57,31 @@
</dn:msbuild>
</target>
+ <target name="fail">
+ <dn:msbuild>
+ <dn:build>
+ <Error Text="Failed"
+ xmlns="http://schemas.microsoft.com/developer/msbuild/2003"/>
+ </dn:build>
+ </dn:msbuild>
+ </target>
+
+ <target name="hidden-failure">
+ <dn:msbuild failOnError="false">
+ <dn:build>
+ <Error Text="Failed"
+ xmlns="http://schemas.microsoft.com/developer/msbuild/2003"/>
+ </dn:build>
+ </dn:msbuild>
+ </target>
+
+ <target name="hidden-failure-property">
+ <dn:msbuild failOnError="false" errorProperty="msbuild.failed">
+ <dn:build>
+ <Error Text="Failed"
+ xmlns="http://schemas.microsoft.com/developer/msbuild/2003"/>
+ </dn:build>
+ </dn:msbuild>
+ </target>
+
</project>
\ No newline at end of file
diff --git a/src/etc/testcases/nant.xml b/src/etc/testcases/nant.xml
index 1e5abce..435398c 100644
--- a/src/etc/testcases/nant.xml
+++ b/src/etc/testcases/nant.xml
@@ -51,10 +51,34 @@
<target name="nested-task">
<property name="foo" value="bar"/>
- <dn:nant>
+ <dn:nant errorProperty="nant.failed">
<dn:build>
<echo message="foo is ${foo}"/>
</dn:build>
</dn:nant>
</target>
+
+ <target name="fail">
+ <dn:nant>
+ <dn:build>
+ <fail message="Failed"/>
+ </dn:build>
+ </dn:nant>
+ </target>
+
+ <target name="hidden-failure">
+ <dn:nant failOnError="false">
+ <dn:build>
+ <fail message="Failed"/>
+ </dn:build>
+ </dn:nant>
+ </target>
+
+ <target name="hidden-failure-property">
+ <dn:nant failOnError="false" errorProperty="nant.failed">
+ <dn:build>
+ <fail message="Failed"/>
+ </dn:build>
+ </dn:nant>
+ </target>
</project>
\ No newline at end of file
diff --git a/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java b/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java
index ad4708e..7cbcdaf 100644
--- a/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java
+++ b/src/main/org/apache/ant/dotnet/build/AbstractBuildTask.java
@@ -65,6 +65,20 @@
private String vm;
/**
+ * Whether a failure should stop the build.
+ *
+ * @since 1.0 Beta 2
+ */
+ private boolean failOnError = true;
+
+ /**
+ * Name of property to set if a build fails.
+ *
+ * @since 1.0 Beta 2
+ */
+ private String errorProperty;
+
+ /**
* Empty constructor.
*/
protected AbstractBuildTask() {
@@ -155,6 +169,24 @@
}
/**
+ * Whether a failure should stop the build.
+ *
+ * @since 1.0 Beta 2
+ */
+ public void setFailOnError(boolean b) {
+ failOnError = b;
+ }
+
+ /**
+ * Name of property to set if a build fails.
+ *
+ * @since 1.0 Beta 2
+ */
+ public void setErrorProperty(String name) {
+ errorProperty = name;
+ }
+
+ /**
* Must return the executable.
*
* @return must not return null
@@ -230,6 +262,8 @@
for (int i = 0; i < args.length; i++) {
exec.createArg().setValue(args[i]);
}
+ exec.setFailonerror(failOnError);
+ exec.internalSetErrorProperty(errorProperty);
try {
exec.execute();
diff --git a/src/tests/junit/org/apache/ant/dotnet/build/MSBuildTaskTest.java b/src/tests/junit/org/apache/ant/dotnet/build/MSBuildTaskTest.java
index 29b792e..ff0e356 100644
--- a/src/tests/junit/org/apache/ant/dotnet/build/MSBuildTaskTest.java
+++ b/src/tests/junit/org/apache/ant/dotnet/build/MSBuildTaskTest.java
@@ -60,6 +60,25 @@
public void testNestedTask() throws Exception {
if (getProject().getProperty("msbuild.found") != null) {
expectLogContaining("nested-task", "foo is bar");
+ assertNull(getProject().getProperty("msbuild.failed"));
+ }
+ }
+
+ public void testFail() throws Exception {
+ if (getProject().getProperty("msbuild.found") != null) {
+ expectBuildException("fail", "Msbuild should fail");
+ }
+ }
+
+ public void testHiddenFail() {
+ if (getProject().getProperty("msbuild.found") != null) {
+ executeTarget("hidden-failure");
+ }
+ }
+
+ public void testHiddenFailWithProperty() {
+ if (getProject().getProperty("msbuild.found") != null) {
+ expectPropertySet("hidden-failure-property", "msbuild.failed");
}
}
}
diff --git a/src/tests/junit/org/apache/ant/dotnet/build/NAntTaskTest.java b/src/tests/junit/org/apache/ant/dotnet/build/NAntTaskTest.java
index 6a3905b..457d960 100644
--- a/src/tests/junit/org/apache/ant/dotnet/build/NAntTaskTest.java
+++ b/src/tests/junit/org/apache/ant/dotnet/build/NAntTaskTest.java
@@ -60,6 +60,25 @@
public void testNestedTask() throws Exception {
if (getProject().getProperty("nant.found") != null) {
expectLogContaining("nested-task", "foo is bar");
+ assertNull(getProject().getProperty("nant.failed"));
+ }
+ }
+
+ public void testFail() throws Exception {
+ if (getProject().getProperty("nant.found") != null) {
+ expectBuildException("fail", "NAnt should fail");
+ }
+ }
+
+ public void testHiddenFail() {
+ if (getProject().getProperty("nant.found") != null) {
+ executeTarget("hidden-failure");
+ }
+ }
+
+ public void testHiddenFailWithProperty() {
+ if (getProject().getProperty("nant.found") != null) {
+ expectPropertySet("hidden-failure-property", "nant.failed");
}
}
}