The file / template set attribute attribute does not expand. How would you write a goal that works with an arbitrary set of files?

I have a set of goals, each of which does essentially the same thing, except for each, contains a specific patternset on which its tasks are performed. I want to collapse these goals into one "reusable" target, which instead accepts a set of files "as a parameter."

For example, this

<target name="echo1">
  <foreach item="File" property="fn">
    <in>
      <items>
        <include name="*.config"/>
      </items>
    </in>
    <do>
      <echo message="${fn}" />
    </do>
  </foreach>
</target>

<target name="echo2">
  <foreach item="File" property="fn">
    <in>
      <items>
        <include name="*.xml"/>
      </items>
    </in>
    <do>
      <echo message="${fn}" />
    </do>
  </foreach>
</target>

<target name="use">
  <call target="echo1"/>
  <call target="echo2"/>
</target>

will be replaced by

<patternset id="configs">
   <include name="*.config"/>
</patternset>

<patternset id="xmls">
   <include name="*.xml"/>
</patternset>

<target name="echo">
  <foreach item="File" property="fn">
    <in>
      <items>
        <patternset refid="${sourcefiles}"/>
      </items>
    </in>
    <do>
      <echo message="${fn}" />
    </do>
  </foreach>
</target>

<target name="use">
  <property name="sourcefiles" value="configs"/>
  <call target="echo"/>
  <property name="sourcefiles" value="xmls"/>
  <call target="echo"/>
</target>

, refid , nant-dev, , , echo, patternset ${sourcefiles}, test.

NAnt-, ? NAnt as-is, ?

+3
2

, , , . .

<project
  name="dynamic-fileset"
  default="use"
  xmlns="http://nant.sourceforge.net/release/0.86-beta1/nant.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <target name="configs">
        <fileset id="files">
           <include name="*.config"/>
        </fileset>
    </target>

    <target name="xmls">
        <fileset id="files">
           <include name="*.xml"/>
        </fileset>
    </target>

    <target name="echo">
      <foreach item="File" property="fn">
        <in>
          <items refid="files"/>
        </in>
        <do>
          <echo message="${fn}" />
        </do>
      </foreach>
    </target>

    <target name="use">
      <property name="grouplist" value="xmls,configs"/>
      <foreach item="String" in="${grouplist}" delim="," property="filegroup">
        <do>
          <call target="${filegroup}"/>
          <call target="echo"/>
        </do>
      </foreach>        
    </target>
</project>
+6

, , , dynamic task property ?

<target name="filesettest">
  <property name="sourcefiles" value="test" dynamic="true" />
  <!-- ... -->
</target>
0

Source: https://habr.com/ru/post/1767564/


All Articles