| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.phoenix.report; |
| 34 | | | |
| 35 | | | import java.io.File; |
| 36 | | | import java.io.FileInputStream; |
| 37 | | | import java.io.IOException; |
| 38 | | | import java.util.ArrayList; |
| 39 | | | import java.util.HashMap; |
| 40 | | | import java.util.Iterator; |
| 41 | | | import java.util.List; |
| 42 | | | import java.util.Map; |
| 43 | | | import java.util.logging.Logger; |
| 44 | | | |
| 45 | | | import javax.xml.bind.JAXBException; |
| 46 | | | |
| 47 | | | import org.jcoderz.phoenix.jcoverage.jaxb.Clazz; |
| 48 | | | import org.jcoderz.phoenix.jcoverage.jaxb.Coverage; |
| 49 | | | import org.jcoderz.phoenix.jcoverage.jaxb.LineType; |
| 50 | | | import org.jcoderz.phoenix.report.jaxb.Item; |
| 51 | | | import org.jcoderz.phoenix.report.jaxb.ObjectFactory; |
| 52 | | | |
| 53 | | | |
| 54 | | | @author |
| 55 | | | |
| 56 | | | public class JCoverageReportReader |
| 57 | | | extends AbstractReportReader |
| 58 | | | { |
| 59 | | | |
| 60 | | | public static final String JCOVERAGE_JAXB_CONTEXT_PATH |
| 61 | | | = "org.jcoderz.phoenix.jcoverage.jaxb"; |
| 62 | | | |
| 63 | 100 | | private static final String CLASSNAME |
| 64 | | | = JCoverageReportReader.class.getName(); |
| 65 | | | |
| 66 | 100 | | private static final Logger logger = Logger.getLogger(CLASSNAME); |
| 67 | | | |
| 68 | | | private Coverage mReportDocument; |
| 69 | | | |
| 70 | | | |
| 71 | | | JCoverageReportReader () |
| 72 | | | throws JAXBException |
| 73 | | | { |
| 74 | 100 | | super(JCOVERAGE_JAXB_CONTEXT_PATH); |
| 75 | 100 | | } |
| 76 | | | |
| 77 | | | {@inheritDoc} |
| 78 | | | public final void parse (File f) |
| 79 | | | throws JAXBException |
| 80 | | | { |
| 81 | | | try |
| 82 | | | { |
| 83 | 0 | (1) | mReportDocument = (Coverage) getUnmarshaller().unmarshal( |
| 84 | | | new FileInputStream(f)); |
| 85 | | | } |
| 86 | 0 | | catch (IOException e) |
| 87 | | | { |
| 88 | 0 | (2) | throw new JAXBException("Cannot read JCoverage report", e); |
| 89 | 0 | | } |
| 90 | 0 | | } |
| 91 | | | |
| 92 | | | {@inheritDoc} |
| 93 | | (3) | public final Map getItems () |
| 94 | | | throws JAXBException |
| 95 | | | { |
| 96 | 0 | | final Map itemMap = new HashMap(); |
| 97 | 0 | | final List files = mReportDocument.getClazzes(); |
| 98 | 0 | | final String baseDir = mReportDocument.getSrc() + File.separator; |
| 99 | | | |
| 100 | 0 | | for (final Iterator iterator = files.iterator(); iterator.hasNext(); ) |
| 101 | | | { |
| 102 | 0 | | final Clazz clazz = (Clazz) iterator.next(); |
| 103 | 0 | | logger.finer("Processing class '" + clazz.getName() + "'"); |
| 104 | 0 | | final String javaFile = clazzname2Filename (clazz.getName()); |
| 105 | 0 | | final List itemList = new ArrayList(); |
| 106 | | | |
| 107 | 0 | | for (final Iterator i = clazz.getCoveredLines().iterator(); |
| 108 | 0 | | i.hasNext(); ) |
| 109 | | | { |
| 110 | 0 | | final LineType line = (LineType) i.next(); |
| 111 | 0 | | final Item item = new ObjectFactory().createItem(); |
| 112 | 0 | | item.setOrigin(Origin.COVERAGE); |
| 113 | 0 | | item.setCounter(line.getHits()); |
| 114 | 0 | | item.setLine(line.getNumber()); |
| 115 | 0 | | item.setSeverity(Severity.COVERAGE); |
| 116 | 0 | (4) | item.setFindingType("coverage"); |
| 117 | | | |
| 118 | 0 | (5) | itemList.add(item); |
| 119 | 0 | | } |
| 120 | 0 | | final ResourceInfo info |
| 121 | | | = ResourceInfo.lookup(normalizeFileName(baseDir + javaFile)); |
| 122 | | | |
| 123 | 0 | | if (info != null) |
| 124 | | | { |
| 125 | 0 | | if (itemMap.containsKey(info)) |
| 126 | | | { |
| 127 | 0 | | final List l = (List) itemMap.get(info); |
| 128 | 0 | (6) | l.addAll(itemList); |
| 129 | 0 | | } |
| 130 | | | else |
| 131 | | | { |
| 132 | 0 | (7) | itemMap.put(info, itemList); |
| 133 | | | } |
| 134 | | | } |
| 135 | | | else |
| 136 | | | { |
| 137 | 0 | | logger.finer( |
| 138 | | | "Ignoring findings for resource " + baseDir + javaFile); |
| 139 | | | } |
| 140 | 0 | | } |
| 141 | | | |
| 142 | 0 | | return itemMap; |
| 143 | | | } |
| 144 | | | |
| 145 | | | private final String clazzname2Filename (String c) |
| 146 | | | { |
| 147 | 0 | | return c.replaceAll("\\.", "/") + ".java"; |
| 148 | | | } |
| 149 | | | } |