changeset 3:61f453c6b172

2012-01-09 Pavel Tisnovsky <ptisnovs@redhat.com> * src/index.html: * src/style.css: * templates/index.html: * templates/style.css: Moved into other directory. * templates/all_classes_template.html: * templates/all_packages_template.html: * templates/package_template.html: Prepared templates for test coverage HTML report. * src/PrintPublicMethods.java: * src/PrintTestCoverage.java: Refactoring and Javadoc. * Makefile: Updated
author Pavel Tisnovsky <ptisnovs@redhat.com>
date Mon, 09 Jan 2012 14:57:59 +0100
parents 8612fcdfab82
children 730c5549c0f9
files ChangeLog Makefile src/PrintPublicMethods.java src/PrintTestCoverage.java src/index.html src/style.css templates/all_classes_template.html templates/all_packages_template.html templates/index.html templates/package_template.html templates/style.css
diffstat 11 files changed, 169 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jan 06 12:25:10 2012 +0100
+++ b/ChangeLog	Mon Jan 09 14:57:59 2012 +0100
@@ -1,3 +1,20 @@
+2012-01-09  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/index.html:
+	* src/style.css:
+	* templates/index.html:
+	* templates/style.css:
+	Moved into other directory.
+	* templates/all_classes_template.html:
+	* templates/all_packages_template.html:
+	* templates/package_template.html:
+	Prepared templates for test coverage HTML report.
+	* src/PrintPublicMethods.java:
+	* src/PrintTestCoverage.java:
+	Refactoring and Javadoc.
+	* Makefile:
+	Updated
+
 2012-01-06  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/PrintClassList.java:
--- a/Makefile	Fri Jan 06 12:25:10 2012 +0100
+++ b/Makefile	Mon Jan 09 14:57:59 2012 +0100
@@ -40,6 +40,7 @@
 CLASSDIR=bin
 REPORTDIR=reports
 DOCS=docs
+TEMPLATEDIR=templates
 
 JAVA=java
 JAVAC=javac
@@ -139,7 +140,7 @@
 	$(JAVA) -cp $(CLASSDIR) PrintClassList `cat $(PATH_TO_RT_JAR_FILE)` > $(REPORTDIR)/$(ALL_CLASS_LIST)
 
 gen_report: $(REPORTDIR)
-	cp -u $(SOURCEPATH)/index.html $(REPORTDIR)
-	cp -u $(SOURCEPATH)/style.css $(REPORTDIR)
+	cp -u $(TEMPLATEDIR)/index.html $(REPORTDIR)
+	cp -u $(TEMPLATEDIR)/style.css $(REPORTDIR)
 	java -cp $(CLASSDIR) ReportGenerator $(REPORTDIR)/$(ALL_CLASS_LIST) $(CLASS_LIST) $(REPORTDIR)
 
--- a/src/PrintPublicMethods.java	Fri Jan 06 12:25:10 2012 +0100
+++ b/src/PrintPublicMethods.java	Mon Jan 09 14:57:59 2012 +0100
@@ -64,10 +64,13 @@
         Class clazz = null;
         try {
             clazz = Class.forName(className);
+            // we need to get a list of public classes only
+            // (Interfaces and non public classes is not interesting ATM)
             if (!clazz.isInterface() && Modifier.isPublic(clazz.getModifiers())) {
                 return clazz;
             }
         }
+        // some exceptions could be thrown by Class.forName()
         catch (ClassNotFoundException e) {
             return null;
         }
