|
From: Timo <Mai...@gm...> - 2015-05-06 19:58:24
|
Hello everyone, I am currently developing a project using Java 8 and want to check the code coverage of my tests. As you know, Cobertura does not fully support Java 8 because JavaNCSS cannot parse Java 8 source code. The coverage reporting does seem to work flawlessly, however the complexity calcuation fails with an unpleasant exception from JavaNCSS. Since I do not care about the complexity reporting right now, I would like to be able to disable it and use Cobertura for code coverage reporting only. As I was searching for a way to do that I discovered this feature in the roadmap [1]. So I thought I would give the source code of Cobertura a look and see how it could be implemented. First of all, I am not sure I understand all design/architecture desicions in Cobertura. That being said, here is my rough proposal how to implement enabling/disabling the code complexity calculator: Preparations - To make Cobertura's reporting flexible and maintainable, I would like to separate data, view and logic. Currently, the various classes generating output (e.g. HTMLReport) mix it all together. Let's call HTMLReport etc. "OutputReports" to distinguish them from net.sourceforge.cobertura.reporting.Report. - There should be a class that can hold complexity information, without any logic. Not the ComplexityCalculator, but something that is filled using the ComplexityCalculator. This way we can separate logic from data and OutputReports do not have to know about the ComplexityCalculator. Let's call this class "ComplexityData". - Cobertura should use a template engine like Velocity or Freemarker to generate output. This way we can easily implement reports with or without complexity information and even "themes" in some future version. - There should be a ReportingTask, much like the CheckCoverageTask, that creates the NativeReport. The ComplexityCalculator and the ComplexityData object should be created there. Only the ComplexityData object should be passed to the NativeReport. Once the preparations are done, we can implement the switch: - Add a Metric enum with two values: COVERAGE and COMPLEXITY - Add a method to the Report interface: hasMetric(Metric) - Use that method in the ReportFormatStrategy implementations to decide which OutputReport to use - Implement OutputReports without complexity information - Add a method named "coverageOnly" to the DSL which sets an internal boolean. - When report() is called, the boolean is passed to the ReportingTask which returns a report with or without complexity information. The default is to calculate both coverage and complexity to stay API compatible with earlier versions. What do you think? Greetings from Germany Timo [1] https://github.com/cobertura/cobertura/wiki/Roadmap |