gpt4 book ai didi

java - 文件集包含某些文件的选择器,但不是全部

转载 作者:行者123 更新时间:2023-11-30 06:34:27 24 4
gpt4 key购买 nike

我正在尝试使用 notcontains 关键字在 Ant 构建中丢弃 @WebService 带注释的类。但是,它不起作用,并且仍然包含用 @WebService 注释的类。以下是将源代码复制到工作构建目录的任务:

<copy todir="${compile.dir}">
<fileset dir="${src.dir}">
<include name="**/*" />
<exclude name="**/*.class" />
<exclude name="log4j.properties" />
<exclude name="log4j.properties.*" />
<exclude name="log4j.xml" />
<exclude name="log4j.xml.*" />
<exclude name="*.jocl" />
<not>
<contains text="@WebService(" casesensitive="true" />
</not>
</fileset>
</copy>

但是,似乎 not 部分被忽略,并且这些类仍然被复制。为什么这不起作用?语法有错误吗?另外,如何添加条件,以便限制仅涉及 .java 文件?

我使用的是 2015 年 7 月 8 日编译的 Apache Ant(TM) 版本 1.9.6

最佳答案

(也许这会指导您,它对我有用,但我不太确定我是否完全理解您的要求。)

尝试这个文件集:

<fileset dir="${src.dir}">
<exclude name="**/*.class" />
<exclude name="log4j.properties" />
<exclude name="log4j.properties.*" />
<exclude name="log4j.xml" />
<exclude name="log4j.xml.*" />
<exclude name="*.jocl" />
<or>
<filename name="**/*.java" negate="yes" />
<not>
<contains text="@WebService(" casesensitive="true" />
</not>
</or>
</fileset>

一些解释性评论:

无需指定<include name="**/*" />这是隐含在文件集中的。

当您包含嵌套 selector 时在文件集(如 <not>...<contains>...</not> )内,它与模式集(彼此隐式或)进行隐式“与”运算。请参阅 <fileset> 文档:

Selectors are available as nested elements within the FileSet. If any of the selectors within the FileSet do not select the file, the file is not considered part of the FileSet. This makes a FileSet equivalent to an <and> selector container.

这样做的结果是您需要使用 <or>带有两个负选择器的选择器容器。换句话说,“如果文件不是 java 文件或者它与文本字符串匹配,则选择该文件”。

如果您愿意,选择器容器也可以这样编写:

<or>
<not>
<filename name="**/*.java" />
</not>
<not>
<contains text="@WebService(" casesensitive="true" />
</not>
</or>

关于java - 文件集包含某些文件的选择器,但不是全部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45437928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com