在 ANT 复制期间重命名文件

发布于 2024-07-30 05:24:50 字数 890 浏览 6 评论 0原文

我想复制一个文件目录,并在此过程中重命名其中一些文件。 当我运行下面的脚本时,没有任何复制。 如果我在下面的文件中评论全局映射器,则会复制文件(不重命名)

感谢您的任何帮助。 詹姆士

<?xml version="1.0" ?>
<project name="Create project structure" default="main">
  <target name="main" description="Copy template files to project folder">
    <echo>Copying template files to project folder</echo>
    <copy todir="${project.dir}" verbose="true" overwrite="true">
      <fileset dir="${shared.files}/templateproject" excludes=".svn"/>
      <mapper>
        <chainedmapper>
          <mapper type="glob" from="*PACKAGENAME*" to="*${package.name}*"/>
          <mapper type="glob" from="*GAMENAME*" to="*${game.name}*"/>
          <mapper type="identity"/>
        </chainedmapper>
      </mapper>
    </copy>
  </target>
</project>

I'd like to copy a directory of files, and rename some of them in the process.
When I run the script below, nothing copies.
If I comment the glob mappers in the file below, the files are copied (without the renaming)

Thanks for any help.
James

<?xml version="1.0" ?>
<project name="Create project structure" default="main">
  <target name="main" description="Copy template files to project folder">
    <echo>Copying template files to project folder</echo>
    <copy todir="${project.dir}" verbose="true" overwrite="true">
      <fileset dir="${shared.files}/templateproject" excludes=".svn"/>
      <mapper>
        <chainedmapper>
          <mapper type="glob" from="*PACKAGENAME*" to="*${package.name}*"/>
          <mapper type="glob" from="*GAMENAME*" to="*${game.name}*"/>
          <mapper type="identity"/>
        </chainedmapper>
      </mapper>
    </copy>
  </target>
</project>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

别理我 2024-08-06 05:24:50

采取了一种解决方法,使用“移动”和正确的映射器类型,如 Mnementh 所示。 谢谢

<?xml version="1.0" ?>
<project name="Create project structure" default="main">
    <target name="main" description="Copy template files to project folder">
    <echo>Copying template files to project folder</echo>
    <copy todir="${project.dir}" verbose="true" overwrite="true">
        <fileset dir="${shared.files}/templateproject" excludes=".svn" />
    </copy>
    <move todir="${project.dir}">
        <fileset dir="${project.dir}" />
        <mapper>
        <mapper type="regexp"
                from="(.*)PACKAGENAME(.*)" to="\1${package.name}\2" />
        <mapper type="regexp"
                from="(.*)GAMENAME(.*)" to="\1${game.name}\2" />
        </mapper>
    </move>
    </target>
</project>

Resorted to a workaround, using "move", and the correct mapper type as indicated by Mnementh. Thanks

<?xml version="1.0" ?>
<project name="Create project structure" default="main">
    <target name="main" description="Copy template files to project folder">
    <echo>Copying template files to project folder</echo>
    <copy todir="${project.dir}" verbose="true" overwrite="true">
        <fileset dir="${shared.files}/templateproject" excludes=".svn" />
    </copy>
    <move todir="${project.dir}">
        <fileset dir="${project.dir}" />
        <mapper>
        <mapper type="regexp"
                from="(.*)PACKAGENAME(.*)" to="\1${package.name}\2" />
        <mapper type="regexp"
                from="(.*)GAMENAME(.*)" to="\1${game.name}\2" />
        </mapper>
    </move>
    </target>
</project>
此刻的回忆 2024-08-06 05:24:50

看来, glob-mapper 仅适用于一个 ' *'。 我会尝试 regexp-mapper

<mapper type="regexp" from="(.*)PACKAGENAME(.*)" to="\1${package.name}\2"/>
<mapper type="regexp" from="(.*)GAMENAME(.*)" to="\1${game.name}\2"/>

It seems, that the glob-mapper works only with one '*'. I would try the regexp-mapper:

<mapper type="regexp" from="(.*)PACKAGENAME(.*)" to="\1${package.name}\2"/>
<mapper type="regexp" from="(.*)GAMENAME(.*)" to="\1${game.name}\2"/>
流星番茄 2024-08-06 05:24:50

您的问题是您没有选择正确的映射器: 会将链中的信息从第一个映射器传递到最后一个映射器

相反, 应该是使用,它将依次尝试所有映射器,直到有一个匹配

参考:http://ant. apache.org/manual/Types/mapper.html

(相当老的问题,但我刚刚发现搜索几乎相同的问题:-))

Your problem is that you did not choose the right mapper: <chainedmapper> will pass information in chain from the first to the last mapper

Instead, <firstmatchmapper> should be used, which will try all mappers in turn, until one matches

Reference: http://ant.apache.org/manual/Types/mapper.html

(quite an old question, but I just found searching for almost the same problem :-))

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