ant/manual/Tasks/fail.html

134 lines
4.0 KiB
HTML
Raw Normal View History

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
<title>Fail Task</title>
</head>
<body>
<h2 id="fail">Fail</h2>
<h3>Description</h3>
2018-02-28 07:58:59 +01:00
<p>Exits the current build (just throwing a BuildException), optionally printing additional
information.</p>
<p>The message of the Exception can be set via the message attribute or character data nested into
the element.</p>
<h3>Parameters</h3>
2018-02-28 07:58:59 +01:00
<table class="attr">
<tr>
2018-02-28 07:58:59 +01:00
<th>Attribute</th>
<th>Description</th>
<th>Required</th>
</tr>
<tr>
2018-02-28 07:58:59 +01:00
<td>message</td>
<td>A message giving further information on why the build exited</td>
<td>No</td>
</tr>
<tr>
2018-02-28 07:58:59 +01:00
<td>if</td>
<td>Only fail <a href="../properties.html#if+unless">if a property of the given name exists</a>
in the current project</td>
2018-02-28 07:58:59 +01:00
<td>No</td>
</tr>
<tr>
2018-02-28 07:58:59 +01:00
<td>unless</td>
<td>Only fail <a href="../properties.html#if+unless">if a property of the given name doesn't
exist</a> in the current project</td>
2018-02-28 07:58:59 +01:00
<td>No</td>
</tr>
<tr>
2018-02-28 07:58:59 +01:00
<td>status</td>
<td>Exit using the specified status code; assuming the generated Exception is not caught, the
JVM will exit with this status. <em>Since Apache Ant 1.6.2</em></td>
2018-02-28 07:58:59 +01:00
<td>No</td>
</tr>
</table>
<h3>Parameters specified as nested elements</h3>
2018-02-28 07:58:59 +01:00
<p>As an alternative to the <var>if</var>/<var>unless</var> attributes, conditional failure can be
achieved using a single nested <code>&lt;condition&gt;</code> element, which should contain exactly
one core or custom condition. For information about conditions,
2018-03-02 08:23:45 +01:00
see <a href="conditions.html">here</a>.<br/><em>Since Ant 1.6.2</em>
</p>
<h3>Examples</h3>
2018-02-28 07:58:59 +01:00
<pre>&lt;fail/&gt;</pre>
<p>will exit the current build with no further information given.</p>
<pre class="output">
BUILD FAILED
2018-02-28 07:58:59 +01:00
build.xml:4: No message</pre>
2018-02-28 07:58:59 +01:00
<pre>&lt;fail message=&quot;Something wrong here.&quot;/&gt;</pre>
<p>will exit the current build and print something like the following to wherever your output
goes:</p>
<pre class="output">
BUILD FAILED
2018-02-28 07:58:59 +01:00
build.xml:4: Something wrong here.</pre>
2018-02-28 07:58:59 +01:00
<pre>&lt;fail&gt;Something wrong here.&lt;/fail&gt;</pre>
<p>will give the same result as above.</p>
2018-02-28 07:58:59 +01:00
<pre>&lt;fail unless=&quot;thisdoesnotexist&quot;/&gt;</pre>
<p>will exit the current build and print something like the following to wherever your output
goes:</p>
<pre class="output">
BUILD FAILED
2018-02-28 07:58:59 +01:00
build.xml:2: unless=thisdoesnotexist</pre>
Using a condition to achieve the same effect:
<pre>
2018-02-28 07:58:59 +01:00
&lt;fail&gt;
&lt;condition&gt;
&lt;not&gt;
&lt;isset property=&quot;thisdoesnotexist&quot;/&gt;
&lt;/not&gt;
&lt;/condition&gt;
&lt;/fail&gt;</pre>
<p>Output:</p>
<pre class="output">
BUILD FAILED
2018-02-28 07:58:59 +01:00
build.xml:2: condition satisfied</pre>
<pre>
&lt;fail message=&quot;Files are missing.&quot;&gt;
&lt;condition&gt;
&lt;not&gt;
&lt;resourcecount count=&quot;2&quot;&gt;
&lt;fileset id=&quot;fs&quot; dir=&quot;.&quot; includes=&quot;one.txt,two.txt&quot;/&gt;
&lt;/resourcecount&gt;
&lt;/not&gt;
&lt;/condition&gt;
2018-02-28 07:58:59 +01:00
&lt;/fail&gt;</pre>
<p>Will check that both files <samp>one.txt</samp> and <samp>two.txt</samp> are present otherwise
the build will fail.</p>
</body>
</html>