如何根据目录内容从 ant 文件集中排除目录

发布于 2024-08-21 00:52:57 字数 599 浏览 12 评论 0原文

如何创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

最后的乘客 2024-08-28 00:52:57

以下方法对我有用:

<exclude name="**/dir_name_to_exclude/**" />

The following approach works for me:

<exclude name="**/dir_name_to_exclude/**" />
败给现实 2024-08-28 00:52:57

您需要在目录名称后添加“/”

<exclude name="WEB-INF/" />

You need to add a '/' after the dir name

<exclude name="WEB-INF/" />
娇纵 2024-08-28 00:52:57

这是一种替代方法,不是向要排除的每个目录添加 incomplete.flag 文件,而是生成一个包含要排除的所有目录的列表的文件,然后使用 excludesfile 属性。像这样:

<fileset dir="${basedir}" excludesfile="FileWithExcludedDirs.properties">
  <include name="locale/"/>
  <exclude name="locale/*/incomplete.flag">
</fileset>

希望有帮助。

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 the excludesfile attribute. Something like this:

<fileset dir="${basedir}" excludesfile="FileWithExcludedDirs.properties">
  <include name="locale/"/>
  <exclude name="locale/*/incomplete.flag">
</fileset>

Hope it helps.

硬不硬你别怂 2024-08-28 00:52:57

Ant 文档中实际上有此类问题的示例。它利用
选择器(如上所述)和映射器。请参阅 http://ant.apache.org/manual/Types/dirset.html 中的最后一个示例

<dirset id="dirset" dir="${workingdir}">
   <present targetdir="${workingdir}">
        <mapper type="glob" from="*" to="*/${markerfile}" />
   </present>
</dirset>

选择 ${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 :

<dirset id="dirset" dir="${workingdir}">
   <present targetdir="${workingdir}">
        <mapper type="glob" from="*" to="*/${markerfile}" />
   </present>
</dirset>

Selects all directories somewhere under ${workingdir} which contain a ${markerfile}.

梦中的蝴蝶 2024-08-28 00:52:57

用户 mgaert 提供的答案对我有用。我认为它应该被标记为正确答案。

它也适用于复杂的选择器,如下例所示:

<!-- 
    selects only direct subdirectories of ${targetdir} if they have a
    sub-subdirectory named either sub1 or sub2
-->
<dirset dir="${targetdir}" >
    <and>
        <depth max="0"/>
        <or>
            <present targetdir="${targetdir}">
                <globmapper from="*" to="*/sub1" />
            </present>
            <present targetdir="${targetdir}">
                <globmapper from="*" to="*/sub2" />
            </present>
        </or>
    </and>
</dirset>

因此,具有这样的目录结构:

targetdir
├── bar
│   └── sub3
├── baz
│   └── sub1
├── foo
│   └── sub2
├── phoo
│   ├── sub1
│   └── sub2
└── qux
    └── xyzzy
        └── sub1

上面的 dirset 将仅包含

baz foo phoo

(bar doesn't match because of sub3 while xyzzy doesn't match because it's not a direct subdirectory of targetdir)

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:

<!-- 
    selects only direct subdirectories of ${targetdir} if they have a
    sub-subdirectory named either sub1 or sub2
-->
<dirset dir="${targetdir}" >
    <and>
        <depth max="0"/>
        <or>
            <present targetdir="${targetdir}">
                <globmapper from="*" to="*/sub1" />
            </present>
            <present targetdir="${targetdir}">
                <globmapper from="*" to="*/sub2" />
            </present>
        </or>
    </and>
</dirset>

Thus, having a directory structure like this:

targetdir
├── bar
│   └── sub3
├── baz
│   └── sub1
├── foo
│   └── sub2
├── phoo
│   ├── sub1
│   └── sub2
└── qux
    └── xyzzy
        └── sub1

the above dirset would contain only

baz foo phoo

(bar doesn't match because of sub3 while xyzzy doesn't match because it's not a direct subdirectory of targetdir)

带刺的爱情 2024-08-28 00:52:57

这可以通过使用“**”模式来实现,如下所示。

<exclude name="maindir/**/incomplete.flag"/>

上面的“排除”将完全排除所有包含 incomplete.flag 文件的目录。

This is possible by using "**" pattern as following.

<exclude name="maindir/**/incomplete.flag"/>

the above 'exclude' will exclude all directories completely which contains incomplete.flag file.

热情消退 2024-08-28 00:52:57

它适用于 jar 目标:

<jar jarfile="${server.jar}" basedir="${classes.dir}" excludes="**/client/">
  <manifest>
    <attribute name="Main-Class" value="${mainServer.class}" />
  </manifest>
</jar>

此代码包含“classes.dir”中的所有文件,但从 jar 中排除目录“client”。

it works for me with a jar target:

<jar jarfile="${server.jar}" basedir="${classes.dir}" excludes="**/client/">
  <manifest>
    <attribute name="Main-Class" value="${mainServer.class}" />
  </manifest>
</jar>

this code include all files in "classes.dir" but exclude the directory "client" from the jar.

╭ゆ眷念 2024-08-28 00:52:57

我认为一种方法是首先检查您的文件是否存在,以及是否存在以从副本中排除该文件夹:

<target name="excludeLocales">

    <property name="de-DE.file" value="${basedir}/locale/de-DE/incompelte.flag"/>
    <available property="de-DE.file.exists" file="${de-DE.file}" />

    <copy todir="C:/temp/">
        <fileset dir="${basedir}/locale">
            <exclude name="de-DE/**" if="${de-DE.file.exists}"/>
            <include name="xy/**"/>
        </fileset>
    </copy>
</target>

这也适用于其他语言。

I think one way is first to check whether your file exists and if it exists to exclude the folder from copy:

<target name="excludeLocales">

    <property name="de-DE.file" value="${basedir}/locale/de-DE/incompelte.flag"/>
    <available property="de-DE.file.exists" file="${de-DE.file}" />

    <copy todir="C:/temp/">
        <fileset dir="${basedir}/locale">
            <exclude name="de-DE/**" if="${de-DE.file.exists}"/>
            <include name="xy/**"/>
        </fileset>
    </copy>
</target>

This should work also for the other languages.

月朦胧 2024-08-28 00:52:57

对我有用:

<target name="build2-jar" depends="compile" >
   <jar destfile="./myJjar.jar">
        <fileset dir="./WebContent/WEB-INF/lib" includes="hibernate*.jar,mysql*.jar" />
        <fileset dir="./WebContent/WEB-INF/classes" excludes="**/controlador/*.class,**/form/*.class,**/orm/*.class,**/reporting/*.class,**/org/w3/xmldsig/*.class"/>
   </jar>

works for me:

<target name="build2-jar" depends="compile" >
   <jar destfile="./myJjar.jar">
        <fileset dir="./WebContent/WEB-INF/lib" includes="hibernate*.jar,mysql*.jar" />
        <fileset dir="./WebContent/WEB-INF/classes" excludes="**/controlador/*.class,**/form/*.class,**/orm/*.class,**/reporting/*.class,**/org/w3/xmldsig/*.class"/>
   </jar>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文