[hibernate-commits] Hibernate SVN: r16069 - validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Mar 4 02:43:57 EST 2009


Author: shane.bryzak at jboss.com
Date: 2009-03-04 02:43:57 -0500 (Wed, 04 Mar 2009)
New Revision: 16069

Modified:
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java
   validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
Log:
support for inline images

Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java	2009-03-04 02:20:50 UTC (rev 16068)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java	2009-03-04 07:43:57 UTC (rev 16069)
@@ -40,7 +40,6 @@
 public class CoverageProcessor extends AbstractProcessor {
     private static final String OUTDIR_OPTION_FLAG = "outputDir";
     private static final String AUDITFILE_OPTION_KEY = "auditXml";
-    private static final String REPORT_FILE_NAME = "coverage.html";
 
     private static final String DEFAULT_AUDIT_FILE_NAME = "tck-audit.xml";
 
@@ -75,31 +74,40 @@
 
     private InputStream getAuditFileInputStream() {
         InputStream in;
-        String auditFileName = processingEnv.getOptions().get(AUDITFILE_OPTION_KEY);
-        
-        if (auditFileName == null || auditFileName.length() == 0) {
-            auditFileName = getCurrentWorkingDirectory() + DEFAULT_AUDIT_FILE_NAME;
-            System.out.println(
-                    "No audit file specified. Trying default: " + auditFileName
-            );
-        }
-        else
-        {
-           System.out.println(
-              "Reading spec assertions from audit file: " + auditFileName);
-        }
         try {
-            in = new FileInputStream(auditFileName);
+            in = new FileInputStream(getAuditFile());
         }
         catch (IOException ex) {
-           System.err.println("Unable to open audit file - " + auditFileName);
+           System.err.println("Unable to open audit file - " + getAuditFile().getAbsolutePath());
            System.err.println("No report generated");
-            return null;
+           return null;
         }
         return in;
     }
+    
+    private File getAuditFile()
+    {
+       String auditFileName = processingEnv.getOptions().get(AUDITFILE_OPTION_KEY);
+       
+       if (auditFileName == null || auditFileName.length() == 0) {
+           auditFileName = getCurrentWorkingDirectory() + DEFAULT_AUDIT_FILE_NAME;
+           System.out.println(
+                   "No audit file specified. Trying default: " + auditFileName
+           );
+       }
+       else
+       {
+          System.out.println(
+             "Reading spec assertions from audit file: " + auditFileName);
+       }
+       
+       return new File(auditFileName);
+    }
+    
+    private File getImagesDir() {
+       return new File(getAuditFile().getParentFile(), "/images");
+    }
 
-
     private void createOutputDir() {
         String baseDirName = processingEnv.getOptions().get(OUTDIR_OPTION_FLAG);
 
@@ -136,7 +144,14 @@
         }
 
         if (roundEnvironment.processingOver()) {
-            new CoverageReport(references, auditParser).writeToFile(new File(baseDir, REPORT_FILE_NAME));
+            try
+            {
+               new CoverageReport(references, auditParser, getImagesDir()).generate(baseDir);
+            } 
+            catch (IOException e)
+            {
+               throw new RuntimeException(e);
+            }
         }
         return false;
     }
Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java	2009-03-04 02:20:50 UTC (rev 16068)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java	2009-03-04 07:43:57 UTC (rev 16069)
@@ -1,9 +1,11 @@
 package org.hibernate.tck.report;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -31,6 +33,7 @@
     
     private static final Pattern PATTERN_BOLD = Pattern.compile("([_][^_]*[_])");
     private static final Pattern PATTERN_STRIKETHROUGH = Pattern.compile("([~][^~]*[~])");    
