Ant fileset's "dir" missing from absolute path when using a mapper

2.1k views Asked by At

I've been trying to write an Ant task to "compile" Sass scripts in my project using the apply task but I kept getting a "No such file or directory" error. I thought it might have been caused by spaces in the buildpath so I went through the trouble of moving the project only to find that Ant seems to omitting the fileset's root directory when it returns the path. This is what the target looks like:

<target name="sass-compile" depends="properties">
    <apply executable="sass">
        <srcfile />
        <targetfile />

        <fileset dir="${project.src.dir}" includes="**/*.scss"  />
        <globmapper from="*.scss" to="*.css" />
    </apply>
</target>

To help troubleshoot, I switched the executable from sass to echo and I noticed that the mapper is transforming paths like this...

/Users/me/Documents/Programming/workspace/Project/src/java/com/proj/web/page/template/Template.scss

...into this...

/Users/me/Documents/Programming/workspace/Project/java/com/proj/web/page/template/Template.css

Notice that the src directory is missing from the target file path. Am I seeing a bug here or is this somehow expected? I would love to know what's going on here. I have also tried using a regexpmapper, and a filtermapper with replacestring. The result is the same.

I'm running Ant 1.7.1, which comes bundled with Eclipse Helios, which I'm running on a Mac. I also tried Ant 1.8 on both Mac and Linux. Nothing works. Does anyone have any ideas?

2

There are 2 answers

0
martin clayton On BEST ANSWER

It's normal behaviour. The mappers use relative paths, not absolute. The path will be relative to the working (probably base) directory, which in your case is the parent of the src directory.

The apply task (glob)mapper provides paths relative to the directory specified in its dest attribute:

A single mapper specifies the target files relative to the dest attribute for dependency checking. If the dest attribute is specified it will be used as a base directory for resolving relative pathnames returned by the mapper. At least one fileset or filelist is required.

The relative path used is derived from the fileset specified, hence they do not contain the leading src directory.

Options that come to mind are:

  • Use the basedir of the project instead of project.src.dir (might work)
  • Specify the directory using <apply dest="src" ... (better)
0
Raghuram On

It looks like the mapper is working with the contents of ${project.src.dir}, excluding the folder itself.

Can you try specifying the parent folder of src in ${project.src.dir}, say ${basedir} and see if it produces the desired result?