|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMatchingTask
javancss.JavancssAntTask
public class JavancssAntTask
Ant task to report and check basic code metrics.
This task wraps the JavaNCSS library for determining code metrics. The library determines several code metrics such as object counts, non-commented source statements (NCSS), cyclomatic complexity numbers (CCN), and javadoc statements. These counts are subtotaled per function, class, and package. This task allows you to place minimum and maximum thresholds on each of these (not all of these make sence but all are included for completeness).
The original version of this task was written by Steve Jernigan and made available on SourceForge as the JavaNCSS2Ant project. It was subsequently extended by Phillip Wells to enable access to the report generation feature of the tool whereupon it was submitted for inclusion in Ant itself.
JavaNCSS was developed by Christoph Clemens Lee and is available here.
Field Summary | |
---|---|
private boolean |
abortOnFail
Whether the build should halt if there is an error or a threshold is exceeded. |
private int |
ccnPerFuncMax
The maximum value of the Cyclomatic Complexity Number per function. |
private int |
ccnPerFuncMin
The minimum value of the Cyclomatic Complexity Number per function. |
private boolean |
classMetrics
Whether class metrics should be generated. |
private Path |
classpath
The classpath to be used. |
private int |
classPerClassMax
The maximum number of inner classes per class. |
private int |
classPerClassMin
The minimum number of inner classes per class. |
private int |
classPerPkgMax
The maximum number of classes per package. |
private int |
classPerPkgMin
The minimum number of classes per package. |
private CommandlineJava |
commandline
The command to be executed to run to tool. |
private static int |
FAILURE
Indicates the failure of the JavaNCSS process. |
private java.lang.String |
format
The format of the output file. |
private int |
funcPerClassMax
The maximum number of functions per class. |
private int |
funcPerClassMin
The minimum number of functions per class. |
private int |
funcPerPkgMax
The maximum number of functions per package. |
private int |
funcPerPkgMin
The minimum number of functions per package. |
private boolean |
functionMetrics
Whether function metrics should be generated. |
private boolean |
generateReport
Whether to generate a report. |
private Javancss |
javancss
The JavaNCSS object containing details of the code whose metrics are to be checked. |
private int |
jvdcPerClassMax
The maximum number of javadoc comments per class. |
private int |
jvdcPerClassMin
The minimum number of javadoc comments per class. |
private int |
jvdcPerFuncMax
The maximum number of javadoc comments per function. |
private int |
jvdcPerFuncMin
The minimum number of javadoc comments per function. |
private int |
ncssPerClassMax
The maximum number of non-commenting source statements per class. |
private int |
ncssPerClassMin
The minimum number of non-commenting source statements per class. |
private int |
ncssPerFuncMax
The maximum number of non-commenting source statements per function. |
private int |
ncssPerFuncMin
The minimum number of non-commenting source statements per function. |
private int |
ncssPerPkgMax
The maximum number of non-commenting source statements per package. |
private int |
ncssPerPkgMin
The minimum number of non-commenting source statements per package. |
private java.io.File |
outputfile
The location of the output file. |
private boolean |
packageMetrics
Whether package metrics should be generated. |
private java.io.File |
srcdir
The directory containing the source files to be scanned by the tool. |
private static int |
SUCCESS
Indicates the success of the JavaNCSS process. |
Constructor Summary | |
---|---|
JavancssAntTask()
Creates a new instance of the task. |
Method Summary | |
---|---|
private boolean |
classThresholdExceeded(java.util.Vector classMetrics)
Checks thresholds for the specified class or interface. |
private boolean |
classThresholdsExceeded(java.util.Vector fileList)
Checks thresholds for all classes and interfaces. |
private java.util.Vector |
copyFiles(java.lang.String[] filesArray)
Converts the specified array of filenames into a vector of paths. |
Path |
createClasspath()
Maybe creates a nested classpath element. |
private java.io.File |
createSourceListFile(java.util.Vector fileList)
Creates a temporary file containing a list of all source files to be analysed. |
void |
execute()
Executes this task. |
private java.util.Vector |
findFilesToAnalyse()
Builds a list of all files to be analysed. |
private boolean |
functionThresholdExceeded(java.util.Vector functionMetrics)
Checks thresholds for the specified function. |
private boolean |
functionThresholdsExceeded(java.util.Vector fileList)
Checks thresholds for all functions. |
private int |
generateReport(java.util.Vector fileList)
Generates a report on the specified files. |
private java.lang.String[] |
getCommandLineArguments(java.util.Vector fileList)
Gets the command line arguments to be sent to JavaNCSS. |
private Javancss |
getJavaNcss(java.util.Vector fileList)
Gets the JavaNCSS object containing details of the code whose metrics are to be checked. |
private boolean |
packageThresholdExceeded(PackageMetric packageMetrics)
Checks thresholds for the specified package. |
private boolean |
packageThresholdsExceeded(java.util.Vector fileList)
Checks package thresholds for all packages. |
void |
setAbortOnFail(boolean abortOnFail)
Sets whether the build should halt if there is an error or a threshold is exceeded. |
void |
setCcnPerFuncMax(int ccnPerFuncMax)
Sets the maximum value of the Cyclomatic Complexity Number per function. |
void |
setCcnPerFuncMin(int ccnPerFuncMin)
Sets the minimum value of the Cyclomatic Complexity Number per function. |
void |
setClassMetrics(boolean classMetrics)
Whether class/interface metrics should be generated. |
void |
setClasspath(Path classpath)
Set the classpath to be used. |
void |
setClassPerClassMax(int classPerClassMax)
Sets the maximum number of inner classes per class. |
void |
setClassPerClassMin(int classPerClassMin)
Sets the minimum number of inner classes per class. |
void |
setClassPerPkgMax(int classPerPkgMax)
Sets the maximum number of classes per package. |
void |
setClassPerPkgMin(int classPerPkgMin)
Sets the minimum number of classes per package. |
void |
setFormat(java.lang.String format)
Sets the format of the output file. |
void |
setFuncPerClassMax(int funcPerClassMax)
Sets the maximum number of functions per class. |
void |
setFuncPerClassMin(int funcPerClassMin)
Sets the minimum number of functions per class. |
void |
setFuncPerPkgMax(int funcPerPkgMax)
Sets the maximum number of functions per package. |
void |
setFuncPerPkgMin(int funcPerPkgMin)
Sets the minimum number of functions per package. |
void |
setFunctionMetrics(boolean functionMetrics)
Whether function metrics should be generated. |
void |
setGenerateReport(boolean generateReport)
Whether a report should be generated. |
void |
setJvdcPerClassMax(int jvdcPerClassMax)
Sets the maximum number of javadoc comments per class. |
void |
setJvdcPerClassMin(int jvdcPerClassMin)
Sets the minimum number of javadoc comments per class. |
void |
setJvdcPerFuncMax(int jvdcPerFuncMax)
Sets the maximum number of javadoc comments per function. |
void |
setJvdcPerFuncMin(int jvdcPerFuncMin)
Sets the minimum number of javadoc comments per function. |
void |
setNcssPerClassMax(int ncssPerClassMax)
Sets the maximum number of non-commenting source statements per class. |
void |
setNcssPerClassMin(int ncssPerClassMin)
Sets the minimum number of non-commenting source statements per class. |
void |
setNcssPerFuncMax(int ncssPerFuncMax)
Sets the maximum number of non-commenting source statements per function. |
void |
setNcssPerFuncMin(int ncssPerFuncMin)
Sets the minimum number of non-commenting source statements per function. |
void |
setNcssPerPkgMax(int ncssPerPkgMax)
Sets the maximum number of non-commenting source statements per package. |
void |
setNcssPerPkgMin(int ncssPerPkgMin)
Sets the minimum number of non-commenting source statements per package. |
void |
setOutputfile(java.io.File outputfile)
Sets the location of the output file. |
void |
setPackageMetrics(boolean packageMetrics)
Whether package metrics should be generated. |
void |
setSrcdir(java.io.File srcdir)
Sets the directory to be scanned by the tool. |
private boolean |
thresholdsExceeded(java.util.Vector fileList)
Checks to see if the metrics of the specified files have exceeded any of the thresholds. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private CommandlineJava commandline
private boolean abortOnFail
private java.io.File srcdir
private Path classpath
private java.io.File outputfile
private java.lang.String format
private static final int FAILURE
private static final int SUCCESS
private int classPerPkgMax
private int classPerPkgMin
private int funcPerPkgMax
private int funcPerPkgMin
private int ncssPerPkgMax
private int ncssPerPkgMin
private int classPerClassMax
private int classPerClassMin
private int funcPerClassMax
private int funcPerClassMin
private int ncssPerClassMax
private int ncssPerClassMin
private int jvdcPerClassMax
private int jvdcPerClassMin
private int jvdcPerFuncMax
private int jvdcPerFuncMin
private int ccnPerFuncMax
private int ccnPerFuncMin
private int ncssPerFuncMax
private int ncssPerFuncMin
private boolean packageMetrics
private boolean classMetrics
private boolean functionMetrics
private boolean generateReport
private Javancss javancss
Constructor Detail |
---|
public JavancssAntTask()
Method Detail |
---|
public void setFormat(java.lang.String format)
format
- the format of the output file. Allowable values are 'plain'
or 'xml'.public void setPackageMetrics(boolean packageMetrics)
packageMetrics
- true if they should; false otherwise.public void setClassMetrics(boolean classMetrics)
classMetrics
- true if they should; false otherwise.public void setFunctionMetrics(boolean functionMetrics)
functionMetrics
- true if they should; false otherwise.public void setGenerateReport(boolean generateReport)
generateReport
- true if they should; false otherwise.public void setSrcdir(java.io.File srcdir)
srcdir
- the directory to be scanned by the tool.public void setOutputfile(java.io.File outputfile)
outputfile
- the location of the output file.public void setClasspath(Path classpath)
classpath
- the classpath to be used.public void setAbortOnFail(boolean abortOnFail)
abortOnFail
- true if it should; false otherwise.public void execute() throws BuildException
BuildException
- if an error occurs.private int generateReport(java.util.Vector fileList)
fileList
- the files to be analysed.
SUCCESS
if there were no errors; otherwise FAILURE
.
BuildException
- if an error occurs whilst generating the report.private boolean thresholdsExceeded(java.util.Vector fileList)
fileList
- the files to be analysed.
private java.util.Vector findFilesToAnalyse()
private java.util.Vector copyFiles(java.lang.String[] filesArray)
filesArray
- an array of filenames.
public Path createClasspath()
private java.lang.String[] getCommandLineArguments(java.util.Vector fileList)
fileList
- a list of all source files to be analysed.
private java.io.File createSourceListFile(java.util.Vector fileList)
fileList
- the source files to be analysed.
private Javancss getJavaNcss(java.util.Vector fileList)
fileList
- the files to be analysed.
private boolean packageThresholdsExceeded(java.util.Vector fileList)
fileList
- the files to be analysed.
private boolean packageThresholdExceeded(PackageMetric packageMetrics)
packageMetrics
- the metrics of the package under test.
private boolean classThresholdsExceeded(java.util.Vector fileList)
fileList
- the files to be analysed.
private boolean classThresholdExceeded(java.util.Vector classMetrics)
classMetrics
- the metrics of the class or interface under test.
private boolean functionThresholdsExceeded(java.util.Vector fileList)
fileList
- the files to be analysed.
private boolean functionThresholdExceeded(java.util.Vector functionMetrics)
functionMetrics
- the metrics of the function under test.
public void setClassPerPkgMax(int classPerPkgMax)
classPerPkgMax
- the maximum number of classes per package.public void setClassPerPkgMin(int classPerPkgMin)
classPerPkgMin
- the minimum number of classes per package.public void setFuncPerPkgMax(int funcPerPkgMax)
funcPerPkgMax
- the maximum number of functions per package.public void setFuncPerPkgMin(int funcPerPkgMin)
funcPerPkgMin
- the minimum number of functions per package.public void setNcssPerPkgMax(int ncssPerPkgMax)
ncssPerPkgMax
- the maximum number of non-commenting source
statements per package.public void setNcssPerPkgMin(int ncssPerPkgMin)
ncssPerPkgMin
- the minimum number of non-commenting source
statements per package.public void setClassPerClassMax(int classPerClassMax)
classPerClassMax
- the maximum number of inner classes per class.public void setClassPerClassMin(int classPerClassMin)
classPerClassMin
- the minimum number of inner classes per class.public void setFuncPerClassMax(int funcPerClassMax)
funcPerClassMax
- the maximum number of functions per class.public void setFuncPerClassMin(int funcPerClassMin)
funcPerClassMin
- the minimum number of functions per class.public void setNcssPerClassMax(int ncssPerClassMax)
ncssPerClassMax
- the maximum number of non-commenting source
statements per class.public void setNcssPerClassMin(int ncssPerClassMin)
ncssPerClassMin
- the minimum number of non-commenting source
statements per class.public void setJvdcPerClassMax(int jvdcPerClassMax)
jvdcPerClassMax
- the maximum number of javadoc comments per class.public void setJvdcPerClassMin(int jvdcPerClassMin)
jvdcPerClassMin
- the minimum number of javadoc comments per class.public void setCcnPerFuncMax(int ccnPerFuncMax)
ccnPerFuncMax
- the maximum value of the Cyclomatic Complexity Number
per function.public void setCcnPerFuncMin(int ccnPerFuncMin)
ccnPerFuncMin
- the minimum value of the Cyclomatic Complexity Number
per function.public void setNcssPerFuncMax(int ncssPerFuncMax)
ncssPerFuncMax
- the maximum number of non-commenting source
statements per function.public void setNcssPerFuncMin(int ncssPerFuncMin)
ncssPerFuncMin
- the minimum number of non-commenting source
statements per function.public void setJvdcPerFuncMax(int jvdcPerFuncMax)
jvdcPerFuncMax
- the maximum number of javadoc comments per function.public void setJvdcPerFuncMin(int jvdcPerFuncMin)
jvdcPerFuncMin
- the minimum number of javadoc comments per function.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |