# HG changeset patch # User Pavel Tisnovsky # Date 1328287185 -3600 # Node ID 4a18f35c8dffa3aef0059331f039ad78cf9b327a # Parent 5bc6733b29bdb0d93ca19132db41e2e9796c099a 2012-02-03 Pavel Tisnovsky * src/ReportGenerator.java: Added new functionality: table with number of all methods and methods coveraged by the test are used in the generated page with all packages list. Added generation of links to external JavaDoc for packages and classes. * templates/all_packages_template.html: Changed table column names to be more consistent with the rest of the report system. * templates/index.html: Updated width of left column to 25% from 20%. * templates/style.css: New styles used by all_classes_list.html. diff -r 5bc6733b29bd -r 4a18f35c8dff ChangeLog --- a/ChangeLog Wed Feb 01 10:24:45 2012 +0100 +++ b/ChangeLog Fri Feb 03 17:39:45 2012 +0100 @@ -1,3 +1,19 @@ +2012-02-03 Pavel Tisnovsky + + * src/ReportGenerator.java: + Added new functionality: table with number of all methods + and methods coveraged by the test are used in the + generated page with all packages list. + Added generation of links to external JavaDoc + for packages and classes. + * templates/all_packages_template.html: + Changed table column names to be more consistent + with the rest of the report system. + * templates/index.html: + Updated width of left column to 25% from 20%. + * templates/style.css: + New styles used by all_classes_list.html. + 2012-02-01 Pavel Tisnovsky * src/ReportGenerator.java: diff -r 5bc6733b29bd -r 4a18f35c8dff src/ReportGenerator.java --- a/src/ReportGenerator.java Wed Feb 01 10:24:45 2012 +0100 +++ b/src/ReportGenerator.java Fri Feb 03 17:39:45 2012 +0100 @@ -57,6 +57,11 @@ public class ReportGenerator { /** + * Location of internal or external URI to standard API JavaDoc + */ + private static final String DOC_BASE = "http://docs.oracle.com/javase/6/docs/api"; + + /** * Read all classes from a file containing its list. * * @param allClassListFileName @@ -168,7 +173,7 @@ // replace text in template where needed if ("${PACKAGE_AND_CLASS_LIST}".equals(templateLine)) { - addPackageAndClassList(usedPackageNames, testedClasses, out); + addPackageAndClassList(reportDirectory, usedPackageNames, testedClasses, out); } // normal line else @@ -209,9 +214,12 @@ // -> in percent final float percentage = 100.0f*testedClassesCnt / allClassesCnt; // table row background color is based on percentual test coverage ration - String backgroundColor = generateTableRowBackground(percentage); - String str = String.format("%s%d%d%5.1f %%", - backgroundColor, packageName, packageName, allClassesCnt, testedClassesCnt, percentage); + String backgroundColor = generateTableRowBackground(percentage); + String doc = DOC_BASE + "/" + packageName.replace('.', '/') + "/package-summary.html"; + // format output string + String str = String.format("%s%d%d%5.1f %%ext", + backgroundColor, packageName, packageName, + allClassesCnt, testedClassesCnt, percentage, doc); out.add(str); } } @@ -285,6 +293,8 @@ * Add list of all packages and all its classes to a list of string which * represents generated report. * + * @param reportDirectory + * directory where report is generated * @param usedPackageNames * all checked package names * @param testedClasses @@ -292,20 +302,38 @@ * @param out * list of string which represents generated report */ - private static void addPackageAndClassList(Set usedPackageNames, Set testedClasses, List out) + private static void addPackageAndClassList(String reportDirectory, Set usedPackageNames, Set testedClasses, List out) { // iterate through all class names for (String packageName : usedPackageNames) { out.add("

Package " + packageName + "

"); + out.add(""); + out.add(""); + http://docs.oracle.com/javase/6/docs/api/java/math/BigDecimal.html for (String className : testedClasses) { if (className.startsWith(packageName)) { - out.add("" + className + "
"); + Set apiMethods = readApiMethods(reportDirectory, className); + Set testedMethods = readTestedMethods(reportDirectory, className); + // compute number of all methods in a class + final int allMethodsCnt = apiMethods.size(); + // compute number of methods covered by tests + final int testedMethodsCnt = testedMethods.size(); + // -> in percent + final float percentage = 100.0f*testedMethodsCnt / allMethodsCnt; + // table row background color is based on percentual test coverage ration + String backgroundColor = generateTableRowBackground(percentage); + String doc = DOC_BASE + "/" + className.replace('.', '/') + ".html"; + // format output string + String outStr = String.format("", + backgroundColor, className, className, + allMethodsCnt, testedMethodsCnt, percentage, doc); + out.add(outStr); } } - out.add("
"); + out.add("
classmethodscoveredratiodoc
%s%d%d%5.1f %%ext
"); } } @@ -448,6 +476,7 @@ private static void printReportForAllPackages(String reportDirectory, Set usedPackageNames, Set testedClasses) { + // iterate through all tested package names for (String packageName : usedPackageNames) { printReportForPackageToFile(reportDirectory, packageName, testedClasses); @@ -456,6 +485,7 @@ private static void printReportForAllClasses(String reportDirectory, Set testedClasses) { + // iterate through all tested classes for (String testedClass : testedClasses) { Set apiMethods = readApiMethods(reportDirectory, testedClass); diff -r 5bc6733b29bd -r 4a18f35c8dff templates/all_packages_template.html --- a/templates/all_packages_template.html Wed Feb 01 10:24:45 2012 +0100 +++ b/templates/all_packages_template.html Fri Feb 03 17:39:45 2012 +0100 @@ -11,7 +11,7 @@

Package list

all classes

- + ${PACKAGE_LIST}
PackageClassesCoveredRatio
packageclassescoveredratiodoc
diff -r 5bc6733b29bd -r 4a18f35c8dff templates/index.html --- a/templates/index.html Wed Feb 01 10:24:45 2012 +0100 +++ b/templates/index.html Fri Feb 03 17:39:45 2012 +0100 @@ -3,7 +3,7 @@ Test coverage report - + diff -r 5bc6733b29bd -r 4a18f35c8dff templates/style.css --- a/templates/style.css Wed Feb 01 10:24:45 2012 +0100 +++ b/templates/style.css Fri Feb 03 17:39:45 2012 +0100 @@ -51,3 +51,28 @@ /* -moz-border-radius: ; */ } +table.classes_list { + border-width: 0px; + border-spacing: 0px; + border-style: dashed; + border-color: black; + border-collapse: collapse; + background-color: white; + width: 100%; +} +table.classes_list th { + border-width: 1px; + padding: 1px; + border-style: inset; + border-color: gray; + background-color: #c0c0ff; + /* -moz-border-radius: ; */ +} +table.classes_list td { + border-width: 1px; + padding: 1px; + border-style: inset; + border-color: gray; + /* -moz-border-radius: ; */ +} +