Skip to content
Permalink
Browse files
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
  • Loading branch information
bodewig committed Sep 21, 2006
1 parent 2a8e0c1 commit 4b6bdbdbb623e1a82a99600850c71e0762c15624
Showing 7 changed files with 151 additions and 2 deletions.
@@ -54,6 +54,19 @@ <h3>Parameters</h3>
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>
@@ -54,6 +54,19 @@ <h3>Parameters</h3>
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>
@@ -49,12 +49,39 @@

<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"/>
</dn:build>
</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>
@@ -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>
@@ -64,6 +64,20 @@ public abstract class AbstractBuildTask extends Task {
*/
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.
*/
@@ -154,6 +168,24 @@ public final void addProperty(Property t) {
properties.add(t);
}

/**
* 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.
*
@@ -230,6 +262,8 @@ public void execute() {
for (int i = 0; i < args.length; i++) {
exec.createArg().setValue(args[i]);
}
exec.setFailonerror(failOnError);
exec.internalSetErrorProperty(errorProperty);

try {
exec.execute();
@@ -60,6 +60,25 @@ public void testNestedFile() throws Exception {
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");
}
}
}
@@ -60,6 +60,25 @@ public void testNestedFile() throws Exception {
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");
}
}
}

0 comments on commit 4b6bdbd

Please sign in to comment.