@@ -92,9 +95,12 @@
      * @return method name without prefixes
      */
     private static String acquireMethodName(String methodName) {
+        // please note, that sequence of prefixes is very important
         final String[] prefixes = new String[] {"public", "final", "native", "synchronized", "static"};
         String methodNameString = methodName;
+        // remove all prefixes
         for (String prefix : prefixes) {
+            // remove one prefix
             methodNameString = removePrefix(methodNameString, prefix);
         }
         return removeThrowsFromDeclaration(methodNameString);
@@ -143,19 +149,22 @@
     }
 
     /**
-     * Print all public method from given class name (if such class exists).
+     * Get all public methods from given class name (if such class exists).
      * 
      * @param className
      *            name of a class (including package name)
+     * @return set of all public methods
      */
     @SuppressWarnings("unchecked")
     private static Set<String> getAllPublicMethodsForClass(String className) {
         Set<String> out = new TreeSet<String>();
         Class clazz = getClass(className);
+        // in case of error, empty set is returned (not null)
         if (clazz == null) {
             return out;
         }
         Method[] methods = clazz.getDeclaredMethods();
+        // process all methods select add only public ones
         for (Method method : methods) {
             if (Modifier.isPublic(method.getModifiers())) {
                 String methodName = acquireMethodName(method.toString());
@@ -165,14 +174,24 @@
         return out;
     }
 
+    /**
+     * Get all public methods from given class name (if such class exists).
+     * 
+     * 
+     * @param className
+     *            name of a class (including package name)
+     * @return set of all public constructors
+     */
     @SuppressWarnings("unchecked")
     private static Set<String> getAllConstructors(String className) {
         Set<String> out = new TreeSet<String>();
         Class clazz = getClass(className);
+        // in case of error, empty set is returned (not null)
         if (clazz == null) {
             return out;
         }
         Constructor[] constructors = clazz.getConstructors();
+        // process all constructors select add only public ones
         for (Constructor constructor : constructors) {
             if (Modifier.isPublic(constructor.getModifiers())) {
                 String methodName = acquireMethodName(constructor.toString());
@@ -182,12 +201,40 @@
         return out;
     }
 
+    /**
+     * List all public methods and public constructors for given class
+     * 
+     * @param className
+     *            name of class to list
+     */
     private static void printAllPublicMethodsAndConstructors(String className)
     {
+        printAllConstructors(className);
+        printAllPublicMethods(className);
+    }
+
+    /**
+     * List all public constructors for given class
+     * 
+     * @param className
+     *            name of class to list
+     */
+    private static void printAllConstructors(String className)
+    {
         for (String methodSignature : getAllConstructors(className))
         {
             System.out.println(methodSignature);
         }
+    }
+
+    /**
+     * List all public methods for given class
+     * 
+     * @param className
+     *            name of class to list
+     */
+    private static void printAllPublicMethods(String className)
+    {
         for (String methodSignature : getAllPublicMethodsForClass(className))
         {
             System.out.println(methodSignature);
@@ -202,6 +249,7 @@
      *            list. 
      */
     public static void main(String[] args) {
+        // first argument should exists - it should contains path to file with class list
         if (args.length == 1)
         {
             printAllPublicMethodsAndConstructors(args[0].trim());
--- a/src/PrintTestCoverage.java	Fri Jan 06 12:25:10 2012 +0100
+++ b/src/PrintTestCoverage.java	Mon Jan 09 14:57:59 2012 +0100
@@ -860,8 +860,15 @@
         }
     }
 
+    /**
+     * Entry point to this tool.
+     * 
+     * @param args
+     *            should contain one argument - full name of class to check
+     */
     public static void main(String[] args)
     {
+        // full name of class to check should be specified on command line
         if (args.length == 1)
         {
             String className = args[0].trim();
--- a/src/index.html	Fri Jan 06 12:25:10 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
-<html>
-    <head>
-        <title>Test coverage report</title>
-    </head>
-        <frameset cols="20%,80%" title="">
-        <frameset rows="40%,60%" title="">
-            <frame src="all_packages.html" name="PackageListFrame" title="Package List" scrolling="yes">
-            <frame src="all_classes.html" name="ClassesListFrame" title="All public classes" scrolling="yes">
-        </frameset>
-        <frame src="all_results.html" name="ResultsFrame" title="Test coverage" scrolling="yes">
-        <noframes>
-            <h2>Frame Alert</h2>
-                <p>This document is designed to be viewed using the frames
-                feature. If you see this message, you are using a
-                non-frame-capable web client.</p>
-        </noframes>
-    </frameset>
-</html>
-
--- a/src/style.css	Fri Jan 06 12:25:10 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-body      {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; background-color:#ffffff; margin-left: 0px; margin-top: 0px}
-h1        {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; text-align:center; padding-left: 1em; margin: 0}
-h2        {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; padding-left: 1em; padding-right:1cm}
-h3        {font-family: arial, helvetica, sans-serif; color:#000000; background:#a0a080; padding-left: 1em; padding-right:1cm}
-h4        {font-family: arial, helvetica, sans-serif; color:#000000; background:#c0c0a0; padding-left: 1em; padding-right:1cm; margin-bottom: 5px}
-a         {font-family: arial, helvetica, sans-serif; color:#0000ff; text-decoration:none}
-a:link    {color:#0000ff}
-a:visited {color:#0000ff}
-a:visited {color:#0000ff}
-a:hover   {color:#ffffff; background:#404040}
-p         {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; padding-left:1em; padding-right:1em}
-li        {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify}
-pre       {}
-tr        {font-family: arial, helvetica, sans-serif; text-align:left}
-td        {font-family: arial, helvetica, sans-serif; text-align:left}
-td.center {font-family: arial, helvetica, sans-serif; text-align:center}
-th.center {font-family: arial, helvetica, sans-serif; text-align:center}
-
-.forms    {background-color: #f0f0dd; vertical-align: top; width: 720px; border-collapse: collapse; border-color:#808080; margin-left:32px}
-
-.present-method     {background-color:#006000}
-.absent-method      {background-color:#600000}
-
-.method-return-type {}
-.method-name        {}
-.method-params      {}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/all_classes_template.html	Mon Jan 09 14:57:59 2012 +0100
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+    <head>
+        <title>Class list</title>
+        <meta name="Generator" content="MauveTestCoverage" />
+        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+        <link type="text/css" rel="StyleSheet" href="style.css" />
+    </head>
+    <body>
+        <h1>Class list</h1>
+${PACKAGE_AND_CLASS_LIST}
+    </body>
+</html>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/all_packages_template.html	Mon Jan 09 14:57:59 2012 +0100
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+    <head>
+        <title>Package list</title>
+        <meta name="Generator" content="MauveTestCoverage" />
+        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+        <link type="text/css" rel="StyleSheet" href="style.css" />
+    </head>
+    <body>
+        <h1>Package list</h1>
+<a target='ClassesListFrame' href='all_classes.html'>all classes</a><br /><br />
+${PACKAGE_LIST}
+    </body>
+</html>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/index.html	Mon Jan 09 14:57:59 2012 +0100
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
+<html>
+    <head>
+        <title>Test coverage report</title>
+    </head>
+        <frameset cols="20%,80%" title="">
+        <frameset rows="40%,60%" title="">
+            <frame src="all_packages.html" name="PackageListFrame" title="Package List" scrolling="yes">
+            <frame src="all_classes.html" name="ClassesListFrame" title="All public classes" scrolling="yes">
+        </frameset>
+        <frame src="all_results.html" name="ResultsFrame" title="Test coverage" scrolling="yes">
+        <noframes>
+            <h2>Frame Alert</h2>
+                <p>This document is designed to be viewed using the frames
+                feature. If you see this message, you are using a
+                non-frame-capable web client.</p>
+        </noframes>
+    </frameset>
+</html>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/package_template.html	Mon Jan 09 14:57:59 2012 +0100
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+    <head>
+        <title>Class list</title>
+        <meta name="Generator" content="MauveTestCoverage" />
+        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+        <link type="text/css" rel="StyleSheet" href="style.css" />
+    </head>
+    <body>
+        <h1>Class list</h1>
+${CLASS_LIST}
+    </body>
+</html>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/style.css	Mon Jan 09 14:57:59 2012 +0100
@@ -0,0 +1,27 @@
+body      {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; background-color:#ffffff; margin-left: 0px; margin-top: 0px}
+h1        {font-family: arial, helvetica, sans-serif; color:#000000; background:#80a0a0; text-align:center; padding-left: 1em; margin: 0}
+h2        {font-family: arial, helvetica, sans-serif; color:#000000; background:#c0c060; padding-left: 1em; padding-right:1cm}
+h3        {font-family: arial, helvetica, sans-serif; color:#000000; background:#a0a080; padding-left: 1em; padding-right:1cm}
+h4        {font-family: arial, helvetica, sans-serif; color:#000000; background:#c0c0a0; padding-left: 1em; padding-right:1cm; margin-bottom: 5px}
+a         {font-family: arial, helvetica, sans-serif; color:#0000ff; text-decoration:none}
+a:link    {color:#0000ff}
+a:visited {color:#0000ff}
+a:visited {color:#0000ff}
+a:hover   {color:#ffffff; background:#404040}
+p         {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify; padding-left:1em; padding-right:1em}
+li        {font-family: arial, helvetica, sans-serif; color:#000000; text-align:justify}
+pre       {}
+tr        {font-family: arial, helvetica, sans-serif; text-align:left}
+td        {font-family: arial, helvetica, sans-serif; text-align:left}
+td.center {font-family: arial, helvetica, sans-serif; text-align:center}
+th.center {font-family: arial, helvetica, sans-serif; text-align:center}
+
+.forms    {background-color: #f0f0dd; vertical-align: top; width: 720px; border-collapse: collapse; border-color:#808080; margin-left:32px}
+
+.present-method     {background-color:#006000}
+.absent-method      {background-color:#600000}
+
+.method-return-type {}
+.method-name        {}
+.method-params      {}
+