蚂蚁 - UPTODATE任务:重新生成唯一过时的文件 [英] ant - uptodate task : regenerate only outdated files

查看:137
本文介绍了蚂蚁 - UPTODATE任务:重新生成唯一过时的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的蚂蚁,而用于Makefile文件。在项目中,名为Message_zh.class等方面的国际化语言模块从zh.po等无条件地建有每个编译,虽然他们已经存在,那样会浪费很多时间。我想这些都是相关部分的build.xml:

I'm new to ant and rather used to Makefiles. In a project, the i18n language modules named Message_zh.class etc are built unconditionally from zh.po etc with every compile, although they already exist, which wastes much time. I figured these are the relevant parts of build.xml:

<target id="msgfmt" name="msgfmt">
    <mkdir dir="po/classes" />
    <propertyregex property="filename"
              input="${file}"
              regexp="[.]*/po/([^\.]*)\.po"
              select="\1"
              casesensitive="false" />
    <exec dir="." executable="msgfmt">
        <arg line="--java2 -d po/classes -r app.i18n.Messages -l ${filename} po/${filename}.po"/>
    </exec>
</target>

<target id="build-languageclasses" name="build-languageclasses" >
    <echo message="Compiling po files." />
    <foreach target="msgfmt" param="file">
      <path>
        <fileset dir="po" casesensitive="yes">
          <include name="**/*.po"/>
        </fileset>
      </path>
    </foreach>
</target>

目标集结languageclasses在编译目标取决于等等,每一个汇总,一大堆再次msgfmted。应如何编写只有1 PO文件被更改,或2类文件不存在调用的msgfmt?我会很高兴,如果这将不通过软件成为可能。你能帮助或点我一个例子吗?

The target build-languageclasses is depended on in the compile target and so, every compile, the whole bunch is msgfmted again. How should this be written to invoke msgfmt only if 1. the po file was changed, or 2. the class file doesn't exist? I would be glad if this would be possible without further software. Can you help or point me to an example?

在溶液中的第一次尝试没有区别蚂蚁的行为:

A first attempt at solution makes no difference in ant's behaviour:

<target id="build-languageclasses" description="compile if Messages??.class files not uptodate" name="build-languageclasses" unless="i18n.uptodate">
  <condition property="i18n.uptodate">
    <uptodate>
      <srcfiles dir="${po}" includes="**/*.po"/>
      <mapper type="glob" from="${po}/*.po" to="${po}/classes/app/i18n/Messages*.class"/>
    </uptodate>
  </condition>
  <echo message="Compiling po files." />
  <foreach target="msgfmt" param="file">
    <path>
      <fileset dir="po" casesensitive="yes">
        <include name="**/*.po"/>
      </fileset>
    </path>
  </foreach>
</target> 

什么是错在这里?

What's wrong here?

推荐答案

的问题是,你正在测试的属性 i18n.uptodate 运行<$ C $前C> UPTODATE 任务。你进入集结languageclasses之前,您的条件块必须运行目标。

The problem is that you are testing the property i18n.uptodate before you run the uptodate task. Your condition block must run before you enter the build-languageclasses target.

您应该重新组织你的code这样的:

You should reorganize your code like that:


  • 删除除非主要目标=i18n.uptodate

  • 拆分集结languageclasses 成2的目标。

  • 首是献给你的病情的初始化和包含&lt;条件方式&gt; 块仅

  • 包含code生成的文件,你的第二个(&LT;&的foreach GT;

  • remove the unless="i18n.uptodate" on the main target
  • split the build-languageclasses into 2 target.
  • the first is dedicated to the initialization of your condition and contains the <condition> block only.
  • the second that contains the code to generate you files (<foreach>)

第二个目标配置为有条件地运行,具体取决于属性 i18n.uptodate 由第一目标设定。

The second target is configured to run conditionally depending on the property i18n.uptodate set by the first target.

修改 - 在这里是UPTODATE任务的工作示例

EDIT - Here is a working example of the uptodate task

<property name="source" value="${basedir}/src"/>
<property name="dist" value="${basedir}/dist"/>

<target name="init">
    <condition property="that.uptodate">
        <uptodate>
            <srcfiles dir="${source}" includes="*.txt"/>
            <mapper type="glob" from="*.txt" to="${dist}/*.bat"/>
        </uptodate>
    </condition>
</target>

<target description="check that" name="dist" unless="that.uptodate" depends="init">
    <echo>we have something to do!</echo>
</target>

HIH

这篇关于蚂蚁 - UPTODATE任务:重新生成唯一过时的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