JDepend, written by Mike Clark, is a free tool used to generate design
quality metrics for each Java package of a set of Java Source file
directories.

Attached are:
- the output of a 'diff -u -r' (contains 'diff -u' output for build.xml,
docs/manual/optionaltasklist.html and
src/main/org/apache/tools/ant/taskdefs/defaults.properties)
- the jdepend.html to put in docs\manual\OptionalTasks
- the JDependTask.java to put in the new
src\main\org\apache\tools\ant\taskdefs\optional\jdepend directory


There is no specific test case but one can test by putting the attached
test.xml file in the Ant build directory, and then run 'ant -f test.xml'
(once the new Ant version is compiled and installed).
'ant -f test.xml clean' removes the generated output files.

jdepend.jar can be retrieved from the address given in the documentation,
i.e. http://www.clarkware.com/software/JDepend.html

The JDependTask requires at least the JDepend 1.2 version.

Hope it helps.

Jerome

PS: the code is mainly based on JUnit Task's one. It seems like a lot could
be shared in a 'smarter' Task class dedicated to run third party programs
both in internal or external VMs. Parameters of JUnit and JDepend tasks are
as well almost identical (fork, haltonerror, vm, dir, timeout,...)

Attachment: JDependTask.java
Description: JavaScript source

<?xml version="1.0"?>

<project name="testanttask" default="main" basedir=".">

  <target name="init">
    <tstamp />  
    <property name="test1.out" 	value="metrics.out" />
    <property name="test2.out" 	value="metrics2.out" />    
    <property name="test3.out" 	value="metrics3.out" />    
    <property name="test4.out" 	value="metrics4.out" />    
    <property name="test5.out" 	value="metrics5.out" />    
  </target>

  	       <path id="base.path">
    		<pathelement path="build.classes"/>
    		<pathelement location="lib/jdepend.jar"/>
    		</path>

<!--
  <taskdef name="jdepend" 
  	   classname="org.apache.tools.ant.taskdefs.optional.jdepend.JDependTask">
  	   <classpath>
  	       <path id="base.path">
    		<pathelement path="build.classes"/>
    		<pathelement location="lib/jdepend.jar"/>
    		</path>
  	   </classpath>
  </taskdef>
-->
  <!--
	Test the use of JDependAntTask 
	Note: test_5 should not be included (cf test_5 comments)
  -->
  <target name="main" depends="init,test_1,test_2,test_3,test_4,test_5"
	description="Runs the JDepend Ant task on itself">
  </target>

  <target name="clean" depends="init"
  	description="delegate cleaning...">
	<delete file="${test2.out}"/>
	<delete file="${test3.out}"/>
	<delete file="${test4.out}"/>	
	<delete file="${test5.out}"/>		
  </target>  
  <!--
	The tests
  -->

  <target name="test_1" depends="init" description="Test: Do not output to a file">
    <jdepend classpathref="base.path">
    	 <sourcespath>
    	 	<pathelement location="src" />
    	 </sourcespath>
    </jdepend>
    
  </target>
  
  <target name="test_2" depends="init" description="Test: Output to a file. Single directory. Use of a classpathref. No Fork">
    <jdepend outputFile="${test2.out}" classpathref="base.path" fork="no">
    	 <sourcespath>
    	 	<pathelement location="src/antidote/org" />
    	 </sourcespath>
    </jdepend>
  </target>
  
  <target name="test_3" depends="init" description="Test: Several directories. Use of a classpathref. Fork">
    <jdepend outputFile="${test3.out}" classpathref="base.path" fork="yes">
    	 <sourcespath>
    	 	<pathelement location="src/antidote/org" />
    	 	<pathelement location="src/main" />
    	 </sourcespath>
    </jdepend>
  </target>

  <target name="test_4" depends="init" description="Test: use the classpath argument instead of classpathref">
    <!-- no output -->
    <jdepend outputfile="${test4.out}" fork="yes">
    	 <sourcespath>
    	 	<pathelement location="src/antidote/org" />
    	 </sourcespath>
         <classpath>
   		 <pathelement path="classes"/>
    		 <pathelement location="lib/jdepend.jar"/>
         </classpath>
    </jdepend>
  </target>

  <target name="test_5" depends="init" description="Test: without classpath set">
    <jdepend outputFile="${test5.out}">
    	 <sourcespath>
    	 	<pathelement location="src/antidote/org" />
    	 	<pathelement location="src/main" />
    	 </sourcespath>
    </jdepend>
  </target>

  <target name="test_6" depends="init" description="Test: without sources path: fails">
    <jdepend haltonerror="false"/>
  </target>


  <target name="test_7" depends="init" description="Test: wrong pathelement (not a dir): fails">
    <jdepend classpathref="base.path" fork="no">
    	 <sourcespath>
    	 	<pathelement location="src/antidote/org/*.java" />
    	 </sourcespath>
    </jdepend>
  </target>

</project>
  
diff -u -r jakarta-ant-1.3/build.xml old/jakarta-ant-1.3/build.xml
--- jakarta-ant-1.3/build.xml   Thu Apr 26 19:18:10 2001
+++ old/jakarta-ant-1.3/build.xml       Fri Mar  2 23:46:36 2001
@@ -143,10 +143,6 @@
     <available property="jmf.present" 
                classname="javax.sound.sampled.Clip"  
                classpathref="classpath"/>
