Audit an Existing Workspace

This example shows how to use the instantiations.audit Ant task to audit one or more projects within an existing Eclipse workspace. We will start with a simple example, and then show how to modify that example to accomplish more complex tasks. For the purposes of this example we will assume that

  • A JRE has been installed in the directory C:\Program Files\Java\jre1.6.0_03
  • Eclipse has been installed in the directory C:\build\eclipse,
  • the workspace is located in the directory workspace within the installation directory,
  • the project to be audited is in the directory named Business Model located inside the workspace directory,
  • we can write to the Eclipse installation directory so that we can use the default location for the configuration directory, and
  • we can also write to the temporary directory located at C:\temp.

A Simple Example

We need to specify where to find the JRE used to run Eclipse as well as where Eclipse was installed. Because this is an existing workspace we also want to specify the location of the configuration and workspace directories (so that they will remain consistent across runs). The temporary directory is also required.

The only other required piece of information is to specify the project to be audited. We do this using the fileset tag, specifying the path to the project directory.

The following source shows an Ant task that will accomplish this audit.

<instantiations.audit
		configurationDir="C:\build\eclipse\configuration"
		eclipseDir="C:\build\eclipse"
		jreDir="C:\Program Files\Java\jre1.6.0_03"
		tempDir="C:\temp"
		workspaceDir="C:\build\eclipse\workspace">
	<fileset dir="C:\build\eclipse\workspace\Business Model"/>
</instantiations.audit>
		

If more than one project should be audited you can simply include more fileset tags with the appropriate directory paths.

Controlling the Build

While this example is complete and will result in the specified project being audited, it isn't very interesting because the results of the audit will simply be discarded.

If you want to use the results to control the success of the build, you can use the violationCountThreshold attribute. For example, the following task would cause the build to fail if there are more than 200 violations of either high or medium severity.

<instantiations.audit
		configurationDir="C:\build\eclipse\configuration"
		eclipseDir="C:\build\eclipse"
		jreDir="C:\Program Files\Java\jre1.6.0_03"
		tempDir="C:\temp"
		violationCountThreshold="high+medium&gt;200";
		workspaceDir="C:\build\eclipse\workspace">
	<fileset dir="C:\build\eclipse\workspace\Business Model"/>
</instantiations.audit>
		

Producing a Report

On the other hand, if you want to produce a report of the results of the audit, you would use a nested report element as shown below. The report element defines several attributes used to control the content and format of the report, but for this example we will only show the file attribute, which specifies where the file containing the report is to be created.

<instantiations.audit
		configurationDir="C:\build\eclipse\configuration"
		eclipseDir="C:\build\eclipse"
		jreDir="C:\Program Files\Java\jre1.6.0_03"
		tempDir="C:\temp"
		workspaceDir="C:\build\eclipse\workspace">
	<fileset dir="C:\build\eclipse\workspace\Business Model"/>
	<report file="C:\build\output\reports\audit.html"/>
</instantiations.audit>