[jboss-cvs] JBossAS SVN: r93214 - in projects/annotations/trunk: core/src/main/java/org/jboss/papaki/impl and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 4 12:55:32 EDT 2009


Author: jesper.pedersen
Date: 2009-09-04 12:55:32 -0400 (Fri, 04 Sep 2009)
New Revision: 93214

Added:
   projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/HTMLWriter.java
   projects/annotations/trunk/indexer/src/main/resources/style.css
Modified:
   projects/annotations/trunk/core/build.xml
   projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AnnotationRepositoryImpl.java
   projects/annotations/trunk/doc/userguide/en/modules/ant.xml
   projects/annotations/trunk/indexer/build.xml
   projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java
Log:
[JBANN-7] Generate a HTML report of annotations

Modified: projects/annotations/trunk/core/build.xml
===================================================================
--- projects/annotations/trunk/core/build.xml	2009-09-04 16:49:40 UTC (rev 93213)
+++ projects/annotations/trunk/core/build.xml	2009-09-04 16:55:32 UTC (rev 93214)
@@ -150,36 +150,37 @@
              classname="org.jboss.papaki.indexer.IndexerTask"
              classpathref="core.lib.path.id"/>
 
+    <mkdir dir="${reports.dir}"/>
+    <mkdir dir="${reports.dir}/indexer"/>
+    <mkdir dir="${reports.dir}/indexer/reports"/>
+
     <!-- Class based tests --> 
-    <indexer input="${build.core.dir}/testjars/classabstract.jar"/>
-    <indexer input="${build.core.dir}/testjars/classconstructor.jar"/>
-    <indexer input="${build.core.dir}/testjars/classconstructorwithparameter.jar"/>
-    <indexer input="${build.core.dir}/testjars/classconstructorwithparameterannotation.jar"/>
-    <indexer input="${build.core.dir}/testjars/classempty.jar"/>
-    <indexer input="${build.core.dir}/testjars/classinterface.jar"/>
-    <indexer input="${build.core.dir}/testjars/classinterfacemethod.jar"/>
-    <indexer input="${build.core.dir}/testjars/classlevel.jar"/>
-    <indexer input="${build.core.dir}/testjars/classmethod.jar"/>
-    <indexer input="${build.core.dir}/testjars/classmethodwithparameter.jar"/>
-    <indexer input="${build.core.dir}/testjars/classmethodwithparameterannotation.jar"/>
-    <indexer input="${build.core.dir}/testjars/classfield.jar"/>
+    <indexer input="${build.core.dir}/testjars/classabstract.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classconstructor.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classconstructorwithparameter.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classconstructorwithparameterannotation.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classempty.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classinterface.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classinterfacemethod.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classlevel.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classmethod.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classmethodwithparameter.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classmethodwithparameterannotation.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/classfield.jar" report="${reports.dir}/indexer/reports"/>
 
     <!-- Inheritance based tests --> 
-    <indexer input="${build.core.dir}/testjars/inheritanceclassabstract.jar"/>
-    <indexer input="${build.core.dir}/testjars/inheritanceclassclass.jar"/>
-    <indexer input="${build.core.dir}/testjars/inheritanceclassinterface.jar"/>
-    <indexer input="${build.core.dir}/testjars/inheritanceclassinterfacemethod.jar"/>
+    <indexer input="${build.core.dir}/testjars/inheritanceclassabstract.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/inheritanceclassclass.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/inheritanceclassinterface.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/inheritanceclassinterfacemethod.jar" report="${reports.dir}/indexer/reports"/>
 
     <!-- Interface based tests --> 
-    <indexer input="${build.core.dir}/testjars/interfaceempty.jar"/>
-    <indexer input="${build.core.dir}/testjars/interfacelevel.jar"/>
-    <indexer input="${build.core.dir}/testjars/interfacemethod.jar"/>
-    <indexer input="${build.core.dir}/testjars/interfacemethodwithparameter.jar"/>
-    <indexer input="${build.core.dir}/testjars/interfacemethodwithparameterannotation.jar"/>
+    <indexer input="${build.core.dir}/testjars/interfaceempty.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/interfacelevel.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/interfacemethod.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/interfacemethodwithparameter.jar" report="${reports.dir}/indexer/reports"/>
+    <indexer input="${build.core.dir}/testjars/interfacemethodwithparameterannotation.jar" report="${reports.dir}/indexer/reports"/>
 
