如何将文件的修改日期设置为最近修改的文件列表的日期?

时间:2017-11-15 10:55:23

标签: ant touch concat last-modified

在使用Ant的构建过程中,我想更新生成文件的上次修改日期。我连接(使用concat任务)几个文件来生成此文件,我想将此文件的修改日期设置为最近修改的源文件的日期。

我没有在触摸任务中看到任何使用多个文件作为日期来源的选项。

1 个答案:

答案 0 :(得分:0)

以下是一个示例解决方案:

<scriptdef name="filedate" language="javascript">
  <attribute name="file"/>
  <attribute name="property"/>
  <![CDATA[
    var file_name = attributes.get( "file" );
    var property_to_set = attributes.get( "property" );

    var file = new java.io.File( file_name );
    var file_date = file.lastModified();

    project.setProperty( property_to_set, file_date );
  ]]>   
</scriptdef>

<last id="last.dir">
  <sort>
    <fileset dir="folder" includes="*" />
    <date />
  </sort>
</last>

<filedate file="${ant.refid:last.dir}" property="file.ts" />

<touch file="concat.file" millis="${file.ts}" />

scriptdef派生自this answer David W.并简化,因为我们不需要格式化日期时间,我们可以使用Java文件{{1}的“epoch毫秒” }提供和Ant touch task期望。

相关问题