gpt4 book ai didi

ant - 我如何将 "expand"一个 Ant 路径(使用 refId=.. 访问)到路径中除某些文件之外的所有文件?

转载 作者:行者123 更新时间:2023-12-04 14:44:13 26 4
gpt4 key购买 nike

我正在尝试让 ant4eclipse 工作,并且我使用了一点 ant,但并不比简单的脚本语言高多少。我们的 Eclipse 项目中有多个源文件夹,因此 ant4eclipse 文档中的示例需要调整:

目前我有以下内容:

<target name="build">

<!-- resolve the eclipse output location -->
<getOutputpath property="classes.dir" workspace="${workspace}" projectName="${project.name}" />

<!-- init output location -->
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}" />

<!-- resolve the eclipse source location -->
<getSourcepath pathId="source.path" project="." allowMultipleFolders='true'/>

<!-- read the eclipse classpath -->
<getEclipseClasspath pathId="build.classpath"
workspace="${workspace}" projectName="${project.name}" />

<!-- compile -->
<javac destdir="${classes.dir}" classpathref="build.classpath" verbose="false" encoding="iso-8859-1">
<src refid="source.path" />
</javac>

<!-- copy resources from src to bin -->
<copy todir="${classes.dir}" preservelastmodified="true">
<fileset refid="source.path">
<include name="**/*"/>
<!--
patternset refid="not.java.files"/>
-->
</fileset>
</copy>
</target>

任务成功运行,但我无法让它工作 - 它应该也复制所有非 java 文件以模拟 eclipse 的行为。

因此,我有一个名为 source.path 的 pathId,其中包含多个目录,我需要以某种方式将其按摩到复制任务之类的内容中。我试过无效的嵌套,以及其他一些疯狂的猜测。

我该怎么做 - 提前致谢。

最佳答案

您可以考虑使用 pathconvert构建 fileset includes 可以使用的模式。

<pathconvert pathsep="/**/*," refid="source.path" property="my_fileset_pattern">
<filtermapper>
<replacestring from="${basedir}/" to="" />
</filtermapper>
</pathconvert>

这将使用如下字符串填充 ${my_fileset_pattern}:

1/**/*,2/**/*,3

如果 source.path 由 basedir 下的三个目录 1、2、3 组成。我们使用 pathsep 插入通配符,稍后将扩展到完整的文件集。

该属性现在可用于生成所有文件的文件集。请注意,需要一个额外的尾随 /**/* 来扩展集合中的最后一个目录。此时可以应用排除。

<fileset dir="." id="my_fileset" includes="${my_fileset_pattern}/**/*">
<exclude name="**/*.java" />
</fileset>

然后所有非 java 文件的副本变为:

<copy todir="${classes.dir}" preservelastmodified="true">
<fileset refid="my_fileset" />
</copy>

这将复制源文件并保留 todir 下的源目录结构。如果需要,可以设置复制任务的 flatten 属性,而不是将所有源文件直接复制到 todir

请注意,此处的路径转换示例适用于 unix 文件系统,而不是 Windows。如果需要可移植的东西,则应使用 file.separator 属性来构建模式:

<property name="wildcard" value="${file.separator}**${file.separator}*" />
<pathconvert pathsep="${wildcard}," refid="source.path" property="my_fileset">
...

关于ant - 我如何将 "expand"一个 Ant 路径(使用 refId=.. 访问)到路径中除某些文件之外的所有文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/685237/

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