Manual

This section provides information on how to use the DSM library to analyze existing Java applications using DSMs. It is assumed that you have already imported the DSM project into Eclipse. For instructions see here.

Extracting dependency information

A utility Ant task can be used to easily extract dependency information from any Java project using Dependency Finder.  This task is called “get.dependencies”, and is located in the following ant script:

		/jDSM/ant/build.xml

Several properties should be set in order to run this task. The properties are located in the following properties file:

		/jDSM/ant/ant.properties        

Below is a short description of these properties. A more detailed description can be found here.


Property

Description

lib.path

A directory containing the JAVA project to be scanned for dependencies. All subdirectories of this directory are scanned recursively for JAR or class files.

package.filter

A regular expression for selecting the classes from which dependencies are extracted. The fully qualified name of the class is matched against this regular expression.

results.folder

Folders where to place the resulting XML file containing the dependency information. This file is named “dependencies.xml”.

Using the jDSM API

Once the dependency XML has been produced it can be used to create DSM instances which can be analyzed using the implemented algorithms. The following code snippet illustrates analyzing a DSM to extract metrics for propagation cost and clustered cost. For more details see the jDSM API.

 //load from Dependency Finder XLM
 DesignStructureMatrix<Dependency> dsm = DependencyFinderDSMProvider
 					.loadDesignStructureMatrix(args[0], args[1]);
 //save the DSM to SVG
 SVGOutput.printDsm(dsm, new FileOutputStream("dsm_original.svg")); 
  
 //Save to a proprietary XML format
 dsm.saveToXml(new FileOutputStream("dsm_original.xml"));
 //Load the proprietary XML
 DependencyDSM newDsmInstance = new DependencyDSM();
 newDsmInstance.loadFromXml(new FileInputStream("dsm_original.xml"));

 //Compute propagation cost
 double propagationCost = PropagationCost.computePropagationCost(dsm);
 //Compute clustered  cost
 ClusteredCostResult clusteredCostResult = 
			ClusteredCost.computeClusteredCost(dsm, 0.1d);
 int nrVerticalBusses = clusteredCostResult.getVerticalBusses().size();
 long clusteredCost = clusteredCostResult.getClusteredCost();
 double relativeClusteredCost = clusteredCostResult.getRelativeClusteredCost();
 clusteredCostResult.getDsm().saveToXml(new FileOutputStream("dsm_clustered.xml"));