| Article: |
Top 15 Ant Best Practices | |
| Subject: | Extension of ANTGRAPH | |
| Date: | 2004-11-17 01:10:32 | |
| From: | Roock | |
|
I found the best practices and the ANTGRAPH tool very useful. I have extended the XSL file of ANTGRAPH to parse the <ant ...> tag also: <?xml version="1.0" encoding="UTF-8"?> <!-- - An XSLT stylesheet that converts an Ant buildfile into a Graphviz/Dot - input file. - @author Eric M. Burke - @version $Id: antgraph.xslt,v 1.3 2003/07/19 02:23:23 Eric Exp $ - - Stefan Roock, 2004-09-17: parse <ant...> also --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>digraph G { </xsl:text> <xsl:apply-templates select="project/target"/> <xsl:apply-templates select="project/target//antcall"/> <xsl:apply-templates select="project/target//ant"/> <xsl:text>} </xsl:text> </xsl:template> <!-- show antcall tasks with dotted lines --> <xsl:template match="antcall"> <xsl:text> "</xsl:text> <xsl:value-of select="ancestor::target/@name"/> <xsl:text>" -> "</xsl:text> <xsl:value-of select="@target"/> <xsl:text>" [style=dotted]; </xsl:text> </xsl:template> <!-- show ant file tasks with dotted lines --> <xsl:template match="ant"> <xsl:text> "</xsl:text> <xsl:value-of select="@antfile"/> <xsl:text>:</xsl:text> <xsl:value-of select="@target"/> <xsl:text>" [shape=box]; </xsl:text> <xsl:text> "</xsl:text> <xsl:value-of select="ancestor::target/@name"/> <xsl:text>" -> "</xsl:text> <xsl:value-of select="@antfile"/> <xsl:text>:</xsl:text> <xsl:value-of select="@target"/> <xsl:text>" [style=dotted]; </xsl:text> </xsl:template> <xsl:template match="target"> <xsl:choose> <xsl:when test="@depends"> <xsl:call-template name="parseDepends"> <xsl:with-param name="target_order" select="1"/> <xsl:with-param name="depends_from" select="@name"/> <xsl:with-param name="depends_to" select="@depends"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <!-- this target has no dependencies --> <xsl:text> "</xsl:text> <xsl:value-of select="@name"/> <xsl:text>"; </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="parseDepends"> <xsl:param name="target_order"/> <xsl:param name="depends_from"/> <xsl:param name="depends_to"/> <xsl:variable name="firstToken"> <xsl:choose> <xsl:when test="contains($depends_to, ',')"> <xsl:value-of select="normalize-space(substring-before($depends_to,','))"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="normalize-space($depends_to)"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="remainingTokens" select="normalize-space(substring-after($depends_to,','))"/> <xsl:text> "</xsl:text> <xsl:value-of select="$depends_from"/> <xsl:text>" -> "</xsl:text> <xsl:value-of select="$firstToken"/> <xsl:text>"</xsl:text> <!-- show the target_order --> <xsl:if test="($target_order > 1) or (contains($depends_to, ','))"> <xsl:text> [label="</xsl:text> <xsl:value-of select="$target_order"/> <xsl:text>"]</xsl:text> </xsl:if> <xsl:text>; </xsl:text> <xsl:if test="$remainingTokens"> <xsl:call-template name="parseDepends"> <xsl:with-param name="target_order" select="$target_order+1"/> <xsl:with-param name="depends_from" select="$depends_from"/> <xsl:with-param name="depends_to" select="$remainingTokens"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> |
||


