开发者

Ant concat task complain on missing files

<concat destfile="dist/external.js">
  <fileset dir=".">
    <include name="a.js" />
    <include name="b.js" />
  </fileset>
<开发者_JAVA百科/concat>

This won't fail if a or b is missing. I've tried setting optional="false" or asis="true" and it always complains that those attributes don't exist.


If you just want to see a warning from the 'concat' task when a file is missing, you can use afilelistresource collection in place of the 'fileset':

<concat destfile="dist/external.js">
  <filelist dir=".">
    <file name="a.js" />
    <file name="b.js" />
  </filelist>
</concat>

Whenb.jsdoesn't exist, that gives the message:

[concat] /Path/.../b.js does not exist.

But proceeds anyway, which is probably not what you want.

One method of checking for the presence of all the files in a resource collection is as follows. Note that you need to add the "antlib:org.apache.tools.ant.types.resources.selectors" namespace to the project to use the resource selectors shown below. (This won't work for Ant versions older than 1.7.0.) Use the Ant fail task to check that no resources are missing.

<project name="stack_overflow"
         xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">

<filelist id="my.js.files" dir=".">
    <file name="a.js" />
    <file name="b.js" />
</filelist>

<restrict id="missing.js.files">
  <filelist refid="my.js.files"/>
  <rsel:not>
    <rsel:exists/>
  </rsel:not>
</restrict>

<property name="missing.files" refid="missing.js.files" />
<fail message="These files are missing: ${missing.files}">
  <condition>
    <length string="${missing.files}" when="greater" length="0" />
  </condition>
</fail>
<concat destfile="dist/external.js">
    <filelist refid="my.js.files" />
</concat>

</project>

When run, as before withb.jsmissing, this fails the build before the 'concat' task with:

BUILD FAILED
/Path/.../build.xml:17: These files are missing: /Path/.../b.js
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