Reputation: 26924
I can use the following Ant syntax to check if there is exactly one file given its pattern or exact name (in fact, I don't know about any file system allowing two files with the same name to coexist)
<condition property="dependenciesXmlOk">
<resourcecount count="1">
<fileset id="fs" dir="ci" includes="dependencies.xml" />
</resourcecount>
</condition>
<fail message="dependencies.xml not found. Please configure CI server to deploy the dependencies.xml file as an artifact to ci/ folder within this project" unless="dependenciesXmlOk" />
However, I now want to add a new condition and related error message. The Ant build must break if no *.jar
file exists in my target directory. Copy&paste and I get the same for .zip
(yes, there must be as many zip and jar files, but at least one of both extensions)
How can I do that in Ant?
Upvotes: 0
Views: 1173
Reputation: 511
You can use the same logic as you do for checking file unicity, using a resourcecount condition with a when
attribute:
<condition property="jarexists">
<and>
<resourcecount when="greater" count="0">
<fileset dir="${target.dir}">
<include name="**/*.jar"/>
</fileset>
</resourcecount>
<resourcecount when="greater" count="0">
<fileset dir="${target.dir}">
<include name="**/*.zip"/>
</fileset>
</resourcecount>
</and>
</condition>
snippet code above sets jarexists
to true if there are at least one jar file and one zip file (but not necessary the same count of both file types) in target directory...
Upvotes: 4