如何根据目录内容从 ant 文件集中排除目录
如何创建一个 ant 文件集,根据目录的内容排除某些目录?
我使用 ant 创建一个发行版 jar,其中每个本地化版本都位于不同的目录中,其中一些不完整,不应发布。
我想向目录添加一些内容(例如名为 incomplete.flag
的文件),以便 ant 排除该目录。然后,我可以在翻译完成后删除该文件,并将其包含在构建中,而无需修改 build.xml。
给定以下目录结构:
proj
+ locale
+ de-DE
+ en-US
+ fr-FR
此文件集排除所有 incompelte.flag
文件,但如何排除包含它们的整个目录?
<fileset dir="${basedir}">
<include name="locale/"/>
<exclude name="locale/*/incomplete.flag">
</fileset>
如果需要,我可以编写一个 ant 任务,但我希望 fileset
可以处理这个用例。
How can I create an ant fileset which excludes certain directories based on the contents of the directory?
I use ant to create a distribution jar which has each localization in separate directories, some of which are incomplete and should not be released.
I would like to add something to the directory (for example a file named incomplete.flag
) so that ant excludes the directory. Then I can delete the file when translation is complete, and include it in the build without modifying build.xml.
Given this directory structure:
proj
+ locale
+ de-DE
+ en-US
+ fr-FR
This fileset excludes all incompelte.flag
files, but how can I exclude the entire directories that contain them?
<fileset dir="${basedir}">
<include name="locale/"/>
<exclude name="locale/*/incomplete.flag">
</fileset>
I can write an ant task if need be, but I'm hoping the fileset
can handle this use case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
以下方法对我有用:
The following approach works for me:
您需要在目录名称后添加“/”
You need to add a '/' after the dir name
这是一种替代方法,不是向要排除的每个目录添加
incomplete.flag
文件,而是生成一个包含要排除的所有目录的列表的文件,然后使用excludesfile
属性。像这样:希望有帮助。
Here's an alternative, instead of adding an
incomplete.flag
file to every dir you want to exclude, generate a file that contains a listing of all the directories you want to exclude and then use theexcludesfile
attribute. Something like this:Hope it helps.
Ant 文档中实际上有此类问题的示例。它利用
选择器(如上所述)和映射器。请参阅 http://ant.apache.org/manual/Types/dirset.html 中的最后一个示例 :
选择
${workingdir}
下包含${markerfile}
的所有目录。There is actually an example for this type of issue in the Ant documentation. It makes use of
Selectors (mentioned above) and mappers. See last example in http://ant.apache.org/manual/Types/dirset.html :
Selects all directories somewhere under
${workingdir}
which contain a${markerfile}
.用户 mgaert 提供的答案对我有用。我认为它应该被标记为正确答案。
它也适用于复杂的选择器,如下例所示:
因此,具有这样的目录结构:
上面的 dirset 将仅包含
(
bar
doesn't match because of sub3 whilexyzzy
doesn't match because it's not a direct subdirectory oftargetdir
)Answer provided by user mgaert works for me. I think it should be marked as the right answer.
It works also with complex selectors like in this example:
Thus, having a directory structure like this:
the above dirset would contain only
(
bar
doesn't match because of sub3 whilexyzzy
doesn't match because it's not a direct subdirectory oftargetdir
)这可以通过使用“**”模式来实现,如下所示。
上面的“排除”将完全排除所有包含 incomplete.flag 文件的目录。
This is possible by using "**" pattern as following.
the above 'exclude' will exclude all directories completely which contains incomplete.flag file.
它适用于 jar 目标:
此代码包含“classes.dir”中的所有文件,但从 jar 中排除目录“client”。
it works for me with a jar target:
this code include all files in "classes.dir" but exclude the directory "client" from the jar.
我认为一种方法是首先检查您的文件是否存在,以及是否存在以从副本中排除该文件夹:
这也适用于其他语言。
I think one way is first to check whether your file exists and if it exists to exclude the folder from copy:
This should work also for the other languages.
对我有用:
works for me: