2012-06-13 44 views
1

在螞蟻螞蟻任務,我想實現一個簡單的任務:如果兩個文件被修改編譯器應該運行。我看過很多使用OutOfDate,UpToDate和Modified的解決方案。我不想使用OutOfDate和UpToDate,因爲如果文件在同一天被修改,我將無法使用該任務。我可以使用修改,但無法從修改器任務調用另一個任務 - 我的編譯器任務。除此之外還有其他解決方案嗎?運行,只有當一個文件已經改變

+1

OutOfDate不限於今天之前修改過的文件。它會檢測目標文件是否是秒,日或年過期。 –

+0

@ChadNouis我不知道它,但如果沒有錯,OutOfDate是來自ant-contrib,我不想使用ant-contrib。謝謝,你能想到其他解決方案嗎? – Madz

回答

6

使用<uptodate>有以下<antcall>給條件<target>會給你你在找什麼:

<project name="ant-uptodate" default="run-tests"> 
    <tstamp> 
     <format property="ten.seconds.ago" offset="-10" unit="second" 
      pattern="MM/dd/yyyy hh:mm aa"/> 
    </tstamp> 

    <target name="uptodate-test"> 
     <uptodate property="build.notRequired" targetfile="target-file.txt"> 
      <srcfiles dir= "." includes="source-file.txt"/> 
     </uptodate> 

     <antcall target="do-compiler-conditionally"/> 
    </target> 

    <target name="do-compiler-conditionally" unless="build.notRequired"> 
     <echo>Call compiler here.</echo> 
    </target> 

    <target name="source-older-than-target-test"> 
     <touch file="source-file.txt" datetime="${ten.seconds.ago}"/> 
     <touch file="target-file.txt" datetime="now"/> 
     <antcall target="uptodate-test"/> 
    </target> 

    <target name="source-newer-than-target-test"> 
     <touch file="target-file.txt" datetime="${ten.seconds.ago}"/> 
     <touch file="source-file.txt" datetime="now"/> 
     <antcall target="uptodate-test"/> 
    </target> 

    <target name="run-tests" 
     depends="source-older-than-target-test,source-newer-than-target-test"/> 
</project> 
+0

非常感謝您的回覆,但我想我已經迷惑了您,因此這不是我所期待的。有沒有什麼辦法讓文件最後修改時間在螞蟻? – Madz

相關問題