+    private static final String REPORT_FILE_NAME = "coverage.html";    
    
     /*
     * References to the spec assertions made by the tck tests
@@ -38,6 +41,9 @@
     private final Map<String, List<SpecReference>> references;
 
     private AuditParser auditParser;
+        
+    private File imageSrcDir;
+    private File imageTargetDir;
     
     private RuntimeProperties properties;
     
@@ -50,7 +56,7 @@
     private int failThreshold;
     private int passThreshold;
 
-    public CoverageReport(List<SpecReference> references, AuditParser auditParser) {
+    public CoverageReport(List<SpecReference> references, AuditParser auditParser, File imageSrcDir) {
         this.references = new HashMap<String, List<SpecReference>>();
 
         for (SpecReference ref : references) {
@@ -62,7 +68,7 @@
         }
 
         this.auditParser = auditParser;
-        
+        this.imageSrcDir = imageSrcDir;
         this.properties = new RuntimeProperties();
         
         try
@@ -90,7 +96,16 @@
         }        
     }
 
-    public void generate(OutputStream out) throws IOException {
+    public void generate(File outputDir) throws IOException {
+       File coverageFile = new File(outputDir, REPORT_FILE_NAME);
+       FileOutputStream out = new FileOutputStream(coverageFile);
+       
+       imageTargetDir = new File(outputDir, "/images");
+       if (!imageTargetDir.exists())
+       {
+          imageTargetDir.mkdirs();
+       }
+       
         calculateUnmatched();
         writeHeader(out);
         writeContents(out);
@@ -155,6 +170,12 @@
         sb.append("   color: #999999;\n");
         sb.append("   font-size: 9px;\n");
         sb.append("   font-weight: bold; }\n");
+        sb.append("  .embeddedImage {\n");
+        sb.append("   margin: 6px;\n");
+        sb.append("   border: 1px solid black;\n");
+        sb.append("   float: right; }\n");
+        sb.append("  .coverage {\n");
+        sb.append("   clear: both; }\n");
         sb.append("  .noCoverage {\n");
         sb.append("   margin-top: 2px;\n");
         sb.append("   margin-bottom: 2px;\n");
@@ -351,7 +372,9 @@
             
             if (coveragePercent >= 0)
             {
-               String bgColor = coveragePercent < 60 ? "#ffaaaa" : coveragePercent < 80 ? "#ffffaa" : coveragePercent > 100 ? "#FF00CC" : "#aaffaa" ;
+               String bgColor = coveragePercent < failThreshold ? "#ffaaaa" : 
+                  coveragePercent < passThreshold ? "#ffffaa" : 
+                     coveragePercent > 100 ? "#FF00CC" : "#aaffaa" ;
             
                sb.append("<td align=\"center\" style=\"background-color:" + bgColor + "\">");
                sb.append(String.format("%.2f%%", coveragePercent));
@@ -405,7 +428,8 @@
        
        if (totalCoveragePercent >= 0)
        {
-          String bgColor = totalCoveragePercent < 60 ? "#ffaaaa" : totalCoveragePercent < 80 ? "#ffffaa" : "#aaffaa" ;
+          String bgColor = totalCoveragePercent < failThreshold ? "#ffaaaa" : 
+             totalCoveragePercent < passThreshold ? "#ffffaa" : "#aaffaa" ;
        
           sb.append("<td align=\"center\" style=\"background-color:" + bgColor + "\">");
           sb.append(String.format("%.2f%%", totalCoveragePercent));
@@ -510,7 +534,8 @@
          
          if (coveragePercent >= 0)
          {
-            String bgColor = coveragePercent < 60 ? "#ffaaaa" : coveragePercent < 80 ? "#ffffaa" : coveragePercent > 100 ? "#FF00CC" : "#aaffaa" ;
+            String bgColor = coveragePercent < failThreshold ? "#ffaaaa" : 
+               coveragePercent < passThreshold ? "#ffffaa" : coveragePercent > 100 ? "#FF00CC" : "#aaffaa" ;
          
             sb.append("<td align=\"center\" style=\"background-color:" + bgColor + "\">");
             sb.append(String.format("%.2f%%", coveragePercent));
@@ -582,12 +607,25 @@
                     sb.append("</span>\n");
 
                     sb.append("    <div class=\"results\">");
+                    
+                    
                     sb.append("<p class=\"description\">");
+                    String imageFilename = sectionId + "." + assertion.getId() + ".png";
+                    File imageFile = new File(imageSrcDir, imageFilename);
                     
-                    String assertionText = parseStrikethrough(parseBold(assertion.getText()));
+                    if (imageFile.exists())
+                    {
+                       sb.append("<img src=\"images/" + imageFile.getName() + "\" class=\"embeddedImage\"/>");
+                       copyFile(imageFile, new File(imageTargetDir, imageFilename));
+                    }
+                    
+                    String assertionText = parseStrikethrough(parseBold(assertion.getText()));                    
+
                     if (!Strings.isEmpty(assertion.getNote()))
                     {
-                       sb.append("<a title=\"" + assertion.getNote() + "\">").append(assertionText).append("</a>");
+                       sb.append("<a title=\"" + assertion.getNote() + "\">");
+                       sb.append(assertionText);
+                       sb.append("</a>");
                     }
                     else
                     {
@@ -776,16 +814,21 @@
         out.write("</table>".getBytes());
         out.write("</body></html>".getBytes());
     }
-
-    public void writeToFile(File file) {
-        try {
-            FileOutputStream out = new FileOutputStream(file);
-            generate(out);
-            out.flush();
-            out.close();
-        }
-        catch (IOException ex) {
-            throw new RuntimeException("Error generating report file", ex);
-        }
+    
+    private void copyFile(File sourceFile, File targetFile) throws IOException 
+    {
+       FileChannel inChannel = new FileInputStream(sourceFile).getChannel();
+    FileChannel outChannel = new FileOutputStream(targetFile).getChannel();
+    try {
+        inChannel.transferTo(0, inChannel.size(),
+                outChannel);
+    } 
+    catch (IOException e) {
+        throw e;
     }
+    finally {
+        if (inChannel != null) inChannel.close();
+        if (outChannel != null) outChannel.close();
+    }
+}    
 }




More information about the hibernate-commits mailing list