-    <available property="jdepend.present" 
-               classname="jdepend.framework.JDepend"  
-               classpathref="classpath"/>
-               
   </target>
 
   <!-- 
@@ -202,7 +198,6 @@
                unless="xalan.present" />
       <exclude name="${optional.package}/junit/AggregateTransformer.java"
                unless="xalan.present" />
-      <exclude name="${optional.package}/jdepend/*" unless="jdepend.present" />
     </javac>
     
     <copy todir="${build.classes}">
Only in jakarta-ant-1.3/docs/manual/OptionalTasks: jdepend.html
diff -u -r jakarta-ant-1.3/docs/manual/optionaltasklist.html 
old/jakarta-ant-1.3/docs/manual/optionaltasklist.html
--- jakarta-ant-1.3/docs/manual/optionaltasklist.html   Tue May 29 15:22:10 2001
+++ old/jakarta-ant-1.3/docs/manual/optionaltasklist.html       Fri Mar  2 
23:46:34 2001
@@ -20,7 +20,6 @@
 <a href="OptionalTasks/ftp.html">FTP</a><br>
 <a href="OptionalTasks/javacc.html">JavaCC</a><br>
 <a href="OptionalTasks/javah.html">Javah</a><br>
-<a href="OptionalTasks/jdepend.html">JDepend</a><br>
 <a href="OptionalTasks/jjtree.html">JJTree</a><br>
 <a href="OptionalTasks/jlink.html">Jlink</a><br>
 <a href="OptionalTasks/junit.html">JUnit</a><br>
Only in jakarta-ant-1.3/docs/manual: optionaltasklist.html.bak
Only in jakarta-ant-1.3/lib: jdepend.jar
diff -u -r 
jakarta-ant-1.3/src/main/org/apache/tools/ant/taskdefs/defaults.properties 
old/jakarta-ant-1.3/src/main/org/apache/tools/ant/taskdefs/defaults.properties
--- jakarta-ant-1.3/src/main/org/apache/tools/ant/taskdefs/defaults.properties  
Thu Apr 26 19:10:51 2001
+++ 
old/jakarta-ant-1.3/src/main/org/apache/tools/ant/taskdefs/defaults.properties  
    Fri Mar  2 23:46:26 2001
@@ -89,7 +89,6 @@
 sound=org.apache.tools.ant.taskdefs.optional.sound.SoundTask
 junitreport=org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator
 vsslabel=org.apache.tools.ant.taskdefs.optional.vss.MSVSSLABEL
-jdepend=org.apache.tools.ant.taskdefs.optional.jdepend.JDependTask
 
 # deprecated ant tasks (kept for back compatibility)
 javadoc2=org.apache.tools.ant.taskdefs.Javadoc
Only in jakarta-ant-1.3/src/main/org/apache/tools/ant/taskdefs/optional: jdepend
Only in jakarta-ant-1.3/: test.xml
Title: JDepend Task

JDepend

Description

Invokes the JDepend parser.

This parser "traverses a set of Java source file directories and generates design quality metrics for each Java package". It allows to "automatically measure the quality of a design in terms of its extensibility, reusability, and maintainability to effectively manage and control package dependencies."

Source file directories are defined by nested <sourcespath>, see nested elements.
Optionally, you can also set the outputfile name where the output is stored. By default the task writes its report to the standard output.

The task requires at least the JDepend 1.2 version.

Note: whereas the JDepend tool can be customized to exclude some packages, the current jdepend And Task does not have parameters to allow these exclusions. Read JDepend specific documentation for that purpose.

Parameters

Attribute Description Required
outputfile The output file name. If not set, the output is printed on the standard output. No
fork Run the tests in a separate VM. No, default is "off"
haltonerror Stop the build process if an error occurs during the jdepend analysis. No, default is "off"
timeout Cancel the operation if it doesn't finish in the given time (measured in milliseconds). (Ignored if fork is disabled.) No
jvm The command used to invoke the Java Virtual Machine, default is 'java'. The command is resolved by java.lang.Runtime.exec(). (Ignored if fork is disabled.) No, default "java"
dir The directory to invoke the VM in. (Ignored if fork is disabled) No
classpathref the classpath to use, given as reference to a PATH defined elsewhere. No

Nested Elements

jdepend supports two nested elements <classpath> and <sourcespath>, that represent PATH like structures.
<sourcespath> is used to define the paths of the source code to analyze.

Examples

<jdepend classpathref="base.path">
    <sourcespath>
        <pathelement location="src" />
    </sourcespath>
</jdepend>
This invokes JDepend on the src directory, writing the output on the standard output. The classpath is defined using a classpath reference.
<jdepend outputfile="docs/jdepend.txt" fork="yes">
    <sourcespath>
        <pathelement location="src" />
    </sourcespath>
    <classpath>
        <pathelement location="classes" />
        <pathelement location="lib/jdepend.jar" />
    </classpath>
</jdepend>
This invokes JDepend in a separate VM on the src and testsrc directories, writing the output in the <docs/jdepend.txt> file. The classpath is defined using nested elements.

Reply via email to