將一個或多個資源串接成單一檔案或主控台。如果目的地檔案不存在,則會建立該檔案,除非資源清單為空且ignoreempty為true
。
自 Apache Ant 1.7.1 起,此工作可以做為資源集合使用,該集合將會傳回一個資源。
資源集合用於選擇要串接哪些資源。沒有單一屬性可指定要串接
的單一資源。
屬性 | 說明 | 必要 |
---|---|---|
destfile | 串接串流的目的地檔案。如果未指定,則會改用主控台。 | 否 |
append | 指定是否要附加destfile指定的檔案。 | 否;預設為no |
force | 指定是否要寫入destfile指定的檔案,即使該檔案比所有來源檔案都新。已棄用,請改用overwrite屬性。 | 否;預設為yes |
overwrite | 指定是否要寫入destfile指定的檔案,即使該檔案比所有來源檔案都新。自 Ant 1.8.2 起。 | 否;預設為yes |
forceReadOnly | 覆寫唯讀的目的地檔案。自 Ant 1.8.2 起 | 否;預設為false |
encoding | 指定輸入檔案的編碼。請參閱支援的編碼,取得可能值清單。 | 否;預設為 JVM 預設字元編碼 |
outputencoding | 寫入輸出檔案時要使用的編碼。自 Ant 1.6 起。 | 否;預設為已設定的encoding,否則為 JVM 預設字元編碼 |
fixlastline | 指定是否要檢查每個串接的檔案是否以換行符號結尾。如果此屬性為yes,則檔案未以換行符號結尾時,會將換行符號附加到串流。自 Ant 1.6 起。此屬性不適用於嵌入文字。 |
否;預設為no |
eol | 指定換行符號字元,供fixlastline屬性使用。自 Ant 1.6 起此屬性的有效值為
|
否;預設值取決於平台:Unix 為 lf,DOS 系列(包括 Windows)為 crlf,Mac OS 9 或更早版本為 cr |
二進位 | 自 Ant 1.6.2 起如果此屬性設為 true,任務會以逐位元組方式串接檔案。如果此屬性為 false,concat 通常無法處理二進位檔案,因為會有字元編碼問題。如果此選項設為 true,則必須設定 destfile 屬性,而且任務無法使用巢狀文字。此外,也無法使用 encoding、outputencoding、filelastline 屬性。 |
否;預設值為 false |
filterbeforeconcat | 如果此屬性設為 true,任務會在套用 fixlastline 之後,將 filterchain 套用至每個輸入。如果此屬性為 false,concat 會只將 filterchain 套用至已串接的輸入一次。此設定不會影響 header 和 footer 的篩選。自 Ant 1.10.10 起 |
否;預設值為 false |
ignoreempty | 自 Ant 1.8.0 起指定如果來源資源清單為空,是否建立 destfile 指定的檔案。 | 否;預設值為 true |
resourcename | 自 Ant 1.8.3 起如果此任務公開為 資源,指定回報的名稱。 | 否 |
自 Ant 1.7 起.
任何各種 資源集合 類型都可以指定要串接的資源。
自 Ant 1.6 起.
任務支援巢狀 FilterChain。
自 Ant 1.6 起.
用於在串接串流中置入或附加文字。
文字可以是內嵌的,也可以在檔案中。
屬性 | 說明 | 必要 |
---|---|---|
filtering | 是否要篩選此子元素提供的文字。 | 否;預設值為 yes |
file | 要置於串接文字開頭或結尾的檔案。 | 否 |
trim | 是否要修剪值。 | 否;預設值為 no |
trimleading | 是否要修剪每一行開頭的空白。 | 否;預設值為 no |
將字串串接至檔案
<concat destfile="README">Hello, World!</concat>
將一系列檔案串接至主控台
<concat> <fileset dir="messages" includes="*important*"/> </concat>
串接單一檔案,如果目的地檔案存在,則附加
<concat destfile="NOTES" append="true"> <filelist dir="notes" files="note.txt"/> </concat>
串接一系列檔案,僅當目的地檔案比所有來源檔案都舊時才更新目的地檔案
<concat destfile="${docbook.dir}/all-sections.xml" force="no"> <filelist dir="${docbook.dir}/sections" files="introduction.xml,overview.xml"/> <fileset dir="${docbook.dir}" includes="sections/*.xml" excludes="introduction.xml,overview.xml"/> </concat>
串接一系列檔案,並展開 Ant 屬性。
<concat destfile="${build.dir}/subs"> <path> <fileset dir="${src.dir}" includes="*.xml"/> <pathelement location="build.xml"/> </path> <filterchain> <expandproperties/> </filterchain> </concat>
從 build.xml 中濾出包含專案的列,並將它們輸出至 report.output,並加上標頭。
<concat destfile="${build.dir}/report.output"> <header filtering="no" trimleading="yes"> Lines that contain project ========================== </header> <path path="build.xml"/> <filterchain> <linecontains> <contains value="project"/> </linecontains> </filterchain> </concat>
串接多個二進位檔案。
<concat destfile="${build.dir}/dist.bin" binary="yes"> <fileset file="${src.dir}/scripts/dist.sh"/> <fileset file="${build.dir}/dist.tar.bz2"/> </concat>