Dear Ant users,

Here's an XSLT script which will give you a graphical
view of the task dependencies in your ant build file.

See the attached postscript (.ps) file for an example
of the end-result.

The process is as follows:
1. Creating a a build.dot file using the supplied build.xsl script
2. Compile this file with the GraphViz 'dot' program
    using the '-Tps' option to produce a PostScript file
    which depicts all the dependencies in the build.xml file graphically.

This is very useful to get a quick overview of the buildfile structure.

It requires:
* graphviz -- open source and available from AT&T
   (binaries available for windows, linux and many other systems).
* A postscript viewer (like ghostview --
         available for many o/ses including windows and linux).

Would appreciate feedback on other utilities which can do the same thing
possibly using Java only (graphviz is written in C or C++).

I'm aware of a jedit plugin, called AntViz;
I haven't tried it out myself, though.

Suggestions are welcome.

Thanks,


Alec Noronha


============================================================== Save the following into a file called 'build.xsl': ----- START BUILD.XSL CODE ----- <!-- This stylesheet has been tested on Apache Xalan 2.5.0 -->

<xsl:stylesheet version="1.1"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
               xmlns:str="http://exslt.org/strings";
               extension-element-prefixes="str">

 <xsl:output method="text"/>

 <!-- Variables for formatting -->
 <xsl:variable name="top">
   <xsl:text>
digraph build_xml_dependencies{
 size="12,12";
 shape="box";

 start [color=yellowgreen, shape=tripleoctagon, label="START"];

</xsl:text>
 </xsl:variable>

<xsl:variable name="bottom">
<xsl:text>
} </xsl:text>
</xsl:variable>
<xsl:variable name="start_node">
start
</xsl:variable>


 <xsl:variable name="join">
   <xsl:text> -> </xsl:text>
 </xsl:variable>

 <xsl:variable name="two_spaces">
   <xsl:text>  </xsl:text>
 </xsl:variable>

 <xsl:variable name="end_of_sentence">
   <xsl:text> ;
</xsl:text>
 </xsl:variable>

<!-- Templates -->
<xsl:template match="project">
<xsl:choose>
<xsl:when test="not(function-available('str:tokenize'))">
<xsl:message terminate="yes">
ERROR: EXSLT - This stylesheet requires the exslt extension strings:tokenize.
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$top"/>
<xsl:apply-templates select="target"/>
<xsl:value-of select="$bottom"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="target">
<xsl:choose>
<xsl:when test="not(attribute::depends)">
<xsl:value-of select="$two_spaces"/>
<xsl:value-of select="translate( attribute::name, '()-' , '___' )"/>
<xsl:value-of select="$join"/>
<xsl:value-of select="$start_node"/>
<xsl:value-of select="$end_of_sentence"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="dependency_loop">
<xsl:with-param name="dependency_list"
select="str:tokenize( translate( @depends, '()-' , '___' ), ' ,-' )" />
<xsl:with-param name="task_node"
select="translate( attribute::name, '()-' , '___' ) "/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="dependency_loop">
<xsl:param name="dependency_list"/>
<xsl:param name="task_node"/>
<xsl:for-each select="$dependency_list">
<xsl:value-of select="$two_spaces"/>
<xsl:value-of select="$task_node"/>
<xsl:value-of select="$join"/>
<xsl:value-of select="."/>
<xsl:value-of select="$end_of_sentence"/>
</xsl:for-each>
</xsl:template>
<!--
The <xsl:value-of select="."/> element in the middle of the named template will be replaced
by the contents of the current node from which this template was called.
-->


</xsl:stylesheet>

----- END BUILD.XSL CODE -----

Incorporate the following code into your 'build.xml' file.

Of course, you need to substitute your own directory names.

Note on the code below: for some reason, I had to place xalan.jar
into the ant/lib directory to get the following working.

----- START ANT BUILD.XML CODE -----

 <target name="view_dependencies"
         depends="prepare"
         description="Generate and view the dependency graph">

   <echo message="Generating the dependency dot file ..."/>
   <xslt basedir="${basedir}"
         destdir="${build_dev_docs_dir}"
         extension=".dot"
         style="build.xsl"
         classpathref="xalan_classpath"
         processor="trax"
         includes="build.xml" />

<echo message="Compiling the dependency dot file ..."/>
<exec executable="${dot_file_compiler}"
dir="${build_dev_docs_dir}"
outputproperty="dotoutput"
resultproperty="dotresult"
failifexecutionfails="true"
failonerror="true">
<arg line="-Tps ${build_dev_docs_dir}/build.dot -o ${build_dev_docs_dir}/build.ps"/>
</exec>


   <echo message="Invoking the gv ps viewer on the dependency file ..."/>
   <exec executable="${ps_viewer}"
         dir="${build_dev_docs_dir}"
         outputproperty="psoutput"
         resultproperty="psresult"
         failifexecutionfails="true"
         failonerror="true">
     <arg line="${build_dev_docs_dir}/build.ps  &amp;  "/>
   </exec>

 </target>

----- END BUILD.XML CODE -----


----- BEGIN SAMPLE OUTPUT ----

ATTACHED: build.ps

Sample output in graphic form generated from my seminal build file.


----- END SAMPLE OUTPUT ----

==============================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to