-    <mkdir dir="${reports.dir}"/>
-    <mkdir dir="${reports.dir}/indexer"/>
-
     <junit dir="src/test"
            printsummary="${junit.printsummary}"
            haltonerror="${junit.haltonerror}"

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AnnotationRepositoryImpl.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AnnotationRepositoryImpl.java	2009-09-04 16:49:40 UTC (rev 93213)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/papaki/impl/AnnotationRepositoryImpl.java	2009-09-04 16:55:32 UTC (rev 93214)
@@ -282,7 +282,7 @@
     * Get the annotation to classes datastructure
     * @return The structure
     */
-   ConcurrentMap<String, Collection<String>> getAnnotationToClasses()
+   public ConcurrentMap<String, Collection<String>> getAnnotationToClasses()
    {
       return annotationToClasses;
    }
@@ -291,7 +291,7 @@
     * Get the class information datastructure
     * @return The strcuture 
     */
-   ConcurrentMap<String, ClassInfo> getClassInfo()
+   public ConcurrentMap<String, ClassInfo> getClassInfo()
    {
       return classInfo;
    }

Modified: projects/annotations/trunk/doc/userguide/en/modules/ant.xml
===================================================================
--- projects/annotations/trunk/doc/userguide/en/modules/ant.xml	2009-09-04 16:49:40 UTC (rev 93213)
+++ projects/annotations/trunk/doc/userguide/en/modules/ant.xml	2009-09-04 16:55:32 UTC (rev 93214)
@@ -64,6 +64,12 @@
               annotation from the metadata.
             </entry>
           </row>
+          <row>
+            <entry>report</entry>
+            <entry>
+              Generate a report about the annotations included to the specified directory.
+            </entry>
+          </row>
         </tbody>
       </tgroup>
     </table>

Modified: projects/annotations/trunk/indexer/build.xml
===================================================================
--- projects/annotations/trunk/indexer/build.xml	2009-09-04 16:49:40 UTC (rev 93213)
+++ projects/annotations/trunk/indexer/build.xml	2009-09-04 16:55:32 UTC (rev 93214)
@@ -54,6 +54,12 @@
        Target: jars 
        ================================= -->
   <target name="jars" depends="compile">
+    <copy todir="${build.indexer.dir}/impl">
+      <fileset dir="src/main/resources">
+        <include name="**/*.css"/>
+      </fileset>
+    </copy>
+
     <jar destfile="${target.dir}/papaki-indexer.jar"
          manifest="src/main/resources/indexer-manifest.mf"
          basedir="${build.indexer.dir}/impl"

