| 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.FileNotFoundException; |
| 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.pmd.jaxb.FileType; |
| 48 | | | import org.jcoderz.phoenix.pmd.jaxb.Pmd; |
| 49 | | | import org.jcoderz.phoenix.pmd.jaxb.Violation; |
| 50 | | | import org.jcoderz.phoenix.report.jaxb.Item; |
| 51 | | | import org.jcoderz.phoenix.report.jaxb.ObjectFactory; |
| 52 | | | |
| 53 | | | |
| 54 | | | |
| 55 | | | |
| 56 | | | @author |
| 57 | | | |
| 58 | | | public final class PmdReportReader |
| 59 | | | extends AbstractReportReader |
| 60 | | | { |
| 61 | | | |
| 62 | | | public static final String PMD_JAXB_CONTEXT_PATH |
| 63 | | | = "org.jcoderz.phoenix.pmd.jaxb"; |
| 64 | | | |
| 65 | 0 | | private static final String CLASSNAME = PmdReportReader.class.getName(); |
| 66 | 0 | | private static final Logger logger = Logger.getLogger(CLASSNAME); |
| 67 | | | |
| 68 | | | private static final int PRIORITY_HIGH = 1; |
| 69 | | | private static final int PRIORITY_MEDIUM_HIGH = 2; |
| 70 | | | private static final int PRIORITY_MEDIUM = 3; |
| 71 | | | private static final int PRIORITY_MEDIUM_LOW = 4; |
| 72 | | | private static final int PRIORITY_LOW = 5; |
| 73 | | | |
| 74 | | | private Pmd mReportDocument; |
| 75 | | | |
| 76 | | | |
| 77 | | | |
| 78 | | | |
| 79 | | | @throws |
| 80 | | | |
| 81 | | | public PmdReportReader () |
| 82 | | (1) | throws JAXBException |
| 83 | | | { |
| 84 | 0 | | super(PMD_JAXB_CONTEXT_PATH); |
| 85 | 0 | | } |
| 86 | | | |
| 87 | | | {@inheritDoc} |
| 88 | | | public void parse (File f) |
| 89 | | | throws JAXBException, FileNotFoundException |
| 90 | | | { |
| 91 | 0 | | logger.entering(CLASSNAME, "parse", f); |
| 92 | 0 | (2) | mReportDocument = (Pmd) getUnmarshaller().unmarshal( |
| 93 | | | new FileInputStream(f)); |
| 94 | 0 | | logger.exiting(CLASSNAME, "parse"); |
| 95 | 0 | | } |
| 96 | | | |
| 97 | | | {@inheritDoc} |
| 98 | | | protected Map<ResourceInfo, List<Item>> getItems () |
| 99 | | | throws JAXBException |
| 100 | | | { |
| 101 | 0 | | logger.entering(CLASSNAME, "getItems()"); |
| 102 | 0 | | final Map<ResourceInfo, List<Item>> result |
| 103 | | | = new HashMap<ResourceInfo, List<Item>>(); |
| 104 | | | |
| 105 | 0 | (3)(4) | for (final Iterator<FileType> iterator = mReportDocument.getFile().iterator(); |
| 106 | 0 | | iterator.hasNext();) |
| 107 | | | { |
| 108 | 0 | | final FileType file = iterator.next(); |
| 109 | | | |
| 110 | 0 | | final String key = normalizeFileName(file.getName()); |
| 111 | 0 | | final List<Item> items = createItemMap(file); |
| 112 | 0 | | final ResourceInfo info = ResourceInfo.lookup(key); |
| 113 | 0 | | if (info != null) |
| 114 | | | { |
| 115 | 0 | | result.put(info, items); |
| 116 | | | } |
| 117 | | | else |
| 118 | | | { |
| 119 | 0 | | logger.finer("Ingoring findings for resource " + key); |
| 120 | | | } |
| 121 | 0 | | } |
| 122 | 0 | | logger.exiting(CLASSNAME, "getItems()", result); |
| 123 | 0 | | return result; |
| 124 | | | } |
| 125 | | | |
| 126 | | (5) | private List<Item> createItemMap (org.jcoderz.phoenix.pmd.jaxb.FileType file) |
| 127 | | | throws JAXBException |
| 128 | | | { |
| 129 | 0 | | final List<Item> items = new ArrayList<Item>(); |
| 130 | 0 | (6)(7) | for (final Iterator<Violation> iterator = file.getViolation().iterator(); iterator |
| 131 | 0 | | .hasNext();) |
| 132 | | | { |
| 133 | 0 | | final Violation violation = iterator.next(); |
| 134 | | | |
| 135 | 0 | | final Item item = new ObjectFactory().createItem(); |
| 136 | 0 | | item.setMessage(violation.getValue().trim()); |
| 137 | 0 | | item.setOrigin(Origin.PMD); |
| 138 | 0 | | item.setSeverity(mapPriority(violation)); |
| 139 | 0 | | item.setFindingType(violation.getRule()); |
| 140 | 0 | | item.setLine(violation.getBeginline()); |
| 141 | 0 | | item.setEndLine(violation.getEndline()); |
| 142 | 0 | | item.setColumn(violation.getBegincolumn()); |
| 143 | 0 | | item.setEndColumn(violation.getEndcolumn()); |
| 144 | 0 | | items.add(item); |
| 145 | 0 | | } |
| 146 | 0 | | return items; |
| 147 | | | } |
| 148 | | | |
| 149 | | | private Severity mapPriority (Violation violation) |
| 150 | | | { |
| 151 | | | final Severity ret; |
| 152 | | | |
| 153 | 0 | | switch (violation.getPriority()) |
| 154 | | | { |
| 155 | | | case PRIORITY_HIGH: |
| 156 | 0 | | ret = Severity.ERROR; |
| 157 | 0 | | break; |
| 158 | | | case PRIORITY_MEDIUM_HIGH: |
| 159 | 0 | (8) | ret = Severity.WARNING; |
| 160 | 0 | | break; |
| 161 | | | case PRIORITY_MEDIUM: |
| 162 | 0 | | ret = Severity.DESIGN; |
| 163 | 0 | | break; |
| 164 | | | case PRIORITY_MEDIUM_LOW: |
| 165 | 0 | | ret = Severity.CODE_STYLE; |
| 166 | 0 | | break; |
| 167 | | | case PRIORITY_LOW: |
| 168 | 0 | | ret = Severity.INFO; |
| 169 | 0 | | break; |
| 170 | | | default: |
| 171 | 0 | | ret = Severity.WARNING; |
| 172 | | | } |
| 173 | 0 | | return ret; |
| 174 | | | } |
| 175 | | | } |