ResourceCount

自 Apache Ant 1.7 起

說明

顯示或設定一個包含巢狀 資源集合 大小的屬性。也可以當作 條件 使用。

參數

屬性 說明 必要
任務 條件
property 要設定的屬性。 否;預設將輸出值記錄到日誌 略過
refid 一個 參考 到資源集合。 是,除非提供巢狀資源集合
count 比較計數。 略過
when 比較類型:equaleqgreatergtlessltge(大於或等於)、ne(不等於)、le(小於或等於)。 否;預設為 equal

指定為巢狀元素的參數

資源集合

應該透過巢狀元素或 refid 屬性指定單一 資源集合

範例

將指定檔案清單(兩個檔案)中的資源數量儲存在名為 count.foo 的屬性中。

<resourcecount property="count.foo">
  <filelist dir="." files="foo,bar"/>
</resourcecount>

將目前建置檔案的列數儲存在屬性 file.lines 中。需要 Ant 1.7.1+,因為 <concat> 必須是資源。

<project>
  <property name="file" value="${ant.file}"/>
  <resourcecount property="file.lines">
    <tokens>
      <concat>
        <filterchain>
          <tokenfilter>
            <linetokenizer/>
          </tokenfilter>
        </filterchain>
        <fileset file="${file}"/>
      </concat>
    </tokens>
  </resourcecount>
  <echo>The file '${file}' has ${file.lines} lines.</echo>
</project>