Added: projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/HTMLWriter.java
===================================================================
--- projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/HTMLWriter.java	                        (rev 0)
+++ projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/HTMLWriter.java	2009-09-04 16:55:32 UTC (rev 93214)
@@ -0,0 +1,212 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.papaki.indexer;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A HTML report generator
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class HTMLWriter
+{
+   private static Logger log = Logger.getLogger(HTMLWriter.class.getName());
+
+   /** New line character */
+   protected static final String NEW_LINE = System.getProperty("line.separator");
+
+   /**
+    * Constructor
+    */
+   private HTMLWriter()
+   {
+   }
+
+   /**
+    * Generate CSS files
+    * @param directory Where the reports go
+    */
+   public static void generateCSS(File directory)
+   {
+      byte buffer[] = new byte[8192];
+      int bytesRead;
+
+      InputStream is = null;
+      OutputStream os = null;
+      try
+      {
+         is = HTMLWriter.class.getClassLoader().getResourceAsStream("style.css");
+
+         if (is != null)
+         {
+            os = new FileOutputStream(directory.getAbsolutePath() + File.separator + "style.css");
+            while ((bytesRead = is.read(buffer)) != -1)
+            {
+               os.write(buffer, 0, bytesRead);
+            }
+            
+            os.flush();
+         }
+      }
+      catch (Throwable t)
+      {
+         log.log(Level.SEVERE, t.getMessage(), t);
+      }
+      finally
+      {
+         try
+         {
+            if (is != null)
+               is.close();
+         }
+         catch (IOException ioe)
+         {
+            // Ignore
+         }
+
+         try
+         {
+            if (os != null)
+               os.close();
+         }
+         catch (IOException ioe)
+         {
+            // Ignore
+         }
+      }
+   }
+
+   /**
+    * Generate report
+    * @param directory Where the reports go
+    * @param name The name of the report
+    * @param data The raw data
+    */
+   public static void generateReport(File directory, String name, Map<String, Collection<String>> data)
+   {
+      BufferedWriter bw = null;
+      try
+      {
+         FileWriter fw = new FileWriter(directory.getAbsolutePath() + File.separator + name + ".html");
+         bw = new BufferedWriter(fw, 8192);
+
+         bw.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" +
+                  "\"http://www.w3.org/TR/html4/loose.dtd\">" + NEW_LINE);
+         bw.write("<html>" + NEW_LINE);
+         bw.write("<head>" + NEW_LINE);
+         bw.write("  <title>Papaki: " + name + "</title>" + NEW_LINE);
+         bw.write("  <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">" + NEW_LINE);
+         bw.write("  <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">" + NEW_LINE);
+         bw.write("</head>" + NEW_LINE);
+         bw.write("<body>" + NEW_LINE);
+         bw.write(NEW_LINE);
+
+         bw.write("<h1>Papaki: " + name + "</h1>" + NEW_LINE);
+
+         bw.write("<table>" + NEW_LINE);
+
+         bw.write("  <tr>" + NEW_LINE);
+         bw.write("     <th>Annotation</th>" + NEW_LINE);
+         bw.write("     <th>Location</th>" + NEW_LINE);
+         bw.write("  </tr>" + NEW_LINE);
+
+         boolean odd = true;
+
+         Iterator<Map.Entry<String, Collection<String>>> it = data.entrySet().iterator();
+         while (it.hasNext())
+         {
+            Map.Entry<String, Collection<String>> entry = it.next();
+
+            String annotation = entry.getKey();
+            Collection<String> classes = entry.getValue();
+
+            if (odd)
+            {
+               bw.write("  <tr class=\"rowodd\">" + NEW_LINE);
+            }
+            else
+            {
+               bw.write("  <tr class=\"roweven\">" + NEW_LINE);
+            }
+            bw.write("     <td>" + annotation + "</td>" + NEW_LINE);
+            bw.write("     <td>");
+
+            Iterator<String> cit = classes.iterator();
+            while (cit.hasNext())
+            {
+               bw.write(cit.next());
+
+               if (cit.hasNext())
+               {
+                  bw.write(", ");
+               }
+            }
+
+            bw.write("</td>" + NEW_LINE);
+            bw.write("  </tr>" + NEW_LINE);
+         
+            odd = !odd;
+         }
+
+         bw.write("</table>" + NEW_LINE);
+
+
+         bw.write(NEW_LINE);
+         bw.write("<p>" + NEW_LINE);
+         bw.write("<hr>" + NEW_LINE);
+         bw.write("Generated by: <a href=\"http://www.jboss.org/projects/papaki\">Papaki</a>" + NEW_LINE);
+         bw.write(NEW_LINE);
+         bw.write("</body>" + NEW_LINE);
+         bw.write("</html>" + NEW_LINE);
+
+         bw.flush();
+      }
+      catch (Throwable t)
+      {
+         log.log(Level.SEVERE, t.getMessage(), t);
+      }
+      finally
+      {
+         try
+         {
+            if (bw != null)
+               bw.close();
+         }
+         catch (IOException ioe)
+         {
+            // Ignore
+         }
+      }
+   }
+}

Modified: projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java
===================================================================
--- projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java	2009-09-04 16:49:40 UTC (rev 93213)
+++ projects/annotations/trunk/indexer/src/main/java/org/jboss/papaki/indexer/IndexerTask.java	2009-09-04 16:55:32 UTC (rev 93214)
@@ -48,6 +48,7 @@
    private boolean update;
    private File metadata;
    private String exclude;
+   private File report;
    
    /**
     * Constructor
@@ -59,6 +60,7 @@
       update = true;
       metadata = null;
       exclude = null;
+      report = null;
    }
 
    /**
@@ -150,8 +152,26 @@
    {
       exclude = s;
    }
+ 
+   /**
+    * Get the report directory
+    * @return The report directory
+    */
+   public File getReport()
+   {
+      return report;
+   }
 
    /**
+    * Set the report directory
+    * @param r The report directory
+    */
+   public void setReport(File r)
+   {
+      report = r;
+   }
+
+  /**
     * Execute Ant task
     * @exception BuildException If an error occurs
     */
@@ -182,6 +202,23 @@
             }
          }
 
