| 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.FileWriter; |
| 38 | | | import java.io.IOException; |
| 39 | | | import java.util.HashMap; |
| 40 | | | import java.util.Iterator; |
| 41 | | | import java.util.List; |
| 42 | | | import java.util.Map; |
| 43 | | | import java.util.Set; |
| 44 | | | import java.util.TreeSet; |
| 45 | | | import java.util.Map.Entry; |
| 46 | | | |
| 47 | | | import net.sourceforge.chart2d.Chart2DProperties; |
| 48 | | | import net.sourceforge.chart2d.Dataset; |
| 49 | | | import net.sourceforge.chart2d.GraphChart2DProperties; |
| 50 | | | import net.sourceforge.chart2d.GraphProperties; |
| 51 | | | import net.sourceforge.chart2d.LBChart2D; |
| 52 | | | import net.sourceforge.chart2d.LegendProperties; |
| 53 | | | import net.sourceforge.chart2d.MultiColorsProperties; |
| 54 | | | import net.sourceforge.chart2d.Object2DProperties; |
| 55 | | | |
| 56 | | | import org.jcoderz.commons.util.IoUtil; |
| 57 | | | import org.jcoderz.commons.util.ObjectUtil; |
| 58 | | | import org.jcoderz.phoenix.report.jaxb.File; |
| 59 | | | import org.jcoderz.phoenix.report.jaxb.Report; |
| 60 | | | |
| 61 | | | |
| 62 | | (1) | |
| 63 | | | |
| 64 | | | @author |
| 65 | | | |
| 66 | | | public final class StatisticCollector |
| 67 | | | { |
| 68 | | | private static final int MAX_SERVICE_PACKAGES = 15; |
| 69 | | | private static final int ROW_ERROR = 0; |
| 70 | | | private static final int ROW_CPD = 1; |
| 71 | | | private static final int ROW_WARNING = 2; |
| 72 | | | private static final int ROW_DESIGN = 3; |
| 73 | | | private static final int ROW_CODE_STYLE = 4; |
| 74 | | | private static final int ROW_INFO = 5; |
| 75 | | | private static final int ROW_COVERAGE = 6; |
| 76 | | | private static final int PERCENT = 100; |
| 77 | | | private static final int LARGE_IMAGE_WIDTH = 1000; |
| 78 | | | private static final int LARGE_IMAGE_HEIGHT = 600; |
| 79 | | | private static final int SMALL_IMAGE_WIDTH = 800; |
| 80 | | | private static final int SMALL_IMAGE_HEIGHT = 300; |
| 81 | 0 | | private static final Dimension LARGE_SIZE |
| 82 | | | = new Dimension(LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT); |
| 83 | 0 | | private static final Dimension SMALL_SIZE |
| 84 | | | = new Dimension(SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
| 85 | | | |
| 86 | | | |
| 87 | | | private final Report mReport; |
| 88 | | | |
| 89 | | | |
| 90 | | | private final String mPrefix; |
| 91 | | | |
| 92 | | | |
| 93 | | | private final java.io.File mOutDir; |
| 94 | | | |
| 95 | | | |
| 96 | | | private final String mTimestamp; |
| 97 | | | |
| 98 | | | |
| 99 | | | |
| 100 | | | |
| 101 | | | |
| 102 | | | @param |
| 103 | | | @param |
| 104 | | | @param |
| 105 | | | |
| 106 | | | public StatisticCollector (Report report, java.io.File outDir, |
| 107 | | | String timestamp) |
| 108 | 0 | | { |
| 109 | 0 | | mReport = report; |
| 110 | | (2) | |
| 111 | 0 | | mPrefix = "org.jcoderz."; |
| 112 | 0 | | mOutDir = outDir; |
| 113 | 0 | | mTimestamp = timestamp; |
| 114 | 0 | | } |
| 115 | | | |
| 116 | | | |
| 117 | | | |
| 118 | | | |
| 119 | | | @param |
| 120 | | | @param |
| 121 | | | @param |
| 122 | | | @param |
| 123 | | | |
| 124 | | | public StatisticCollector (Report report, String prefix, java.io.File outDir, |
| 125 | | | String timestamp) |
| 126 | 0 | | { |
| 127 | 0 | | mReport = report; |
| 128 | 0 | | mPrefix = prefix; |
| 129 | 0 | | mOutDir = outDir; |
| 130 | 0 | | mTimestamp = timestamp; |
| 131 | 0 | | } |
| 132 | | | |
| 133 | | | |
| 134 | | | |
| 135 | | | @throws |
| 136 | | | |
| 137 | | | public void createCharts () |
| 138 | | | throws IOException |
| 139 | | | { |
| 140 | | | |
| 141 | | | |
| 142 | | | |
| 143 | | | |
| 144 | 0 | | final Map<String, FileSummary> productionPackages |
| 145 | | | = new HashMap<String, FileSummary>(); |
| 146 | 0 | | final Map<String, FileSummary> testPackages |
| 147 | | | = new HashMap<String, FileSummary>(); |
| 148 | 0 | | final Map<String, FileSummary> allPackages |
| 149 | | | = new HashMap<String, FileSummary>(); |
| 150 | | | |
| 151 | 0 | | summarize(productionPackages, testPackages, allPackages); |
| 152 | | | |
| 153 | 0 | | writeSummary(allPackages); |
| 154 | | | |
| 155 | 0 | | allPackages.clear(); |
| 156 | | | |
| 157 | | | final Map<String, FileSummary> production; |
| 158 | | | final Map<String, FileSummary> test; |
| 159 | | | final String level; |
| 160 | | | |
| 161 | 0 | | if (productionPackages.size() > MAX_SERVICE_PACKAGES) |
| 162 | | | { |
| 163 | 0 | | production = generateServiceLevelMap(productionPackages); |
| 164 | 0 | | test = generateServiceLevelMap(testPackages); |
| 165 | 0 | | level = "Service"; |
| 166 | | | } |
| 167 | | | else |
| 168 | | | { |
| 169 | 0 | | production = productionPackages; |
| 170 | 0 | | test = testPackages; |
| 171 | 0 | | level = "Package"; |
| 172 | | | } |
| 173 | | | |
| 174 | 0 | | createLocChart(production, test, level); |
| 175 | | | |
| 176 | 0 | | createQualityChart(production, level); |
| 177 | 0 | | } |
| 178 | | | |
| 179 | | | |
| 180 | | | |
| 181 | | | @param |
| 182 | | | |
| 183 | | | @throws |
| 184 | | | |
| 185 | | | private void writeSummary (Map<String, FileSummary> packages) |
| 186 | | | throws IOException |
| 187 | | | { |
| 188 | 0 | (3) | final StringBuffer sb = new StringBuffer(); |
| 189 | | | |
| 190 | | | |
| 191 | 0 | | final FileSummary all = new FileSummary(); |
| 192 | 0 | | final Iterator<FileSummary> i = packages.values().iterator(); |
| 193 | | | |
| 194 | 0 | | while (i.hasNext()) |
| 195 | | | { |
| 196 | 0 | | all.add(i.next()); |
| 197 | | | } |
| 198 | | | |
| 199 | 0 | | sb.append("<findingsummary "); |
| 200 | 0 | | fillSummaryLine(sb, all); |
| 201 | 0 | | sb.append(">\n"); |
| 202 | | | |
| 203 | 0 | | sb.append(" <packagelevelxml>\n"); |
| 204 | 0 | | for (Entry<String, FileSummary> entry : packages.entrySet()) |
| 205 | | | { |
| 206 | 0 | | final String pkg = entry.getKey(); |
| 207 | 0 | | final FileSummary summary = entry.getValue(); |
| 208 | 0 | | sb.append(" <package name='"); |
| 209 | 0 | | sb.append(pkg); |
| 210 | 0 | | sb.append("' "); |
| 211 | 0 | | fillSummaryLine(sb, summary); |
| 212 | 0 | | sb.append("/>\n"); |
| 213 | 0 | | } |
| 214 | 0 | | sb.append(" </packagelevelxml>\n"); |
| 215 | | | |
| 216 | | | |
| 217 | 0 | | final Map<String, FileSummary> serviceLevelMap |
| 218 | | | = generateServiceLevelMap(packages); |
| 219 | | | |
| 220 | | | |
| 221 | 0 | | sb.append(" <servicelevelxml>\n"); |
| 222 | 0 | | for (Entry<String, FileSummary> service : serviceLevelMap.entrySet()) |
| 223 | | | { |
| 224 | 0 | | final String pkg = service.getKey(); |
| 225 | 0 | | final FileSummary summary = service.getValue(); |
| 226 | 0 | | sb.append(" <service name='"); |
| 227 | 0 | | sb.append(pkg); |
| 228 | 0 | | sb.append("' "); |
| 229 | 0 | | fillSummaryLine(sb, summary); |
| 230 | 0 | | sb.append("/>\n"); |
| 231 | 0 | | } |
| 232 | 0 | | sb.append(" </servicelevelxml>\n"); |
| 233 | | | |
| 234 | 0 | | sb.append("</findingsummary>\n"); |
| 235 | | | |
| 236 | 0 | | FileWriter w = null; |
| 237 | | | try |
| 238 | | | { |
| 239 | 0 | | final java.io.File out = new java.io.File(mOutDir, "summary.xml"); |
| 240 | 0 | | w = new FileWriter(out); |
| 241 | 0 | | w.write(sb.toString()); |
| 242 | | | } |
| 243 | | | finally |
| 244 | | | { |
| 245 | 0 | | IoUtil.close(w); |
| 246 | 0 | | } |
| 247 | 0 | | } |
| 248 | | | |
| 249 | | | private Map<String, FileSummary> generateServiceLevelMap ( |
| 250 | | | Map<String, FileSummary> packages) |
| 251 | | | { |
| 252 | 0 | | final Map<String, FileSummary> serviceLevelMap |
| 253 | | | = new HashMap<String, FileSummary>(); |
| 254 | | | |
| 255 | 0 | | for (Entry<String, FileSummary> packagz : packages.entrySet()) |
| 256 | | | { |
| 257 | 0 | | final String pkg = packagz.getKey(); |
| 258 | 0 | | final FileSummary summary = packagz.getValue(); |
| 259 | 0 | | final String service = getService(pkg); |
| 260 | | | |
| 261 | 0 | | FileSummary serviceSummary = serviceLevelMap.get(service); |
| 262 | 0 | | if (serviceSummary == null) |
| 263 | | | { |
| 264 | 0 | | serviceSummary = new FileSummary(service); |
| 265 | 0 | | serviceLevelMap.put(service, serviceSummary); |
| 266 | | | } |
| 267 | 0 | | serviceSummary.add(summary); |
| 268 | 0 | | } |
| 269 | 0 | | return serviceLevelMap; |
| 270 | | | } |
| 271 | | | |
| 272 | | | private void fillSummaryLine (final StringBuffer sb, FileSummary summary) |
| 273 | | | { |
| 274 | 0 | | sb.append("timestamp='"); |
| 275 | 0 | | sb.append(mTimestamp); |
| 276 | 0 | | sb.append("' "); |
| 277 | 0 | | for (int i = 0; i < Severity.VALUES.size(); i++) |
| 278 | | | { |
| 279 | 0 | | final Severity currentSeverity = Severity.fromInt(i); |
| 280 | 0 | | sb.append(currentSeverity.toString()); |
| 281 | 0 | | sb.append("='"); |
| 282 | 0 | | sb.append(summary.getViolations(currentSeverity)); |
| 283 | 0 | | sb.append("' "); |
| 284 | | | } |
| 285 | 0 | | sb.append(" loc='"); |
| 286 | 0 | | sb.append(summary.getLinesOfCode()); |
| 287 | 0 | | sb.append("' codeLoc='"); |
| 288 | 0 | | sb.append(summary.getCoverage() |
| 289 | | | + summary.getViolations(Severity.COVERAGE)); |
| 290 | 0 | | sb.append("' quality='"); |
| 291 | 0 | | sb.append(summary.getQualityAsFloat()); |
| 292 | 0 | | sb.append('\''); |
| 293 | 0 | | } |
| 294 | | | |
| 295 | | | private String getService (String pkg) |
| 296 | | | { |
| 297 | | | String result; |
| 298 | 0 | | if (pkg != null && pkg.startsWith(mPrefix)) |
| 299 | | | { |
| 300 | 0 | | result = pkg.substring(mPrefix.length()); |
| 301 | 0 | | if (result.indexOf('.') != -1) |
| 302 | | | { |
| 303 | 0 | | result = result.substring(result.indexOf('.') + 1); |
| 304 | | | } |
| 305 | 0 | | if (result.indexOf('.') != -1) |
| 306 | | | { |
| 307 | 0 | | result = result.substring(0, result.indexOf('.')); |
| 308 | | | } |
| 309 | | | } |
| 310 | | | else |
| 311 | | | { |
| 312 | 0 | | result = ObjectUtil.toStringOrEmpty(pkg); |
| 313 | | | } |
| 314 | 0 | | return result; |
| 315 | | | } |
| 316 | | | |
| 317 | | | |
| 318 | | | |
| 319 | | | @param |
| 320 | | | @param |
| 321 | | | @param |
| 322 | | | |
| 323 | | | private void summarize (final Map<String, FileSummary> productionPackages, |
| 324 | | | final Map<String, FileSummary> testPackages, |
| 325 | | | final Map<String, FileSummary> all) |
| 326 | | | { |
| 327 | 0 | (4) | final List<File> allFiles = mReport.getFile(); |
| 328 | 0 | | for (final File currentFile : allFiles) |
| 329 | | | { |
| 330 | | | |
| 331 | 0 | | if (currentFile.getLevel().equals(ReportLevel.TEST)) |
| 332 | | | { |
| 333 | 0 | | addToMap(testPackages, currentFile); |
| 334 | 0 | | addToMap(all, currentFile); |
| 335 | | | } |
| 336 | | | else |
| 337 | | | { |
| 338 | 0 | | addToMap(productionPackages, currentFile); |
| 339 | 0 | | addToMap(all, currentFile); |
| 340 | | | } |
| 341 | | | } |
| 342 | 0 | | } |
| 343 | | | |
| 344 | | | private FileSummary addToMap (final Map<String, FileSummary> map, |
| 345 | | | final File file) |
| 346 | | | { |
| 347 | 0 | | final String pkg = file.getPackage(); |
| 348 | 0 | | FileSummary counter = map.get(pkg); |
| 349 | 0 | | if (counter == null) |
| 350 | | | { |
| 351 | 0 | | counter = new FileSummary(pkg); |
| 352 | 0 | | map.put(pkg, counter); |
| 353 | | | } |
| 354 | 0 | | calculateSummary(file, counter); |
| 355 | 0 | | return counter; |
| 356 | | | } |
| 357 | | | |
| 358 | | | |
| 359 | | | |
| 360 | | | @param |
| 361 | | | @param |
| 362 | | | |
| 363 | | | private void calculateSummary (File currentFile, FileSummary counter) |
| 364 | | | { |
| 365 | 0 | | counter.add(currentFile); |
| 366 | 0 | | } |
| 367 | | | |
| 368 | | | |
| 369 | | | |
| 370 | | | |
| 371 | | | |
| 372 | | | |
| 373 | | | @throws |
| 374 | | | |
| 375 | | | private void createLocChart (Map<String, FileSummary> src, |
| 376 | | | Map<String, FileSummary> test, String level) |
| 377 | | | throws IOException |
| 378 | | | { |
| 379 | | | |
| 380 | | | |
| 381 | | | |
| 382 | 0 | | final Object2DProperties object2DProps = new Object2DProperties(); |
| 383 | 0 | | object2DProps.setObjectTitleText ("LOC by " + level); |
| 384 | | | |
| 385 | | | |
| 386 | 0 | | final Chart2DProperties chart2DProps = new Chart2DProperties(); |
| 387 | 0 | | chart2DProps.setChartDataLabelsPrecision (1); |
| 388 | | | |
| 389 | | | |
| 390 | 0 | | final LegendProperties legendProps = new LegendProperties(); |
| 391 | 0 | (5) | final String[] legendLabels = {"Production", "Test"}; |
| 392 | 0 | | legendProps.setLegendLabelsTexts (legendLabels); |
| 393 | | | |
| 394 | | | |
| 395 | 0 | | final GraphChart2DProperties graphChart2DProps |
| 396 | | | = new GraphChart2DProperties(); |
| 397 | | | |
| 398 | 0 | | final Set<String> labels = new TreeSet<String>(src.keySet()); |
| 399 | 0 | | labels.addAll(test.keySet()); |
| 400 | | | |
| 401 | 0 | | if (labels.size() == 0) |
| 402 | | | { |
| 403 | 0 | (6) | throw new RuntimeException("No packages found for chart!"); |
| 404 | | | } |
| 405 | | | |
| 406 | 0 | (7) | final String [] labelsLongAxisLabels |
| 407 | | | = labels.toArray(new String[]{}); |
| 408 | 0 | | final String [] labelsAxisLabels |
| 409 | | | = cutPackages(labelsLongAxisLabels); |
| 410 | | | |
| 411 | 0 | | graphChart2DProps.setLabelsAxisLabelsTexts(labelsAxisLabels); |
| 412 | 0 | | graphChart2DProps.setLabelsAxisTitleText(level + " Name"); |
| 413 | 0 | | graphChart2DProps.setNumbersAxisTitleText("LOC"); |
| 414 | 0 | | graphChart2DProps.setLabelsAxisTicksAlignment( |
| 415 | | | GraphChart2DProperties.CENTERED); |
| 416 | | | |
| 417 | | | |
| 418 | 0 | | final GraphProperties graphProps = new GraphProperties(); |
| 419 | 0 | | graphProps.setGraphBarsExistence(false); |
| 420 | 0 | | graphProps.setGraphDotsExistence(true); |
| 421 | 0 | | graphProps.setGraphAllowComponentAlignment(true); |
| 422 | 0 | | graphProps.setGraphDotsWithinCategoryOverlapRatio(1); |
| 423 | | | |
| 424 | | | |
| 425 | 0 | | final Dataset dataset = new Dataset (legendLabels.length, |
| 426 | | | labelsAxisLabels.length, 1); |
| 427 | | | |
| 428 | | | |
| 429 | 0 | | for (int j = 0; j < dataset.getNumCats(); ++j) |
| 430 | | | { |
| 431 | 0 | | dataset.set(0, j, 0, getCounter(src, labelsLongAxisLabels[j])); |
| 432 | 0 | | dataset.set(1, j, 0, getCounter(test, labelsLongAxisLabels[j])); |
| 433 | | | } |
| 434 | | | |
| 435 | | | |
| 436 | 0 | | final MultiColorsProperties multiColorsProps |
| 437 | | | = new MultiColorsProperties(); |
| 438 | | | |
| 439 | | | |
| 440 | 0 | | final LBChart2D chart2D = new LBChart2D(); |
| 441 | 0 | | chart2D.setObject2DProperties (object2DProps); |
| 442 | 0 | | chart2D.setChart2DProperties (chart2DProps); |
| 443 | 0 | | chart2D.setLegendProperties (legendProps); |
| 444 | 0 | | chart2D.setGraphChart2DProperties (graphChart2DProps); |
| 445 | 0 | | chart2D.addGraphProperties (graphProps); |
| 446 | 0 | | chart2D.addDataset (dataset); |
| 447 | 0 | | chart2D.addMultiColorsProperties (multiColorsProps); |
| 448 | | | |
| 449 | | | |
| 450 | | | |
| 451 | | | |
| 452 | 0 | | chart2D.setMaximumSize(LARGE_SIZE); |
| 453 | 0 | | chart2D.setPreferredSize(LARGE_SIZE); |
| 454 | | | |
| 455 | 0 | | if (chart2D.validate(false)) |
| 456 | | | { |
| 457 | 0 | | java.io.File file = new java.io.File(mOutDir, "loc_large.png"); |
| 458 | 0 | | javax.imageio.ImageIO.write(chart2D.getImage(), "PNG", file); |
| 459 | 0 | | chart2D.setMaximumSize(SMALL_SIZE); |
| 460 | 0 | | chart2D.setPreferredSize(SMALL_SIZE); |
| 461 | 0 | | chart2D.pack(); |
| 462 | 0 | | file = new java.io.File(mOutDir, "loc_small.png"); |
| 463 | 0 | | javax.imageio.ImageIO.write(chart2D.getImage(), "PNG", file); |
| 464 | 0 | | } |
| 465 | | | else |
| 466 | | | { |
| 467 | 0 | | chart2D.validate(true); |
| 468 | | | } |
| 469 | 0 | | } |
| 470 | | | |
| 471 | | | |
| 472 | | | |
| 473 | | | |
| 474 | | | |
| 475 | | | @throws |
| 476 | | | |
| 477 | | (8) | private void createQualityChart (Map<String, FileSummary> src, String level) |
| 478 | | | throws IOException |
| 479 | | | { |
| 480 | | | |
| 481 | | | |
| 482 | | | |
| 483 | 0 | | final Object2DProperties object2DProps = new Object2DProperties(); |
| 484 | 0 | | object2DProps.setObjectTitleText ("Quality by " + level); |
| 485 | | | |
| 486 | | | |
| 487 | 0 | | final Chart2DProperties chart2DProps = new Chart2DProperties(); |
| 488 | 0 | | chart2DProps.setChartDataLabelsPrecision(0); |
| 489 | | | |
| 490 | | | |
| 491 | 0 | | final LegendProperties legendProps = new LegendProperties(); |
| 492 | 0 | (9) | final String[] legendLabels = { |
| 493 | | | "Error", "C&P", "Warning", "Design", "Code Style", |
| 494 | | | "Info", "Coverage"}; |
| 495 | 0 | | legendProps.setLegendLabelsTexts (legendLabels); |
| 496 | | | |
| 497 | | | |
| 498 | 0 | | final GraphChart2DProperties graphChart2DProps |
| 499 | | | = new GraphChart2DProperties(); |
| 500 | | | |
| 501 | 0 | | final Set<String> labels = new TreeSet<String>(src.keySet()); |
| 502 | | | |
| 503 | 0 | | if (labels.size() == 0) |
| 504 | | | { |
| 505 | 0 | (10) | throw new RuntimeException("No packages found for chart!"); |
| 506 | | | } |
| 507 | | | |
| 508 | 0 | | final String [] labelsLongAxisLabels |
| 509 | | | = labels.toArray(new String[labels.size()]); |
| 510 | 0 | | final String [] labelsAxisLabels = cutPackages(labelsLongAxisLabels); |
| 511 | | | |
| 512 | 0 | | graphChart2DProps.setLabelsAxisLabelsTexts(labelsAxisLabels); |
| 513 | 0 | | graphChart2DProps.setLabelsAxisTitleText(level + " Name"); |
| 514 | 0 | | graphChart2DProps.setNumbersAxisTitleText("Finding/Loc %"); |
| 515 | 0 | | graphChart2DProps.setLabelsAxisTicksAlignment( |
| 516 | | | GraphChart2DProperties.CENTERED); |
| 517 | | | |
| 518 | | | |
| 519 | 0 | | final GraphProperties graphProps = new GraphProperties(); |
| 520 | 0 | | graphProps.setGraphBarsExistence(false); |
| 521 | 0 | | graphProps.setGraphDotsExistence(true); |
| 522 | 0 | | graphProps.setGraphAllowComponentAlignment(true); |
| 523 | 0 | | graphProps.setGraphDotsWithinCategoryOverlapRatio(1); |
| 524 | | | |
| 525 | | | |
| 526 | 0 | | final Dataset dataset = new Dataset (legendLabels.length, |
| 527 | | | labelsAxisLabels.length, 1); |
| 528 | | | |
| 529 | | | |
| 530 | 0 | | for (int j = 0; j < dataset.getNumCats(); ++j) |
| 531 | | | { |
| 532 | 0 | | final FileSummary sum = src.get(labelsLongAxisLabels[j]); |
| 533 | 0 | | if (sum != null && sum.getLinesOfCode() != 0) |
| 534 | | | { |
| 535 | 0 | | final float loc = sum.getLinesOfCode(); |
| 536 | 0 | | final float codeLoc = sum.getCoverage() |
| 537 | | | + sum.getViolations(Severity.COVERAGE); |
| 538 | | | |
| 539 | 0 | | dataset.set(ROW_ERROR, j, 0, |
| 540 | | | (PERCENT * sum.getViolations(Severity.ERROR)) / loc); |
| 541 | 0 | | dataset.set(ROW_CPD, j, 0, |
| 542 | | | (PERCENT * sum.getViolations(Severity.CPD)) / loc); |
| 543 | 0 | | dataset.set(ROW_WARNING, j, 0, |
| 544 | | | (PERCENT * sum.getViolations(Severity.WARNING)) / loc); |
| 545 | 0 | | dataset.set(ROW_DESIGN, j, 0, |
| 546 | | | (PERCENT * sum.getViolations(Severity.DESIGN)) / loc); |
| 547 | 0 | | dataset.set(ROW_CODE_STYLE, j, 0, |
| 548 | | | (PERCENT * sum.getViolations(Severity.CODE_STYLE)) / loc); |
| 549 | 0 | | dataset.set(ROW_INFO, j, 0, |
| 550 | | | (PERCENT * sum.getViolations(Severity.INFO)) / loc); |
| 551 | | | |
| 552 | 0 | | if (codeLoc != 0) |
| 553 | | | { |
| 554 | 0 | | dataset.set(ROW_COVERAGE, j, 0, |
| 555 | | | (PERCENT * sum.getCoverage()) / codeLoc); |
| 556 | | | } |
| 557 | | | else |
| 558 | | | { |
| 559 | 0 | | dataset.set(ROW_COVERAGE, j, 0, PERCENT); |
| 560 | | | } |
| 561 | 0 | | } |
| 562 | | | else |
| 563 | | | { |
| 564 | 0 | | dataset.set(ROW_ERROR, j, 0, 0); |
| 565 | 0 | | dataset.set(ROW_CPD, j, 0, 0); |
| 566 | 0 | | dataset.set(ROW_WARNING, j, 0, 0); |
| 567 | 0 | | dataset.set(ROW_DESIGN, j, 0, 0); |
| 568 | 0 | | dataset.set(ROW_CODE_STYLE, j, 0, 0); |
| 569 | 0 | | dataset.set(ROW_INFO, j, 0, 0); |
| 570 | 0 | | dataset.set(ROW_COVERAGE, j, 0, 0); |
| 571 | | | } |
| 572 | | | } |
| 573 | | | |
| 574 | | | |
| 575 | 0 | | final MultiColorsProperties multiColorsProps |
| 576 | | | = new MultiColorsProperties(); |
| 577 | | | |
| 578 | 0 | | multiColorsProps.setColorsCustomize(true); |
| 579 | | | |
| 580 | 0 | | multiColorsProps.setColorsCustom(new Color[] |
| 581 | | | { |
| 582 | | | Color.RED, |
| 583 | | | Color.BLUE, |
| 584 | | | Color.ORANGE, |
| 585 | | | Color.YELLOW, |
| 586 | | | Color.YELLOW, |
| 587 | | | Color.CYAN, |
| 588 | | | Color.MAGENTA |
| 589 | | | }); |
| 590 | | | |
| 591 | | | |
| 592 | 0 | | final LBChart2D chart2D = new LBChart2D(); |
| 593 | 0 | | chart2D.setObject2DProperties (object2DProps); |
| 594 | 0 | | chart2D.setChart2DProperties (chart2DProps); |
| 595 | 0 | | chart2D.setLegendProperties (legendProps); |
| 596 | 0 | | chart2D.setGraphChart2DProperties (graphChart2DProps); |
| 597 | 0 | | chart2D.addGraphProperties (graphProps); |
| 598 | 0 | | chart2D.addDataset (dataset); |
| 599 | 0 | | chart2D.addMultiColorsProperties (multiColorsProps); |
| 600 | | | |
| 601 | | | |
| 602 | | | |
| 603 | 0 | | chart2D.setMaximumSize(LARGE_SIZE); |
| 604 | 0 | | chart2D.setPreferredSize(LARGE_SIZE); |
| 605 | | | |
| 606 | 0 | | if (chart2D.validate(false)) |
| 607 | | | { |
| 608 | 0 | | java.io.File file = new java.io.File(mOutDir, "quality_large.png"); |
| 609 | 0 | | javax.imageio.ImageIO.write(chart2D.getImage(), "PNG", file); |
| 610 | 0 | | chart2D.setMaximumSize(SMALL_SIZE); |
| 611 | 0 | | chart2D.setPreferredSize(SMALL_SIZE); |
| 612 | 0 | | chart2D.pack(); |
| 613 | 0 | | file = new java.io.File(mOutDir, "quality_small.png"); |
| 614 | 0 | | javax.imageio.ImageIO.write(chart2D.getImage(), "PNG", file); |
| 615 | 0 | | } |
| 616 | | | else |
| 617 | | | { |
| 618 | 0 | | chart2D.validate(true); |
| 619 | | | } |
| 620 | 0 | | } |
| 621 | | | |
| 622 | | | |
| 623 | | | |
| 624 | | | |
| 625 | | | private float getCounter (Map<String, FileSummary> src, |
| 626 | | | String string) |
| 627 | | | { |
| 628 | 0 | | final FileSummary counter = src.get(string); |
| 629 | | | final int result; |
| 630 | | | |
| 631 | 0 | | if (counter != null) |
| 632 | | | { |
| 633 | 0 | | result = counter.getLinesOfCode(); |
| 634 | | | } |
| 635 | | | else |
| 636 | | | { |
| 637 | 0 | | result = 0; |
| 638 | | | } |
| 639 | 0 | | return result; |
| 640 | | | } |
| 641 | | | |
| 642 | | | |
| 643 | | | |
| 644 | | | @param |
| 645 | | | @return |
| 646 | | | |
| 647 | | | private String[] cutPackages (String[] labelsAxisLabels) |
| 648 | | | { |
| 649 | 0 | | final String [] result = new String[labelsAxisLabels.length]; |
| 650 | | | |
| 651 | 0 | | for (int i = 0; i < labelsAxisLabels.length; i++) |
| 652 | | | { |
| 653 | 0 | | if (labelsAxisLabels[i].startsWith(mPrefix)) |
| 654 | | | { |
| 655 | 0 | | result[i] |
| 656 | | | = labelsAxisLabels[i].substring(mPrefix.length()); |
| 657 | 0 | | if (result[i].indexOf('.') != -1) |
| 658 | | | { |
| 659 | 0 | | result[i] = result[i].substring(result[i].indexOf('.') + 1); |
| 660 | | | } |
| 661 | | | } |
| 662 | | | else |
| 663 | | | { |
| 664 | 0 | (11) | result[i] = labelsAxisLabels[i]; |
| 665 | | | } |
| 666 | | | } |
| 667 | | | |
| 668 | 0 | | return result; |
| 669 | | | } |
| 670 | | | |
| 671 | | | } |