Ant を使用して各ファイルの名前を先頭に追加する方法はありますか? したがって、foo.txt は
bar
に
// foo.txt
bar
これは、ant スクリプトにハードコーディングできない一連のファイルで機能する必要があります。
Ant を使用して各ファイルの名前を先頭に追加する方法はありますか? したがって、foo.txt は
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>