tjb
tjb

Reputation: 11728

Is there an ant command which lists all targets in a file and there depends?

Is there an ant command which lists all targets in a file and there depends?

Right now I just use a little power shell script to match lines that contain <target but its not really a good solution. Is there any sort of built in command?

Upvotes: 2

Views: 2540

Answers (3)

ewan.chalmers
ewan.chalmers

Reputation: 16235

If you search for "ant dependency graph", you'll find some suggestions on how to produce a .dot file from your build file which can be rendered into a visual graph by GraphViz.

Upvotes: 0

FailedDev
FailedDev

Reputation: 26930

No there isn't but you can do it like this :

<target name="list.targets">
    <xslt in="${basedir}\{build.file}"
          out="tmp"
          style="${display.targets.xsl}">
    </xslt>
    <delete file="tmp"/>
</target>

Where ${display.targets.xsl} points to the following .xsl file :

<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method='text'/>

    <xsl:template match="/">
        <xsl:for-each select="//target">
            <xsl:sort data-type="text" select="@name"/>
            <xsl:message terminate="no">
Target : <xsl:value-of select="@name"/><xsl:if test="@depends"> depends on : <xsl:value-of select="@depends"/>
                </xsl:if>
                <xsl:if test="@description">
Description : <xsl:value-of select="@description"/>
                </xsl:if>
            </xsl:message>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

And ${basedir}{build.file} points to your current build.xml file. The output will be something like this :

 [xslt] Loading stylesheet D:\Tools\StackOverFlow\test.xslt
 [xslt]
 [xslt] Target : build
 [xslt]
 [xslt] Target : modify.trs
 [xslt] Description : Modifies .trs file targets
 [xslt]
 [xslt] Target : regex depends on : modify.trs

Depending on your build.xml of course.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691765

The closest is ant -p (or ant -p -v to get more information). This won't list the target dependencies, but I don't see it as a problem: dependencies are not important for the end user (they just tell how the target works).

What's important is what the target does, which is what should be in its description:

<target name="foo" depends="bar" description="Does the foo operation">
    ...
</target>

I what you really want is the target dependencies, then reading the xml file is the best you can do.

Upvotes: 2

Related Questions