| 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.BufferedWriter; |
| 36 | | | import java.io.File; |
| 37 | | | import java.io.FileInputStream; |
| 38 | | | import java.io.FileNotFoundException; |
| 39 | | | import java.io.FileOutputStream; |
| 40 | | | import java.io.IOException; |
| 41 | | | import java.io.InputStream; |
| 42 | | | import java.io.OutputStream; |
| 43 | | | import java.io.OutputStreamWriter; |
| 44 | | | import java.io.Serializable; |
| 45 | | | import java.io.Writer; |
| 46 | | | import java.nio.charset.Charset; |
| 47 | | | import java.util.ArrayList; |
| 48 | | | import java.util.Arrays; |
| 49 | | | import java.util.Calendar; |
| 50 | | | import java.util.Collection; |
| 51 | | | import java.util.Collections; |
| 52 | | | import java.util.Comparator; |
| 53 | | | import java.util.HashMap; |
| 54 | | | import java.util.HashSet; |
| 55 | | | import java.util.Iterator; |
| 56 | | | import java.util.LinkedList; |
| 57 | | | import java.util.List; |
| 58 | | | import java.util.Map; |
| 59 | | | import java.util.Set; |
| 60 | | | import java.util.TimeZone; |
| 61 | | | import java.util.TreeSet; |
| 62 | | | import java.util.logging.Level; |
| 63 | | | import java.util.logging.Logger; |
| 64 | | | |
| 65 | | | import javax.xml.bind.JAXBContext; |
| 66 | | | import javax.xml.bind.JAXBException; |
| 67 | | | import javax.xml.bind.Unmarshaller; |
| 68 | | | |
| 69 | | | import org.jcoderz.commons.types.Date; |
| 70 | | | import org.jcoderz.commons.util.ArraysUtil; |
| 71 | | | import org.jcoderz.commons.util.Assert; |
| 72 | | | import org.jcoderz.commons.util.Constants; |
| 73 | | | import org.jcoderz.commons.util.EmptyIterator; |
| 74 | | | import org.jcoderz.commons.util.FileUtils; |
| 75 | | | import org.jcoderz.commons.util.IoUtil; |
| 76 | | | import org.jcoderz.commons.util.LoggingUtils; |
| 77 | | | import org.jcoderz.commons.util.ObjectUtil; |
| 78 | | | import org.jcoderz.commons.util.StringUtil; |
| 79 | | | import org.jcoderz.commons.util.XmlUtil; |
| 80 | | | import org.jcoderz.phoenix.report.jaxb.Item; |
| 81 | | | import org.jcoderz.phoenix.report.jaxb.Report; |
| 82 | | | |
| 83 | | | |
| 84 | | (1) | |
| 85 | | (2) | |
| 86 | | (3) | |
| 87 | | (4) | |
| 88 | | | |
| 89 | | | @author |
| 90 | | | |
| 91 | | | public final class Java2Html |
| 92 | | | { |
| 93 | | | |
| 94 | | | public static final String WIKI_BASE_PROPERTY = "report.wiki-prefix"; |
| 95 | | | |
| 96 | | | |
| 97 | 100 | | private static final String[] PATTERN = {"odd", "even"}; |
| 98 | | | |
| 99 | | | |
| 100 | 100 | | private static final int PATTERN_SIZE = PATTERN.length; |
| 101 | | | |
| 102 | | | |
| 103 | 100 | | private static final String CLASSNAME = Java2Html.class.getName(); |
| 104 | | | |
| 105 | | | |
| 106 | 100 | | private static final Logger logger = Logger.getLogger(CLASSNAME); |
| 107 | | | |
| 108 | | | |
| 109 | | | private static final String NEWLINE = "\n"; |
| 110 | | | |
| 111 | | | |
| 112 | | | private static final String SORT_BY_PACKAGE_INDEX = "index.html"; |
| 113 | | | |
| 114 | | | private static final String SORT_BY_QUALITY_INDEX = "index_q.html"; |
| 115 | | | |
| 116 | | | private static final String SORT_BY_COVERAGE_INDEX = "index_c.html"; |
| 117 | | | |
| 118 | | | |
| 119 | | | private static final String LAST_MARKER = "_last"; |
| 120 | | | |
| 121 | | | private static final String DEFAULT_STYLESHEET = "reportstyle.css"; |
| 122 | | | |
| 123 | | | private static final int NUMBER_OF_AGE_SEGMENTS = 5; |
| 124 | | | |
| 125 | | | |
| 126 | | | private static final String UNNAMED_PACKAGE_NAME = "unnamed-package"; |
| 127 | | | |
| 128 | | | |
| 129 | | | |
| 130 | | | |
| 131 | | | |
| 132 | | | private static final int MAX_LINES_WITH_INLINE_MARK = 3; |
| 133 | | | |
| 134 | | | private static final int ABSOLUTE_END_OF_LINE = 9999; |
| 135 | | | |
| 136 | | | |
| 137 | | | private static final int DEFAULT_TAB_WIDTH = 8; |
| 138 | | | |
| 139 | | | <code></code> |
| 140 | 0 | | private final List<FileSummary> mAllFiles |
| 141 | | | = new ArrayList<FileSummary>(); |
| 142 | | | |
| 143 | | | |
| 144 | 0 | | private final Map<String, FileSummary> mPackageSummary |
| 145 | | | = new HashMap<String, FileSummary>(); |
| 146 | 0 | | private final Map<String, List<FileSummary>> mAllPackages |
| 147 | | | = new HashMap<String, List<FileSummary>>(); |
| 148 | | | |
| 149 | | | |
| 150 | | | |
| 151 | | | |
| 152 | 0 | | private final Map<Integer, List<Item>> mFindingsInFile |
| 153 | | | = new HashMap<Integer, List<Item>>(); |
| 154 | 0 | | private final Set<Item> mFindingsInCurrentLine |
| 155 | | | = new HashSet<Item>(); |
| 156 | 0 | | private final List<Item> mCurrentFindings = new ArrayList<Item>(); |
| 157 | 0 | | private final List<Item> mHandledFindings |
| 158 | | | = new ArrayList<Item>(); |
| 159 | | | |
| 160 | 0 | | private final List<org.jcoderz.phoenix.report.jaxb.File> mGlobalFindings |
| 161 | | | = new ArrayList<org.jcoderz.phoenix.report.jaxb.File>(); |
| 162 | | | |
| 163 | | | private FileSummary mGlobalSummary; |
| 164 | | | |
| 165 | | | |
| 166 | 0 | | private String mProjectName = ""; |
| 167 | 0 | | private String mWebVcBase = null; |
| 168 | 0 | | private String mWebVcSuffix = ""; |
| 169 | | | private String mProjectHome; |
| 170 | 0 | | private String mTimestamp = null; |
| 171 | 0 | | private String mStyle = DEFAULT_STYLESHEET; |
| 172 | | | private String mClassname; |
| 173 | | | private String mPackage; |
| 174 | | | private String mPackageBase; |
| 175 | 0 | | private final StringBuilder mStringBuilder |
| 176 | | | = new StringBuilder(); |
| 177 | | | |
| 178 | 0 | | private final StringBuilder mGetIconsStringBuffer |
| 179 | | | = new StringBuilder(); |
| 180 | | | |
| 181 | | | private java.io.File mInputData; |
| 182 | | | private java.io.File mOutDir; |
| 183 | | | |
| 184 | 0 | | private boolean mCoverageData = true; |
| 185 | | | |
| 186 | 0 | | private Level mLogLevel = Level.INFO; |
| 187 | | | |
| 188 | | | |
| 189 | | | |
| 190 | | | |
| 191 | | | |
| 192 | 0 | | private final List<Item> mActiveItems |
| 193 | | | = new LinkedList<Item>(); |
| 194 | | | |
| 195 | 0 | | private Charset mCharSet = Charset.defaultCharset(); |
| 196 | | | |
| 197 | 0 | | private int mTabWidth = DEFAULT_TAB_WIDTH; |
| 198 | | | |
| 199 | | | |
| 200 | | | private Report mReport; |
| 201 | | | |
| 202 | 0 | | private final Map<Item, org.jcoderz.phoenix.report.jaxb.File> mItemToFileMap |
| 203 | | | = new HashMap<Item, org.jcoderz.phoenix.report.jaxb.File>(); |
| 204 | | | |
| 205 | | | |
| 206 | | | |
| 207 | | | |
| 208 | | | @throws |
| 209 | | | |
| 210 | | | |
| 211 | | | public Java2Html () |
| 212 | | | throws IOException |
| 213 | 0 | | { |
| 214 | 0 | | mProjectHome = new java.io.File(".").getCanonicalPath(); |
| 215 | 0 | | } |
| 216 | | | |
| 217 | | | |
| 218 | | | |
| 219 | | | |
| 220 | | | @param |
| 221 | | | @throws |
| 222 | | | @throws |
| 223 | | | |
| 224 | | | public static void main (String[] args) |
| 225 | | | throws IOException, JAXBException |
| 226 | | | { |
| 227 | 0 | | final Java2Html engine = new Java2Html(); |
| 228 | | | |
| 229 | 0 | | engine.parseArguments(args); |
| 230 | | | |
| 231 | 0 | | Logger.getLogger("org.jcoderz.phoenix.report").setLevel(Level.FINEST); |
| 232 | 0 | | engine.process(); |
| 233 | 0 | | } |
| 234 | | | |
| 235 | | | |
| 236 | | | |
| 237 | | | @param |
| 238 | | | @return |
| 239 | | | |
| 240 | | | |
| 241 | | | public static String toOddEvenString (int number) |
| 242 | | | { |
| 243 | 0 | | return PATTERN[number % PATTERN_SIZE]; |
| 244 | | | } |
| 245 | | | |
| 246 | | | |
| 247 | | | |
| 248 | | | |
| 249 | | | @param |
| 250 | | | |
| 251 | | | public void setPackageBase (String packageBase) |
| 252 | | | { |
| 253 | 0 | | mPackageBase = packageBase; |
| 254 | 0 | | logger.config("Package base set to '" + mPackageBase + "'."); |
| 255 | 0 | | } |
| 256 | | | |
| 257 | | | |
| 258 | | | |
| 259 | | | |
| 260 | | | @param |
| 261 | | | |
| 262 | | | public void setTimestamp (String timestamp) |
| 263 | | | { |
| 264 | 0 | | mTimestamp = timestamp; |
| 265 | 0 | | logger.config("Timestamp set to '" + mTimestamp + "'."); |
| 266 | 0 | | } |
| 267 | | | |
| 268 | | | |
| 269 | | | |
| 270 | | | |
| 271 | | | @param |
| 272 | | | |
| 273 | | | |
| 274 | | | public void setCoverageData (boolean coverageDataAvailable) |
| 275 | | | { |
| 276 | 0 | | mCoverageData = coverageDataAvailable; |
| 277 | 0 | | logger.config("Coverage data set to '" + mCoverageData + "'."); |
| 278 | 0 | | } |
| 279 | | | |
| 280 | | | |
| 281 | | | |
| 282 | | | |
| 283 | | | @param |
| 284 | | | |
| 285 | | | |
| 286 | | | public void setStyle (String style) |
| 287 | | | { |
| 288 | 0 | | mStyle = style; |
| 289 | 0 | | logger.config("Style set to '" + mStyle + "'."); |
| 290 | 0 | | } |
| 291 | | | |
| 292 | | | |
| 293 | | | |
| 294 | | | |
| 295 | | | |
| 296 | | | @param |
| 297 | | | |
| 298 | | | public void setWikiBase (String wikiBase) |
| 299 | | | { |
| 300 | 0 | | logger.config("Wiki base set to '" + wikiBase + "'."); |
| 301 | 0 | | System.getProperties().setProperty(WIKI_BASE_PROPERTY, |
| 302 | | | wikiBase); |
| 303 | 0 | | } |
| 304 | | | |
| 305 | | | |
| 306 | | | |
| 307 | | | |
| 308 | | | @param |
| 309 | | | |
| 310 | | | public void setCvsBase (String cvsBase) |
| 311 | | | { |
| 312 | 0 | | mWebVcBase = cvsBase; |
| 313 | 0 | | logger.config("CVS base set to '" + mWebVcBase + "'."); |
| 314 | 0 | | } |
| 315 | | | |
| 316 | | | |
| 317 | | | |
| 318 | | | @param |
| 319 | | | |
| 320 | | | public void setCvsSuffix (String suffix) |
| 321 | | | { |
| 322 | 0 | | mWebVcSuffix = suffix; |
| 323 | 0 | | logger.config("CVS suffix set to '" + suffix + "'."); |
| 324 | 0 | | } |
| 325 | | | |
| 326 | | | |
| 327 | | | |
| 328 | | | @return |
| 329 | | | |
| 330 | | | public String getProjectName () |
| 331 | | | { |
| 332 | 0 | | return mProjectName; |
| 333 | | | } |
| 334 | | | |
| 335 | | | |
| 336 | | | |
| 337 | | | |
| 338 | | | @param |
| 339 | | | |
| 340 | | | |
| 341 | | | public void setProjectName (String name) |
| 342 | | | { |
| 343 | 0 | | Assert.notNull(name, "name"); |
| 344 | 0 | | mProjectName = name; |
| 345 | 0 | | logger.config("Project name set to '" + getProjectName() + "'."); |
| 346 | 0 | | } |
| 347 | | | |
| 348 | | | |
| 349 | | | |
| 350 | | | |
| 351 | | | @param |
| 352 | | | |
| 353 | | | public void setTabwidth (String tabWidth) |
| 354 | | | { |
| 355 | 0 | | Assert.notNull(tabWidth, "width"); |
| 356 | 0 | | mTabWidth = Integer.parseInt(tabWidth); |
| 357 | 0 | | logger.config("Source tab width set to '" + mTabWidth + "'."); |
| 358 | 0 | | } |
| 359 | | | |
| 360 | | | |
| 361 | | | |
| 362 | | | {@link } |
| 363 | | | @param |
| 364 | | | |
| 365 | | | public void setLoglevel (String loglevel) |
| 366 | | | { |
| 367 | 0 | | mLogLevel = Level.parse(loglevel); |
| 368 | 0 | | LoggingUtils.setGlobalHandlerLogLevel(Level.ALL); |
| 369 | 0 | | logger.fine("Setting log level: " + mLogLevel); |
| 370 | 0 | | logger.setLevel(mLogLevel); |
| 371 | 0 | | } |
| 372 | | | |
| 373 | | | |
| 374 | | | |
| 375 | | | @param |
| 376 | | | |
| 377 | | | public void setSourceCharset (Charset charset) |
| 378 | | | { |
| 379 | 0 | | Assert.notNull(charset, "charset"); |
| 380 | 0 | | mCharSet = charset; |
| 381 | 0 | | logger.config("Source charset set to '" + charset + "'."); |
| 382 | 0 | | } |
| 383 | | | |
| 384 | | | |
| 385 | | | |
| 386 | | | @param |
| 387 | | | @throws |
| 388 | | | |
| 389 | | | public void setProjectHome (java.io.File file) throws IOException |
| 390 | | | { |
| 391 | 0 | | final java.io.File projectHomeFile = file.getCanonicalFile(); |
| 392 | 0 | | mProjectHome = projectHomeFile.getCanonicalPath(); |
| 393 | 0 | | if (!projectHomeFile.isDirectory()) |
| 394 | | | { |
| 395 | 0 | | throw new RuntimeException("'projectHome' must be a directory '" |
| 396 | | | + projectHomeFile + "'."); |
| 397 | | | } |
| 398 | 0 | | logger.config("Using project home " + mProjectHome + "."); |
| 399 | 0 | | } |
| 400 | | | |
| 401 | | | |
| 402 | | | |
| 403 | | | @param |
| 404 | | | @throws |
| 405 | | | |
| 406 | | | public void setInputFile (java.io.File file) throws IOException |
| 407 | | | { |
| 408 | 0 | | mInputData = file.getCanonicalFile(); |
| 409 | 0 | | if (!mInputData.canRead()) |
| 410 | | | { |
| 411 | 0 | | throw new RuntimeException("Can not read report file '" |
| 412 | | | + mInputData + "'."); |
| 413 | | | } |
| 414 | 0 | | logger.config("Using report file " + mInputData + "."); |
| 415 | 0 | | } |
| 416 | | | |
| 417 | | | |
| 418 | | | |
| 419 | | | |
| 420 | | | @param |
| 421 | | | @throws |
| 422 | | | |
| 423 | | | public void setOutDir (java.io.File dir) throws IOException |
| 424 | | | { |
| 425 | 0 | | mOutDir = dir.getCanonicalFile(); |
| 426 | 0 | | if (!mOutDir.exists()) |
| 427 | | | { |
| 428 | 0 | | if (!mOutDir.mkdir()) |
| 429 | | | { |
| 430 | 0 | | throw new RuntimeException("Could not create 'outDir' '" |
| 431 | | | + mOutDir + "'."); |
| 432 | | | } |
| 433 | | | } |
| 434 | 0 | | if (!mOutDir.isDirectory()) |
| 435 | | | { |
| 436 | 0 | | throw new RuntimeException("'outDir' must be a directory '" |
| 437 | | | + mOutDir + "'."); |
| 438 | | | } |
| 439 | 0 | | logger.config("Using out dir " + mOutDir + "."); |
| 440 | 0 | | } |
| 441 | | | |
| 442 | | | |
| 443 | | | |
| 444 | | | @throws |
| 445 | | | @throws |
| 446 | | | |
| 447 | | | public void process () |
| 448 | | | throws JAXBException, IOException |
| 449 | | | { |
| 450 | 0 | | final JAXBContext jaxbContext |
| 451 | | | = JAXBContext.newInstance("org.jcoderz.phoenix.report.jaxb", |
| 452 | | | this.getClass().getClassLoader()); |
| 453 | 0 | | final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); |
| 454 | 0 | (5) | unmarshaller.setValidating(true); |
| 455 | 0 | | mReport = (Report) unmarshaller.unmarshal(mInputData); |
| 456 | 0 | | mGlobalSummary = new FileSummary(); |
| 457 | | | |
| 458 | 0 | | initialiteFindingTypes(); |
| 459 | | | |
| 460 | | | for (final org.jcoderz.phoenix.report.jaxb.File file |
| 461 | 0 | (6) | : (List<org.jcoderz.phoenix.report.jaxb.File>) mReport.getFile()) |
| 462 | | | { |
| 463 | | | try |
| 464 | | | { |
| 465 | 0 | | if (file.getName() != null) |
| 466 | | | { |
| 467 | 0 | | java2html(new java.io.File(file.getName()), file); |
| 468 | | | } |
| 469 | | | else |
| 470 | | | { |
| 471 | 0 | | mGlobalFindings.add(file); |
| 472 | | | } |
| 473 | | | } |
| 474 | 0 | | catch (Exception ex) |
| 475 | | | { |
| 476 | 0 | | if (file.getItem().isEmpty()) |
| 477 | | | { |
| 478 | 0 | | logger.log(Level.FINE, |
| 479 | | | "No report for file without items '" + file.getName() |
| 480 | | | + "'.", ex); |
| 481 | | | } |
| 482 | | | else |
| 483 | | | { |
| 484 | 0 | | logger.log(Level.SEVERE, |
| 485 | | | "Failed to generate report for '" + file.getName() |
| 486 | | | + "'.", ex); |
| 487 | 0 | | mGlobalFindings.add(file); |
| 488 | | | } |
| 489 | 0 | | } |
| 490 | | | } |
| 491 | | | |
| 492 | | | |
| 493 | 0 | | for (final List<FileSummary> pkg : mAllPackages.values()) |
| 494 | | | { |
| 495 | 0 | | createPackageSummary(pkg); |
| 496 | | | } |
| 497 | 0 | | createFullSummary(); |
| 498 | | | |
| 499 | 0 | | createFindingsSummary(); |
| 500 | 0 | | createPerFindingSummary(); |
| 501 | 0 | | createAgeSummary(); |
| 502 | | | |
| 503 | 0 | | logger.fine("Charts."); |
| 504 | | | |
| 505 | | | try |
| 506 | | | { |
| 507 | | | final StatisticCollector sc; |
| 508 | 0 | | if (mPackageBase == null) |
| 509 | | | { |
| 510 | 0 | | sc = new StatisticCollector(mReport, mOutDir, mTimestamp); |
| 511 | | | } |
| 512 | | | else |
| 513 | | | { |
| 514 | 0 | | sc = new StatisticCollector( |
| 515 | | | mReport, mPackageBase, mOutDir, mTimestamp); |
| 516 | | | } |
| 517 | 0 | | sc.createCharts(); |
| 518 | | | } |
| 519 | | | |
| 520 | | | |
| 521 | 0 | | catch (Exception ex) |
| 522 | | | { |
| 523 | 0 | | logger.log(Level.SEVERE, |
| 524 | | | "Failed to create charts for report. " |
| 525 | | | + ex.getMessage(), ex); |
| 526 | 0 | | } |
| 527 | | | |
| 528 | 0 | | copyStylesheet(); |
| 529 | 0 | | copyIcons(); |
| 530 | | | |
| 531 | 0 | | logger.fine("Done."); |
| 532 | 0 | | } |
| 533 | | | |
| 534 | | | private void initialiteFindingTypes () |
| 535 | | | { |
| 536 | | | for (final org.jcoderz.phoenix.report.jaxb.File file |
| 537 | 0 | (7) | : (List<org.jcoderz.phoenix.report.jaxb.File>) mReport.getFile()) |
| 538 | | | { |
| 539 | 0 | (8) | for (Item i : (List<Item>) file.getItem()) |
| 540 | | | { |
| 541 | | | try |
| 542 | | | { |
| 543 | 0 | | FindingType.initialize(i.getOrigin()); |
| 544 | | | } |
| 545 | 0 | | catch (Exception ex) |
| 546 | | | { |
| 547 | 0 | | logger.log(Level.WARNING, |
| 548 | | | "Could not initialize finding type " |
| 549 | | | + i.getFindingType()); |
| 550 | 0 | | } |
| 551 | | | } |
| 552 | | | } |
| 553 | | | |
| 554 | 0 | | } |
| 555 | | | |
| 556 | | | private void createAgeSummary () |
| 557 | | | throws IOException |
| 558 | | | { |
| 559 | 0 | | final List<Item> items = new ArrayList<Item>(); |
| 560 | | | for (final org.jcoderz.phoenix.report.jaxb.File file |
| 561 | 0 | (9) | : (List<org.jcoderz.phoenix.report.jaxb.File>) mReport.getFile()) |
| 562 | | | { |
| 563 | 0 | (10) | for (Item i : (List<Item>) file.getItem()) |
| 564 | | | { |
| 565 | 0 | | if (i.isSetSince()) |
| 566 | | | { |
| 567 | 0 | | items.add(i); |
| 568 | 0 | | mItemToFileMap.put(i, file); |
| 569 | | | } |
| 570 | | | } |
| 571 | | | } |
| 572 | 0 | | Collections.sort(items, |
| 573 | | | Collections.reverseOrder(new ItemAgeComperator())); |
| 574 | | | |
| 575 | 0 | | renderAgePage(items, Date.FUTURE_DATE, ReportInterval.BUILD); |
| 576 | 0 | | renderAgePage(items, Date.FUTURE_DATE, ReportInterval.DAY); |
| 577 | 0 | | renderAgePage(items, Date.FUTURE_DATE, ReportInterval.WEEK); |
| 578 | 0 | | final Date oldest |
| 579 | | | = renderAgePage(items, Date.FUTURE_DATE, ReportInterval.MONTH); |
| 580 | 0 | | renderAgePage(items, oldest, ReportInterval.OLD); |
| 581 | 0 | | } |
| 582 | | | |
| 583 | | | private void copyIcons () |
| 584 | | | throws IOException |
| 585 | | | { |
| 586 | | | |
| 587 | 0 | | final File outDir = new File(mOutDir, "images"); |
| 588 | 0 | | FileUtils.mkdirs(outDir); |
| 589 | | | |
| 590 | 0 | | for (int i = 0; i < Severity.VALUES.size(); i++) |
| 591 | | | { |
| 592 | 0 | | final Severity s = Severity.fromInt(i); |
| 593 | 0 | | if (s.equals(Severity.COVERAGE)) |
| 594 | | | { |
| 595 | 0 | | continue; |
| 596 | | | } |
| 597 | 0 | | copyImage(outDir, "icon_" + s.toString() + ".gif"); |
| 598 | 0 | | copyImage(outDir, "bg-" + s.toString() + ".gif"); |
| 599 | | | } |
| 600 | 0 | | } |
| 601 | | | |
| 602 | | | private void copyImage (final File outDir, final String name) |
| 603 | | | { |
| 604 | 0 | | final InputStream in |
| 605 | | | = this.getClass().getResourceAsStream(name); |
| 606 | | | try |
| 607 | | | { |
| 608 | 0 | | if (in != null) |
| 609 | | | { |
| 610 | 0 | | copyResource(in, name, outDir); |
| 611 | | | } |
| 612 | | | else |
| 613 | | | { |
| 614 | 0 | | logger.warning( |
| 615 | | | "Could not find resource '" + name + "'!"); |
| 616 | | | } |
| 617 | | | } |
| 618 | | | finally |
| 619 | | | { |
| 620 | 0 | | IoUtil.close(in); |
| 621 | 0 | | } |
| 622 | 0 | | } |
| 623 | | | |
| 624 | | | private void copyResource (InputStream in, String resource, File outDir) |
| 625 | | | { |
| 626 | | | |
| 627 | 0 | | OutputStream out = null; |
| 628 | | | try |
| 629 | | | { |
| 630 | 0 | | out = new FileOutputStream(new File(outDir, resource)); |
| 631 | 0 | | FileUtils.copy(in, out); |
| 632 | | | } |
| 633 | 0 | | catch (FileNotFoundException ex) |
| 634 | | | { |
| 635 | 0 | | throw new RuntimeException("Can not find output folder '" |
| 636 | | | + mOutDir + "'.", ex); |
| 637 | | | } |
| 638 | 0 | | catch (IOException ex) |
| 639 | | | { |
| 640 | 0 | | throw new RuntimeException("Could not copy resource '" |
| 641 | | | + resource + "'.", ex); |
| 642 | | | } |
| 643 | | | finally |
| 644 | | | { |
| 645 | 0 | | IoUtil.close(out); |
| 646 | 0 | | } |
| 647 | 0 | | } |
| 648 | | | |
| 649 | | | private void copyStylesheet () |
| 650 | | | { |
| 651 | | | |
| 652 | | | |
| 653 | | | |
| 654 | 0 | | InputStream in = this.getClass().getResourceAsStream(mStyle); |
| 655 | | | try |
| 656 | | | { |
| 657 | 0 | | if (in == null) |
| 658 | | | { |
| 659 | | | try |
| 660 | | | { |
| 661 | 0 | | final File style = new File(mStyle); |
| 662 | 0 | | in = new FileInputStream(style); |
| 663 | | | } |
| 664 | 0 | | catch (FileNotFoundException ex) |
| 665 | | | { |
| 666 | 0 | | IoUtil.close(in); |
| 667 | 0 | | in = this.getClass().getResourceAsStream(DEFAULT_STYLESHEET); |
| 668 | 0 | | if (in == null) |
| 669 | | | { |
| 670 | 0 | | throw new RuntimeException("Can not find stylesheet file '" |
| 671 | | | + mStyle + "'.", ex); |
| 672 | | | } |
| 673 | 0 | | } |
| 674 | | | } |
| 675 | 0 | | copyResource(in, DEFAULT_STYLESHEET, mOutDir); |
| 676 | | | } |
| 677 | | | finally |
| 678 | | | { |
| 679 | 0 | | IoUtil.close(in); |
| 680 | 0 | | } |
| 681 | 0 | | } |
| 682 | | | |
| 683 | | (11) | private void parseArguments (String[] args) |
| 684 | | | { |
| 685 | | | try |
| 686 | | | { |
| 687 | 0 | | for (int i = 0; i < args.length; ) |
| 688 | | | { |
| 689 | 0 | | if ("-outDir".equals(args[i])) |
| 690 | | | { |
| 691 | 0 | | setOutDir(new java.io.File(args[i + 1])); |
| 692 | | | } |
| 693 | 0 | | else if ("-report".equals(args[i])) |
| 694 | | | { |
| 695 | 0 | | setInputFile(new java.io.File(args[i + 1])); |
| 696 | | | } |
| 697 | 0 | | else if ("-projectHome".equals(args[i])) |
| 698 | | | { |
| 699 | 0 | | setProjectHome(new java.io.File(args[i + 1])); |
| 700 | | | } |
| 701 | 0 | | else if ("-projectName".equals(args[i])) |
| 702 | | | { |
| 703 | 0 | | setProjectName(args[i + 1]); |
| 704 | | | } |
| 705 | 0 | | else if ("-cvsBase".equals(args[i])) |
| 706 | | | { |
| 707 | 0 | | setCvsBase(args[i + 1]); |
| 708 | | | } |
| 709 | 0 | | else if ("-cvsSuffix".equals(args[i])) |
| 710 | | | { |
| 711 | 0 | | setCvsSuffix(args[i + 1]); |
| 712 | | | } |
| 713 | 0 | | else if ("-timestamp".equals(args[i])) |
| 714 | | | { |
| 715 | 0 | | setTimestamp(args[i + 1]); |
| 716 | | | } |
| 717 | 0 | | else if ("-wikiBase".equals(args[i])) |
| 718 | | | { |
| 719 | 0 | | setWikiBase(args[i + 1]); |
| 720 | | | } |
| 721 | 0 | | else if ("-reportStyle".equals(args[i])) |
| 722 | | | { |
| 723 | 0 | | setStyle(args[i + 1]); |
| 724 | | | } |
| 725 | 0 | | else if ("-noCoverage".equals(args[i])) |
| 726 | | | { |
| 727 | 0 | | setCoverageData(false); |
| 728 | 0 | | i -= 1; |
| 729 | | | } |
| 730 | 0 | | else if ("-sourceEncoding".equals(args[i])) |
| 731 | | | { |
| 732 | 0 | | setSourceCharset(Charset.forName(args[i + 1])); |
| 733 | | | } |
| 734 | 0 | | else if ("-packageBase".equals(args[i])) |
| 735 | | | { |
| 736 | 0 | | setPackageBase(args[i + 1]); |
| 737 | | | } |
| 738 | 0 | | else if ("-loglevel".equals(args[i])) |
| 739 | | | { |
| 740 | 0 | | setLoglevel(args[i + 1]); |
| 741 | | | } |
| 742 | 0 | | else if ("-tabwidth".equals(args[i])) |
| 743 | | | { |
| 744 | 0 | | setTabwidth(args[i + 1]); |
| 745 | | | } |
| 746 | | | else |
| 747 | | | { |
| 748 | 0 | | throw new IllegalArgumentException( |
| 749 | | | "Invalid argument '" + args[i] + "'"); |
| 750 | | | } |
| 751 | 0 | | i += 1 + 1 ; |
| 752 | | | } |
| 753 | | | } |
| 754 | 0 | | catch (IndexOutOfBoundsException e) |
| 755 | | | { |
| 756 | 0 | | final IllegalArgumentException ex |
| 757 | | | = new IllegalArgumentException("Missing value for " |
| 758 | | | + args[args.length - 1]); |
| 759 | 0 | | ex.initCause(e); |
| 760 | 0 | | throw ex; |
| 761 | | | } |
| 762 | 0 | | catch (Exception e) |
| 763 | | | { |
| 764 | 0 | | final IllegalArgumentException ex = new IllegalArgumentException( |
| 765 | | | "Problem with arument value for " + args[args.length - 1] |
| 766 | | | + "Argument line was " + ArraysUtil.toString(args)); |
| 767 | 0 | | ex.initCause(e); |
| 768 | 0 | | throw ex; |
| 769 | 0 | | } |
| 770 | 0 | | } |
| 771 | | | |
| 772 | | | |
| 773 | | | |
| 774 | | | |
| 775 | | | private void createPerFindingSummary () throws IOException |
| 776 | | | { |
| 777 | | | for (final FindingsSummary.FindingSummary summary |
| 778 | 0 | | : FindingsSummary.getFindingsSummary().getFindings().values()) |
| 779 | | | { |
| 780 | 0 | | final String filename = summary.createFindingDetailFilename(); |
| 781 | 0 | | final BufferedWriter out = openWriter(filename); |
| 782 | | | try |
| 783 | | | { |
| 784 | 0 | | htmlHeader(out, "Finding-" + summary.getFindingType().getSymbol() |
| 785 | | | + "-report " + mProjectName, ""); |
| 786 | 0 | | summary.createFindingTypeContent(out); |
| 787 | 0 | | out.write("</body></html>"); |
| 788 | | | } |
| 789 | | | finally |
| 790 | | | { |
| 791 | 0 | | IoUtil.close(out); |
| 792 | 0 | | } |
| 793 | 0 | | } |
| 794 | 0 | | } |
| 795 | | | |
| 796 | | | private void createFindingsSummary () throws IOException |
| 797 | | | { |
| 798 | 0 | | final BufferedWriter out = openWriter("findings.html"); |
| 799 | | | try |
| 800 | | | { |
| 801 | 0 | | htmlHeader(out, "Finding report " + mProjectName, ""); |
| 802 | 0 | | out.write("<h1><a href='index.html'>View by Classes</a></h1>"); |
| 803 | 0 | | out.write("<h1><a href='age-Build.html'>View by Age per Build</a> " |
| 804 | | | + "<a href='age-Day.html'> Day</a> " |
| 805 | | | + "<a href='age-Week.html'> Week</a> " |
| 806 | | | + "<a href='age-Month.html'> Month</a> " |
| 807 | | | + "<a href='age-Old.html'> Old</a></h1>"); |
| 808 | 0 | | out.write("<h1>Findings - Overview</h1>"); |
| 809 | 0 | | createNewFindingsList(out); |
| 810 | 0 | | createOldFindingsList(out); |
| 811 | 0 | | FindingsSummary.createOverallContent(out); |
| 812 | 0 | | out.write("</body></html>"); |
| 813 | | | } |
| 814 | | | finally |
| 815 | | | { |
| 816 | 0 | | IoUtil.close(out); |
| 817 | 0 | | } |
| 818 | 0 | | } |
| 819 | | | |
| 820 | | | private void createNewFindingsList (BufferedWriter out) |
| 821 | | | throws IOException |
| 822 | | | { |
| 823 | 0 | | int row = 0; |
| 824 | | | for (org.jcoderz.phoenix.report.jaxb.File file |
| 825 | 0 | (12) | : (List<org.jcoderz.phoenix.report.jaxb.File>) mReport.getFile()) |
| 826 | | | { |
| 827 | 0 | (13) | for (Item item : (List<Item>) file.getItem()) |
| 828 | | | { |
| 829 | 0 | | if (item.isNew()) |
| 830 | | | { |
| 831 | 0 | | if (row == 0) |
| 832 | | | { |
| 833 | 0 | | openTable(out, "New"); |
| 834 | | | } |
| 835 | 0 | | createRow(out, file, item, row); |
| 836 | 0 | | row++; |
| 837 | | | } |
| 838 | | | } |
| 839 | | | } |
| 840 | 0 | | if (row > 0) |
| 841 | | | { |
| 842 | 0 | | closeTable(out); |
| 843 | | | } |
| 844 | 0 | | } |
| 845 | | | |
| 846 | | | private void createOldFindingsList (BufferedWriter out) |
| 847 | | | throws IOException |
| 848 | | | { |
| 849 | 0 | | int row = 0; |
| 850 | | | for (org.jcoderz.phoenix.report.jaxb.File file |
| 851 | 0 | (14) | : (List<org.jcoderz.phoenix.report.jaxb.File>) mReport.getFile()) |
| 852 | | | { |
| 853 | 0 | (15) | for (Item item : (List<Item>) file.getItem()) |
| 854 | | | { |
| 855 | 0 | | if (item.isOld()) |
| 856 | | | { |
| 857 | 0 | | if (row == 0) |
| 858 | | | { |
| 859 | 0 | | openTable(out, "Fixed"); |
| 860 | | | } |
| 861 | 0 | | createRow(out, file, item, row); |
| 862 | 0 | | row++; |
| 863 | | | } |
| 864 | | | } |
| 865 | | | } |
| 866 | 0 | | if (row > 0) |
| 867 | | | { |
| 868 | 0 | | closeTable(out); |
| 869 | | | } |
| 870 | 0 | | } |
| 871 | | | |
| 872 | | | private void createRow (Writer bw, |
| 873 | | | org.jcoderz.phoenix.report.jaxb.File file, Item item, int rowCounter) |
| 874 | | | throws IOException |
| 875 | | | { |
| 876 | | | |
| 877 | | | |
| 878 | 0 | | bw.write("<tr class='findings-"); |
| 879 | 0 | | bw.write(Java2Html.toOddEvenString(rowCounter)); |
| 880 | 0 | | bw.write("row'><td class='findings-image'>"); |
| 881 | 0 | | appendSeverityImage(bw, item, ""); |
| 882 | 0 | | bw.write("</td><td width='100%' class='findings-data'>"); |
| 883 | 0 | | bw.write("<a href='"); |
| 884 | 0 | | bw.write(createReportLink(file)); |
| 885 | 0 | | bw.write("#LINE"); |
| 886 | 0 | | bw.write(String.valueOf(item.getLine())); |
| 887 | 0 | | bw.write("'>"); |
| 888 | 0 | | bw.write(XmlUtil.escape(file.getClassname())); |
| 889 | 0 | | bw.write(": "); |
| 890 | 0 | | appendItemMessage(bw, item); |
| 891 | 0 | | bw.write("</a></td><td>"); |
| 892 | 0 | | if (item.isSetSince()) |
| 893 | | | { |
| 894 | 0 | | bw.write(item.getSince().toDateString()); |
| 895 | | | } |
| 896 | 0 | | bw.write("</td></tr>\n"); |
| 897 | | | |
| 898 | 0 | | } |
| 899 | | | |
| 900 | | | private void openTable (Writer writer, String string) |
| 901 | | | throws IOException |
| 902 | | | { |
| 903 | 0 | | writer.write("<h2 class='severity-header'>"); |
| 904 | 0 | | writer.write(string); |
| 905 | 0 | | writer.write(" Findings</h2>"); |
| 906 | 0 | | writer.write("<table width='95%' cellpadding='2' cellspacing='0' " |
| 907 | | | + "border='0'>"); |
| 908 | 0 | | } |
| 909 | | | |
| 910 | | | private void closeTable (Writer bw) |
| 911 | | | throws IOException |
| 912 | | | { |
| 913 | 0 | | bw.append("</table>"); |
| 914 | 0 | | } |
| 915 | | | |
| 916 | | | |
| 917 | | | |
| 918 | | | |
| 919 | | | |
| 920 | | | |
| 921 | | (16) | private void java2html (java.io.File inFile, |
| 922 | | | org.jcoderz.phoenix.report.jaxb.File data) |
| 923 | | | { |
| 924 | | | |
| 925 | 0 | | mCurrentFindings.clear(); |
| 926 | 0 | | mHandledFindings.clear(); |
| 927 | 0 | | mFindingsInFile.clear(); |
| 928 | 0 | | mFindingsInCurrentLine.clear(); |
| 929 | 0 | | mActiveItems.clear(); |
| 930 | 0 | (17) | mCurrentFindings.addAll(data.getItem()); |
| 931 | 0 | | fillFindingsInFile(data); |
| 932 | 0 | | logger.finest("Processing file " + inFile); |
| 933 | | | |
| 934 | 0 | | BufferedWriter bw = null; |
| 935 | 0 | | String file = null; |
| 936 | | | try |
| 937 | | | { |
| 938 | 0 | | mPackage = data.getPackage(); |
| 939 | 0 | | if (StringUtil.isEmptyOrNull(mPackage)) |
| 940 | | | { |
| 941 | 0 | | mPackage = UNNAMED_PACKAGE_NAME; |
| 942 | | | } |
| 943 | 0 | | mClassname = data.getClassname(); |
| 944 | | | |
| 945 | | | |
| 946 | 0 | | if (StringUtil.isEmptyOrNull(mClassname)) |
| 947 | | | { |
| 948 | 0 | | mClassname = inFile.getName(); |
| 949 | | | } |
| 950 | | | |
| 951 | 0 | | final String subdir = mPackage.replaceAll("\\.", "/"); |
| 952 | 0 | | final java.io.File dir = new java.io.File(mOutDir, subdir); |
| 953 | 0 | | FileUtils.mkdirs(dir); |
| 954 | | | |
| 955 | 0 | | bw = openWriter(dir, mClassname + ".html"); |
| 956 | | | |
| 957 | 0 | | final Syntax src = new Syntax(inFile, mCharSet, mTabWidth); |
| 958 | 0 | | final FileSummary summary |
| 959 | | | = createFileSummary(src.getNumberOfLines(), subdir); |
| 960 | 0 | | addSummary(summary); |
| 961 | | | |
| 962 | 0 | | file = mPackage + "." + mClassname; |
| 963 | | | |
| 964 | 0 | | htmlHeader(bw, mClassname, mPackage); |
| 965 | | | |
| 966 | 0 | | bw.write("<h1><a href='"); |
| 967 | 0 | | bw.write(relativeRoot(mPackage)); |
| 968 | 0 | | bw.write("'>Project Report: "); |
| 969 | 0 | | bw.write(mProjectName); |
| 970 | 0 | | bw.write("</a></h1>" + NEWLINE); |
| 971 | 0 | | bw.write("<h2><a href ='index.html'>Packagesummary "); |
| 972 | 0 | | bw.write(mPackage); |
| 973 | 0 | | bw.write("</a></h2>" + NEWLINE); |
| 974 | | | |
| 975 | 0 | | final String cvsLink = getCvsLink(inFile.getAbsolutePath()); |
| 976 | 0 | | if (cvsLink != null) |
| 977 | | | { |
| 978 | 0 | | bw.write("<h3><a href='" + cvsLink |
| 979 | | | + "' class='cvs' title='cvs version'>" + file |
| 980 | | | + "</a></h3>" + NEWLINE); |
| 981 | | | } |
| 982 | | | else |
| 983 | | | { |
| 984 | 0 | | bw.write("<h3>" + file + "</h3>" + NEWLINE); |
| 985 | | | } |
| 986 | | | |
| 987 | | | |
| 988 | 0 | | bw.write("<table border='0' cellpadding='2' cellspacing='0' " |
| 989 | | | + "width='95%'>"); |
| 990 | 0 | | bw.write("<thead><tr><th>Line</th><th>Hits</th><th>Note</th>" |
| 991 | | | + "<th class='remainder'>Source</th></tr></thead>"); |
| 992 | 0 | | bw.write("<tbody>"); |
| 993 | | | |
| 994 | | | |
| 995 | 0 | | final int lastLine = src.getNumberOfLines(); |
| 996 | 0 | | for (int currentLine = 1; currentLine <= lastLine; currentLine++) |
| 997 | | | { |
| 998 | 0 | | bw.write("<tr class='" |
| 999 | | | + errorLevel(currentLine) |
| 1000 | | | + Java2Html.toOddEvenString(currentLine) + "'>"); |
| 1001 | 0 | | bw.write("<td align='right' class='lineno"); |
| 1002 | 0 | | final boolean isLast = currentLine == lastLine; |
| 1003 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 1004 | 0 | | bw.write("'><a name='LINE" + currentLine + "' />"); |
| 1005 | 0 | | bw.write(String.valueOf(currentLine)); |
| 1006 | 0 | | bw.write("</td>"); |
| 1007 | 0 | | hitsCell(bw, String.valueOf(getHits(currentLine)), isLast); |
| 1008 | 0 | | bw.write("<td class='note"); |
| 1009 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 1010 | 0 | | bw.write("'>"); |
| 1011 | 0 | | bw.write(getIcons(currentLine)); |
| 1012 | 0 | | bw.write("</td><td class='code-"); |
| 1013 | 0 | | bw.write(Java2Html.toOddEvenString(currentLine)); |
| 1014 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 1015 | 0 | | bw.write("'>"); |
| 1016 | 0 | | createCodeLine(bw, src); |
| 1017 | 0 | | bw.write("</td></tr>\n"); |
| 1018 | | | } |
| 1019 | 0 | | bw.write("</tbody>"); |
| 1020 | 0 | | bw.write("</table>\n"); |
| 1021 | | | |
| 1022 | | | |
| 1023 | 0 | | bw.write("<h2 class='findings-header'>Findings in this File</h2>"); |
| 1024 | 0 | | bw.write("<table width='95%' cellpadding='0' cellspacing='0' " |
| 1025 | | | + "border='0'>\n"); |
| 1026 | 0 | | int rowCounter = 0; |
| 1027 | | | |
| 1028 | 0 | | final String relativeRoot = relativeRoot(mPackage, ""); |
| 1029 | | | |
| 1030 | 0 | | int pos = mHandledFindings.size(); |
| 1031 | | | |
| 1032 | 0 | | for (final List<Item> lineFindings : mFindingsInFile.values()) |
| 1033 | | | { |
| 1034 | 0 | | for (final Item item : lineFindings) |
| 1035 | | | { |
| 1036 | 0 | | if (!Origin.COVERAGE.equals(item.getOrigin())) |
| 1037 | | | { |
| 1038 | 0 | | pos++; |
| 1039 | 0 | | rowCounter++; |
| 1040 | | | |
| 1041 | 0 | | bw.write("<tr class='findings-"); |
| 1042 | 0 | | bw.write(Java2Html.toOddEvenString(rowCounter)); |
| 1043 | 0 | | bw.write("row'>\n"); |
| 1044 | 0 | | bw.write(" <td class='findings-image'>\n"); |
| 1045 | 0 | | appendSeverityImage(bw, item, relativeRoot); |
| 1046 | 0 | | bw.write(" </td>\n"); |
| 1047 | 0 | | bw.write(" <td class='findings-id'>\n"); |
| 1048 | 0 | | bw.write(" <a name='FINDING" + pos + "' />\n"); |
| 1049 | 0 | | bw.write(" (" + pos + ")\n"); |
| 1050 | 0 | | bw.write(" </td>\n"); |
| 1051 | 0 | | bw.write(" <td></td><td></td><td></td>\n"); |
| 1052 | 0 | | bw.write(" <td width='100%' class='findings-data'>\n"); |
| 1053 | 0 | | appendItemMessage(bw, item); |
| 1054 | 0 | | bw.write(" </td>\n"); |
| 1055 | 0 | | bw.write("</tr>\n"); |
| 1056 | | | } |
| 1057 | | | } |
| 1058 | | | } |
| 1059 | | | |
| 1060 | | | |
| 1061 | 0 | | pos = 0; |
| 1062 | 0 | | for (final Item item : mHandledFindings) |
| 1063 | | | { |
| 1064 | 0 | | pos++; |
| 1065 | 0 | | rowCounter++; |
| 1066 | | | |
| 1067 | 0 | | final String link = "#LINE" + item.getLine(); |
| 1068 | | | |
| 1069 | 0 | | bw.write("<tr class='findings-"); |
| 1070 | 0 | | bw.write(Java2Html.toOddEvenString(rowCounter)); |
| 1071 | 0 | | bw.write("row'>\n"); |
| 1072 | 0 | | bw.write(" <td class='findings-image'>\n"); |
| 1073 | 0 | | appendSeverityImage(bw, item, relativeRoot); |
| 1074 | 0 | | bw.write(" </td>\n"); |
| 1075 | 0 | | bw.write(" <td class='findings-id'>\n"); |
| 1076 | 0 | | bw.write(" <a name='FINDING" + pos + "' />\n"); |
| 1077 | 0 | | bw.write(" <a href='" + link + "' title='" + item.getOrigin() |
| 1078 | | | + "' >\n"); |
| 1079 | 0 | | bw.write(" (" + pos + ")\n"); |
| 1080 | 0 | | bw.write(" </a>\n"); |
| 1081 | 0 | | bw.write(" </td>\n"); |
| 1082 | 0 | | bw.write(" <td class='findings-line-number' align='right'>\n"); |
| 1083 | 0 | | bw.write(" <a href='" + link + "' >\n"); |
| 1084 | 0 | | bw.write(String.valueOf(item.getLine())); |
| 1085 | 0 | | bw.write(" </a>\n"); |
| 1086 | 0 | | bw.write(" </td>\n"); |
| 1087 | 0 | | bw.write(" <td class='findings-line-number' align='center'>\n"); |
| 1088 | 0 | | bw.write(" <a href='" + link + "' >:</a>\n"); |
| 1089 | 0 | | bw.write(" </td>\n"); |
| 1090 | 0 | | bw.write(" <td class='findings-line-number' align='left'>\n"); |
| 1091 | 0 | | bw.write(" <a href='" + link + "' >\n"); |
| 1092 | 0 | | bw.write(String.valueOf(item.getColumn())); |
| 1093 | 0 | | bw.write(" </a>\n"); |
| 1094 | 0 | | bw.write(" </td>\n"); |
| 1095 | 0 | | bw.write(" <td width='100%' class='findings-data'>\n"); |
| 1096 | 0 | | bw.write(" <a href='" + link + "' >\n"); |
| 1097 | 0 | | appendItemMessage(bw, item); |
| 1098 | 0 | | bw.write("\n"); |
| 1099 | 0 | | bw.write(" </a>\n"); |
| 1100 | 0 | | bw.write(" </td>\n"); |
| 1101 | 0 | | bw.write("</tr>\n"); |
| 1102 | 0 | | } |
| 1103 | | | |
| 1104 | 0 | | bw.write("</table>\n"); |
| 1105 | 0 | | bw.write("\n</body>\n</html>"); |
| 1106 | | | } |
| 1107 | 0 | | catch (FileNotFoundException fnfe) |
| 1108 | | | { |
| 1109 | 0 | | logger.log(Level.WARNING, "Source file '" + file + "' not found.", |
| 1110 | | | fnfe); |
| 1111 | | | } |
| 1112 | 0 | | catch (IOException ioe) |
| 1113 | | | { |
| 1114 | 0 | | logger.log(Level.WARNING, "Problem with '" + file + "'.", ioe); |
| 1115 | | | } |
| 1116 | | | finally |
| 1117 | | | { |
| 1118 | 0 | | IoUtil.close(bw); |
| 1119 | 0 | | } |
| 1120 | 0 | | } |
| 1121 | | | |
| 1122 | | | private void appendItemMessage (Writer bw, final Item item) |
| 1123 | | | throws IOException |
| 1124 | | | { |
| 1125 | 0 | | if (item.isOld()) |
| 1126 | | | { |
| 1127 | 0 | | bw.write("Fixed: "); |
| 1128 | | | } |
| 1129 | 0 | | if (item.isNew()) |
| 1130 | | | { |
| 1131 | 0 | | bw.write("New: "); |
| 1132 | | | } |
| 1133 | 0 | | bw.write(XmlUtil.escape(item.getMessage())); |
| 1134 | 0 | | if (item.getSeverityReason() != null) |
| 1135 | | | { |
| 1136 | 0 | | bw.write(' '); |
| 1137 | 0 | | bw.write(XmlUtil.escape(item.getSeverityReason())); |
| 1138 | | | } |
| 1139 | 0 | | } |
| 1140 | | | |
| 1141 | | | |
| 1142 | | | |
| 1143 | | | |
| 1144 | | | |
| 1145 | | | @param |
| 1146 | | | @param |
| 1147 | | | @param |
| 1148 | | | @throws |
| 1149 | | | |
| 1150 | | | |
| 1151 | | | private void appendSeverityImage (Writer w, Item item, String root) |
| 1152 | | | throws IOException |
| 1153 | | | { |
| 1154 | 0 | | w.write("<a href='"); |
| 1155 | 0 | | w.write(root); |
| 1156 | 0 | | w.write(FindingsSummary.getFindingsSummary() |
| 1157 | | | .getFindingSummary(item).createFindingDetailFilename()); |
| 1158 | 0 | | w.write("'><img border='0' title='"); |
| 1159 | 0 | | w.write(String.valueOf(item.getSeverity())); |
| 1160 | 0 | | w.write(" ["); |
| 1161 | 0 | | w.write(String.valueOf(item.getOrigin())); |
| 1162 | 0 | | w.write("]' alt='"); |
| 1163 | 0 | | w.write(item.getSeverity().toString().substring(0, 1)); |
| 1164 | 0 | | w.write("' src='"); |
| 1165 | 0 | | w.write(root); |
| 1166 | 0 | | w.write(getImage(item.getSeverity())); |
| 1167 | 0 | | w.write("' /></a>\n"); |
| 1168 | 0 | | } |
| 1169 | | | |
| 1170 | | | private String getImage (Severity severity) |
| 1171 | | | { |
| 1172 | 0 | | return "images/icon_" + severity.toString() + ".gif"; |
| 1173 | | | } |
| 1174 | | | |
| 1175 | | | private FileSummary createFileSummary (final int linesCount, |
| 1176 | | | final String subdir) |
| 1177 | | | { |
| 1178 | | | |
| 1179 | 0 | | final FileSummary summary = new FileSummary(mClassname, mPackage, |
| 1180 | | | subdir + "/" + mClassname + ".html", linesCount, mCoverageData); |
| 1181 | 0 | | for (final Item item : mCurrentFindings) |
| 1182 | | | { |
| 1183 | 0 | | FindingsSummary.addFinding(item, summary); |
| 1184 | 0 | | if (Origin.COVERAGE.equals(item.getOrigin())) |
| 1185 | | | { |
| 1186 | 0 | | if (item.getCounter() != 0) |
| 1187 | | | { |
| 1188 | 0 | | summary.addCoveredLine(); |
| 1189 | | | } |
| 1190 | | | else |
| 1191 | | | { |
| 1192 | 0 | | summary.addViolation(Severity.COVERAGE); |
| 1193 | | | } |
| 1194 | | | } |
| 1195 | | | else |
| 1196 | | | { |
| 1197 | 0 | | summary.addViolation(item.getSeverity()); |
| 1198 | | | } |
| 1199 | | | } |
| 1200 | 0 | | return summary; |
| 1201 | | | } |
| 1202 | | | |
| 1203 | | | private void fillFindingsInFile ( |
| 1204 | | | org.jcoderz.phoenix.report.jaxb.File data) |
| 1205 | | | { |
| 1206 | 0 | (18) | for (final Item item : (List<Item>) data.getItem()) |
| 1207 | | | { |
| 1208 | 0 | | final int lineNumber = item.getLine(); |
| 1209 | 0 | | List<Item> itemsInLine = mFindingsInFile.get(lineNumber); |
| 1210 | 0 | | if (itemsInLine == null) |
| 1211 | | | { |
| 1212 | 0 | | itemsInLine = new ArrayList<Item>(); |
| 1213 | 0 | | mFindingsInFile.put(lineNumber, itemsInLine); |
| 1214 | | | } |
| 1215 | 0 | | itemsInLine.add(item); |
| 1216 | 0 | | } |
| 1217 | 0 | | } |
| 1218 | | | |
| 1219 | | | |
| 1220 | | | |
| 1221 | | | @param |
| 1222 | | | |
| 1223 | | | @param |
| 1224 | | | @return |
| 1225 | | | |
| 1226 | | | |
| 1227 | | | private static String createStyle (String packageName, String style) |
| 1228 | | | { |
| 1229 | | (19) | |
| 1230 | 0 | | String result = ""; |
| 1231 | 0 | | if (style != null) |
| 1232 | | | { |
| 1233 | | | final String styleLink; |
| 1234 | 0 | | if (style.indexOf("//") != -1) |
| 1235 | | | { |
| 1236 | 0 | | styleLink = style; |
| 1237 | | | } |
| 1238 | | | else |
| 1239 | | | { |
| 1240 | 0 | | styleLink = relativeRoot(packageName, style); |
| 1241 | | | } |
| 1242 | 0 | | result = "<link rel='stylesheet' type='text/css' href='" |
| 1243 | | | + styleLink + "' />"; |
| 1244 | | | } |
| 1245 | 0 | | return result; |
| 1246 | | | } |
| 1247 | | | |
| 1248 | | | private Severity errorLevel (int line) |
| 1249 | | | { |
| 1250 | 0 | | Severity severity = Severity.OK; |
| 1251 | | | |
| 1252 | 0 | | final Iterator<Item> active = mActiveItems.iterator(); |
| 1253 | | | |
| 1254 | 0 | | while (active.hasNext()) |
| 1255 | | | { |
| 1256 | 0 | | final Item item = active.next(); |
| 1257 | 0 | | if (item.getEndLine() < line) |
| 1258 | | | { |
| 1259 | 0 | | active.remove(); |
| 1260 | | | } |
| 1261 | | | else |
| 1262 | | | { |
| 1263 | 0 | | severity = severity.max(item.getSeverity()); |
| 1264 | | | } |
| 1265 | 0 | | } |
| 1266 | | | |
| 1267 | | | |
| 1268 | 0 | | final Iterator<Item> items = findingsInLine(line); |
| 1269 | 0 | | while (items.hasNext()) |
| 1270 | | | { |
| 1271 | 0 | | final Item item = items.next(); |
| 1272 | 0 | | if (item.getOrigin().equals(Origin.COVERAGE)) |
| 1273 | | | { |
| 1274 | 0 | | if (item.getCounter() == 0) |
| 1275 | | | { |
| 1276 | 0 | | severity = severity.max(Severity.COVERAGE); |
| 1277 | | | } |
| 1278 | | | } |
| 1279 | | | else |
| 1280 | | | { |
| 1281 | 0 | | severity = severity.max(item.getSeverity()); |
| 1282 | 0 | | if (item.getEndLine() > line) |
| 1283 | | | { |
| 1284 | 0 | | mActiveItems.add(item); |
| 1285 | | | } |
| 1286 | | | } |
| 1287 | 0 | | } |
| 1288 | 0 | | return severity; |
| 1289 | | | } |
| 1290 | | | |
| 1291 | | | private Iterator<Item> findingsInLine (int line) |
| 1292 | | | { |
| 1293 | 0 | | final List<Item> findingsInLine = mFindingsInFile.get(line); |
| 1294 | | | final Iterator<Item> result; |
| 1295 | 0 | | if (findingsInLine == null) |
| 1296 | | | { |
| 1297 | 0 | (20) | result = EmptyIterator.EMPTY_ITERATOR; |
| 1298 | | | } |
| 1299 | | | else |
| 1300 | | | { |
| 1301 | 0 | | result = findingsInLine.iterator(); |
| 1302 | | | } |
| 1303 | 0 | | return result; |
| 1304 | | | } |
| 1305 | | | |
| 1306 | | | private String getHits (int line) |
| 1307 | | | { |
| 1308 | 0 | | String hits = " "; |
| 1309 | | | |
| 1310 | 0 | | final Iterator<Item> items = findingsInLine(line); |
| 1311 | | | |
| 1312 | 0 | | while (items.hasNext()) |
| 1313 | | | { |
| 1314 | 0 | | final Item item = items.next(); |
| 1315 | 0 | | if (Origin.COVERAGE.equals(item.getOrigin())) |
| 1316 | | | { |
| 1317 | 0 | | hits = String.valueOf(item.getCounter()); |
| 1318 | 0 | | break; |
| 1319 | | | } |
| 1320 | 0 | | } |
| 1321 | 0 | | return hits; |
| 1322 | | | } |
| 1323 | | | |
| 1324 | | | |
| 1325 | | | |
| 1326 | | | @param |
| 1327 | | | @return |
| 1328 | | | |
| 1329 | | | private String getIcons (int line) |
| 1330 | | | { |
| 1331 | 0 | | final StringBuilder icons = new StringBuilder(); |
| 1332 | | | |
| 1333 | | | |
| 1334 | 0 | | final Iterator<Item> items = findingsInLine(line); |
| 1335 | 0 | | while (items.hasNext()) |
| 1336 | | | { |
| 1337 | 0 | | final Item item = items.next(); |
| 1338 | 0 | | if (Origin.COVERAGE.equals(item.getOrigin())) |
| 1339 | | | { |
| 1340 | 0 | | if (item.getCounter() == 0) |
| 1341 | | | { |
| 1342 | 0 | | items.remove(); |
| 1343 | | | } |
| 1344 | | | } |
| 1345 | 0 | | else if (item.getSeverity() == Severity.FILTERED |
| 1346 | | | || item.isOld()) |
| 1347 | | | { |
| 1348 | | | |
| 1349 | | | |
| 1350 | | | } |
| 1351 | | | else |
| 1352 | | | { |
| 1353 | 0 | | mHandledFindings.add(item); |
| 1354 | | | |
| 1355 | 0 | | mGetIconsStringBuffer.setLength(0); |
| 1356 | 0 | | mGetIconsStringBuffer.append("<a href='#FINDING"); |
| 1357 | 0 | | mGetIconsStringBuffer.append(mHandledFindings.size()); |
| 1358 | 0 | | mGetIconsStringBuffer.append("' title='"); |
| 1359 | 0 | | mGetIconsStringBuffer.append( |
| 1360 | | | XmlUtil.attributeEscape(item.getMessage())); |
| 1361 | 0 | | mGetIconsStringBuffer.append("'><span class='"); |
| 1362 | 0 | | mGetIconsStringBuffer.append(item.getOrigin()); |
| 1363 | 0 | | mGetIconsStringBuffer.append("note'>("); |
| 1364 | 0 | | mGetIconsStringBuffer.append(mHandledFindings.size()); |
| 1365 | 0 | | mGetIconsStringBuffer.append(")</span></a>"); |
| 1366 | 0 | | icons.append(mGetIconsStringBuffer); |
| 1367 | 0 | | if (item.isSetColumn() |
| 1368 | | | && (!item.isSetEndLine() |
| 1369 | | | || item.getEndLine() - line <= MAX_LINES_WITH_INLINE_MARK)) |
| 1370 | | | { |
| 1371 | 0 | | mFindingsInCurrentLine.add(item); |
| 1372 | | | } |
| 1373 | 0 | | items.remove(); |
| 1374 | | | } |
| 1375 | 0 | | } |
| 1376 | 0 | | if (icons.length() == 0) |
| 1377 | | | { |
| 1378 | 0 | | icons.append(" "); |
| 1379 | | | } |
| 1380 | 0 | | return icons.toString(); |
| 1381 | | | } |
| 1382 | | | |
| 1383 | | | |
| 1384 | | | |
| 1385 | | | |
| 1386 | | | |
| 1387 | | | <code></code> |
| 1388 | | | @param |
| 1389 | | | @return |
| 1390 | | | |
| 1391 | | | private String replaceLeadingSpaces (String in) |
| 1392 | | | { |
| 1393 | | | final String result; |
| 1394 | 0 | | if (in == null || in.length() == 0) |
| 1395 | | | { |
| 1396 | 0 | | result = " "; |
| 1397 | | | } |
| 1398 | 0 | | else if (in.charAt(0) == ' ' || in.charAt(0) == '\t') |
| 1399 | | | { |
| 1400 | 0 | | mStringBuilder.setLength(0); |
| 1401 | | | int i; |
| 1402 | 0 | (21) | int pos = 0; |
| 1403 | 0 | | for (i = 0; i < in.length() |
| 1404 | 0 | | && (in.charAt(i) == ' ' || in.charAt(i) == '\t'); i++) |
| 1405 | | | { |
| 1406 | 0 | | if (in.charAt(i) == ' ') |
| 1407 | | | { |
| 1408 | 0 | | mStringBuilder.append(" "); |
| 1409 | 0 | | pos++; |
| 1410 | | | } |
| 1411 | 0 | | else if (in.charAt(i) == '\t') |
| 1412 | | | { |
| 1413 | 0 | | mStringBuilder.append(" "); |
| 1414 | 0 | | pos++; |
| 1415 | 0 | | while (pos % mTabWidth != 0) |
| 1416 | | | { |
| 1417 | 0 | | mStringBuilder.append(" "); |
| 1418 | 0 | | pos++; |
| 1419 | | | } |
| 1420 | | | } |
| 1421 | | | |
| 1422 | | | } |
| 1423 | 0 | | mStringBuilder.append(in.substring(i)); |
| 1424 | 0 | | result = mStringBuilder.toString(); |
| 1425 | 0 | | } |
| 1426 | | | else |
| 1427 | | | { |
| 1428 | 0 | | result = in; |
| 1429 | | | } |
| 1430 | 0 | | return result; |
| 1431 | | | } |
| 1432 | | | |
| 1433 | | | |
| 1434 | | | |
| 1435 | | | |
| 1436 | | | private void addSummary (FileSummary summary) |
| 1437 | | | { |
| 1438 | 0 | | mAllFiles.add(summary); |
| 1439 | | | |
| 1440 | 0 | | List<FileSummary> packageList |
| 1441 | | | = mAllPackages.get(summary.getPackage()); |
| 1442 | | | |
| 1443 | 0 | | if (packageList == null) |
| 1444 | | | { |
| 1445 | 0 | | packageList = new ArrayList<FileSummary>(); |
| 1446 | 0 | | mAllPackages.put(summary.getPackage(), packageList); |
| 1447 | | | } |
| 1448 | 0 | | packageList.add(summary); |
| 1449 | | | |
| 1450 | 0 | | FileSummary packageSummary |
| 1451 | | | = mPackageSummary.get(summary.getPackage()); |
| 1452 | 0 | | if (packageSummary == null) |
| 1453 | | | { |
| 1454 | 0 | | packageSummary = new FileSummary(mPackage); |
| 1455 | 0 | | mPackageSummary.put(summary.getPackage(), packageSummary); |
| 1456 | | | } |
| 1457 | 0 | | packageSummary.add(summary); |
| 1458 | 0 | | mGlobalSummary.add(summary); |
| 1459 | 0 | | } |
| 1460 | | | |
| 1461 | | | private void createPackageSummary (List<FileSummary> pkg) |
| 1462 | | | throws IOException |
| 1463 | | | { |
| 1464 | 0 | | createPackageSummary(new FileSummary.SortByPackage(), pkg); |
| 1465 | 0 | | createPackageSummary(new FileSummary.SortByQuality(), pkg); |
| 1466 | 0 | | createPackageSummary(new FileSummary.SortByCoverage(), pkg); |
| 1467 | 0 | | } |
| 1468 | | | |
| 1469 | | | private void createPackageSummary (Comparator<FileSummary> order, |
| 1470 | | | List<FileSummary> pkg) |
| 1471 | | | throws IOException |
| 1472 | | | { |
| 1473 | 0 | | final String filename = fileNameForOrder(order); |
| 1474 | 0 | | final String packageName = pkg.get(0).getPackage(); |
| 1475 | 0 | | final String subdir = packageName.replaceAll("\\.", "/"); |
| 1476 | 0 | | final java.io.File dir = new java.io.File(mOutDir, subdir); |
| 1477 | 0 | | FileUtils.mkdirs(dir); |
| 1478 | | | |
| 1479 | 0 | | final BufferedWriter bw = openWriter(dir, filename); |
| 1480 | | | try |
| 1481 | | | { |
| 1482 | 0 | | htmlHeader(bw, packageName, packageName); |
| 1483 | 0 | | bw.write("<h1><a href='" + relativeRoot(packageName, filename) |
| 1484 | | | + "'>Project-Report " |
| 1485 | | | + mProjectName + "</a></h1>"); |
| 1486 | 0 | | bw.write("<h2>Packagesummary " + packageName + "</h2>"); |
| 1487 | 0 | | createClassListTable(bw, pkg, false, order); |
| 1488 | 0 | | bw.write("</body></html>"); |
| 1489 | | | } |
| 1490 | | | finally |
| 1491 | | | { |
| 1492 | 0 | | IoUtil.close(bw); |
| 1493 | 0 | | } |
| 1494 | 0 | | } |
| 1495 | | | |
| 1496 | | | private void createFullSummary () |
| 1497 | | | throws IOException |
| 1498 | | | { |
| 1499 | 0 | | createFullSummary(new FileSummary.SortByPackage()); |
| 1500 | 0 | | createFullSummary(new FileSummary.SortByQuality()); |
| 1501 | 0 | | createFullSummary(new FileSummary.SortByCoverage()); |
| 1502 | 0 | | } |
| 1503 | | | |
| 1504 | | (22) | private void createFullSummary (Comparator<FileSummary> order) |
| 1505 | | | throws IOException |
| 1506 | | | { |
| 1507 | 0 | | final String filename = fileNameForOrder(order); |
| 1508 | 0 | | final BufferedWriter bw = openWriter(filename); |
| 1509 | | | try |
| 1510 | | | { |
| 1511 | 0 | | htmlHeader(bw, "Project Report " + mProjectName, ""); |
| 1512 | | | |
| 1513 | 0 | | bw.write("<h1>Project Report " + mProjectName + "</h1>"); |
| 1514 | | | |
| 1515 | 0 | | bw.write("<table border='0' cellpadding='2' cellspacing='0' " |
| 1516 | | | + "width='95%'>"); |
| 1517 | 0 | | bw.write("<thead><tr><th>"); |
| 1518 | 0 | (23) | if (filename != SORT_BY_PACKAGE_INDEX) |
| 1519 | | | { |
| 1520 | 0 | | bw.write("<a href='" + SORT_BY_PACKAGE_INDEX |
| 1521 | | | + "' title='Sort by name'>"); |
| 1522 | | | } |
| 1523 | 0 | | bw.write("Package"); |
| 1524 | 0 | | if (filename != SORT_BY_PACKAGE_INDEX) |
| 1525 | | | { |
| 1526 | 0 | | bw.write("</a>"); |
| 1527 | | | } |
| 1528 | 0 | | bw.write("</th><th>findings</th>"); |
| 1529 | 0 | | bw.write("<th>files</th><th>lines</th>"); |
| 1530 | 0 | | if (mCoverageData) |
| 1531 | | | { |
| 1532 | 0 | | bw.write("<th>%</th><th>"); |
| 1533 | 0 | | if (filename != SORT_BY_COVERAGE_INDEX) |
| 1534 | | | { |
| 1535 | 0 | | bw.write("<a href='" + SORT_BY_COVERAGE_INDEX |
| 1536 | | | + "' title='Sort by coverage'>"); |
| 1537 | | | } |
| 1538 | 0 | | bw.write("Coverage"); |
| 1539 | 0 | | if (filename != SORT_BY_COVERAGE_INDEX) |
| 1540 | | | { |
| 1541 | 0 | | bw.write("</a>"); |
| 1542 | | | } |
| 1543 | 0 | | bw.write("</th>"); |
| 1544 | | | } |
| 1545 | 0 | | bw.write("<th>%</th><th class='remainder'>"); |
| 1546 | 0 | | if (filename != SORT_BY_QUALITY_INDEX) |
| 1547 | | | { |
| 1548 | 0 | | bw.write("<a href='" + SORT_BY_QUALITY_INDEX |
| 1549 | | | + "' title='Sort by quality'>"); |
| 1550 | | | } |
| 1551 | 0 | | bw.write("Quality"); |
| 1552 | 0 | | if (filename != SORT_BY_QUALITY_INDEX) |
| 1553 | | | { |
| 1554 | 0 | | bw.write("</a>"); |
| 1555 | | | } |
| 1556 | 0 | | bw.write("</th></tr></thead>"); |
| 1557 | 0 | | bw.write("<tbody>"); |
| 1558 | 0 | | bw.write(NEWLINE); |
| 1559 | 0 | | bw.write("<tr class='odd'><td class='classname" + LAST_MARKER + "'>"); |
| 1560 | 0 | | bw.write("Overall summary"); |
| 1561 | 0 | | bw.write("</td>"); |
| 1562 | 0 | | hitsCell(bw, String.valueOf(mGlobalSummary.getNumberOfFindings()), |
| 1563 | | | true); |
| 1564 | 0 | | hitsCell(bw, String.valueOf(mGlobalSummary.getNumberOfFiles()), true); |
| 1565 | 0 | | hitsCell(bw, String.valueOf(mGlobalSummary.getLinesOfCode()), true); |
| 1566 | 0 | | if (mCoverageData) |
| 1567 | | | { |
| 1568 | 0 | | hitsCell(bw, String.valueOf(mGlobalSummary.getCoverageAsString()), |
| 1569 | | | true); |
| 1570 | 0 | | bw.write("<td valign='middle' class='hits" + LAST_MARKER |
| 1571 | | | + "' width='100'>"); |
| 1572 | 0 | | bw.write(mGlobalSummary.getCoverageBar()); |
| 1573 | 0 | | bw.write("</td>"); |
| 1574 | | | } |
| 1575 | 0 | | hitsCell(bw, String.valueOf(mGlobalSummary.getQuality()) + "%", true); |
| 1576 | 0 | | bw.write("<td valign='middle' class='code" + LAST_MARKER |
| 1577 | | | + "' width='100'>"); |
| 1578 | 0 | | bw.write(mGlobalSummary.getPercentBar()); |
| 1579 | 0 | | bw.write("</td></tr>"); |
| 1580 | 0 | | bw.write(NEWLINE); |
| 1581 | 0 | | bw.write("</tbody>"); |
| 1582 | 0 | | bw.write("</table>"); |
| 1583 | | | |
| 1584 | 0 | | bw.write("<h1><a href='findings.html'>View by Finding</a></h1>"); |
| 1585 | 0 | | bw.write("<h1><a href='age-Build.html'>View by Age per Build</a> " |
| 1586 | | | + "<a href='age-Day.html'> Day</a> " |
| 1587 | | | + "<a href='age-Week.html'> Week</a> " |
| 1588 | | | + "<a href='age-Month.html'> Month</a> " |
| 1589 | | | + "<a href='age-Old.html'> Old</a></h1>"); |
| 1590 | | | |
| 1591 | 0 | | bw.write("<h1>Packages</h1>"); |
| 1592 | 0 | | bw.write("<table border='0' cellpadding='2' cellspacing='0' " |
| 1593 | | | + "width='95%'>"); |
| 1594 | 0 | | bw.write("<thead><tr><th>Package</th>" |
| 1595 | | | + "<th>findings</th><th>files</th><th>lines</th>"); |
| 1596 | 0 | | if (mCoverageData) |
| 1597 | | | { |
| 1598 | 0 | | bw.write("<th>%</th><th>Coverage</th>"); |
| 1599 | | | } |
| 1600 | 0 | | bw.write("<th>%</th><th class='remainder'>Quality</th></tr></thead>"); |
| 1601 | 0 | | bw.write("<tbody>"); |
| 1602 | 0 | | bw.write(NEWLINE); |
| 1603 | | | |
| 1604 | 0 | | final Set<FileSummary> packages = new TreeSet<FileSummary>(order); |
| 1605 | 0 | | packages.addAll(mPackageSummary.values()); |
| 1606 | | | |
| 1607 | 0 | | int pos = 0; |
| 1608 | 0 | | final Iterator<FileSummary> i = packages.iterator(); |
| 1609 | 0 | | while (i.hasNext()) |
| 1610 | | | { |
| 1611 | 0 | | pos++; |
| 1612 | 0 | | final FileSummary pkg = i.next(); |
| 1613 | 0 | | final boolean isLast = !i.hasNext(); |
| 1614 | 0 | | appendPackageLink(bw, pkg, filename, pos, isLast); |
| 1615 | 0 | | } |
| 1616 | 0 | | bw.write("</tbody></table>\n"); |
| 1617 | | | |
| 1618 | | | |
| 1619 | 0 | | createUnassignedFindingsTable(bw); |
| 1620 | | | |
| 1621 | 0 | | bw.write("<h1>Java Files</h1>"); |
| 1622 | 0 | | createClassListTable(bw, mAllFiles, true, order); |
| 1623 | | | |
| 1624 | 0 | | bw.write("</body></html>"); |
| 1625 | | | } |
| 1626 | | | finally |
| 1627 | | | { |
| 1628 | 0 | | IoUtil.close(bw); |
| 1629 | 0 | | } |
| 1630 | 0 | | } |
| 1631 | | | |
| 1632 | | | private void createUnassignedFindingsTable (final BufferedWriter bw) |
| 1633 | | | throws IOException |
| 1634 | | | { |
| 1635 | 0 | | boolean tableOpened = false; |
| 1636 | 0 | | int row = 0; |
| 1637 | 0 | | for (final org.jcoderz.phoenix.report.jaxb.File file : mGlobalFindings) |
| 1638 | | | { |
| 1639 | 0 | (24) | for (final Item item : (List<Item>) file.getItem()) |
| 1640 | | | { |
| 1641 | 0 | | row++; |
| 1642 | 0 | | if (!tableOpened) |
| 1643 | | | { |
| 1644 | 0 | | bw.write("<h1>Unassigned findings</h1>"); |
| 1645 | 0 | | bw.write("<table border='0' cellpadding='0' " |
| 1646 | | | + "cellspacing='0' width='95%'>"); |
| 1647 | 0 | | tableOpened = true; |
| 1648 | | | } |
| 1649 | 0 | | bw.write("<tr class='"); |
| 1650 | 0 | | bw.write(item.getSeverity().toString()); |
| 1651 | 0 | | bw.write(Java2Html.toOddEvenString(row)); |
| 1652 | 0 | | bw.write("'><td class='unassigned-origin'>"); |
| 1653 | 0 | | bw.write(ObjectUtil.toStringOrEmpty(item.getOrigin())); |
| 1654 | 0 | | bw.write("</td><td class='unassigned-filename'>"); |
| 1655 | 0 | | bw.write(cutPath(file.getName())); |
| 1656 | 0 | | bw.write("</td><td class='unassigned-data' width='100%'>"); |
| 1657 | 0 | | bw.write(item.getMessage()); |
| 1658 | 0 | | bw.write("</td></tr>"); |
| 1659 | | | |
| 1660 | 0 | | FindingsSummary.addFinding(item, mGlobalSummary); |
| 1661 | | | } |
| 1662 | | | } |
| 1663 | 0 | | if (tableOpened) |
| 1664 | | | { |
| 1665 | 0 | | bw.write("</table>"); |
| 1666 | | | } |
| 1667 | 0 | | } |
| 1668 | | | |
| 1669 | | | private void appendPackageLink (final BufferedWriter bw, |
| 1670 | | | final FileSummary pkg, final String filename, final int pos, |
| 1671 | | | final boolean isLast) |
| 1672 | | | throws IOException |
| 1673 | | | { |
| 1674 | 0 | | final String name = pkg.getPackage(); |
| 1675 | 0 | | final String subdir = name.replaceAll("\\.", "/"); |
| 1676 | 0 | | bw.write("<tr class='" + Java2Html.toOddEvenString(pos) |
| 1677 | | | + "'><td class='classname"); |
| 1678 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 1679 | 0 | | bw.write("'><a href='" + subdir + "/" + filename + "'>"); |
| 1680 | 0 | | bw.write(pkg.getPackage()); |
| 1681 | 0 | | bw.write("</a></td>"); |
| 1682 | 0 | | hitsCell(bw, String.valueOf(pkg.getNumberOfFindings()), isLast); |
| 1683 | 0 | | hitsCell(bw, String.valueOf(pkg.getNumberOfFiles()), isLast); |
| 1684 | 0 | | hitsCell(bw, String.valueOf(pkg.getLinesOfCode()), isLast); |
| 1685 | 0 | | if (mCoverageData) |
| 1686 | | | { |
| 1687 | 0 | | hitsCell(bw, String.valueOf(pkg.getCoverageAsString()), isLast); |
| 1688 | 0 | | bw.write("<td valign='middle' class='hits"); |
| 1689 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 1690 | 0 | | bw.write("' width='100'>"); |
| 1691 | 0 | | bw.write(pkg.getCoverageBar()); |
| 1692 | 0 | | bw.write("</td>"); |
| 1693 | | | } |
| 1694 | 0 | | hitsCell(bw, String.valueOf(pkg.getQuality()) + "%", isLast); |
| 1695 | 0 | | bw.write("<td valign='middle' class='code"); |
| 1696 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 1697 | 0 | | bw.write("' width='100'>"); |
| 1698 | 0 | | bw.write(pkg.getPercentBar()); |
| 1699 | 0 | | bw.write("</td></tr>" + NEWLINE); |
| 1700 | 0 | | } |
| 1701 | | | |
| 1702 | | | |
| 1703 | | | |
| 1704 | | | @param |
| 1705 | | | @param |
| 1706 | | | |
| 1707 | | | |
| 1708 | | | private void htmlHeader (Writer bw, String title, String packageName) |
| 1709 | | | throws IOException |
| 1710 | | | { |
| 1711 | 0 | | bw.write("<?xml version='1.0' encoding='UTF-8'?>" + NEWLINE |
| 1712 | | | + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " |
| 1713 | | | + NEWLINE |
| 1714 | | | + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" |
| 1715 | | | + NEWLINE |
| 1716 | | | + "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'" |
| 1717 | | | + " lang='en'>" + NEWLINE |
| 1718 | | | + "<head>" + NEWLINE |
| 1719 | | | + "\t<title>"); |
| 1720 | 0 | | bw.write(title); |
| 1721 | 0 | | bw.write("</title>" + NEWLINE |
| 1722 | | | + "\t<meta name='author' content='jCoderZ java2html' />" + NEWLINE); |
| 1723 | 0 | | bw.write(createStyle(packageName, mStyle)); |
| 1724 | 0 | | bw.write(NEWLINE + "</head>" + NEWLINE + "<body>" + NEWLINE); |
| 1725 | 0 | | } |
| 1726 | | | |
| 1727 | | | |
| 1728 | | | |
| 1729 | | | |
| 1730 | | | |
| 1731 | | | private Date renderAgePage ( |
| 1732 | | | List<Item> findings, Date startDate, ReportInterval periode) |
| 1733 | | | throws IOException |
| 1734 | | | { |
| 1735 | 0 | | final Writer bw |
| 1736 | | | = openWriter(mOutDir, "age-" + periode.toString() + ".html"); |
| 1737 | 0 | | htmlHeader(bw, "Finding in " + periode.toString(), ""); |
| 1738 | | | |
| 1739 | 0 | | bw.write("<h1><a href='index.html'>View by Classes</a></h1>"); |
| 1740 | 0 | | bw.write("<h1><a href='findings.html'>View by Finding</a></h1>"); |
| 1741 | 0 | | bw.write("<h1><a href='age-Build.html'>View by Age per Build</a> " |
| 1742 | | | + "<a href='age-Day.html'> Day</a> " |
| 1743 | | | + "<a href='age-Week.html'> Week</a> " |
| 1744 | | | + "<a href='age-Month.html'> Month</a> " |
| 1745 | | | + "<a href='age-Old.html'> Old</a></h1>"); |
| 1746 | | | |
| 1747 | 0 | | if (ReportInterval.OLD != periode) |
| 1748 | | | { |
| 1749 | 0 | | bw.write("<h1>Current Findings by " + periode.toString() + "</h1>"); |
| 1750 | | | } |
| 1751 | | | else |
| 1752 | | | { |
| 1753 | 0 | | bw.write("<h1>Old findings since " + startDate + "</h1>"); |
| 1754 | | | } |
| 1755 | | | |
| 1756 | | | |
| 1757 | 0 | | int numberOfSegments = 0; |
| 1758 | 0 | | Date iStart = null; |
| 1759 | | | try |
| 1760 | | | { |
| 1761 | 0 | | Date iEnd = null; |
| 1762 | 0 | | final List<Item> interval = new ArrayList<Item>(); |
| 1763 | 0 | | for (Item i : findings) |
| 1764 | | | { |
| 1765 | 0 | | if (iEnd == null) |
| 1766 | | | { |
| 1767 | 0 | | if (i.getSince().before(startDate)) |
| 1768 | | | { |
| 1769 | 0 | | iStart = getPeriodStart(periode, i.getSince()); |
| 1770 | 0 | | iEnd = getPeriodEnd(periode, i.getSince()); |
| 1771 | | | } |
| 1772 | | | else |
| 1773 | | | { |
| 1774 | | | continue; |
| 1775 | | | } |
| 1776 | | | } |
| 1777 | 0 | | if (i.getSince().before(iStart)) |
| 1778 | | | { |
| 1779 | 0 | | Collections.sort(interval, new ItemSeverityComperator()); |
| 1780 | 0 | | createSegment(bw, interval, iStart, iEnd); |
| 1781 | 0 | | interval.clear(); |
| 1782 | 0 | | numberOfSegments++; |
| 1783 | 0 | | if (numberOfSegments > NUMBER_OF_AGE_SEGMENTS) |
| 1784 | | | { |
| 1785 | 0 | | break; |
| 1786 | | | } |
| 1787 | 0 | | iStart = getPeriodStart(periode, i.getSince()); |
| 1788 | 0 | | iEnd = getPeriodEnd(periode, i.getSince()); |
| 1789 | | | } |
| 1790 | 0 | | interval.add(i); |
| 1791 | | | } |
| 1792 | | | |
| 1793 | 0 | | if (!interval.isEmpty()) |
| 1794 | | | { |
| 1795 | 0 | | Collections.sort(interval, new ItemSeverityComperator()); |
| 1796 | 0 | | createSegment(bw, interval, iStart, iEnd); |
| 1797 | 0 | | interval.clear(); |
| 1798 | | | } |
| 1799 | | | } |
| 1800 | | | finally |
| 1801 | | | { |
| 1802 | 0 | | IoUtil.close(bw); |
| 1803 | 0 | | } |
| 1804 | 0 | | return iStart == null ? startDate : iStart; |
| 1805 | | | } |
| 1806 | | | |
| 1807 | | | |
| 1808 | | | |
| 1809 | | | private void createSegment ( |
| 1810 | | | Writer bw, List<Item> items, Date start, Date end) |
| 1811 | | | throws IOException |
| 1812 | | | { |
| 1813 | 0 | | if (!items.isEmpty()) |
| 1814 | | | { |
| 1815 | 0 | | openTable(bw, "Findings " + start |
| 1816 | | | + (start.equals(end) ? "" : (" - " + end)) |
| 1817 | | | + " " + items.size()); |
| 1818 | | | } |
| 1819 | 0 | | int pos = 0; |
| 1820 | 0 | | for (final Item item : items) |
| 1821 | | | { |
| 1822 | 0 | | createRow(bw, getFile(item), item, pos); |
| 1823 | 0 | | pos++; |
| 1824 | | | } |
| 1825 | 0 | | if (!items.isEmpty()) |
| 1826 | | | { |
| 1827 | 0 | | closeTable(bw); |
| 1828 | | | } |
| 1829 | | | |
| 1830 | 0 | | } |
| 1831 | | | |
| 1832 | | | private org.jcoderz.phoenix.report.jaxb.File getFile (Item item) |
| 1833 | | | { |
| 1834 | 0 | | return mItemToFileMap.get(item); |
| 1835 | | | } |
| 1836 | | | |
| 1837 | | | static Date getPeriodEnd ( |
| 1838 | | | ReportInterval periode, Date actualStart) |
| 1839 | | | { |
| 1840 | | | final Date result; |
| 1841 | 100 | | if (ReportInterval.BUILD == periode) |
| 1842 | | | { |
| 1843 | 0 | | result = actualStart.plus(1); |
| 1844 | | | } |
| 1845 | 100 | | else if (ReportInterval.DAY == periode) |
| 1846 | | | { |
| 1847 | 0 | | final Calendar cal |
| 1848 | | | = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
| 1849 | 0 | | cal.setTimeInMillis(actualStart.getTime()); |
| 1850 | 0 | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 1851 | 0 | | cal.set(Calendar.MINUTE, 0); |
| 1852 | 0 | | cal.set(Calendar.SECOND, 0); |
| 1853 | 0 | | cal.set(Calendar.MILLISECOND, 0); |
| 1854 | 0 | | cal.add(Calendar.DAY_OF_MONTH, 1); |
| 1855 | 0 | | result = new Date(cal.getTimeInMillis()); |
| 1856 | 0 | | } |
| 1857 | 100 | | else if (ReportInterval.WEEK == periode) |
| 1858 | | | { |
| 1859 | 100 | | final Calendar cal |
| 1860 | | | = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
| 1861 | 100 | | cal.setFirstDayOfWeek(Calendar.MONDAY); |
| 1862 | 100 | | cal.setTimeInMillis(actualStart.getTime()); |
| 1863 | 100 | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 1864 | 100 | | cal.set(Calendar.MINUTE, 0); |
| 1865 | 100 | | cal.set(Calendar.SECOND, 0); |
| 1866 | 100 | | cal.set(Calendar.MILLISECOND, 0); |
| 1867 | | | |
| 1868 | 100 | | int dayOffset |
| 1869 | | | = Calendar.MONDAY - cal.get(Calendar.DAY_OF_WEEK); |
| 1870 | 100 | | if (dayOffset <= 0) |
| 1871 | | | { |
| 1872 | 100 | | dayOffset += cal.getMaximum(Calendar.DAY_OF_WEEK); |
| 1873 | | | } |
| 1874 | 100 | | cal.add(Calendar.DAY_OF_MONTH, dayOffset); |
| 1875 | 100 | | result = new Date(cal.getTimeInMillis()); |
| 1876 | 100 | | } |
| 1877 | 0 | | else if (ReportInterval.MONTH == periode) |
| 1878 | | | { |
| 1879 | 0 | | final Calendar cal |
| 1880 | | | = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
| 1881 | 0 | | cal.setFirstDayOfWeek(Calendar.MONDAY); |
| 1882 | 0 | | cal.setTimeInMillis(actualStart.getTime()); |
| 1883 | 0 | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 1884 | 0 | | cal.set(Calendar.MINUTE, 0); |
| 1885 | 0 | | cal.set(Calendar.SECOND, 0); |
| 1886 | 0 | | cal.set(Calendar.MILLISECOND, 0); |
| 1887 | 0 | | cal.set(Calendar.DAY_OF_MONTH, 1); |
| 1888 | 0 | | cal.add(Calendar.MONTH, 1); |
| 1889 | 0 | | result = new Date(cal.getTimeInMillis()); |
| 1890 | 0 | | } |
| 1891 | 0 | | else if (ReportInterval.OLD == periode) |
| 1892 | | | { |
| 1893 | 0 | | result = actualStart; |
| 1894 | | | } |
| 1895 | | | else |
| 1896 | | | { |
| 1897 | 0 | | Assert.fail("Unsupported value for ReportInterval " + periode); |
| 1898 | 0 | | result = null; |
| 1899 | | | } |
| 1900 | 100 | | return result; |
| 1901 | | | } |
| 1902 | | | |
| 1903 | | | static Date getPeriodStart (ReportInterval periode, Date pos) |
| 1904 | | | { |
| 1905 | | | final Date result; |
| 1906 | 100 | | if (ReportInterval.BUILD == periode) |
| 1907 | | | { |
| 1908 | 0 | | result = pos; |
| 1909 | | | } |
| 1910 | 100 | | else if (ReportInterval.DAY == periode) |
| 1911 | | | { |
| 1912 | 0 | | final Calendar cal |
| 1913 | | | = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
| 1914 | 0 | | cal.setTimeInMillis(pos.getTime()); |
| 1915 | 0 | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 1916 | 0 | | cal.set(Calendar.MINUTE, 0); |
| 1917 | 0 | | cal.set(Calendar.SECOND, 0); |
| 1918 | 0 | | cal.set(Calendar.MILLISECOND, 0); |
| 1919 | 0 | | result = new Date(cal.getTimeInMillis()); |
| 1920 | 0 | | } |
| 1921 | 100 | | else if (ReportInterval.WEEK == periode) |
| 1922 | | | { |
| 1923 | 100 | | final Calendar cal |
| 1924 | | | = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
| 1925 | 100 | | cal.setFirstDayOfWeek(Calendar.MONDAY); |
| 1926 | 100 | | cal.setTimeInMillis(pos.getTime()); |
| 1927 | 100 | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 1928 | 100 | | cal.set(Calendar.MINUTE, 0); |
| 1929 | 100 | | cal.set(Calendar.SECOND, 0); |
| 1930 | 100 | | cal.set(Calendar.MILLISECOND, 0); |
| 1931 | 100 | | int dayOffset |
| 1932 | | | = Calendar.MONDAY - cal.get(Calendar.DAY_OF_WEEK); |
| 1933 | 100 | | if (dayOffset > 0) |
| 1934 | | | { |
| 1935 | 0 | | dayOffset -= cal.getMaximum(Calendar.DAY_OF_WEEK); |
| 1936 | | | } |
| 1937 | 100 | | cal.add(Calendar.DAY_OF_MONTH, dayOffset); |
| 1938 | 100 | | result = new Date(cal.getTimeInMillis()); |
| 1939 | 100 | | } |
| 1940 | 0 | | else if (ReportInterval.MONTH == periode) |
| 1941 | | | { |
| 1942 | 0 | | final Calendar cal |
| 1943 | | | = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
| 1944 | 0 | | cal.setFirstDayOfWeek(Calendar.MONDAY); |
| 1945 | 0 | | cal.setTimeInMillis(pos.getTime()); |
| 1946 | 0 | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 1947 | 0 | | cal.set(Calendar.MINUTE, 0); |
| 1948 | 0 | | cal.set(Calendar.SECOND, 0); |
| 1949 | 0 | | cal.set(Calendar.MILLISECOND, 0); |
| 1950 | 0 | | cal.set(Calendar.DAY_OF_MONTH, 1); |
| 1951 | 0 | | result = new Date(cal.getTimeInMillis()); |
| 1952 | 0 | | } |
| 1953 | 0 | | else if (ReportInterval.OLD == periode) |
| 1954 | | | { |
| 1955 | 0 | | result = Date.OLD_DATE; |
| 1956 | | | } |
| 1957 | | | else |
| 1958 | | | { |
| 1959 | 0 | | Assert.fail("Unsupported value for ReportInterval " + periode); |
| 1960 | 0 | | result = null; |
| 1961 | | | } |
| 1962 | 100 | | return result; |
| 1963 | | | } |
| 1964 | | | |
| 1965 | | | |
| 1966 | | | private static String relativeRoot (String currentPackage) |
| 1967 | | | { |
| 1968 | 0 | | return relativeRoot(currentPackage, "index.html"); |
| 1969 | | | } |
| 1970 | | | |
| 1971 | | | private static String relativeRoot (String currentPackage, String page) |
| 1972 | | | { |
| 1973 | 0 | | final StringBuilder rootDir = new StringBuilder(); |
| 1974 | | | |
| 1975 | 0 | | if (currentPackage.length() != 0) |
| 1976 | | | { |
| 1977 | 0 | | rootDir.append("../"); |
| 1978 | | | } |
| 1979 | | | |
| 1980 | 0 | | for (int i = 0; i < currentPackage.length(); i++) |
| 1981 | | | { |
| 1982 | 0 | | if (currentPackage.charAt(i) == '.') |
| 1983 | | | { |
| 1984 | 0 | | rootDir.append("../"); |
| 1985 | | | } |
| 1986 | | | } |
| 1987 | 0 | | rootDir.append(page); |
| 1988 | | | |
| 1989 | 0 | | return rootDir.toString().replaceAll("//", "/"); |
| 1990 | | | } |
| 1991 | | | |
| 1992 | | | private String cutPath (String fileName) |
| 1993 | | | { |
| 1994 | 0 | | String result = ObjectUtil.toStringOrEmpty(fileName); |
| 1995 | 0 | | if (fileName != null && fileName.toLowerCase(Constants.SYSTEM_LOCALE) |
| 1996 | | | .startsWith(mProjectHome.toLowerCase(Constants.SYSTEM_LOCALE))) |
| 1997 | | | { |
| 1998 | 0 | | result = fileName.substring(mProjectHome.length()); |
| 1999 | | | } |
| 2000 | 0 | | return result; |
| 2001 | | | } |
| 2002 | | | |
| 2003 | | | private String getCvsLink (String absFile) |
| 2004 | | | { |
| 2005 | | | String result; |
| 2006 | 0 | | if (mWebVcBase == null || mProjectHome == null) |
| 2007 | | | { |
| 2008 | 0 | | result = null; |
| 2009 | | | } |
| 2010 | 0 | | else if (absFile.toLowerCase(Constants.SYSTEM_LOCALE) |
| 2011 | | | .startsWith(mProjectHome.toLowerCase(Constants.SYSTEM_LOCALE))) |
| 2012 | | | { |
| 2013 | 0 | | result = absFile.substring(mProjectHome.length()); |
| 2014 | | | } |
| 2015 | | | else |
| 2016 | | | { |
| 2017 | 0 | | final String absPath |
| 2018 | | | = (new java.io.File(absFile)).getAbsolutePath(); |
| 2019 | 0 | | if (absPath.toLowerCase(Constants.SYSTEM_LOCALE).startsWith( |
| 2020 | | | mProjectHome.toLowerCase(Constants.SYSTEM_LOCALE))) |
| 2021 | | | { |
| 2022 | 0 | | result = absPath.substring(mProjectHome.length()); |
| 2023 | | | } |
| 2024 | | | else |
| 2025 | | | { |
| 2026 | 0 | | result = null; |
| 2027 | | | } |
| 2028 | | | |
| 2029 | | | } |
| 2030 | 0 | | if (result != null) |
| 2031 | | | { |
| 2032 | 0 | | result = mWebVcBase + result + mWebVcSuffix; |
| 2033 | 0 | | result = result.replaceAll("\\\\", "/"); |
| 2034 | | | } |
| 2035 | 0 | | return result; |
| 2036 | | | } |
| 2037 | | | |
| 2038 | | | |
| 2039 | | | |
| 2040 | | | @param |
| 2041 | | | @param |
| 2042 | | | @throws |
| 2043 | | | |
| 2044 | | | |
| 2045 | | | private void createCodeLine (Writer out, Syntax src) |
| 2046 | | | throws IOException |
| 2047 | | | { |
| 2048 | 0 | | String text = src.nextToken(); |
| 2049 | 0 | | String lastTokenType = null; |
| 2050 | 0 | | Item lastFinding = null; |
| 2051 | 0 | | boolean isFirst = true; |
| 2052 | 0 | | while (null != src.getCurrentTokenType()) |
| 2053 | | | { |
| 2054 | 0 | | final Item currentFinding |
| 2055 | | | = getCurrentFinding(text, src.getCurrentLineNumber(), |
| 2056 | | | src.getCurrentLinePos(), src.getCurrentTokenLength()); |
| 2057 | 0 | | if (currentFinding != lastFinding) |
| 2058 | | | { |
| 2059 | 0 | | if (lastTokenType != null) |
| 2060 | | | { |
| 2061 | 0 | | out.write("</span>"); |
| 2062 | 0 | | lastTokenType = null; |
| 2063 | | | } |
| 2064 | 0 | | if (lastFinding != null) |
| 2065 | | | { |
| 2066 | 0 | | out.write("</span>"); |
| 2067 | | | } |
| 2068 | 0 | | if (currentFinding != null) |
| 2069 | | | { |
| 2070 | 0 | | out.write("<span class='finding-"); |
| 2071 | 0 | | out.write(currentFinding.getSeverity().toString()); |
| 2072 | 0 | | out.write("' title='"); |
| 2073 | 0 | | out.write( |
| 2074 | | | XmlUtil.attributeEscape(currentFinding.getMessage())); |
| 2075 | 0 | | out.write("'>"); |
| 2076 | | | } |
| 2077 | 0 | | lastFinding = currentFinding; |
| 2078 | | | } |
| 2079 | 0 | | final String tokenType = src.getCurrentTokenType(); |
| 2080 | 0 | | if (!tokenType.equals(lastTokenType)) |
| 2081 | | | { |
| 2082 | 0 | | if (lastTokenType != null) |
| 2083 | | | { |
| 2084 | 0 | | out.write("</span>"); |
| 2085 | 0 | | isFirst = false; |
| 2086 | | | } |
| 2087 | 0 | | out.write("<span class='code-"); |
| 2088 | 0 | | out.write(tokenType); |
| 2089 | 0 | | out.write("'>"); |
| 2090 | | | } |
| 2091 | 0 | | String xml = XmlUtil.escape(text); |
| 2092 | 0 | | if (isFirst) |
| 2093 | | | { |
| 2094 | 0 | | xml = replaceLeadingSpaces(xml); |
| 2095 | | | } |
| 2096 | 0 | | out.write(xml); |
| 2097 | | | |
| 2098 | 0 | | lastTokenType = tokenType; |
| 2099 | 0 | | text = src.nextToken(); |
| 2100 | 0 | | } |
| 2101 | 0 | | if (lastTokenType != null) |
| 2102 | | | { |
| 2103 | 0 | | out.write("</span>"); |
| 2104 | | | } |
| 2105 | 0 | | if (lastFinding != null) |
| 2106 | | | { |
| 2107 | 0 | | out.write("</span>"); |
| 2108 | | | } |
| 2109 | 0 | | } |
| 2110 | | | |
| 2111 | | (25) | private Item getCurrentFinding ( |
| 2112 | | | String text, int currentLineNumber, int currentLinePos, int tokenLen) |
| 2113 | | | { |
| 2114 | 0 | | Item theFinding = null; |
| 2115 | 0 | | final Iterator<Item> i = mFindingsInCurrentLine.iterator(); |
| 2116 | 0 | | while (i.hasNext()) |
| 2117 | | | { |
| 2118 | 0 | | final Item finding = i.next(); |
| 2119 | | | |
| 2120 | 0 | | if (finding.getEndLine() < currentLineNumber |
| 2121 | | | && finding.getLine() < currentLineNumber) |
| 2122 | | | { |
| 2123 | 0 | | i.remove(); |
| 2124 | 0 | | continue; |
| 2125 | | | } |
| 2126 | | | |
| 2127 | 0 | | final int start = |
| 2128 | | | finding.getLine() == currentLineNumber |
| 2129 | | | ? finding.getColumn() : 0; |
| 2130 | 0 | | int end = |
| 2131 | | | finding.getEndLine() == currentLineNumber |
| 2132 | | | ? finding.getEndColumn() : ABSOLUTE_END_OF_LINE; |
| 2133 | 0 | | if (finding.getEndLine() == 0) |
| 2134 | | | { |
| 2135 | 0 | | end = finding.getEndColumn(); |
| 2136 | | | } |
| 2137 | | | |
| 2138 | | (26) | |
| 2139 | | | |
| 2140 | 0 | | if ((start == currentLinePos && end == 0) |
| 2141 | | | |
| 2142 | | | || (start <= currentLinePos && end >= currentLinePos) |
| 2143 | | | |
| 2144 | | | || (start >= currentLinePos |
| 2145 | | | && start < currentLinePos + tokenLen)) |
| 2146 | | | { |
| 2147 | 0 | | if (theFinding == null |
| 2148 | | | || finding.getSeverity().compareTo( |
| 2149 | | | theFinding.getSeverity()) > 0) |
| 2150 | | | { |
| 2151 | 0 | | theFinding = finding; |
| 2152 | | | } |
| 2153 | | | } |
| 2154 | 0 | | } |
| 2155 | 0 | | return theFinding; |
| 2156 | | | } |
| 2157 | | | |
| 2158 | | | |
| 2159 | | | |
| 2160 | | | |
| 2161 | | | |
| 2162 | | | |
| 2163 | | | private void createClassListTable (BufferedWriter bw, |
| 2164 | | | Collection<FileSummary> files, boolean fullPackageNames, |
| 2165 | | | Comparator<FileSummary> order) |
| 2166 | | | throws IOException |
| 2167 | | | { |
| 2168 | | | |
| 2169 | 0 | | if (!files.isEmpty()) |
| 2170 | | | { |
| 2171 | 0 | | final String filename = fileNameForOrder(order); |
| 2172 | 0 | | final FileSummary[] summaries = |
| 2173 | | | files.toArray(new FileSummary[files.size()]); |
| 2174 | | | |
| 2175 | 0 | | Arrays.sort(summaries, order); |
| 2176 | | | |
| 2177 | 0 | | bw.write("<table border='0' cellpadding='2' cellspacing='0' " |
| 2178 | | | + "width='95%'>"); |
| 2179 | 0 | | bw.write("<thead><tr><th>"); |
| 2180 | 0 | (27) | if (filename != SORT_BY_PACKAGE_INDEX) |
| 2181 | | | { |
| 2182 | 0 | | bw.write("<a href='"); |
| 2183 | 0 | | bw.write(SORT_BY_PACKAGE_INDEX); |
| 2184 | 0 | | bw.write("' title='Sort by name'>"); |
| 2185 | | | } |
| 2186 | 0 | | bw.write("Classfile"); |
| 2187 | 0 | | if (filename != SORT_BY_PACKAGE_INDEX) |
| 2188 | | | { |
| 2189 | 0 | | bw.write("</a>"); |
| 2190 | | | } |
| 2191 | 0 | | bw.write("</th><th>findings</th><th>lines</th>"); |
| 2192 | 0 | | if (mCoverageData) |
| 2193 | | | { |
| 2194 | 0 | | bw.write("<th>%</th><th>"); |
| 2195 | 0 | | if (filename != SORT_BY_COVERAGE_INDEX) |
| 2196 | | | { |
| 2197 | 0 | | bw.write("<a href='"); |
| 2198 | 0 | | bw.write(SORT_BY_COVERAGE_INDEX); |
| 2199 | 0 | | bw.write("' title='Sort by coverage'>"); |
| 2200 | | | } |
| 2201 | 0 | | bw.write("Coverage"); |
| 2202 | 0 | | if (filename != SORT_BY_COVERAGE_INDEX) |
| 2203 | | | { |
| 2204 | 0 | | bw.write("</a>"); |
| 2205 | | | } |
| 2206 | 0 | | bw.write("</th>"); |
| 2207 | | | } |
| 2208 | 0 | | bw.write("<th>%</th><th class='remainder'>"); |
| 2209 | 0 | | if (filename != SORT_BY_QUALITY_INDEX) |
| 2210 | | | { |
| 2211 | 0 | | bw.write("<a href='"); |
| 2212 | 0 | | bw.write(SORT_BY_QUALITY_INDEX); |
| 2213 | 0 | | bw.write("' title='Sort by quality'>"); |
| 2214 | | | } |
| 2215 | 0 | | bw.write("Quality"); |
| 2216 | 0 | | if (filename != SORT_BY_QUALITY_INDEX) |
| 2217 | | | { |
| 2218 | 0 | | bw.write("</a>"); |
| 2219 | | | } |
| 2220 | 0 | | bw.write("</th></tr></thead>"); |
| 2221 | 0 | | bw.write("<tbody>"); |
| 2222 | 0 | | bw.write(NEWLINE); |
| 2223 | | | |
| 2224 | 0 | | int pos = 0; |
| 2225 | 0 | | final Iterator<FileSummary> i = Arrays.asList(summaries).iterator(); |
| 2226 | 0 | | while (i.hasNext()) |
| 2227 | | | { |
| 2228 | 0 | | pos++; |
| 2229 | 0 | | final FileSummary file = i.next(); |
| 2230 | 0 | | final boolean isLast = !i.hasNext(); |
| 2231 | 0 | | appendClassLink(bw, file, fullPackageNames, pos, isLast); |
| 2232 | 0 | | } |
| 2233 | 0 | | bw.write("</tbody>"); |
| 2234 | 0 | | bw.write("</table>"); |
| 2235 | 0 | | } |
| 2236 | | | else |
| 2237 | | | { |
| 2238 | 0 | | bw.write("EMPTY!?"); |
| 2239 | | | } |
| 2240 | 0 | | } |
| 2241 | | | |
| 2242 | | | private void appendClassLink (BufferedWriter bw, final FileSummary file, |
| 2243 | | | boolean fullPackageNames, int pos, final boolean isLast) |
| 2244 | | | throws IOException |
| 2245 | | | { |
| 2246 | | | final String name; |
| 2247 | | | final String link; |
| 2248 | 0 | | if (fullPackageNames) |
| 2249 | | | { |
| 2250 | 0 | | name = file.getPackage() + '.' + file.getClassName(); |
| 2251 | 0 | | link = file.getPackage().replaceAll("\\.", "/") + "/" |
| 2252 | | | + file.getClassName() + ".html"; |
| 2253 | | | } |
| 2254 | | | else |
| 2255 | | | { |
| 2256 | 0 | | name = file.getClassName(); |
| 2257 | 0 | | link = file.getClassName() + ".html"; |
| 2258 | | | } |
| 2259 | 0 | | bw.write("<tr class='"); |
| 2260 | 0 | | bw.write(Java2Html.toOddEvenString(pos)); |
| 2261 | 0 | | bw.write("'><td class='classname"); |
| 2262 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 2263 | 0 | | bw.write("'><a href='"); |
| 2264 | 0 | | bw.write(link); |
| 2265 | 0 | | bw.write("'>"); |
| 2266 | 0 | | bw.write(name); |
| 2267 | 0 | | bw.write("</a></td>"); |
| 2268 | 0 | | hitsCell(bw, String.valueOf(file.getNumberOfFindings()), isLast); |
| 2269 | 0 | | hitsCell(bw, String.valueOf(file.getLinesOfCode()), isLast); |
| 2270 | 0 | | if (mCoverageData) |
| 2271 | | | { |
| 2272 | 0 | | hitsCell(bw, file.getCoverageAsString(), isLast); |
| 2273 | 0 | | bw.write("<td valign='middle' class='hits"); |
| 2274 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 2275 | 0 | | bw.write("' width='100'>"); |
| 2276 | 0 | | bw.write(file.getCoverageBar()); |
| 2277 | 0 | | bw.write("</td>"); |
| 2278 | | | } |
| 2279 | 0 | | hitsCell(bw, String.valueOf(file.getQuality()) + "%", isLast); |
| 2280 | 0 | | bw.write("<td valign='middle' class='code"); |
| 2281 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 2282 | 0 | | bw.write("' width='100'>"); |
| 2283 | 0 | | bw.write(file.getPercentBar()); |
| 2284 | 0 | | bw.write("</td></tr>"); |
| 2285 | 0 | | bw.write(NEWLINE); |
| 2286 | 0 | | } |
| 2287 | | | |
| 2288 | | | private static String fileNameForOrder (Comparator<FileSummary> order) |
| 2289 | | | { |
| 2290 | | | String filename; |
| 2291 | 0 | (28) | if (order instanceof FileSummary.SortByPackage) |
| 2292 | | | { |
| 2293 | 0 | | filename = SORT_BY_PACKAGE_INDEX; |
| 2294 | | | } |
| 2295 | 0 | | else if (order instanceof FileSummary.SortByQuality) |
| 2296 | | | { |
| 2297 | 0 | | filename = SORT_BY_QUALITY_INDEX; |
| 2298 | | | } |
| 2299 | 0 | | else if (order instanceof FileSummary.SortByCoverage) |
| 2300 | | | { |
| 2301 | 0 | | filename = SORT_BY_COVERAGE_INDEX; |
| 2302 | | | } |
| 2303 | | | else |
| 2304 | | | { |
| 2305 | 0 | | throw new RuntimeException("Order not expected " + order); |
| 2306 | | | } |
| 2307 | 0 | | return filename; |
| 2308 | | | } |
| 2309 | | | |
| 2310 | | | |
| 2311 | | | |
| 2312 | | | |
| 2313 | | | @param |
| 2314 | | | @param |
| 2315 | | | @param |
| 2316 | | | @throws |
| 2317 | | | |
| 2318 | | | private static void hitsCell (BufferedWriter bw, |
| 2319 | | | String content, boolean isLast) |
| 2320 | | | throws IOException |
| 2321 | | | { |
| 2322 | 0 | | bw.write("<td valign='middle' class='hits"); |
| 2323 | 0 | | appendIf(bw, isLast, LAST_MARKER); |
| 2324 | 0 | | bw.write("'>"); |
| 2325 | 0 | | bw.write(content); |
| 2326 | 0 | | bw.write("</td>"); |
| 2327 | 0 | | } |
| 2328 | | | |
| 2329 | | | private static void appendIf (BufferedWriter bw, boolean condition, |
| 2330 | | | String str) |
| 2331 | | | throws IOException |
| 2332 | | | { |
| 2333 | 0 | | if (condition) |
| 2334 | | | { |
| 2335 | 0 | | bw.write(str); |
| 2336 | | | } |
| 2337 | 0 | | } |
| 2338 | | | |
| 2339 | | | private BufferedWriter openWriter (String filename) |
| 2340 | | | throws IOException |
| 2341 | | | { |
| 2342 | 0 | | return openWriter(mOutDir, filename); |
| 2343 | | | } |
| 2344 | | | |
| 2345 | | | private BufferedWriter openWriter (File dir, String filename) |
| 2346 | | | throws IOException |
| 2347 | | | { |
| 2348 | 0 | | FileOutputStream fos = null; |
| 2349 | 0 | | OutputStreamWriter osw = null; |
| 2350 | 0 | | BufferedWriter result = null; |
| 2351 | | | try |
| 2352 | | | { |
| 2353 | 0 | | fos = new FileOutputStream(new java.io.File(dir, filename)); |
| 2354 | 0 | | osw = new OutputStreamWriter(fos, Constants.ENCODING_UTF8); |
| 2355 | 0 | | result = new BufferedWriter(osw); |
| 2356 | | | } |
| 2357 | 0 | | catch (RuntimeException ex) |
| 2358 | | | { |
| 2359 | 0 | | IoUtil.close(result); |
| 2360 | 0 | | IoUtil.close(osw); |
| 2361 | 0 | | IoUtil.close(fos); |
| 2362 | 0 | | throw ex; |
| 2363 | | | } |
| 2364 | 0 | | catch (IOException ex) |
| 2365 | | | { |
| 2366 | 0 | | IoUtil.close(result); |
| 2367 | 0 | | IoUtil.close(osw); |
| 2368 | 0 | | IoUtil.close(fos); |
| 2369 | 0 | | throw ex; |
| 2370 | 0 | | } |
| 2371 | 0 | | return result; |
| 2372 | | | } |
| 2373 | | | |
| 2374 | | | private static String createReportLink ( |
| 2375 | | | org.jcoderz.phoenix.report.jaxb.File file) |
| 2376 | | | { |
| 2377 | 0 | | final String pkg |
| 2378 | | | = StringUtil.isEmptyOrNull(file.getPackage()) |
| 2379 | | | ? UNNAMED_PACKAGE_NAME : file.getPackage(); |
| 2380 | 0 | | String clazzName = ObjectUtil.toStringOrEmpty(file.getClassname()); |
| 2381 | | | |
| 2382 | | | |
| 2383 | 0 | | if (StringUtil.isEmptyOrNull(clazzName)) |
| 2384 | | | { |
| 2385 | 0 | | if (!StringUtil.isEmptyOrNull(file.getName())) |
| 2386 | | | { |
| 2387 | 0 | | clazzName = new File(file.getName()).getName(); |
| 2388 | | | } |
| 2389 | | | else |
| 2390 | | | { |
| 2391 | 0 | | clazzName = ""; |
| 2392 | | | } |
| 2393 | | | } |
| 2394 | | | |
| 2395 | 0 | | final String subdir = pkg.replaceAll("\\.", "/"); |
| 2396 | | | |
| 2397 | 0 | | return subdir + "/" + clazzName + ".html"; |
| 2398 | | | } |
| 2399 | | | |
| 2400 | 0 | | private static class ItemSeverityComperator |
| 2401 | | | implements Comparator<Item>, Serializable |
| 2402 | | | { |
| 2403 | | | private static final long serialVersionUID = 1L; |
| 2404 | | | |
| 2405 | | | public int compare (Item o1, Item o2) |
| 2406 | | | { |
| 2407 | 0 | | int result = 0; |
| 2408 | 0 | | result = -(o1.getSeverity().compareTo(o2.getSeverity())); |
| 2409 | 0 | | if (result == 0) |
| 2410 | | | { |
| 2411 | 0 | | result = o1.getSince().compareTo(o2.getSince()); |
| 2412 | | | } |
| 2413 | 0 | | if (result == 0) |
| 2414 | | | { |
| 2415 | 0 | | if (o1.getLine() > o2.getLine()) |
| 2416 | | | { |
| 2417 | 0 | | result = 1; |
| 2418 | | | } |
| 2419 | 0 | | else if (o1.getLine() < o2.getLine()) |
| 2420 | | | { |
| 2421 | 0 | | result = -1; |
| 2422 | | | } |
| 2423 | | | else |
| 2424 | | | { |
| 2425 | 0 | | result = 0; |
| 2426 | | | } |
| 2427 | | | } |
| 2428 | 0 | | if (result == 0) |
| 2429 | | | { |
| 2430 | 0 | | result = o1.getFindingType().compareTo(o2.getFindingType()); |
| 2431 | | | } |
| 2432 | 0 | | return result; |
| 2433 | | | } |
| 2434 | | | } |
| 2435 | | | |
| 2436 | 0 | | private static class ItemAgeComperator |
| 2437 | | | implements Comparator<Item>, Serializable |
| 2438 | | | { |
| 2439 | | | private static final long serialVersionUID = 1L; |
| 2440 | | | |
| 2441 | | | public int compare (Item o1, Item o2) |
| 2442 | | | { |
| 2443 | 0 | | final Date since1 |
| 2444 | | | = o1.isSetSince() ? o1.getSince() : Date.OLD_DATE; |
| 2445 | 0 | | final Date since2 |
| 2446 | | | = o2.isSetSince() ? o2.getSince() : Date.OLD_DATE; |
| 2447 | 0 | | return since1.compareTo(since2); |
| 2448 | | | } |
| 2449 | | | } |
| 2450 | | | } |