Search code examples
phing

Phing: get a filename without the extension


Given a Phing loop such as this

<target name="lessc">
  <exec command="lessc ${absolute-filename}" logoutput="false" output="${project.basedir}/public/assets/css/libraries/${filename}" />
</target>

<target name="build-in-loop">
  <foreach param="filename" absparam="absolute-filename" target="lessc">
    <fileset dir="${project.basedir}/assets/less/libraries/">
      <include name="*.less"/>
    </fileset>
  </foreach>
</target>

In target lessc, how can I extract the file name without extension from the variable absolute-filename? In the example above, the output file will have the extension .less - obviously not what I need.

I know there is a task made for less, and that I could extend Phing to support this specific operation, but I would like to know first if Phing basically allows simple string manipulation on variables.


Solution

  • Found the answer, not sure if it's the best solution, but works for me:

    just need to use the mapper tag

        <mapper type="glob" from="*.less" to="*"/>
    

    in the foreach loop, like this:

    <target name="build-in-loop">
      <foreach param="filename" absparam="absolute-filename" target="lessc">
        <fileset dir="${project.basedir}/assets/less/libraries/">
          <include name="*.less"/>
        </fileset>
      </foreach>
    </target>
    

    At this point, in the variable ${filename} in the target task there will be the filename without extension.