0
有什麼辦法可以用Ant來預先給每個文件的名字加上它?所以foo.txt的會去從如何將文件名預先加載到Ant中的文件本身?
bar
到
// foo.txt
bar
這需要對一組文件不能被硬編碼到ant腳本工作。
有什麼辦法可以用Ant來預先給每個文件的名字加上它?所以foo.txt的會去從如何將文件名預先加載到Ant中的文件本身?
bar
到
// foo.txt
bar
這需要對一組文件不能被硬編碼到ant腳本工作。
由於您要動態確定要使用的文件,我建議您獲取ant-contrib.jar並使用for
任務。我應該指出,這將在評論中寫出文件的完整路徑。
<!-- Sample usage -->
<target name="run">
<prepend>
<!-- Assuming you are interested in *.txt files in the resource directory -->
<fileset dir="resource">
<include name="**/*.txt"/>
</fileset>
</prepend>
</target>
<!-- Import the definitions from ant-contrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="../ant-contrib*.jar"/>
</classpath>
</taskdef>
<!-- Create the prepend task -->
<macrodef name="prepend">
<!-- Declare that it contains an element named "files". Implicit means it needn't be named -->
<element name="files" implicit="yes"/>
<sequential>
<!-- For loop, assigning the value of each iteration to "file" -->
<for param="file">
<!-- Give the for loop the files -->
<files/>
<sequential>
<!-- Load the contents of the file into a property -->
<loadfile property="@{file}-content" srcfile="@{file}"/>
<!-- Echo the header you want into the file -->
<echo message="// @{file}${line.separator}" file="@{file}"/>
<!-- Append the original contents to the file -->
<echo message="${@{file}-content}" append="true" file="@{file}"/>
</sequential>
</for>
</sequential>
</macrodef>
這不是一個長長的清單,但問題是我沒有提前列出清單。 – teryret