| 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.OutputStream; |
| 37 | | | import java.util.Collections; |
| 38 | | (1) | import java.util.Iterator; |
| 39 | | | import java.util.List; |
| 40 | | | import java.util.Map; |
| 41 | | | import java.util.Map.Entry; |
| 42 | | | import java.util.logging.Logger; |
| 43 | | | |
| 44 | | | import javax.xml.bind.JAXBException; |
| 45 | | | |
| 46 | | | import org.jcoderz.phoenix.report.jaxb.Item; |
| 47 | | | import org.jcoderz.phoenix.report.jaxb.ObjectFactory; |
| 48 | | | import org.jcoderz.phoenix.report.jaxb.Report; |
| 49 | | | |
| 50 | | | |
| 51 | | | <code></code> |
| 52 | | | |
| 53 | | | @author |
| 54 | | | |
| 55 | | | public final class JcoderzReport |
| 56 | | | extends AbstractReportReader |
| 57 | | | { |
| 58 | | | |
| 59 | | | public static final String JCODERZ_JAXB_CONTEXT_PATH |
| 60 | | | = "org.jcoderz.phoenix.report.jaxb"; |
| 61 | | | |
| 62 | | | |
| 63 | 0 | | private static final String CLASSNAME = JcoderzReport.class.getName(); |
| 64 | | | |
| 65 | 0 | | private static final Logger logger = Logger.getLogger(CLASSNAME); |
| 66 | | | |
| 67 | 0 | | private final Report mReport = new ObjectFactory().createReport(); |
| 68 | | | |
| 69 | | | |
| 70 | 0 | | private ReportLevel mLevel = ReportLevel.PROD; |
| 71 | | | |
| 72 | | | |
| 73 | | | JcoderzReport () |
| 74 | | | throws JAXBException |
| 75 | | | { |
| 76 | 0 | | super(JCODERZ_JAXB_CONTEXT_PATH); |
| 77 | 0 | | } |
| 78 | | | |
| 79 | | | |
| 80 | | | {@inheritDoc} |
| 81 | | (2) | public Map getItems () |
| 82 | | | throws JAXBException |
| 83 | | | { |
| 84 | 0 | | throw new NoSuchMethodError(); |
| 85 | | | } |
| 86 | | | |
| 87 | | | |
| 88 | | | |
| 89 | | | |
| 90 | | | |
| 91 | | | @param |
| 92 | | | |
| 93 | | | public void setLevel (ReportLevel level) |
| 94 | | | { |
| 95 | 0 | | mLevel = level; |
| 96 | 0 | | } |
| 97 | | | |
| 98 | | | |
| 99 | | | {@inheritDoc} |
| 100 | | | public void parse (File f) |
| 101 | | | throws JAXBException |
| 102 | | | { |
| 103 | | (3) | |
| 104 | 0 | (4) | throw new RuntimeException("Method not implemented. (TODO)"); |
| 105 | | | } |
| 106 | | | |
| 107 | | | |
| 108 | | | |
| 109 | | | |
| 110 | | | |
| 111 | | | @param |
| 112 | | | @param |
| 113 | | | |
| 114 | | | @throws |
| 115 | | | |
| 116 | | | public void write (OutputStream out, Map<ResourceInfo, List<Item>> items) |
| 117 | | | throws JAXBException |
| 118 | | | { |
| 119 | 0 | | addItems(mLevel, items); |
| 120 | 0 | | writeReport(out); |
| 121 | 0 | | } |
| 122 | | | |
| 123 | | | |
| 124 | | | |
| 125 | | | |
| 126 | | | |
| 127 | | | |
| 128 | | | @param |
| 129 | | | @param |
| 130 | | | @throws |
| 131 | | | |
| 132 | | | |
| 133 | | | public void addItems (ReportLevel level, Map<ResourceInfo, List<Item>> items) |
| 134 | | | throws JAXBException |
| 135 | | | { |
| 136 | 0 | | final Map<ResourceInfo, List<Item>> files = items; |
| 137 | | | |
| 138 | 0 | | for (Entry<ResourceInfo, List<Item>> entry : files.entrySet()) |
| 139 | | | { |
| 140 | 0 | | final ResourceInfo info = entry.getKey(); |
| 141 | 0 | | final List<Item> itemList = entry.getValue(); |
| 142 | 0 | | final org.jcoderz.phoenix.report.jaxb.File f |
| 143 | | | = new org.jcoderz.phoenix.report.jaxb.ObjectFactory().createFile(); |
| 144 | 0 | | if (info != null) |
| 145 | | | { |
| 146 | 0 | | f.setName(info.getResourceName()); |
| 147 | 0 | | f.setClassname(info.getClassname()); |
| 148 | 0 | | f.setPackage(info.getPackage()); |
| 149 | 0 | | f.setSrcDir(info.getSourcDir()); |
| 150 | 0 | | f.setLoc(info.getLinesOfCode()); |
| 151 | | | } |
| 152 | 0 | | f.setLevel(level); |
| 153 | 0 | (5) | f.getItem().addAll(itemList); |
| 154 | | | |
| 155 | 0 | (6) | mReport.getFile().add(f); |
| 156 | 0 | | } |
| 157 | 0 | | } |
| 158 | | | |
| 159 | | | |
| 160 | | | |
| 161 | | | |
| 162 | | | |
| 163 | | | @param |
| 164 | | | @throws |
| 165 | | | |
| 166 | | | public void writeReport (OutputStream out) |
| 167 | | | throws JAXBException |
| 168 | | | { |
| 169 | 0 | | getMarshaller().marshal(mReport, out); |
| 170 | 0 | | } |
| 171 | | | |
| 172 | | | |
| 173 | | | |
| 174 | | | |
| 175 | | | |
| 176 | | | @param |
| 177 | | | |
| 178 | | | public void setProjectHome (String s) |
| 179 | | | { |
| 180 | 0 | | mReport.setProjectHome(s); |
| 181 | 0 | | } |
| 182 | | | |
| 183 | | | |
| 184 | | | |
| 185 | | | |
| 186 | | | |
| 187 | | | @return |
| 188 | | | |
| 189 | | | public String getProjectHome () |
| 190 | | | { |
| 191 | 0 | | return mReport.getProjectHome(); |
| 192 | | | } |
| 193 | | | |
| 194 | | | |
| 195 | | | |
| 196 | | | |
| 197 | | | |
| 198 | | | @param |
| 199 | | | |
| 200 | | | public void setProjectName (String s) |
| 201 | | | { |
| 202 | 0 | | mReport.setName(s); |
| 203 | 0 | | } |
| 204 | | | |
| 205 | | | |
| 206 | | | |
| 207 | | | |
| 208 | | | |
| 209 | | | @return |
| 210 | | | |
| 211 | | | public String getProjectName () |
| 212 | | | { |
| 213 | 0 | | return mReport.getName(); |
| 214 | | | } |
| 215 | | | |
| 216 | | (7) | public void addSystemLevelIssue (String message, Throwable e, |
| 217 | | | ResourceInfo res) |
| 218 | | | { |
| 219 | | | try |
| 220 | | | { |
| 221 | 0 | | final Item item = new ObjectFactory().createItem(); |
| 222 | 0 | | item.setMessage(message); |
| 223 | 0 | | item.setSeverity(Severity.ERROR); |
| 224 | 0 | | item.setFindingType(SystemFindingType.SYS_ERROR.getSymbol()); |
| 225 | 0 | | item.setOrigin(Origin.SYSTEM); |
| 226 | 0 | | addItems(ReportLevel.PROD, Collections.singletonMap(res, |
| 227 | | | Collections.singletonList(item))); |
| 228 | | | } |
| 229 | 0 | | catch (JAXBException ex) |
| 230 | | | { |
| 231 | | | |
| 232 | 0 | | throw new RuntimeException( |
| 233 | | | "Failed to add detail for " + e, ex); |
| 234 | 0 | | } |
| 235 | 0 | | } |
| 236 | | | |
| 237 | | | } |