+         if (report != null)
+         {
+            if (!report.exists())
+            {
+               if (!report.mkdirs())
+                  throw new IOException("Couldn't create directory: " + report);
+            }
+            else
+            {
+               if (!report.isDirectory())
+                  throw new IOException(report + " is not a directory");
+            }
+
+            HTMLWriter.generateCSS(report);
+            HTMLWriter.generateReport(report, output.getName(), ari.getAnnotationToClasses());
+         }
+
          if (update)
          {
             File tmp = new File(System.getProperty("java.io.tmpdir"));

Added: projects/annotations/trunk/indexer/src/main/resources/style.css
===================================================================
--- projects/annotations/trunk/indexer/src/main/resources/style.css	                        (rev 0)
+++ projects/annotations/trunk/indexer/src/main/resources/style.css	2009-09-04 16:55:32 UTC (rev 93214)
@@ -0,0 +1,147 @@
+/*
+ * Papaki
+ * Copyright (C) 2009 Red Hat Middleware LLC.
+ * All rights reserved.
+ * 
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+html {
+    height: 100%;
+    min-height: 100%;
+    background-color : #ffffff;
+    color : #454545;
+    border-collapse : collapse; 
+    border-style: none;
+    margin : 0px auto; 
+    padding: 0px;
+}
+
+body {
+    background-color : #ffffff;
+    color : #454545;
+    margin : 0px auto; 
+    text-align : left;
+    font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+    font-size: 10pt;
+    border-collapse : collapse; 
+    border-style: none;
+    padding: 5px;
+}
+
+p {
+    margin: 5px;
+}
+
+a {
+    color: #527fa8;
+}
+
+hr {
+    border-top: 1px solid #a4b2b9;
+    border-right: 0px solid #a4b2b9;
+    border-left: 0px solid #a4b2b9;
+    border-bottom: 0px solid #a4b2b9;
+    margin-bottom: 3px;
+}
+
+img {
+    border: 0px;
+}
+
+h1 {
+    font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+    font-size : 14pt; 
+    font-weight : bold; 
+    background-color: white;
+    color: #50667c;
+}
+
+h2 {
+    font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+    font-size : 11pt; 
+    font-weight : bold; 
+    background-color: white;
+    color: #50667c;
+}
+
+h3 {
+    font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+    font-size : 11pt; 
+    font-weight : bold; 
+    background-color: white;
+    color: #50667c;
+}
+
+h4 {
+    font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+    font-size : 10pt; 
+    font-weight : bold; 
+    background-color: white;
+    color: #50667c;
+}
+
+h5 {
+    font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+    font-size : 10pt; 
+    font-weight : bold; 
+    background-color: white;
+    color: #50667c;
+}
+
+h6 {
+    font-family : "Lucida Grand", Verdana, Arial, Helvetica, sans-serif;
+    font-size : 10pt; 
+    font-weight : bold; 
+    background-color: white;
+    color: #50667c;
+}
+
+table {
+    width: 100%;
+    border-collapse : collapse; 
+    border-style: none;
+}
+
+tr th {
+    background-color: #d9e0e3;
+    font-size: 10pt;
+    font-weight: bold;
+    color: #5f6a6f;
+    text-align: left;
+    padding: 3px;
+}
+
+tr td {
+    font-size: 10pt;
+    font-weight: bold;
+    vertical-align: top;
+    text-align: left;
+    padding: 3px;
+}
+
+.roweven {
+    background-color: white;
+}
+
+.rowodd {
+    background-color: #eff4f7;
+}




More information about the jboss-cvs-commits mailing list