View Javadoc
1 /*** 2 3 * XMLReport 4 5 * 6 7 * This is a detailed coverage report 8 9 * in XML. 10 11 * 12 13 * Report looks like: 14 15 * <PRE> 16 17 * <?xml version="1.0"?> 18 19 * 20 21 * <CoverageReport date="2001/12/29 10:30AM"> 22 23 * ... 24 25 * <Statement> 26 27 * <LineFrom>1</LineFrom> 28 29 * <LineTo>5</LineTo> 30 31 * ... 32 33 * </Statement> 34 35 * ... 36 37 * </CoverageReport> 38 39 *</pre> 40 41 * The CoverageReport/Metric are fixed in this XML Report. 42 43 * 44 45 * The Class/Method values are actually supplied by the 46 47 * QuiltRegistry. Future versions of the instrumentor may 48 49 * measure different things (like Package, etc.) 50 51 * 52 53 * The Statement values are pulled from the CoverageSegment 54 55 * interface. 56 57 */ 58 59 package junit.quilt.reports; 60 61 62 63 import java.io.OutputStream; 64 65 import java.io.OutputStreamWriter; 66 67 import java.io.PrintWriter; 68 69 import java.io.IOException; 70 71 72 73 import java.text.DateFormat; 74 75 import java.text.SimpleDateFormat; 76 77 import java.util.Date; 78 79 import java.util.Enumeration; 80 81 import java.util.Iterator; 82 83 import java.util.Set; 84 85 86 87 import javax.swing.tree.*; 88 89 90 91 import junit.quilt.framework.*; 92 93 94 95 public class XMLReport 96 97 extends Object 98 99 implements Report 100 101 { 102 103 public XMLReport() { } 104 105 106 107 public void writeNode( PrintWriter out, 108 109 QuiltRegistry registry, 110 111 int level, 112 113 String levels[], 114 115 TreeNode nodes[]) { 116 117 118 119 TreeNode node = nodes[level]; 120 indentTo(out, level); 121 122 out.println("<" + levels[level] + 123 124 " name=\"" + nodes[level].toString() + "\">"); 125 126 127 128 if (level == levels.length - 1) { // Base Case 129 130 TreePath tp = new TreePath( nodes ); 131 132 QuiltCollector collect = registry.getCollector( tp ); 133 134 if (collect != null) { 135 136 Set all = collect.getAll(QuiltCollector.BRANCH_COVERAGE); 137 138 Iterator i = all.iterator(); 139 140 while (i.hasNext()) { 141 142 CoverageSegment segment = (CoverageSegment)i.next(); 143 144 out.println(segment.toXML()); 145 146 } 147 148 } 149 150 } else { 151 152 Enumeration children = node.children(); 153 154 while (children.hasMoreElements()) { 155 156 TreeNode next = (TreeNode) children.nextElement(); 157 158 nodes[level + 1] = next; 159 160 writeNode(out, registry, level + 1, levels, nodes); 161 162 } 163 164 } 165 166 167 168 indentTo(out, level); 169 170 out.println("</" + levels[level] + ">"); 171 172 } 173 174 175 176 public void writeReport( OutputStream out, 177 178 QuiltRegistry registry ) 179 180 throws IOException 181 182 { 183 184 String levels[] = registry.getLevels(); 185 186 187 188 PrintWriter pw = new PrintWriter( new OutputStreamWriter( out ) ); 189 190 pw.println("<?xml version=\"1.0\"?>"); 191 192 pw.println("<CoverageReport>"); 193 194 195 196 TreeNode nodes[] = new TreeNode[levels.length]; 197 198 199 200 nodes[0] = registry.getContents(); 201 202 writeNode( pw, registry, 0, levels, nodes ); 203 204 pw.println("</CoverageReport>"); 205 206 207 208 pw.flush(); 209 210 } 211 212 private void indentTo(PrintWriter out, int size) { 213 for (int j = 0; j < size + 1; j++) { 214 out.print(" "); 215 } 216 } 217 218 219 220 221 } 222

This page was automatically generated by Maven