| 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.awt.Color; |
| 36 | | | import java.awt.Dimension; |
| 37 | | | import java.io.BufferedReader; |
| 38 | | | import java.io.File; |
| 39 | | | import java.io.FileOutputStream; |
| 40 | | | import java.io.FileReader; |
| 41 | | | import java.io.FilenameFilter; |
| 42 | | | import java.io.IOException; |
| 43 | | | import java.io.PrintWriter; |
| 44 | | | import java.util.ArrayList; |
| 45 | | | import java.util.Collections; |
| 46 | | | import java.util.HashMap; |
| 47 | | | import java.util.Iterator; |
| 48 | | | import java.util.List; |
| 49 | | | import java.util.Map; |
| 50 | | | import java.util.Set; |
| 51 | | | import java.util.StringTokenizer; |
| 52 | | | import java.util.TreeSet; |
| 53 | | | |
| 54 | | | import javax.xml.parsers.DocumentBuilderFactory; |
| 55 | | | import javax.xml.parsers.ParserConfigurationException; |
| 56 | | | |
| 57 | | | import net.sourceforge.chart2d.Chart2DProperties; |
| 58 | | | import net.sourceforge.chart2d.Dataset; |
| 59 | | | import net.sourceforge.chart2d.GraphChart2DProperties; |
| 60 | | | import net.sourceforge.chart2d.GraphProperties; |
| 61 | | | import net.sourceforge.chart2d.LBChart2D; |
| 62 | | | import net.sourceforge.chart2d.LegendProperties; |
| 63 | | | import net.sourceforge.chart2d.MultiColorsProperties; |
| 64 | | | import net.sourceforge.chart2d.Object2DProperties; |
| 65 | | | |
| 66 | | | import org.apache.tools.ant.BuildException; |
| 67 | | | import org.apache.tools.ant.Task; |
| 68 | | | import org.jcoderz.commons.util.FileUtils; |
| 69 | | | import org.jcoderz.commons.util.IoUtil; |
| 70 | | | import org.w3c.dom.Document; |
| 71 | | | import org.w3c.dom.NamedNodeMap; |
| 72 | | | import org.w3c.dom.Node; |
| 73 | | | import org.xml.sax.SAXException; |
| 74 | | | |
| 75 | | | |
| 76 | | | |
| 77 | | | |
| 78 | | | |
| 79 | | | |
| 80 | | (1) | |
| 81 | | | |
| 82 | | | <ol> |
| 83 | | | <li></li> |
| 84 | | | <li></li> |
| 85 | | | <li></li> |
| 86 | | | <li></li> |
| 87 | | | </ol> |
| 88 | | | |
| 89 | | | @author |
| 90 | | | |
| 91 | 0 | | public class JcSummaryReportAntTask |
| 92 | | | extends Task |
| 93 | | | { |
| 94 | | | |
| 95 | | | private static final int COLUMN_COUNT = 12; |
| 96 | 0 | | private static final String[] MONTHS = new String[] {"January", "February", |
| 97 | | | "March", "April", "Mai", "June", "July", "August", "September", |
| 98 | | | "October", "November", "December"}; |
| 99 | | | private static final int YEAR_LEN = 4; |
| 100 | | | private static final int MONTH_LEN = 2; |
| 101 | | | private static final int DAY_LEN = 2; |
| 102 | | | |
| 103 | | | private static final int ROW_ERROR = 0; |
| 104 | | | private static final int ROW_CPD = 1; |
| 105 | | | private static final int ROW_WARNING = 2; |
| 106 | | | private static final int ROW_DESIGN = 3; |
| 107 | | | private static final int ROW_COVERAGE = 4; |
| 108 | | | private static final int ROW_CODESTYLE = 5; |
| 109 | | | private static final int ROW_INFO = 6; |
| 110 | | | private static final int ROW_FILTERED = 7; |
| 111 | | | |
| 112 | | | private static final int ROW_LOC = 0; |
| 113 | | | |
| 114 | | | private static final int ROW_QUALITY = 0; |
| 115 | | | |
| 116 | | | private static final int LARGE_IMAGE_WIDTH = 800; |
| 117 | | | private static final int LARGE_IMAGE_HEIGHT = 600; |
| 118 | | | private static final int SMALL_IMAGE_WIDTH = 300; |
| 119 | | | private static final int SMALL_IMAGE_HEIGHT = 234; |
| 120 | 0 | | private static final Dimension LARGE_SIZE |
| 121 | | | = new Dimension(LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT); |
| 122 | 0 | | private static final Dimension SMALL_SIZE |
| 123 | | | = new Dimension(SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
| 124 | | | |
| 125 | 0 | | private String mName = null; |
| 126 | 0 | | private File mDestDir = null; |
| 127 | 0 | | private File mBaseDir = null; |
| 128 | 0 | | private File mSummaryDbFile = null; |
| 129 | | | |
| 130 | | | |
| 131 | | | |
| 132 | | | |
| 133 | | | @param |
| 134 | | | |
| 135 | | | public void setName (String name) |
| 136 | | | { |
| 137 | 0 | | mName = name; |
| 138 | 0 | | } |
| 139 | | | |
| 140 | | | |
| 141 | | | |
| 142 | | | |
| 143 | | | |
| 144 | | | @param |
| 145 | | | |
| 146 | | | public void setDest (String dest) |
| 147 | | | { |
| 148 | 0 | | mDestDir = new File(dest); |
| 149 | 0 | | if (!mDestDir.exists()) |
| 150 | | | { |
| 151 | 0 | (2) | mDestDir.mkdirs(); |
| 152 | | | } |
| 153 | 0 | | } |
| 154 | | | |
| 155 | | | |
| 156 | | | |
| 157 | | | |
| 158 | | | |
| 159 | | | @param |
| 160 | | | |
| 161 | | | public void setBaseDir (String base) |
| 162 | | | { |
| 163 | 0 | | mBaseDir = new File(base); |
| 164 | 0 | | if (!mBaseDir.exists()) |
| 165 | | | { |
| 166 | 0 | (3) | mBaseDir.mkdirs(); |
| 167 | | | } |
| 168 | 0 | | } |
| 169 | | | |
| 170 | | | |
| 171 | | | |
| 172 | | | |
| 173 | | | |
| 174 | | | @param |
| 175 | | | |
| 176 | | | public void setSummary (String summary) |
| 177 | | | { |
| 178 | 0 | | mSummaryDbFile = new File(summary); |
| 179 | 0 | | } |
| 180 | | | |
| 181 | | | |
| 182 | | | |
| 183 | | | |
| 184 | | | |
| 185 | | | @throws |
| 186 | | | |
| 187 | | | public void execute () |
| 188 | | | throws BuildException |
| 189 | | | { |
| 190 | | | try |
| 191 | | | { |
| 192 | | | |
| 193 | 0 | | log("Executing JcSummaryReportAntTask..."); |
| 194 | | | |
| 195 | 0 | | if (mSummaryDbFile == null) |
| 196 | | | { |
| 197 | 0 | | throw new BuildException("Summary database must be specified!"); |
| 198 | | | } |
| 199 | | | |
| 200 | 0 | | if (mDestDir == null) |
| 201 | | | { |
| 202 | 0 | | throw new BuildException("Destination folder must be specified!"); |
| 203 | | | } |
| 204 | 0 | | if (mDestDir.exists()) |
| 205 | | | { |
| 206 | 0 | | if (!mDestDir.isDirectory()) |
| 207 | | | { |
| 208 | 0 | | throw new BuildException("The destination directory '" + mDestDir |
| 209 | | | + "' must be folder!"); |
| 210 | | | } |
| 211 | | | } |
| 212 | | | else |
| 213 | | | { |
| 214 | 0 | (4) | mDestDir.mkdirs(); |
| 215 | | | } |
| 216 | | | |
| 217 | 0 | | if (mBaseDir == null) |
| 218 | | | { |
| 219 | 0 | | throw new BuildException("The base directory must be specified!"); |
| 220 | | | } |
| 221 | 0 | | if (!mBaseDir.exists() || !mBaseDir.isDirectory()) |
| 222 | | | { |
| 223 | 0 | | throw new BuildException("The base directory '" |
| 224 | | | + mBaseDir + "' must exists and must be a folder!"); |
| 225 | | | } |
| 226 | | | |
| 227 | | | |
| 228 | | | |
| 229 | | | |
| 230 | 0 | | final Map summaryMap = readSummaryDb(mSummaryDbFile, mBaseDir); |
| 231 | | | |
| 232 | 0 | | writeSummaryDb(mSummaryDbFile, summaryMap); |
| 233 | | | |
| 234 | | | |
| 235 | | | |
| 236 | | | |
| 237 | 0 | | final Map ymd2SummaryMap = createSummaryDbMap(summaryMap); |
| 238 | | | |
| 239 | 0 | | createFindingsChart(ymd2SummaryMap, summaryMap, "Findings"); |
| 240 | 0 | | createQualityChart(ymd2SummaryMap, summaryMap, "Quality"); |
| 241 | 0 | | createLocChart(ymd2SummaryMap, summaryMap, "LOC"); |
| 242 | | | |
| 243 | 0 | | renderHtmlView(ymd2SummaryMap, summaryMap); |
| 244 | | | } |
| 245 | 0 | | catch (IOException ex) |
| 246 | | | { |
| 247 | 0 | | throw new BuildException("An unexpected IO exception occured!", ex); |
| 248 | 0 | | } |
| 249 | 0 | | } |
| 250 | | | |
| 251 | | | |
| 252 | | | |
| 253 | | | |
| 254 | | | |
| 255 | | | @param |
| 256 | | | |
| 257 | | | private void writeSummaryDb (File summaryDbFile, Map summaryMap) |
| 258 | | | { |
| 259 | | | try |
| 260 | | | { |
| 261 | 0 | | log("Writing summary file " + summaryDbFile); |
| 262 | 0 | (5) | summaryDbFile.createNewFile(); |
| 263 | 0 | | final FileOutputStream fos = new FileOutputStream(summaryDbFile); |
| 264 | 0 | | final PrintWriter pw = new PrintWriter(fos); |
| 265 | 0 | | pw.println("Timestamp;Error;Warning;Info;" |
| 266 | | | + "Coverage;Loc;CodeLoc;Filtered;Codestyle;Design;Cpd;Quality"); |
| 267 | | | |
| 268 | | | |
| 269 | 0 | | final Set keySet = summaryMap.keySet(); |
| 270 | 0 | (6) | final List keyList = new ArrayList(keySet); |
| 271 | 0 | (7)(8) | Collections.sort(keyList); |
| 272 | 0 | | final Iterator iter = keyList.iterator(); |
| 273 | 0 | | while (iter.hasNext()) |
| 274 | | | { |
| 275 | 0 | | final Long ts = (Long) iter.next(); |
| 276 | 0 | | final Summary sum = (Summary) summaryMap.get(ts); |
| 277 | 0 | | pw.print(sum.getTimestamp() + ";"); |
| 278 | 0 | | pw.print(sum.getError() + ";"); |
| 279 | 0 | | pw.print(sum.getWarning() + ";"); |
| 280 | 0 | | pw.print(sum.getInfo() + ";"); |
| 281 | 0 | | pw.print(sum.getCoverage() + ";"); |
| 282 | 0 | | pw.print(sum.getLoc() + ";"); |
| 283 | 0 | | pw.print(sum.getCodeLoc() + ";"); |
| 284 | 0 | | pw.print(sum.getFiltered() + ";"); |
| 285 | 0 | | pw.print(sum.getCodestyle() + ";"); |
| 286 | 0 | | pw.print(sum.getDesign() + ";"); |
| 287 | 0 | | pw.print(sum.getCpd() + ";"); |
| 288 | 0 | | pw.println(FileSummary.calculateQuality(sum.getLoc(), |
| 289 | | | sum.getInfo(), sum.getWarning(), sum.getError(), |
| 290 | | | sum.getCoverage(), sum.getFiltered(), |
| 291 | | | sum.getCodestyle(), sum.getDesign(), sum.getCpd())); |
| 292 | 0 | | } |
| 293 | 0 | | fos.flush(); |
| 294 | 0 | | IoUtil.close(pw); |
| 295 | 0 | | IoUtil.close(fos); |
| 296 | | | } |
| 297 | 0 | | catch (IOException ex) |
| 298 | | | { |
| 299 | 0 | | throw new BuildException("Could not write summary database '" |
| 300 | | | + summaryDbFile + "'!"); |
| 301 | 0 | | } |
| 302 | 0 | | } |
| 303 | | | |
| 304 | | | |
| 305 | | | |
| 306 | | | |
| 307 | | | |
| 308 | | | |
| 309 | | | @param |
| 310 | | | @param |
| 311 | | | @return |
| 312 | | | |
| 313 | | | private Map readSummaryDb (File summaryDbFile, File baseDir) |
| 314 | | | { |
| 315 | 0 | | final Map files = new HashMap(); |
| 316 | 0 | | if (summaryDbFile.exists()) |
| 317 | | | { |
| 318 | 0 | | log("Reading summary database..."); |
| 319 | 0 | | FileReader fr = null; |
| 320 | 0 | | BufferedReader br = null; |
| 321 | | | try |
| 322 | | | { |
| 323 | 0 | | fr = new FileReader(summaryDbFile); |
| 324 | 0 | | br = new BufferedReader(fr); |
| 325 | 0 | | String line = br.readLine(); |
| 326 | 0 | | while (line != null) |
| 327 | | | { |
| 328 | 0 | | if (line.indexOf("Error") == -1 |
| 329 | | | && line.indexOf("Warning") == -1 |
| 330 | | | && line.indexOf("Info") == -1 |
| 331 | | | && line.indexOf("Coverage") == -1) |
| 332 | | | { |
| 333 | 0 | | final Summary sum = createSummary(line, baseDir); |
| 334 | 0 | | log("Summary information from database: " + sum); |
| 335 | 0 | | if (sum != null) |
| 336 | | | { |
| 337 | 0 | (9)(10) | files.put(new Long(sum.getTimestamp()), sum); |
| 338 | | | } |
| 339 | | | } |
| 340 | 0 | | line = br.readLine(); |
| 341 | | | } |
| 342 | | | } |
| 343 | 0 | | catch (IOException ex) |
| 344 | | | { |
| 345 | 0 | | throw new BuildException("An IO exception occured while reading '" |
| 346 | | | + summaryDbFile + "'!", ex); |
| 347 | | | } |
| 348 | | | finally |
| 349 | | | { |
| 350 | 0 | (11) | FileUtils.safeClose(br); |
| 351 | 0 | (12) | FileUtils.safeClose(fr); |
| 352 | 0 | | } |
| 353 | | | } |
| 354 | | | |
| 355 | | | |
| 356 | 0 | | final String[] folders = baseDir.list(new JcoderReportFilter()); |
| 357 | 0 | | for (int i = 0; i < folders.length; i++) |
| 358 | | | { |
| 359 | 0 | | if (!files.containsKey(Long.valueOf(folders[i]))) |
| 360 | | | { |
| 361 | 0 | | log("New report sub-folder found: " + folders[i]); |
| 362 | 0 | | final File folder = new File(baseDir, folders[i]); |
| 363 | 0 | | Long ts = null; |
| 364 | | | try |
| 365 | | | { |
| 366 | 0 | | ts = Long.valueOf(folders[i]); |
| 367 | | | } |
| 368 | 0 | | catch (NumberFormatException ex) |
| 369 | | | { |
| 370 | 0 | | log("The folder '" + folders[i] |
| 371 | | | + "' is not a timestamp folder!"); |
| 372 | 0 | | } |
| 373 | 0 | | final Summary sum = readSummaryXml(findSummaryXml(folder), ts); |
| 374 | 0 | (13) | files.put(new Long(sum.getTimestamp()), sum); |
| 375 | 0 | | } |
| 376 | | | else |
| 377 | | | { |
| 378 | 0 | | log("Report sub-folder '" + folders[i] + "' already in database!"); |
| 379 | | | } |
| 380 | | | } |
| 381 | 0 | | return files; |
| 382 | | | } |
| 383 | | | |
| 384 | | | private static File findSummaryXml(File folder) |
| 385 | | | { |
| 386 | 0 | | File result = null; |
| 387 | 0 | | if (folder.isFile() && "summary.xml".equals(folder.getName())) |
| 388 | | | { |
| 389 | 0 | | result = folder; |
| 390 | | | } |
| 391 | 0 | | else if (folder.isDirectory()) |
| 392 | | | { |
| 393 | 0 | | for (File file : folder.listFiles()) |
| 394 | | | { |
| 395 | 0 | | result = findSummaryXml(file); |
| 396 | 0 | | if (result != null) |
| 397 | | | { |
| 398 | 0 | | break; |
| 399 | | | } |
| 400 | | | } |
| 401 | | | } |
| 402 | 0 | | return result; |
| 403 | | | } |
| 404 | | | |
| 405 | | | |
| 406 | | | private Summary readSummaryXml (File summaryXml, Long folderTimestamp) |
| 407 | | | { |
| 408 | 0 | | Summary sum = null; |
| 409 | | | try |
| 410 | | | { |
| 411 | 0 | | final DocumentBuilderFactory factory = |
| 412 | | | DocumentBuilderFactory.newInstance(); |
| 413 | 0 | | final Document doc = factory.newDocumentBuilder().parse(summaryXml); |
| 414 | | | |
| 415 | 0 | | final Node root = doc.getDocumentElement(); |
| 416 | 0 | | final NamedNodeMap attrs = root.getAttributes(); |
| 417 | | | |
| 418 | | | |
| 419 | | | |
| 420 | | | long ts; |
| 421 | 0 | | if (folderTimestamp == null) |
| 422 | | | { |
| 423 | 0 | | ts = Long.parseLong( |
| 424 | | | attrs.getNamedItem("timestamp").getNodeValue().trim()); |
| 425 | | | } |
| 426 | | | else |
| 427 | | | { |
| 428 | 0 | | ts = folderTimestamp.longValue(); |
| 429 | | | } |
| 430 | | | |
| 431 | 0 | | final int filtered = Integer.parseInt( |
| 432 | | | attrs.getNamedItem("filtered").getNodeValue().trim()); |
| 433 | 0 | | final int coverage = Integer.parseInt( |
| 434 | | | attrs.getNamedItem("coverage").getNodeValue().trim()); |
| 435 | 0 | | final int info = Integer.parseInt( |
| 436 | | | attrs.getNamedItem("info").getNodeValue().trim()); |
| 437 | 0 | | final int codestyle = Integer.parseInt( |
| 438 | | | attrs.getNamedItem("code-style").getNodeValue().trim()); |
| 439 | 0 | | final int design = Integer.parseInt( |
| 440 | | | attrs.getNamedItem("design").getNodeValue().trim()); |
| 441 | 0 | | final int warning = Integer.parseInt( |
| 442 | | | attrs.getNamedItem("warning").getNodeValue().trim()); |
| 443 | 0 | | final int cpd = Integer.parseInt( |
| 444 | | | attrs.getNamedItem("cpd").getNodeValue().trim()); |
| 445 | 0 | | final int error = Integer.parseInt( |
| 446 | | | attrs.getNamedItem("error").getNodeValue().trim()); |
| 447 | 0 | | final int loc = Integer.parseInt( |
| 448 | | | attrs.getNamedItem("loc").getNodeValue().trim()); |
| 449 | 0 | | final int codeloc = Integer.parseInt( |
| 450 | | | attrs.getNamedItem("codeLoc").getNodeValue().trim()); |
| 451 | 0 | | final double quality = Double.parseDouble( |
| 452 | | | attrs.getNamedItem("quality").getNodeValue()); |
| 453 | 0 | | sum = new Summary(ts, error, warning, info, coverage, loc, codeloc, |
| 454 | | | filtered, codestyle, design, cpd, quality, summaryXml); |
| 455 | | | } |
| 456 | 0 | | catch (ParserConfigurationException ex) |
| 457 | | | { |
| 458 | 0 | (14) | throw new BuildException("A parser configuration error occured!", ex); |
| 459 | | | } |
| 460 | 0 | | catch (SAXException ex) |
| 461 | | | { |
| 462 | 0 | | throw new BuildException("A SAX exception occured while parsing '" |
| 463 | | | + summaryXml + "'!", ex); |
| 464 | | | } |
| 465 | 0 | | catch (IOException ex) |
| 466 | | | { |
| 467 | 0 | | throw new BuildException("An IO exception occured while parsing '" |
| 468 | | | + summaryXml + "'!", ex); |
| 469 | 0 | | } |
| 470 | | | |
| 471 | 0 | | return sum; |
| 472 | | | } |
| 473 | | | |
| 474 | | | |
| 475 | | | private void storeInMap (Map files, long timestamp, Summary sum) |
| 476 | | | { |
| 477 | 0 | | log("Storing summmary: " + sum); |
| 478 | 0 | (15) | final Long ts = new Long(timestamp); |
| 479 | 0 | | final String tsStr = ts.toString(); |
| 480 | 0 | | final Integer y = Integer.valueOf(tsStr.substring(0, 4)); |
| 481 | 0 | | final Integer m = Integer.valueOf(tsStr.substring(4, 6)); |
| 482 | 0 | | final Integer d = Integer.valueOf(tsStr.substring(6, 8)); |
| 483 | 0 | | if (!files.containsKey(y)) |
| 484 | | | { |
| 485 | 0 | | log("Adding hash map for year " + y); |
| 486 | 0 | (16) | files.put(y, new HashMap()); |
| 487 | | | } |
| 488 | 0 | | final Map year = (Map) files.get(y); |
| 489 | 0 | | if (!year.containsKey(m)) |
| 490 | | | { |
| 491 | 0 | | log("Adding hash map for month " + m); |
| 492 | 0 | (17) | year.put(m, new HashMap()); |
| 493 | | | } |
| 494 | 0 | | final Map month = (Map) year.get(m); |
| 495 | 0 | | if (!month.containsKey(d)) |
| 496 | | | { |
| 497 | 0 | | log("Adding report list for day " + d); |
| 498 | 0 | (18) | month.put(d, new ArrayList()); |
| 499 | | | } |
| 500 | 0 | | final List reports = (List) month.get(d); |
| 501 | 0 | (19) | reports.add(sum); |
| 502 | 0 | | } |
| 503 | | | |
| 504 | | | |
| 505 | | | private Map createSummaryDbMap (Map ts2SumMap) |
| 506 | | | { |
| 507 | 0 | | final Map files = new HashMap(); |
| 508 | 0 | | final Iterator iter = ts2SumMap.keySet().iterator(); |
| 509 | 0 | | while (iter.hasNext()) |
| 510 | | | { |
| 511 | 0 | | final Long ts = (Long) iter.next(); |
| 512 | 0 | (20) | final Summary sum = (Summary) ts2SumMap.get(ts); |
| 513 | 0 | | storeInMap(files, ts.longValue(), sum); |
| 514 | 0 | | } |
| 515 | 0 | | return files; |
| 516 | | | } |
| 517 | | | |
| 518 | | | |
| 519 | | | private Summary createSummary (String sum, File baseDir) |
| 520 | | | { |
| 521 | 0 | | final StringTokenizer strtok = new StringTokenizer(sum, ";"); |
| 522 | 0 | | if (strtok.countTokens() != COLUMN_COUNT) |
| 523 | | | { |
| 524 | 0 | | throw new BuildException( |
| 525 | | | "Number of columns in summary database file '" |
| 526 | | | + strtok.countTokens() |
| 527 | | | + "' does not match the expected number of '" |
| 528 | | | + COLUMN_COUNT + "'!"); |
| 529 | | | } |
| 530 | 0 | | Summary summary = null; |
| 531 | 0 | | final long timestamp = Long.parseLong(strtok.nextToken()); |
| 532 | 0 | (21) | final int error = Integer.parseInt(strtok.nextToken()); |
| 533 | 0 | (22) | final int warning = Integer.parseInt(strtok.nextToken()); |
| 534 | 0 | (23) | final int info = Integer.parseInt(strtok.nextToken()); |
| 535 | 0 | (24) | final int coverage = Integer.parseInt(strtok.nextToken()); |
| 536 | 0 | (25) | final int loc = Integer.parseInt(strtok.nextToken()); |
| 537 | 0 | (26) | final int codeloc = Integer.parseInt(strtok.nextToken()); |
| 538 | 0 | (27) | final int filtered = Integer.parseInt(strtok.nextToken()); |
| 539 | 0 | (28) | final int codestyle = Integer.parseInt(strtok.nextToken()); |
| 540 | 0 | (29) | final int design = Integer.parseInt(strtok.nextToken()); |
| 541 | 0 | (30) | final int cpd = Integer.parseInt(strtok.nextToken()); |
| 542 | 0 | (31) | final double quality = Double.parseDouble(strtok.nextToken()); |
| 543 | 0 | | final File summaryFile = new File(baseDir, String.valueOf(timestamp) |
| 544 | | | + File.separator + "summary.xml"); |
| 545 | 0 | | if (summaryFile.exists() && summaryFile.isFile()) |
| 546 | | | { |
| 547 | 0 | | summary = new Summary(timestamp, error, warning, info, coverage, loc, |
| 548 | | | codeloc, filtered, codestyle, design, cpd, |
| 549 | | | quality, summaryFile); |
| 550 | | | } |
| 551 | | | else |
| 552 | | | { |
| 553 | 0 | | log("Summary file does not exist: " + summaryFile); |
| 554 | | | } |
| 555 | 0 | | return summary; |
| 556 | | | } |
| 557 | | | |
| 558 | | | |
| 559 | | | |
| 560 | | | |
| 561 | | | |
| 562 | | | |
| 563 | | | @throws |
| 564 | | | |
| 565 | | | private void createQualityChart (Map ymd2SummaryMap, Map summaryMap, |
| 566 | | | String title) |
| 567 | | | throws IOException |
| 568 | | | { |
| 569 | 0 | (32) | final Set labels = new TreeSet(summaryMap.keySet()); |
| 570 | 0 | | if (labels.size() == 0) |
| 571 | | | { |
| 572 | 0 | (33) | throw new RuntimeException("No reports found for chart!"); |
| 573 | | | } |
| 574 | | | |
| 575 | 0 | (34)(35) | final String[] legendLabels = {"Quality"}; |
| 576 | | | |
| 577 | | | |
| 578 | 0 | | final Dataset dataset = new Dataset(legendLabels.length, |
| 579 | | | summaryMap.size(), 1); |
| 580 | 0 | | final List labelsAxisLabels = new ArrayList(); |
| 581 | 0 | | final List sortedKeyList = new ArrayList(); |
| 582 | 0 | (36) | sortedKeyList.addAll(summaryMap.keySet()); |
| 583 | 0 | (37)(38) | Collections.sort(sortedKeyList); |
| 584 | 0 | | final Iterator iter = sortedKeyList.iterator(); |
| 585 | 0 | | int i = 0; |
| 586 | 0 | | while (iter.hasNext()) |
| 587 | | | { |
| 588 | 0 | | final Long ts = (Long) iter.next(); |
| 589 | 0 | (39) | labelsAxisLabels.add(ts.toString()); |
| 590 | 0 | | final Summary sum = (Summary) summaryMap.get(ts); |
| 591 | | | |
| 592 | 0 | | dataset.set(ROW_QUALITY, i, 0, (float) sum.getQuality()); |
| 593 | 0 | | i++; |
| 594 | 0 | | } |
| 595 | | | |
| 596 | 0 | | final GraphChart2DProperties graphChart2DProps |
| 597 | | | = createGraphChart2DProperties(labelsAxisLabels, title); |
| 598 | 0 | | final MultiColorsProperties multiColorsProps |
| 599 | | | = createMultiColorsProperties(new Color[] {Color.GREEN}); |
| 600 | 0 | | createChart(title, legendLabels, dataset, graphChart2DProps, |
| 601 | | | multiColorsProps); |
| 602 | 0 | | } |
| 603 | | | |
| 604 | | | |
| 605 | | | |
| 606 | | | |
| 607 | | | |
| 608 | | | |
| 609 | | | @throws |
| 610 | | | |
| 611 | | | private void createLocChart (Map ymd2SummaryMap, Map summaryMap, |
| 612 | | | String title) |
| 613 | | | throws IOException |
| 614 | | | { |
| 615 | 0 | (40) | final Set labels = new TreeSet(summaryMap.keySet()); |
| 616 | 0 | | if (labels.size() == 0) |
| 617 | | | { |
| 618 | 0 | (41) | throw new RuntimeException("No reports found for chart!"); |
| 619 | | | } |
| 620 | | | |
| 621 | 0 | (42)(43) | final String[] legendLabels = {"Loc"}; |
| 622 | | | |
| 623 | | | |
| 624 | 0 | | final Dataset dataset = new Dataset(legendLabels.length, |
| 625 | | | summaryMap.size(), 1); |
| 626 | 0 | | final List labelsAxisLabels = new ArrayList(); |
| 627 | 0 | | final List sortedKeyList = new ArrayList(); |
| 628 | 0 | (44) | sortedKeyList.addAll(summaryMap.keySet()); |
| 629 | 0 | (45)(46) | Collections.sort(sortedKeyList); |
| 630 | 0 | | final Iterator iter = sortedKeyList.iterator(); |
| 631 | 0 | | int i = 0; |
| 632 | 0 | | while (iter.hasNext()) |
| 633 | | | { |
| 634 | 0 | | final Long ts = (Long) iter.next(); |
| 635 | 0 | (47) | labelsAxisLabels.add(ts.toString()); |
| 636 | 0 | | final Summary sum = (Summary) summaryMap.get(ts); |
| 637 | | | |
| 638 | 0 | | dataset.set(ROW_LOC, i, 0, sum.getLoc()); |
| 639 | 0 | | i++; |
| 640 | 0 | | } |
| 641 | | | |
| 642 | 0 | | final GraphChart2DProperties graphChart2DProps |
| 643 | | | = createGraphChart2DProperties(labelsAxisLabels, title); |
| 644 | 0 | | final MultiColorsProperties multiColorsProps |
| 645 | | | = createMultiColorsProperties( |
| 646 | | | new Color[] {new Color(115, 117, 255)}); |
| 647 | 0 | | createChart(title, legendLabels, dataset, graphChart2DProps, |
| 648 | | | multiColorsProps); |
| 649 | 0 | | } |
| 650 | | | |
| 651 | | | |
| 652 | | | |
| 653 | | | |
| 654 | | | |
| 655 | | | |
| 656 | | | @throws |
| 657 | | | |
| 658 | | | private void createFindingsChart (Map ymd2SummaryMap, Map summaryMap, |
| 659 | | | String title) |
| 660 | | | throws IOException |
| 661 | | | { |
| 662 | 0 | (48) | final Set labels = new TreeSet(summaryMap.keySet()); |
| 663 | 0 | | if (labels.size() == 0) |
| 664 | | | { |
| 665 | 0 | (49) | throw new RuntimeException("No reports found for chart!"); |
| 666 | | | } |
| 667 | | | |
| 668 | 0 | (50) | final String[] legendLabels = {"Error", "Warning", "Info", "Coverage", |
| 669 | | (51) | "Filtered", "Codestyle", "Design", "Cpd"}; |
| 670 | | | |
| 671 | | | |
| 672 | 0 | | final Dataset dataset = new Dataset(legendLabels.length, |
| 673 | | | summaryMap.size(), 1); |
| 674 | 0 | | final List labelsAxisLabels = new ArrayList(); |
| 675 | 0 | | final List sortedKeyList = new ArrayList(); |
| 676 | 0 | (52) | sortedKeyList.addAll(summaryMap.keySet()); |
| 677 | 0 | (53)(54) | Collections.sort(sortedKeyList); |
| 678 | 0 | | final Iterator iter = sortedKeyList.iterator(); |
| 679 | 0 | | int i = 0; |
| 680 | 0 | | while (iter.hasNext()) |
| 681 | | | { |
| 682 | 0 | | final Long ts = (Long) iter.next(); |
| 683 | 0 | (55) | labelsAxisLabels.add(ts.toString()); |
| 684 | 0 | | final Summary sum = (Summary) summaryMap.get(ts); |
| 685 | | | |
| 686 | 0 | | dataset.set(ROW_ERROR, i, 0, sum.getError()); |
| 687 | 0 | | dataset.set(ROW_CPD, i, 0, sum.getCpd()); |
| 688 | 0 | | dataset.set(ROW_WARNING, i, 0, sum.getWarning()); |
| 689 | 0 | | dataset.set(ROW_DESIGN, i, 0, sum.getDesign()); |
| 690 | 0 | | dataset.set(ROW_COVERAGE, i, 0, sum.getCoverage()); |
| 691 | 0 | | dataset.set(ROW_CODESTYLE, i, 0, sum.getCodestyle()); |
| 692 | 0 | | dataset.set(ROW_INFO, i, 0, sum.getInfo()); |
| 693 | 0 | | dataset.set(ROW_FILTERED, i, 0, sum.getFiltered()); |
| 694 | 0 | | i++; |
| 695 | 0 | | } |
| 696 | | | |
| 697 | 0 | | final GraphChart2DProperties graphChart2DProps |
| 698 | | | = createGraphChart2DProperties(labelsAxisLabels, title); |
| 699 | 0 | | final MultiColorsProperties multiColorsProps |
| 700 | | | = createMultiColorsProperties(new Color[] { |
| 701 | | | new Color(255, 65, 66), |
| 702 | | | new Color(214, 243, 214), |
| 703 | | | new Color(255, 162, 66), |
| 704 | | | new Color(255, 243, 66), |
| 705 | | | new Color(255, 255, 231), |
| 706 | | | new Color(255, 243, 132), |
| 707 | | | new Color(214, 211, 255), |
| 708 | | | new Color(247, 247, 247) |
| 709 | | | }); |
| 710 | 0 | | createChart(title, legendLabels, dataset, graphChart2DProps, |
| 711 | | | multiColorsProps); |
| 712 | 0 | | } |
| 713 | | | |
| 714 | | | |
| 715 | | | private void createChart (final String title, final String[] legendLabels, |
| 716 | | | final Dataset dataset, |
| 717 | | | final GraphChart2DProperties graphChart2DProps, |
| 718 | | | final MultiColorsProperties multiColorsProps) throws IOException |
| 719 | | | { |
| 720 | | | |
| 721 | 0 | | final LBChart2D chart2D = new LBChart2D(); |
| 722 | 0 | | chart2D.setObject2DProperties(createObject2DProps()); |
| 723 | 0 | | chart2D.setChart2DProperties(createChart2DProperties()); |
| 724 | 0 | | chart2D.setLegendProperties(createLegendProperties(legendLabels)); |
| 725 | | | |
| 726 | 0 | | chart2D.setGraphChart2DProperties(graphChart2DProps); |
| 727 | 0 | | chart2D.addGraphProperties(createGraphProperties()); |
| 728 | 0 | | chart2D.addDataset(dataset); |
| 729 | 0 | | chart2D.addMultiColorsProperties(multiColorsProps); |
| 730 | | | |
| 731 | 0 | | chart2D.setMaximumSize(LARGE_SIZE); |
| 732 | 0 | | chart2D.setPreferredSize(LARGE_SIZE); |
| 733 | | | |
| 734 | 0 | (56)(57) | final String titleSmall = title.toLowerCase(); |
| 735 | 0 | | if (chart2D.validate(false)) |
| 736 | | | { |
| 737 | 0 | | java.io.File file = new java.io.File(mDestDir, titleSmall + ".png"); |
| 738 | 0 | | javax.imageio.ImageIO.write(chart2D.getImage(), "PNG", file); |
| 739 | 0 | | chart2D.setMaximumSize(SMALL_SIZE); |
| 740 | 0 | | chart2D.setPreferredSize(SMALL_SIZE); |
| 741 | 0 | | chart2D.pack(); |
| 742 | 0 | | file = new java.io.File(mDestDir, titleSmall + "_small.png"); |
| 743 | 0 | | javax.imageio.ImageIO.write(chart2D.getImage(), "PNG", file); |
| 744 | 0 | | } |
| 745 | | | else |
| 746 | | | { |
| 747 | 0 | | chart2D.validate(true); |
| 748 | | | } |
| 749 | 0 | | } |
| 750 | | | |
| 751 | | | |
| 752 | | | private MultiColorsProperties createMultiColorsProperties (Color[] colors) |
| 753 | | | { |
| 754 | | | |
| 755 | 0 | | final MultiColorsProperties multiColorsProps |
| 756 | | | = new MultiColorsProperties(); |
| 757 | 0 | | multiColorsProps.setColorsCustomize(true); |
| 758 | 0 | | multiColorsProps.setColorsCustom(colors); |
| 759 | 0 | | return multiColorsProps; |
| 760 | | | } |
| 761 | | | |
| 762 | | | |
| 763 | | | private Object2DProperties createObject2DProps () |
| 764 | | | { |
| 765 | 0 | | final Object2DProperties object2DProps = new Object2DProperties(); |
| 766 | 0 | | object2DProps.setObjectBackgroundLightSource(Object2DProperties.NONE); |
| 767 | 0 | | object2DProps.setObjectBackgroundColor(Color.LIGHT_GRAY); |
| 768 | 0 | | return object2DProps; |
| 769 | | | } |
| 770 | | | |
| 771 | | | |
| 772 | | | private GraphProperties createGraphProperties () |
| 773 | | | { |
| 774 | | | |
| 775 | 0 | | final GraphProperties graphProps = new GraphProperties(); |
| 776 | 0 | | graphProps.setGraphBarsExistence(false); |
| 777 | 0 | | graphProps.setGraphLinesExistence(true); |
| 778 | 0 | | graphProps.setGraphLinesThicknessModel(1); |
| 779 | 0 | | return graphProps; |
| 780 | | | } |
| 781 | | | |
| 782 | | | |
| 783 | | | private Chart2DProperties createChart2DProperties () |
| 784 | | | { |
| 785 | | | |
| 786 | 0 | | final Chart2DProperties chart2DProps = new Chart2DProperties(); |
| 787 | 0 | | chart2DProps.setChartDataLabelsPrecision(0); |
| 788 | 0 | | return chart2DProps; |
| 789 | | | } |
| 790 | | | |
| 791 | | | |
| 792 | | | private LegendProperties createLegendProperties (String[] legendLabels) |
| 793 | | | { |
| 794 | | | |
| 795 | 0 | | final LegendProperties legendProps = new LegendProperties(); |
| 796 | 0 | | legendProps.setLegendLabelsTexts(legendLabels); |
| 797 | 0 | | return legendProps; |
| 798 | | | } |
| 799 | | | |
| 800 | | | |
| 801 | | | private GraphChart2DProperties createGraphChart2DProperties ( |
| 802 | | | List labelsAxisLabels, String title) |
| 803 | | | { |
| 804 | | | |
| 805 | 0 | | final GraphChart2DProperties graphChart2DProps = |
| 806 | | | new GraphChart2DProperties(); |
| 807 | 0 | | final String[] labelsTexts = new String[labelsAxisLabels.size()]; |
| 808 | 0 | | graphChart2DProps.setLabelsAxisLabelsTexts((String[]) |
| 809 | | (58) | labelsAxisLabels.toArray(labelsTexts)); |
| 810 | | | |
| 811 | 0 | | graphChart2DProps.setNumbersAxisTitleText(title); |
| 812 | 0 | | graphChart2DProps.setLabelsAxisTicksAlignment( |
| 813 | | | GraphChart2DProperties.CENTERED); |
| 814 | 0 | | return graphChart2DProps; |
| 815 | | | } |
| 816 | | | |
| 817 | | | |
| 818 | | | private void renderHtmlView (Map summaryDbMap, Map ts2BaseFolder) |
| 819 | | | { |
| 820 | | | try |
| 821 | | | { |
| 822 | 0 | | final FileOutputStream fos = new FileOutputStream( |
| 823 | | | new File(mDestDir, "index.html")); |
| 824 | 0 | | final PrintWriter pw = new PrintWriter(fos); |
| 825 | 0 | | pw.println("<html><head>\n<title>"); |
| 826 | 0 | | pw.println(mName); |
| 827 | 0 | | pw.println("</title>"); |
| 828 | 0 | | pw.println("<style type=\"text/css\">"); |
| 829 | 0 | | pw.println("<!--"); |
| 830 | | | |
| 831 | 0 | | pw.println("body { font-family: verdana, tahoma; }"); |
| 832 | 0 | | pw.println("img { border:none; }"); |
| 833 | 0 | | pw.println("a { text-decoration: none; }"); |
| 834 | 0 | | pw.println("a:hover { text-decoration: underline; }"); |
| 835 | | | |
| 836 | 0 | | pw.println(".bold { font-weight: bold; }"); |
| 837 | 0 | | pw.println("table { border-collapse: collapse; " |
| 838 | | | + "border: 1px solid black; text-align: right; }"); |
| 839 | 0 | | pw.println("table td { padding: 5px; border-collapse: collapse; " |
| 840 | | | + "border: 1px solid black; font-size: small; vertical-align: " |
| 841 | | | + "top; }"); |
| 842 | 0 | | pw.println("td.month { padding: 10px; border: 1px solid black; " |
| 843 | | | + "margin: 1em; background-color: #eeeeee; text-align: left; " |
| 844 | | | + "font-size: large; }"); |
| 845 | 0 | | pw.println("td.day_odd { background: #aaaaaa; }"); |
| 846 | 0 | | pw.println("td.day_even { background: #cccccc; }"); |
| 847 | 0 | | pw.println("td.quality_odd { background:#88b888; }"); |
| 848 | 0 | | pw.println("td.quality_even { background:#88e888; }"); |
| 849 | 0 | | pw.println("td.loc_odd { background:#7777cf; }"); |
| 850 | 0 | | pw.println("td.loc_even { background:#7777ff; }"); |
| 851 | 0 | | pw.println("td.filtered_odd { background:#e0e0e0; }"); |
| 852 | 0 | | pw.println("td.filtered_even { background:#f7f7f7; }"); |
| 853 | 0 | | pw.println("td.ok_odd { background:#e0e0e0; }"); |
| 854 | 0 | | pw.println("td.ok_even { background:#ffffff; }"); |
| 855 | 0 | | pw.println("td.info_odd { background:#b0b0e0; }"); |
| 856 | 0 | | pw.println("td.info_even { background:#d0d0ff; }"); |
| 857 | 0 | | pw.println("td.codestyle_odd { background:#e0e070; }"); |
| 858 | 0 | | pw.println("td.codestyle_even { background:#fff080; }"); |
| 859 | 0 | | pw.println("td.coverage_odd { background:#e0e0c0; }"); |
| 860 | 0 | | pw.println("td.coverage_even { background:#ffffe0; }"); |
| 861 | 0 | | pw.println("td.design_odd { background:#e0d020; }"); |
| 862 | 0 | | pw.println("td.design_even { background:#fff040; }"); |
| 863 | 0 | | pw.println("td.warning_odd { background:#e08020; }"); |
| 864 | 0 | | pw.println("td.warning_even { background:#ffa040; }"); |
| 865 | 0 | | pw.println("td.cpd_odd { background: #c0e0c0; }"); |
| 866 | 0 | | pw.println("td.cpd_even { background:#d0f0d0; }"); |
| 867 | 0 | | pw.println("td.error_odd { background:#e08080; }"); |
| 868 | 0 | | pw.println("td.error_even { background:#ff4040; }"); |
| 869 | | | |
| 870 | 0 | | pw.println("-->"); |
| 871 | 0 | | pw.println("</style>"); |
| 872 | 0 | | pw.println("<body>"); |
| 873 | | | |
| 874 | 0 | | pw.println("<table>"); |
| 875 | | | |
| 876 | 0 | | pw.println("<tr>"); |
| 877 | 0 | | pw.println("<td colspan=\"4\">"); |
| 878 | 0 | (59) | pw.println("<a href=\"findings.png\"><img src=\"findings_small.png\"></a>"); |
| 879 | 0 | | pw.println("</td><td colspan=\"4\">"); |
| 880 | 0 | (60) | pw.println("<a href=\"quality.png\"><img src=\"quality_small.png\"></a>"); |
| 881 | 0 | | pw.println("</td><td colspan=\"3\">"); |
| 882 | 0 | | pw.println("<a href=\"loc.png\"><img src=\"loc_small.png\"></a>"); |
| 883 | 0 | | pw.println("</td>"); |
| 884 | 0 | | pw.println("</tr>"); |
| 885 | | | |
| 886 | | | |
| 887 | 0 | | final Map yearMap = summaryDbMap; |
| 888 | 0 | | final List sortedYearList = new ArrayList(); |
| 889 | 0 | (61) | sortedYearList.addAll(yearMap.keySet()); |
| 890 | 0 | (62)(63) | Collections.sort(sortedYearList); |
| 891 | 0 | | Collections.reverse(sortedYearList); |
| 892 | 0 | | final Iterator yearIter = sortedYearList.iterator(); |
| 893 | 0 | | while (yearIter.hasNext()) |
| 894 | | | { |
| 895 | 0 | | final Integer year = (Integer) yearIter.next(); |
| 896 | 0 | | log("Rendering detail tables for year " + year); |
| 897 | | | |
| 898 | 0 | | final Map monthMap = (Map) summaryDbMap.get(year); |
| 899 | 0 | | final List sortedMonthList = new ArrayList(); |
| 900 | 0 | (64) | sortedMonthList.addAll(monthMap.keySet()); |
| 901 | 0 | (65)(66) | Collections.sort(sortedMonthList); |
| 902 | 0 | | Collections.reverse(sortedMonthList); |
| 903 | 0 | | final Iterator monthIter = sortedMonthList.iterator(); |
| 904 | 0 | | while (monthIter.hasNext()) |
| 905 | | | { |
| 906 | 0 | | final Integer month = (Integer) monthIter.next(); |
| 907 | 0 | | log("Rendering detail table for month " + month); |
| 908 | | | |
| 909 | 0 | | pw.println("<tr><td class=\"month bold\" colspan=\"11\">" |
| 910 | | | + MONTHS[month.intValue() - 1] |
| 911 | | | + " " + year + "</td></tr>"); |
| 912 | 0 | | pw.println("<tr>"); |
| 913 | 0 | | pw.println(" <td class=\"day_even bold\">Date</td>"); |
| 914 | 0 | | pw.println(" <td class=\"quality_even bold\">Quality</td>"); |
| 915 | 0 | | pw.println(" <td class=\"loc_even bold\">Loc</td>"); |
| 916 | 0 | | pw.println(" <td class=\"error_even bold\">Error</td>"); |
| 917 | 0 | | pw.println(" <td class=\"cpd_even bold\">Cpd</td>"); |
| 918 | 0 | | pw.println(" <td class=\"warning_even bold\">Warning</td>"); |
| 919 | 0 | | pw.println(" <td class=\"design_even bold\">Design</td>"); |
| 920 | 0 | | pw.println(" <td class=\"coverage_even bold\">Coverage</td>"); |
| 921 | 0 | | pw.println(" <td class=\"codestyle_even bold\">Codestyle</td>"); |
| 922 | 0 | | pw.println(" <td class=\"info_even bold\">Info</td>"); |
| 923 | 0 | | pw.println(" <td class=\"filtered_even bold\">Filtered</td>"); |
| 924 | 0 | | pw.println("</tr>"); |
| 925 | | | |
| 926 | 0 | | int i = 0; |
| 927 | 0 | | final Map dayMap = (Map) monthMap.get(month); |
| 928 | 0 | | final List sortedDayList = new ArrayList(); |
| 929 | 0 | (67) | sortedDayList.addAll(dayMap.keySet()); |
| 930 | 0 | (68)(69) | Collections.sort(sortedDayList); |
| 931 | 0 | | Collections.reverse(sortedDayList); |
| 932 | 0 | | final Iterator dayIter = sortedDayList.iterator(); |
| 933 | 0 | | while (dayIter.hasNext()) |
| 934 | | | { |
| 935 | 0 | | final Integer day = (Integer) dayIter.next(); |
| 936 | 0 | | final List reportsList = (List) dayMap.get(day); |
| 937 | | | |
| 938 | 0 | | final Iterator reportsIter = reportsList.iterator(); |
| 939 | 0 | | while (reportsIter.hasNext()) |
| 940 | | | { |
| 941 | 0 | | pw.println("<tr>"); |
| 942 | | | |
| 943 | 0 | | final Summary sum = (Summary) reportsIter.next(); |
| 944 | 0 | | String suffix = "odd"; |
| 945 | 0 | | if ((i & 1) == 0) |
| 946 | | | { |
| 947 | 0 | | suffix = "even"; |
| 948 | | | } |
| 949 | | | |
| 950 | 0 | | pw.println(wrapTimestamp(sum, suffix)); |
| 951 | | | |
| 952 | 0 | | pw.println(wrapValue(sum.getQuality(), "quality", suffix)); |
| 953 | 0 | | pw.println(wrapValue(sum.getLoc(), "loc", suffix)); |
| 954 | | | |
| 955 | 0 | (70) | pw.println(wrapValue(sum, sum.getError(), "error", suffix)); |
| 956 | 0 | | pw.println(wrapValue(sum, sum.getCpd(), "cpd", suffix)); |
| 957 | 0 | (71) | pw.println(wrapValue(sum, sum.getWarning(), "warning", suffix)); |
| 958 | 0 | (72) | pw.println(wrapValue(sum, sum.getDesign(), "design", suffix)); |
| 959 | 0 | (73) | pw.println(wrapValue(sum, sum.getCoverage(), "coverage", suffix)); |
| 960 | 0 | (74) | pw.println(wrapValue(sum, sum.getCodestyle(), "codestyle", suffix)); |
| 961 | 0 | | pw.println(wrapValue(sum, sum.getInfo(), "info", suffix)); |
| 962 | 0 | (75) | pw.println(wrapValue(sum, sum.getFiltered(), "filtered", suffix)); |
| 963 | | | |
| 964 | 0 | | pw.println("</tr>"); |
| 965 | | | |
| 966 | 0 | | i++; |
| 967 | 0 | | } |
| 968 | 0 | | } |
| 969 | 0 | | } |
| 970 | 0 | | } |
| 971 | | | |
| 972 | 0 | | pw.println("</table>"); |
| 973 | 0 | | pw.println("</body>"); |
| 974 | 0 | | pw.println("</html>"); |
| 975 | 0 | | pw.close(); |
| 976 | 0 | | fos.flush(); |
| 977 | 0 | | fos.close(); |
| 978 | | | } |
| 979 | 0 | | catch (IOException ex) |
| 980 | | | { |
| 981 | 0 | (76) | throw new BuildException("An IO exception occured!", ex); |
| 982 | 0 | | } |
| 983 | 0 | | } |
| 984 | | | |
| 985 | | | |
| 986 | | | private String wrapTimestamp (Summary sum, String oddeven) |
| 987 | | | { |
| 988 | 0 | | final StringBuilder sb = new StringBuilder(); |
| 989 | 0 | | sb.append("<td class=\"day_"); |
| 990 | 0 | | sb.append(oddeven); |
| 991 | 0 | | sb.append("\">"); |
| 992 | 0 | | if (sum.getSummaryXml() != null) |
| 993 | | | { |
| 994 | 0 | | sb.append("<a href=\""); |
| 995 | 0 | | sb.append(sum.getTimestamp()); |
| 996 | 0 | | sb.append("/index.html\">"); |
| 997 | | | } |
| 998 | 0 | | sb.append(extractDay(sum.getTimestamp())); |
| 999 | 0 | | sb.append("."); |
| 1000 | 0 | | sb.append(extractMonth(sum.getTimestamp())); |
| 1001 | 0 | | sb.append("."); |
| 1002 | 0 | | sb.append(extractYear(sum.getTimestamp())); |
| 1003 | 0 | | if (sum.getSummaryXml() != null) |
| 1004 | | | { |
| 1005 | 0 | | sb.append("</a>"); |
| 1006 | | | } |
| 1007 | 0 | | return sb.toString(); |
| 1008 | | | } |
| 1009 | | | |
| 1010 | | | |
| 1011 | | | private String wrapValue (Summary sum, int value, String severity, |
| 1012 | | | String oddeven) |
| 1013 | | | { |
| 1014 | 0 | | final StringBuilder sb = new StringBuilder(); |
| 1015 | 0 | | sb.append("<td class=\""); |
| 1016 | 0 | | sb.append(severity); |
| 1017 | 0 | | sb.append("_"); |
| 1018 | 0 | | sb.append(oddeven); |
| 1019 | 0 | | sb.append("\">"); |
| 1020 | 0 | | if (sum.getSummaryXml() != null) |
| 1021 | | | { |
| 1022 | 0 | (77) | sb.append("<a href=\"" + sum.getTimestamp() |
| 1023 | | | + "/findings.html"); |
| 1024 | 0 | | sb.append("#"); |
| 1025 | 0 | | sb.append(severity); |
| 1026 | 0 | | sb.append("\">"); |
| 1027 | | | } |
| 1028 | 0 | | sb.append(value); |
| 1029 | 0 | | if (sum.getSummaryXml() != null) |
| 1030 | | | { |
| 1031 | 0 | | sb.append("</a>"); |
| 1032 | | | } |
| 1033 | 0 | | sb.append("</td>"); |
| 1034 | 0 | | return sb.toString(); |
| 1035 | | | } |
| 1036 | | | |
| 1037 | | | |
| 1038 | | | private String wrapValue (int value, String severity, String oddeven) |
| 1039 | | | { |
| 1040 | 0 | | final StringBuilder sb = new StringBuilder(); |
| 1041 | 0 | | sb.append("<td class=\""); |
| 1042 | 0 | | sb.append(severity); |
| 1043 | 0 | | sb.append("_"); |
| 1044 | 0 | | sb.append(oddeven); |
| 1045 | 0 | | sb.append("\">"); |
| 1046 | 0 | | sb.append(value); |
| 1047 | 0 | | sb.append("</td>"); |
| 1048 | 0 | | return sb.toString(); |
| 1049 | | | } |
| 1050 | | | |
| 1051 | | | |
| 1052 | | | private String wrapValue (double value, String severity, String oddeven) |
| 1053 | | | { |
| 1054 | 0 | | final StringBuilder sb = new StringBuilder(); |
| 1055 | 0 | | sb.append("<td class=\""); |
| 1056 | 0 | | sb.append(severity); |
| 1057 | 0 | | sb.append("_"); |
| 1058 | 0 | | sb.append(oddeven); |
| 1059 | 0 | | sb.append("\">"); |
| 1060 | 0 | | sb.append(value); |
| 1061 | 0 | | sb.append("%"); |
| 1062 | 0 | | sb.append("</td>"); |
| 1063 | 0 | | return sb.toString(); |
| 1064 | | | } |
| 1065 | | | |
| 1066 | | | |
| 1067 | | | private String extractDay (long timestamp) |
| 1068 | | | { |
| 1069 | 0 | | final String ts = String.valueOf(timestamp); |
| 1070 | 0 | | return ts.substring(YEAR_LEN + MONTH_LEN, YEAR_LEN + MONTH_LEN + DAY_LEN); |
| 1071 | | | } |
| 1072 | | | |
| 1073 | | | |
| 1074 | | | private String extractMonth (long timestamp) |
| 1075 | | | { |
| 1076 | 0 | | final String ts = String.valueOf(timestamp); |
| 1077 | 0 | | return ts.substring(YEAR_LEN, YEAR_LEN + MONTH_LEN); |
| 1078 | | | } |
| 1079 | | | |
| 1080 | | | |
| 1081 | | | private String extractYear (long timestamp) |
| 1082 | | | { |
| 1083 | 0 | | final String ts = String.valueOf(timestamp); |
| 1084 | 0 | | return ts.substring(0, YEAR_LEN); |
| 1085 | | | } |
| 1086 | | | |
| 1087 | | | |
| 1088 | | | |
| 1089 | | | |
| 1090 | | | |
| 1091 | | | @author |
| 1092 | | | |
| 1093 | | | private static final class Summary |
| 1094 | | | { |
| 1095 | | | private final long mTimestamp; |
| 1096 | | | private final int mError; |
| 1097 | | | private final int mFiltered; |
| 1098 | | | private final int mDesign; |
| 1099 | | | private final int mCodestyle; |
| 1100 | | | private final int mCpd; |
| 1101 | | | private final int mWarning; |
| 1102 | | | private final int mInfo; |
| 1103 | | | private final int mCoverage; |
| 1104 | | | private final int mLoc; |
| 1105 | | | |
| 1106 | | | private final int mCodeLoc; |
| 1107 | | | private final double mQuality; |
| 1108 | | | private final File mSummaryXml; |
| 1109 | | | |
| 1110 | | | public Summary (long timestamp, int error, |
| 1111 | | | int warning, int info, int coverage, int loc, int codeloc, |
| 1112 | | | int filtered, int codestyle, int design, int cpd, double quality) |
| 1113 | 0 | | { |
| 1114 | 0 | | mFiltered = filtered; |
| 1115 | 0 | | mCodestyle = codestyle; |
| 1116 | 0 | | mDesign = design; |
| 1117 | 0 | | mCpd = cpd; |
| 1118 | 0 | | mTimestamp = timestamp; |
| 1119 | 0 | | mError = error; |
| 1120 | 0 | | mWarning = warning; |
| 1121 | 0 | | mInfo = info; |
| 1122 | 0 | | mCoverage = coverage; |
| 1123 | 0 | | mLoc = loc; |
| 1124 | 0 | | mCodeLoc = codeloc; |
| 1125 | 0 | | mQuality = quality; |
| 1126 | 0 | | mSummaryXml = null; |
| 1127 | 0 | | } |
| 1128 | | | |
| 1129 | | | public Summary (long timestamp, int error, |
| 1130 | | | int warning, int info, int coverage, int loc, int codeloc, |
| 1131 | | | int filtered, int codestyle, int design, int cpd, |
| 1132 | | | double quality, File summaryXml) |
| 1133 | 0 | | { |
| 1134 | 0 | | mFiltered = filtered; |
| 1135 | 0 | | mCodestyle = codestyle; |
| 1136 | 0 | | mDesign = design; |
| 1137 | 0 | | mCpd = cpd; |
| 1138 | 0 | | mTimestamp = timestamp; |
| 1139 | 0 | | mError = error; |
| 1140 | 0 | | mWarning = warning; |
| 1141 | 0 | | mInfo = info; |
| 1142 | 0 | | mCoverage = coverage; |
| 1143 | 0 | | mLoc = loc; |
| 1144 | 0 | | mCodeLoc = codeloc; |
| 1145 | 0 | | mQuality = quality; |
| 1146 | 0 | | mSummaryXml = summaryXml; |
| 1147 | 0 | | } |
| 1148 | | | |
| 1149 | | | public long getTimestamp () |
| 1150 | | | { |
| 1151 | 0 | | return mTimestamp; |
| 1152 | | | } |
| 1153 | | | |
| 1154 | | | public int getError () |
| 1155 | | | { |
| 1156 | 0 | | return mError; |
| 1157 | | | } |
| 1158 | | | |
| 1159 | | | public int getWarning () |
| 1160 | | | { |
| 1161 | 0 | | return mWarning; |
| 1162 | | | } |
| 1163 | | | |
| 1164 | | | public int getInfo () |
| 1165 | | | { |
| 1166 | 0 | | return mInfo; |
| 1167 | | | } |
| 1168 | | | |
| 1169 | | | public int getCoverage () |
| 1170 | | | { |
| 1171 | 0 | | return mCoverage; |
| 1172 | | | } |
| 1173 | | | |
| 1174 | | | public int getFiltered () |
| 1175 | | | { |
| 1176 | 0 | | return mFiltered; |
| 1177 | | | } |
| 1178 | | | |
| 1179 | | | public int getCodestyle () |
| 1180 | | | { |
| 1181 | 0 | | return mCodestyle; |
| 1182 | | | } |
| 1183 | | | |
| 1184 | | | public int getDesign () |
| 1185 | | | { |
| 1186 | 0 | | return mDesign; |
| 1187 | | | } |
| 1188 | | | |
| 1189 | | | public int getCpd () |
| 1190 | | | { |
| 1191 | 0 | | return mCpd; |
| 1192 | | | } |
| 1193 | | | |
| 1194 | | | public int getLoc () |
| 1195 | | | { |
| 1196 | 0 | | return mLoc; |
| 1197 | | | } |
| 1198 | | | |
| 1199 | | | public int getCodeLoc () |
| 1200 | | | { |
| 1201 | 0 | | return mCodeLoc; |
| 1202 | | | } |
| 1203 | | | |
| 1204 | | | public double getQuality () |
| 1205 | | | { |
| 1206 | 0 | | return mQuality; |
| 1207 | | | } |
| 1208 | | | |
| 1209 | | | public File getSummaryXml () |
| 1210 | | | { |
| 1211 | 0 | | return mSummaryXml; |
| 1212 | | | } |
| 1213 | | | |
| 1214 | | | public int hashCode () |
| 1215 | | | { |
| 1216 | | | |
| 1217 | | | |
| 1218 | | | |
| 1219 | 0 | | final long div = 10000000000L; |
| 1220 | 0 | | final int mul = 1000000; |
| 1221 | | | |
| 1222 | 0 | | final long rest = mTimestamp % div; |
| 1223 | | | |
| 1224 | 0 | | final long year = mTimestamp / div; |
| 1225 | | | |
| 1226 | 0 | | return (int) (year * mul + rest); |
| 1227 | | | } |
| 1228 | | | |
| 1229 | | | public boolean equals (Object sum) |
| 1230 | | | { |
| 1231 | 0 | (78) | boolean result = false; |
| 1232 | 0 | | if (sum != null) |
| 1233 | | | { |
| 1234 | 0 | | if (sum == this) |
| 1235 | | | { |
| 1236 | 0 | | result = true; |
| 1237 | | | } |
| 1238 | | | else |
| 1239 | | | { |
| 1240 | 0 | | result = hashCode() == sum.hashCode(); |
| 1241 | | | } |
| 1242 | | | } |
| 1243 | 0 | | return result; |
| 1244 | | | } |
| 1245 | | | |
| 1246 | | | public String toString () |
| 1247 | | | { |
| 1248 | 0 | | return "[" + mTimestamp + ", " + mError + ", " |
| 1249 | | | + mWarning + ", " + mInfo + ", " + mCoverage + ", " + mLoc |
| 1250 | | | + ", " + mCodeLoc + ", " + mFiltered + ", " + mCodestyle + ", " |
| 1251 | | | + mDesign + ", " + mCpd + ", " + mQuality + ", " |
| 1252 | | | + mSummaryXml + "]"; |
| 1253 | | | } |
| 1254 | | | } |
| 1255 | | | |
| 1256 | | | |
| 1257 | | | |
| 1258 | | | |
| 1259 | | | |
| 1260 | | | @author |
| 1261 | | | |
| 1262 | 0 | | public static class JcoderReportFilter |
| 1263 | | | implements FilenameFilter |
| 1264 | | | { |
| 1265 | | | |
| 1266 | | | |
| 1267 | | | |
| 1268 | | | @param |
| 1269 | | | @param |
| 1270 | | | |
| 1271 | | | public boolean accept (File dir, String name) |
| 1272 | | | { |
| 1273 | 0 | | boolean result = false; |
| 1274 | | | try |
| 1275 | | | { |
| 1276 | 0 | | Long.parseLong(name); |
| 1277 | 0 | | final File folder = new File(dir, name); |
| 1278 | 0 | | if (folder.exists() && folder.isDirectory()) |
| 1279 | | | { |
| 1280 | 0 | | final File summaryXml = findSummaryXml(folder); |
| 1281 | 0 | | result = summaryXml != null |
| 1282 | | | && summaryXml.exists() && summaryXml.isFile(); |
| 1283 | | | } |
| 1284 | | | } |
| 1285 | 0 | | catch (NumberFormatException ex) |
| 1286 | | | { |
| 1287 | | | |
| 1288 | 0 | | } |
| 1289 | 0 | | return result; |
| 1290 | | | } |
| 1291 | | | } |
| 1292 | | | } |