Get the number of rows in a property using a resource

I am trying to get ANT-Buildscript to count the lines stored in ANT -property. From the examples I got a way to count the lines in a file, for example:

<resourcecount count="0" when="eq">
    <tokens>
        <concat>
            <filterchain>
                <tokenfilter>
                    <linetokenizer/>
                </tokenfilter>
            </filterchain>
            <fileset file="${file}" />
        </concat>
    </tokens>
</resourcecount>

Now I want to reference ANT -property instead of a file. Is there any way to do this? I know about the decision to write the contents of a property to a file using <echo file="${temp.file}">${the.property.with.many.lines}</echo>and using the code above. But I am wondering if there is a solution that works without a temporary file.

+5
source share
1 answer

A propertyresourceelement can be used instead filesetas follows:

<property name="lines"
    value="line01${line.separator}line02${line.separator}line03"/>

<target name="count-lines">
  <resourcecount property="line.count" count="0" when="eq">
    <tokens>
      <concat>
        <filterchain>
          <tokenfilter>
            <stringtokenizer delims="${line.separator}" />
          </tokenfilter>
        </filterchain>
        <propertyresource name="lines" />
      </concat>
    </tokens>
  </resourcecount>
  <echo message="${line.count}" />
</target>

Output

count lines: [echo] 3

CREATE SUCCESSFULL Total Time: 0 seconds

+5
source

All Articles