Echoing out ant fileset to screen for Debugging
Asked Answered
W

3

41

I have this:

    <ivy:buildlist reference="build-path">
        <fileset dir="${root.dir}">
            <include name="*/build.xml" />
            <include name="controllers/*/build.xml" />
        </fileset>
    </ivy:buildlist>


    <subant buildpathref="build-path">
        <target name="jar.all" />
        <target name="publish-local" />
    </subant>

I want to echo out everything that is in the "build-path" reference (for debugging some things).

I have tried:

<echo>${build-path}</echo>

but it just echos that exact text "${build-path}"

Woad answered 14/10, 2010 at 14:36 Comment(0)
E
65

You can use the documented (honest, it's in there somewhere...) toString helper:

<echo message="My build-path is ${toString:build-path}" />
Epstein answered 14/10, 2010 at 15:10 Comment(2)
It used to be an informal hack... However it was fully "formalized" and documented for Ant 1.8.1.Telencephalon
Thanks, I knew there was something like this, but searching the docs is a bit painful ... was close to writing my own task.Cite
N
28

To debug what files are include in your fileset you can use this example, which prints the contents of a fileset in a readable format:

<?xml version="1.0" encoding="UTF-8"?>
<project name="de.foo.ant" basedir=".">

<!-- Print path manually -->
<target name="print-path-manually" description="" >
    <path id="example.path">
        <fileset dir="${ant.library.dir}"/>
    </path>

    <!-- Format path -->
    <pathconvert pathsep="${line.separator}|   |-- "             
        property="echo.path.compile"             
        refid="example.path">
    </pathconvert>
    <echo>${echo.path.compile}</echo>
</target>

</project>

Output of this is:

Buildfile: D:\Workspaces\IvyTutorial\de.foo.ant\prettyPrintPath.xml
print-path-manually:
 [echo] D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-antlr.jar
 [echo] |   |-- D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-bcel.jar
 [echo] |   |-- D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-bsf.jar
 [echo] |   |-- D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-log4j.jar
 [echo] |   |-- D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-oro.jar
 [echo] |   |-- D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-regexp.jar
 [echo] |   |-- D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-resolver.jar
....
Nonprofit answered 18/10, 2010 at 12:30 Comment(1)
Note that using <pathconvert .. /> without the 'property' attribute prints out to the stdout/console so you can use a more compact syntax.Leland
A
9

Enable ant's debug logging:

$ ant -h
ant [options] [target [target2 [target3] ...]]
Options:
...
  -verbose, -v           be extra verbose
  -debug, -d             print debugging information

Note though that this will generate a ton of output, so it may be best to capture the output to a file and then find the fileset info in a text editor:

ant -debug compile > ant-out.txt
Apnea answered 14/10, 2010 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.