[webbeans-commits] Webbeans SVN: r1392 - in tck/trunk/impl: src/main/java/org/jboss/webbeans/tck/impl and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Feb 2 22:49:06 EST 2009
Author: shane.bryzak at jboss.com
Date: 2009-02-02 22:49:06 -0500 (Mon, 02 Feb 2009)
New Revision: 1392
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditAssertion.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessorFactory.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/SpecReference.java
Modified:
tck/trunk/impl/pom.xml
Log:
initial attempt at coverage report, still under construction
Modified: tck/trunk/impl/pom.xml
===================================================================
--- tck/trunk/impl/pom.xml 2009-02-02 22:23:54 UTC (rev 1391)
+++ tck/trunk/impl/pom.xml 2009-02-03 03:49:06 UTC (rev 1392)
@@ -124,10 +124,32 @@
</execution>
</executions>
<configuration>
+ <factory>org.jboss.webbeans.tck.impl.report.CoverageProcessorFactory</factory>
<testOutputDirectory>${project.build.directory}/site</testOutputDirectory>
</configuration>
</plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>default-tools.jar</id>
+ <activation>
+ <property>
+ <name>java.vendor</name>
+ <value>Sun Microsystems Inc.</value>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>com.sun</groupId>
+ <artifactId>tools</artifactId>
+ <version>1.5.0</version>
+ <scope>system</scope>
+ <systemPath>${java.home}/../lib/tools.jar</systemPath>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
</project>
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditAssertion.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditAssertion.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/AuditAssertion.java 2009-02-03 03:49:06 UTC (rev 1392)
@@ -0,0 +1,51 @@
+package org.jboss.webbeans.tck.impl.report;
+
+/**
+ * Represents a single assertion as defined in the audit xml
+ *
+ * @author Shane Bryzak
+ *
+ */
+public class AuditAssertion implements Comparable<AuditAssertion>
+{
+ private String section;
+ private String id;
+ private String text;
+ private String note;
+
+ public AuditAssertion(String section, String id, String text, String note)
+ {
+ this.section = section;
+ this.id = id;
+ this.text = text;
+ this.note = note;
+ }
+
+ public String getSection()
+ {
+ return section;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public String getNote()
+ {
+ return note;
+ }
+
+ public int compareTo(AuditAssertion other)
+ {
+ int i = section.compareTo(other.section);
+ return i != 0 ? i : id.compareTo(other.id);
+ }
+
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessor.java 2009-02-03 03:49:06 UTC (rev 1392)
@@ -0,0 +1,176 @@
+package org.jboss.webbeans.tck.impl.report;
+
+import com.sun.mirror.util.DeclarationVisitors;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.jboss.webbeans.tck.impl.SpecAssertion;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.Declaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.util.SimpleDeclarationVisitor;
+
+/**
+ * Annotation processor for generating TCK coverage report
+ *
+ * @author Shane Bryzak
+ */
+public class CoverageProcessor implements AnnotationProcessor
+{
+ private static final String OUTDIR_OPTION_NAME = "-s";
+ private static final String REPORT_FILE_NAME = "coverage.html";
+
+ private static final String AUDIT_FILE_NAME = "tck-audit.xml";
+
+ private Map<String,List<AuditAssertion>> assertions = new HashMap<String,List<AuditAssertion>>();
+ private Map<String,String> sections = new HashMap<String,String>();
+
+ private final AnnotationProcessorEnvironment env;
+ private final File baseDir;
+
+ private final List<SpecReference> references = new ArrayList<SpecReference>();
+
+ public CoverageProcessor(AnnotationProcessorEnvironment env)
+ {
+ this.env = env;
+ String baseDirName = env.getOptions().get( OUTDIR_OPTION_NAME );
+ baseDir = new File( baseDirName );
+ baseDir.mkdirs();
+
+ try
+ {
+ loadAssertions();
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException("Error parsing tck-audit.xml: " +
+ ex.getClass().getName() + " - " + ex.getMessage(), ex);
+ }
+ }
+
+ /**
+ * Load the spec assertions defined in tck-audit.xml
+ */
+ private void loadAssertions() throws Exception
+ {
+ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
+ Document doc = builder.parse(new FileInputStream(AUDIT_FILE_NAME));
+ NodeList sectionNodes = doc.getDocumentElement().getChildNodes();
+
+ for (int i = 0; i < sectionNodes.getLength(); i++)
+ {
+ if (sectionNodes.item(i) instanceof Element &&
+ "section".equals(sectionNodes.item(i).getNodeName()))
+ {
+ processSectionNode((Element) sectionNodes.item(i));
+ }
+ }
+ }
+
+ private void processSectionNode(Element node)
+ {
+ String sectionId = node.getAttribute("id");
+ sections.put(sectionId, node.getAttribute("title"));
+
+ NodeList assertionNodes = node.getChildNodes();
+
+ for (int i = 0; i < assertionNodes.getLength(); i++)
+ {
+ if (assertionNodes.item(i) instanceof Element &&
+ "assertion".equals(assertionNodes.item(i).getNodeName()))
+ {
+ processAssertionNode(sectionId, (Element) assertionNodes.item(i));
+ }
+ }
+ }
+
+ private void processAssertionNode(String sectionId, Element node)
+ {
+ List<AuditAssertion> value = assertions.get(sectionId);
+ if (value == null)
+ {
+ value = new ArrayList<AuditAssertion>();
+ assertions.put(sectionId, value);
+ }
+
+ String text = null;
+ String note = null;
+
+ for (int i = 0; i < node.getChildNodes().getLength(); i++)
+ {
+ Node child = node.getChildNodes().item(i);
+
+ if (child instanceof Element)
+ {
+ if ("text".equals(child.getNodeName()))
+ {
+ text = child.getTextContent();
+ }
+ else if ("note".equals(child.getNodeName()))
+ {
+ note = child.getTextContent();
+ }
+ }
+ }
+
+ value.add(new AuditAssertion(node.getAttribute("section"),
+ node.getAttribute("id"), text, note));
+ }
+
+ public void process()
+ {
+ AnnotationTypeDeclaration annotationType = (AnnotationTypeDeclaration)
+ env.getTypeDeclaration(SpecAssertion.class.getCanonicalName());
+
+ for (Declaration d : env.getDeclarationsAnnotatedWith(annotationType))
+ {
+ d.accept(DeclarationVisitors.getDeclarationScanner(
+ new CreateReferenceVisitor(), DeclarationVisitors.NO_OP));
+ }
+
+ CoverageReport report = new CoverageReport(references, assertions, sections);
+
+ try
+ {
+ File reportFile = new File(baseDir, REPORT_FILE_NAME);
+ FileOutputStream out = new FileOutputStream(reportFile);
+ report.generate(out);
+ out.flush();
+ out.close();
+ }
+ catch (IOException ex)
+ {
+ throw new RuntimeException("Error generating report file", ex);
+ }
+ }
+
+ private class CreateReferenceVisitor extends SimpleDeclarationVisitor
+ {
+ public void visitMethodDeclaration(MethodDeclaration d)
+ {
+ SpecAssertion annotation = d.getAnnotation( SpecAssertion.class );
+ SpecReference ref = new SpecReference(
+ annotation.section(), annotation.id(),
+ d.getDeclaringType().getQualifiedName(), d.getSimpleName());
+ references.add( ref );
+ }
+ }
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessorFactory.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessorFactory.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageProcessorFactory.java 2009-02-03 03:49:06 UTC (rev 1392)
@@ -0,0 +1,41 @@
+package org.jboss.webbeans.tck.impl.report;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.jboss.webbeans.tck.impl.SpecAssertion;
+import org.jboss.webbeans.tck.impl.SpecAssertions;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+
+public class CoverageProcessorFactory implements AnnotationProcessorFactory
+{
+ private static final Collection<String> supportedAnnotations = Collections.unmodifiableCollection(
+ Arrays.asList(
+ SpecAssertion.class.getCanonicalName(),
+ SpecAssertions.class.getCanonicalName()
+ )
+ );
+
+ public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> annotationTypeDeclarations,
+ AnnotationProcessorEnvironment env)
+ {
+ return new CoverageProcessor(env);
+ }
+
+ public Collection<String> supportedAnnotationTypes()
+ {
+ return supportedAnnotations;
+ }
+
+ public Collection<String> supportedOptions()
+ {
+ return null;
+ }
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/CoverageReport.java 2009-02-03 03:49:06 UTC (rev 1392)
@@ -0,0 +1,121 @@
+package org.jboss.webbeans.tck.impl.report;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Generates the TCK spec coverage report
+ *
+ * @author Shane Bryzak
+ */
+public class CoverageReport
+{
+ /**
+ * References to the spec assertions made by the tck tests
+ */
+ private final Map<String,List<SpecReference>> references;
+
+ /**
+ * Assertions, mapped by section id
+ */
+ private final Map<String,List<AuditAssertion>> assertions;
+
+ /*
+ * Section titles
+ */
+ private final Map<String,String> sections;
+
+ public CoverageReport(List<SpecReference> references, Map<String,List<AuditAssertion>> assertions,
+ Map<String,String> sections)
+ {
+ this.references = new HashMap<String,List<SpecReference>>();
+
+ for (SpecReference ref : references)
+ {
+ if (!this.references.containsKey(ref.getSection()))
+ {
+ this.references.put(ref.getSection(), new ArrayList<SpecReference>());
+ }
+
+ this.references.get(ref.getSection()).add(ref);
+ }
+
+ this.assertions = assertions;
+ this.sections = sections;
+ }
+
+ public void generate(OutputStream out) throws IOException
+ {
+ writeHeader(out);
+ writeBody(out);
+ writeFooter(out);
+ }
+
+ private void writeHeader(OutputStream out) throws IOException
+ {
+ out.write("<html><head><title>JSR-299 TCK Coverage Report</title></head><body".getBytes());
+ out.write("<h1>TCK Coverage Report</h1>".getBytes());
+ }
+
+ private void writeBody(OutputStream out) throws IOException
+ {
+ List<String> keys = new ArrayList<String>(sections.keySet());
+ Collections.sort(keys);
+
+ for (String key : keys)
+ {
+ out.write(("<h2>Section " + key + " - " + sections.get(key) + "</h2>").getBytes());
+
+ List<AuditAssertion> sectionAssertions = assertions.get(key);
+
+ if (sectionAssertions != null && !sectionAssertions.isEmpty())
+ {
+ Collections.sort(sectionAssertions);
+
+ StringBuilder sb = new StringBuilder();
+
+ for (AuditAssertion assertion : sectionAssertions)
+ {
+ sb.append("<div>");
+
+ sb.append("<div style='float:left'>");
+ sb.append(assertion.getId());
+ sb.append(")");
+ sb.append("</div>");
+
+ sb.append("<div style='float:left;margin-left:50px'>");
+ sb.append(assertion.getText());
+ sb.append("</div>");
+
+ sb.append("<br style='clear:both'/>");
+
+ if (references.get(key) != null)
+ {
+ for (SpecReference ref : references.get(key))
+ {
+ sb.append(ref.getClassName());
+ sb.append(".");
+ sb.append(ref.getMethodName());
+ sb.append("()");
+ }
+ }
+
+ sb.append("</div>");
+ }
+
+ out.write(sb.toString().getBytes());
+ }
+ }
+ }
+
+ private void writeFooter(OutputStream out) throws IOException
+ {
+ out.write("</table>".getBytes());
+ out.write("</body></html>".getBytes());
+ }
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/SpecReference.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/SpecReference.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/report/SpecReference.java 2009-02-03 03:49:06 UTC (rev 1392)
@@ -0,0 +1,42 @@
+package org.jboss.webbeans.tck.impl.report;
+
+/**
+ * Represents the metadata for a single instance of @SpecAssertion
+ *
+ * @author Shane Bryzak
+ */
+public class SpecReference
+{
+ private String section;
+ private String assertion;
+ private String className;
+ private String methodName;
+
+ SpecReference(String section, String assertion, String className, String methodName)
+ {
+ this.section = section;
+ this.assertion = assertion;
+ this.className = className;
+ this.methodName = methodName;
+ }
+
+ public String getSection()
+ {
+ return section;
+ }
+
+ public String getAssertion()
+ {
+ return assertion;
+ }
+
+ public String getClassName()
+ {
+ return className;
+ }
+
+ public String getMethodName()
+ {
+ return methodName;
+ }
+}
More information about the weld-commits
mailing list