To export the metrics using a headless build, there are two steps, both of which can be contained in an Ant build file:
<project name="metrics" default="export"> <!-- This target actually exports the metrics. It runs inside Eclipse after the "launch" target launches Eclipse in headless mode --> <target name="export"> <eclipse.refreshLocal resource="ECLIPSE_PROJECT_NAME" depth="infinite"/> <eclipse-metrics.export eclipseProject="ECLIPSE_PROJECT_NAME" dir="YOUR_EXPORT_DIRECTORY_HERE" html="true" htmlRowsPerPage="10" htmlDashboard="true" csv="true"/> <compilationUnits dir="src"> <exclude name="**/*Bean.java"/> </compilationUnits> </eclipse-metrics.export </target> <!-- This target launches Eclipse in headless mode and runs the default target ("export") of this build file --> <target name="launch"> <java fork="true" jar="ECLIPSE_INSTALL_DIR/plugins/org.eclipse.equinox.launcher_VERSION.jar"> <jvmarg value="-Djava.awt.headless=true"/> <!-- Only for MacOS X --> <arg value="-application"/> <arg value="org.eclipse.ant.core.antRunner"/> <arg value="-buildfile"/> <arg value="THE_NAME_OF_THIS_BUILD_FILE"/> <arg value="-data"/> <arg value="PATH_TO_YOUR_WORKSPACE"/> </java> </target> </project>
Change the parts in capitals to appropriate values for your setup.
Run ant specifying the "launch" target. This should launch Eclipse in headless mode and produce the metrics. You can put the two targets in different Ant build files if you like. The "export" target must be the default target wherever it is placed (you can of course call it anything you like as long as it is the default target).
The above procedure does not work on some versions of Eclipse Europa running under Windows. This problem appears to have been fixed in Ganymede.
The attributes of the eclipse-metrics.export task are:
Attribute Name | Type | Required | Default | Description |
---|---|---|---|---|
eclipseProject | String | Yes | The name of the project in the Eclipse workspace | |
dir | String | Yes | The directory to which the metrics will be written | |
html | Boolean | No | true | Whether to export the metrics as HTML |
htmlRowsPerPage | Integer | No | Integer.MAX_VALUE | The number of rows per page when exporting metrics as HTML |
htmlDashboard | Boolean | No | true | Whether to produce the 'dashboard' page when exporting metrics as HTML |
htmlJava | Boolean | No | false | Whether to export the Java source and link to it from the HTML metrics tables |
csv | Boolean | No | true | Whether to export the metrics as CSV |
The eclipse-metrics.export task supports an optional compilationUnits child element. This is an ant FileSet. The dir attribute for this element must refer to one of the Eclipse project's source folders. The compilationUnits child element may be repeated as often as necessary to include / exclude all of the required source files. If this element is omitted, the configuration defined in the Metrics Properties page (within Eclipse) for the project will be used.