Classycle logo

1.2 Dependency Checker

Classycle's Dependency Checker can be used as a command-line tool and as an Ant Task.

1.2 Command Line Tool

Analyser is called from the command line as follows:
java -cp classycle.jar classycle.dependency.DependencyChecker \
                        [-mergeInnerClasses] \
                        [-includingClasses=<pattern1>[,<pattern2>,...]] \
                        [-excludingClasses=<pattern1>[,<pattern2>,...]] \
                        [-reflectionPattern=[<pattern1>,<pattern2>,...]] \
                        [-renderer=<fully qualified class name>] \
                        -dependencies=<description>|@<description file> \
                        <class files, zip/jar/war/ear files, or folders>
The argument is a list of sources for class files to be analyzed:
  • Particular .class file
  • zip/jar/war/ear files: All class files in such a compressed file
  • Folder: All class files in the folder (including all subfolders) and all class files in zip/jar/war/ear files of the folder

The options have the following meaning:

-mergeInnerClasses
Inner class vertices will be merged with their outer classes.
-includingClasses
Comma-separated list of one or more wild-card patterns for fully-qualified class names of classes which are included in the graph. Only '*' is interpreted as wild-card character.
-excludingClasses
Comma-separated list of one or more wild-card patterns for fully-qualified class names of classes which are excluded from the graph. Only '*' is interpreted as wild-card character.
-reflectionPattern
Comma-separated list of zero or more wild-card patterns for fully-qualified class names which are referred in the class file by plain string constants. For more details see section 1.1.1.
-renderer
The fully-qualified class name of a ResultRenderer. By default DefaultResultRenderer is used. classycle.dependency.XMLResultRenderer renders the result as XML.
-dependencies
Either a dependency definition file (if preceeded by a '@') or a description with syntax of dependency definition files. Note, that this is a mandatory option.

1.2.2 Ant Task

The ant task works similar as the ant task for Analyser. Here is a simple example showing its usage:

<project name="DependencyCheckingTaskTest" default="test" 
         basedir="temporaryTestDirectory">
         
  <property name="package" value="classycle"/>>

  <target name="test">
    <taskdef name="classycleDependencyCheck" 
             classname="classycle.ant.DependencyCheckingTask"/>
	
    <classycleDependencyCheck failOnUnwantedDependencies="true"
                              excludingClasses="*Test,*.All*Tests">
      <fileset dir="../classes">
        <include name="**/*.class"/>
      </fileset>
      show allResults
      [util] = ${package}.util.*
      [notUtil] = ${package}.A* excluding [util]
      check [util] independentOf [notUtil]
      check [notUtil] independentOf [util]
    </classycleDependencyCheck>
  </target>
</project>  

The source of class files can be specified by filesets and zipfilesets. The dependency definitions commands (red lines) are embedded in the task. For their syntax see section 4. Instead of embedding one can also specify a dependency definition file with the attribute definitionFile. All embedded definition commands will be ignored if this attribute is specified. For the attributes and their meaning see the API documentation of DependencyCheckingTask.

Running this example build file on the console yields


Buildfile: dependencyCheckingTaskTestBuild.xml

test:
[classycleDependencyCheck] show onlyShortestPaths allResults
[classycleDependencyCheck] check [util] independentOf [notUtil] OK
[classycleDependencyCheck] check [notUtil] independentOf [util]
[classycleDependencyCheck]   Dependency found:
[classycleDependencyCheck]   classycle.AnalyserCommandLine
[classycleDependencyCheck]     -> classycle.CommandLine
[classycleDependencyCheck]       -> classycle.util.StringPatternSequence
[classycleDependencyCheck]       -> classycle.util.StringPattern
[classycleDependencyCheck]       -> classycle.util.AndStringPattern
[classycleDependencyCheck]       -> classycle.util.WildCardPattern
[classycleDependencyCheck]       -> classycle.util.NotStringPattern
[classycleDependencyCheck]       -> classycle.util.TrueStringPattern
[classycleDependencyCheck]   classycle.Analyser
[classycleDependencyCheck]     -> classycle.util.StringPattern
[classycleDependencyCheck]     -> classycle.util.TrueStringPattern
[classycleDependencyCheck]     -> classycle.util.Text

BUILD FAILED
/home/fj/dev/Classycle/dependencyCheckingTaskTestBuild.xml:8: 
        Unwanted dependencies found. See output for details.

Total time: 2 seconds