| 1 | |
package org.apache.maven.plugin.checkstyle; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import java.io.File; |
| 23 | |
import java.util.ArrayList; |
| 24 | |
import java.util.Arrays; |
| 25 | |
import java.util.Collections; |
| 26 | |
import java.util.Iterator; |
| 27 | |
import java.util.List; |
| 28 | |
import java.util.ResourceBundle; |
| 29 | |
|
| 30 | |
import org.apache.maven.doxia.sink.Sink; |
| 31 | |
import org.apache.maven.doxia.tools.SiteTool; |
| 32 | |
import org.apache.maven.plugin.logging.Log; |
| 33 | |
import org.apache.maven.plugin.logging.SystemStreamLog; |
| 34 | |
import org.codehaus.plexus.util.StringUtils; |
| 35 | |
|
| 36 | |
import com.puppycrawl.tools.checkstyle.api.AuditEvent; |
| 37 | |
import com.puppycrawl.tools.checkstyle.api.CheckstyleException; |
| 38 | |
import com.puppycrawl.tools.checkstyle.api.Configuration; |
| 39 | |
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public class CheckstyleReportGenerator |
| 47 | |
{ |
| 48 | |
private Log log; |
| 49 | |
|
| 50 | |
private File basedir; |
| 51 | |
|
| 52 | |
private ResourceBundle bundle; |
| 53 | |
|
| 54 | |
private Sink sink; |
| 55 | |
|
| 56 | |
private SeverityLevel severityLevel; |
| 57 | |
|
| 58 | |
private Configuration checkstyleConfig; |
| 59 | |
|
| 60 | |
private boolean enableRulesSummary; |
| 61 | |
|
| 62 | |
private boolean enableSeveritySummary; |
| 63 | |
|
| 64 | |
private boolean enableFilesSummary; |
| 65 | |
|
| 66 | |
private boolean enableRSS; |
| 67 | |
|
| 68 | |
private SiteTool siteTool; |
| 69 | |
|
| 70 | |
private String xrefLocation; |
| 71 | |
|
| 72 | |
public CheckstyleReportGenerator( Sink sink, ResourceBundle bundle, File basedir, SiteTool siteTool ) |
| 73 | 0 | { |
| 74 | 0 | this.bundle = bundle; |
| 75 | |
|
| 76 | 0 | this.sink = sink; |
| 77 | |
|
| 78 | 0 | this.basedir = basedir; |
| 79 | |
|
| 80 | 0 | this.siteTool = siteTool; |
| 81 | |
|
| 82 | 0 | this.enableRulesSummary = true; |
| 83 | 0 | this.enableSeveritySummary = true; |
| 84 | 0 | this.enableFilesSummary = true; |
| 85 | 0 | this.enableRSS = true; |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
public Log getLog() |
| 89 | |
{ |
| 90 | 0 | if ( this.log == null ) |
| 91 | |
{ |
| 92 | 0 | this.log = new SystemStreamLog(); |
| 93 | |
} |
| 94 | 0 | return this.log; |
| 95 | |
} |
| 96 | |
|
| 97 | |
public void setLog( Log log ) |
| 98 | |
{ |
| 99 | 0 | this.log = log; |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
private String getTitle() |
| 103 | |
{ |
| 104 | |
String title; |
| 105 | |
|
| 106 | 0 | if ( getSeverityLevel() == null ) |
| 107 | |
{ |
| 108 | 0 | title = bundle.getString( "report.checkstyle.title" ); |
| 109 | |
} |
| 110 | |
else |
| 111 | |
{ |
| 112 | 0 | title = bundle.getString( "report.checkstyle.severity_title" ) + severityLevel.getName(); |
| 113 | |
} |
| 114 | |
|
| 115 | 0 | return title; |
| 116 | |
} |
| 117 | |
|
| 118 | |
public void generateReport( CheckstyleResults results ) |
| 119 | |
{ |
| 120 | 0 | doHeading(); |
| 121 | |
|
| 122 | 0 | if ( getSeverityLevel() == null ) |
| 123 | |
{ |
| 124 | 0 | if ( enableSeveritySummary ) |
| 125 | |
{ |
| 126 | 0 | doSeveritySummary( results ); |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | if ( enableFilesSummary ) |
| 130 | |
{ |
| 131 | 0 | doFilesSummary( results ); |
| 132 | |
} |
| 133 | |
|
| 134 | 0 | if ( enableRulesSummary ) |
| 135 | |
{ |
| 136 | 0 | doRulesSummary( results ); |
| 137 | |
} |
| 138 | |
} |
| 139 | |
|
| 140 | 0 | doDetails( results ); |
| 141 | 0 | sink.body_(); |
| 142 | 0 | sink.flush(); |
| 143 | 0 | sink.close(); |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
private void doHeading() |
| 147 | |
{ |
| 148 | 0 | sink.head(); |
| 149 | 0 | sink.title(); |
| 150 | 0 | sink.text( getTitle() ); |
| 151 | 0 | sink.title_(); |
| 152 | 0 | sink.head_(); |
| 153 | |
|
| 154 | 0 | sink.body(); |
| 155 | |
|
| 156 | 0 | sink.section1(); |
| 157 | 0 | sink.sectionTitle1(); |
| 158 | 0 | sink.text( getTitle() ); |
| 159 | 0 | sink.sectionTitle1_(); |
| 160 | |
|
| 161 | 0 | sink.paragraph(); |
| 162 | 0 | sink.text( bundle.getString( "report.checkstyle.checkstylelink" ) + " " ); |
| 163 | 0 | sink.link( "http://checkstyle.sourceforge.net/" ); |
| 164 | 0 | sink.text( "Checkstyle" ); |
| 165 | 0 | sink.link_(); |
| 166 | 0 | sink.text( "." ); |
| 167 | |
|
| 168 | 0 | if ( enableRSS ) |
| 169 | |
{ |
| 170 | 0 | sink.nonBreakingSpace(); |
| 171 | 0 | sink.link( "checkstyle.rss" ); |
| 172 | 0 | sink.figure(); |
| 173 | 0 | sink.figureCaption(); |
| 174 | 0 | sink.text( "rss feed" ); |
| 175 | 0 | sink.figureCaption_(); |
| 176 | 0 | sink.figureGraphics( "images/rss.png" ); |
| 177 | 0 | sink.figure_(); |
| 178 | 0 | sink.link_(); |
| 179 | |
} |
| 180 | |
|
| 181 | 0 | sink.paragraph_(); |
| 182 | 0 | sink.section1_(); |
| 183 | 0 | } |
| 184 | |
|
| 185 | |
private void iconSeverity( String level ) |
| 186 | |
{ |
| 187 | 0 | if ( SeverityLevel.INFO.getName().equalsIgnoreCase( level ) ) |
| 188 | |
{ |
| 189 | 0 | iconInfo(); |
| 190 | |
} |
| 191 | 0 | else if ( SeverityLevel.WARNING.getName().equalsIgnoreCase( level ) ) |
| 192 | |
{ |
| 193 | 0 | iconWarning(); |
| 194 | |
} |
| 195 | 0 | else if ( SeverityLevel.ERROR.getName().equalsIgnoreCase( level ) ) |
| 196 | |
{ |
| 197 | 0 | iconError(); |
| 198 | |
} |
| 199 | 0 | } |
| 200 | |
|
| 201 | |
private void iconInfo() |
| 202 | |
{ |
| 203 | 0 | sink.figure(); |
| 204 | 0 | sink.figureCaption(); |
| 205 | 0 | sink.text( bundle.getString( "report.checkstyle.infos" ) ); |
| 206 | 0 | sink.figureCaption_(); |
| 207 | 0 | sink.figureGraphics( "images/icon_info_sml.gif" ); |
| 208 | 0 | sink.figure_(); |
| 209 | 0 | } |
| 210 | |
|
| 211 | |
private void iconWarning() |
| 212 | |
{ |
| 213 | 0 | sink.figure(); |
| 214 | 0 | sink.figureCaption(); |
| 215 | 0 | sink.text( bundle.getString( "report.checkstyle.warnings" ) ); |
| 216 | 0 | sink.figureCaption_(); |
| 217 | 0 | sink.figureGraphics( "images/icon_warning_sml.gif" ); |
| 218 | 0 | sink.figure_(); |
| 219 | 0 | } |
| 220 | |
|
| 221 | |
private void iconError() |
| 222 | |
{ |
| 223 | 0 | sink.figure(); |
| 224 | 0 | sink.figureCaption(); |
| 225 | 0 | sink.text( bundle.getString( "report.checkstyle.errors" ) ); |
| 226 | 0 | sink.figureCaption_(); |
| 227 | 0 | sink.figureGraphics( "images/icon_error_sml.gif" ); |
| 228 | 0 | sink.figure_(); |
| 229 | 0 | } |
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
private String getConfigAttribute( Configuration config, List parentConfigurations, String attributeName, |
| 245 | |
String defaultValue ) |
| 246 | |
{ |
| 247 | |
String ret; |
| 248 | |
try |
| 249 | |
{ |
| 250 | 0 | ret = config.getAttribute( attributeName ); |
| 251 | |
} |
| 252 | 0 | catch ( CheckstyleException e ) |
| 253 | |
{ |
| 254 | |
|
| 255 | 0 | if ( parentConfigurations != null && !parentConfigurations.isEmpty() ) |
| 256 | |
{ |
| 257 | 0 | Configuration parentConfiguration = |
| 258 | |
(Configuration) parentConfigurations.get( parentConfigurations.size() - 1 ); |
| 259 | 0 | List newParentConfigurations = new ArrayList( parentConfigurations ); |
| 260 | |
|
| 261 | 0 | newParentConfigurations.remove( parentConfiguration ); |
| 262 | 0 | ret = getConfigAttribute( parentConfiguration, newParentConfigurations, attributeName, defaultValue ); |
| 263 | 0 | } |
| 264 | |
else |
| 265 | |
{ |
| 266 | 0 | ret = defaultValue; |
| 267 | |
} |
| 268 | 0 | } |
| 269 | 0 | return ret; |
| 270 | |
} |
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
private void doRulesSummary( CheckstyleResults results ) |
| 278 | |
{ |
| 279 | 0 | if ( checkstyleConfig == null ) |
| 280 | |
{ |
| 281 | 0 | return; |
| 282 | |
} |
| 283 | |
|
| 284 | 0 | sink.section1(); |
| 285 | 0 | sink.sectionTitle1(); |
| 286 | 0 | sink.text( bundle.getString( "report.checkstyle.rules" ) ); |
| 287 | 0 | sink.sectionTitle1_(); |
| 288 | |
|
| 289 | 0 | sink.table(); |
| 290 | |
|
| 291 | 0 | sink.tableRow(); |
| 292 | 0 | sink.tableHeaderCell(); |
| 293 | 0 | sink.text( bundle.getString( "report.checkstyle.rules" ) ); |
| 294 | 0 | sink.tableHeaderCell_(); |
| 295 | |
|
| 296 | 0 | sink.tableHeaderCell(); |
| 297 | 0 | sink.text( bundle.getString( "report.checkstyle.violations" ) ); |
| 298 | 0 | sink.tableHeaderCell_(); |
| 299 | |
|
| 300 | 0 | sink.tableHeaderCell(); |
| 301 | 0 | sink.text( bundle.getString( "report.checkstyle.column.severity" ) ); |
| 302 | 0 | sink.tableHeaderCell_(); |
| 303 | 0 | sink.tableRow_(); |
| 304 | |
|
| 305 | |
|
| 306 | 0 | if ( "checker".equalsIgnoreCase( checkstyleConfig.getName() ) ) |
| 307 | |
{ |
| 308 | 0 | doRuleChildren( checkstyleConfig, null, results ); |
| 309 | |
} |
| 310 | |
else |
| 311 | |
{ |
| 312 | 0 | sink.tableRow(); |
| 313 | 0 | sink.tableCell(); |
| 314 | 0 | sink.text( bundle.getString( "report.checkstyle.norule" ) ); |
| 315 | 0 | sink.tableCell_(); |
| 316 | 0 | sink.tableRow_(); |
| 317 | |
} |
| 318 | |
|
| 319 | 0 | sink.table_(); |
| 320 | |
|
| 321 | 0 | sink.section1_(); |
| 322 | 0 | } |
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
private void doRuleChildren( Configuration configuration, List parentConfigurations, CheckstyleResults results ) |
| 332 | |
{ |
| 333 | |
|
| 334 | 0 | if ( parentConfigurations == null ) |
| 335 | |
{ |
| 336 | 0 | parentConfigurations = new ArrayList(); |
| 337 | |
} |
| 338 | |
|
| 339 | 0 | parentConfigurations.add( configuration ); |
| 340 | |
|
| 341 | 0 | if ( getLog().isDebugEnabled() ) |
| 342 | |
{ |
| 343 | |
|
| 344 | 0 | StringBuffer parentPath = new StringBuffer(); |
| 345 | 0 | Iterator iterator = parentConfigurations.iterator(); |
| 346 | 0 | while ( iterator.hasNext() ) |
| 347 | |
{ |
| 348 | 0 | Configuration parentConfiguration = (Configuration) iterator.next(); |
| 349 | 0 | parentPath.append( parentConfiguration.getName() ); |
| 350 | 0 | if ( iterator.hasNext() ) |
| 351 | |
{ |
| 352 | 0 | parentPath.append( " --> " ); |
| 353 | |
} |
| 354 | 0 | } |
| 355 | 0 | if ( parentPath.length() > 0 ) |
| 356 | |
{ |
| 357 | 0 | getLog().debug( "Parent Configuration Path: " + parentPath.toString() ); |
| 358 | |
} |
| 359 | |
} |
| 360 | |
|
| 361 | 0 | Configuration configChildren[] = configuration.getChildren(); |
| 362 | 0 | for ( int cci = 0; cci < configChildren.length; cci++ ) |
| 363 | |
{ |
| 364 | 0 | String ruleName = configChildren[cci].getName(); |
| 365 | |
|
| 366 | 0 | if ( "TreeWalker".equals( ruleName ) ) |
| 367 | |
{ |
| 368 | |
|
| 369 | 0 | doRuleChildren( configChildren[cci], parentConfigurations, results ); |
| 370 | |
} |
| 371 | |
else |
| 372 | |
{ |
| 373 | 0 | doRuleRow( configChildren[cci], parentConfigurations, ruleName, results ); |
| 374 | |
} |
| 375 | |
} |
| 376 | 0 | } |
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
private void doRuleRow( Configuration checkerConfig, List parentConfigurations, String ruleName, |
| 387 | |
CheckstyleResults results ) |
| 388 | |
{ |
| 389 | 0 | sink.tableRow(); |
| 390 | 0 | sink.tableCell(); |
| 391 | 0 | sink.text( ruleName ); |
| 392 | |
|
| 393 | 0 | List attribnames = new ArrayList( Arrays.asList( checkerConfig.getAttributeNames() ) ); |
| 394 | 0 | attribnames.remove( "severity" ); |
| 395 | 0 | if ( !attribnames.isEmpty() ) |
| 396 | |
{ |
| 397 | 0 | sink.list(); |
| 398 | 0 | Iterator it = attribnames.iterator(); |
| 399 | 0 | while ( it.hasNext() ) |
| 400 | |
{ |
| 401 | 0 | sink.listItem(); |
| 402 | 0 | String name = (String) it.next(); |
| 403 | 0 | sink.bold(); |
| 404 | 0 | sink.text( name ); |
| 405 | 0 | sink.bold_(); |
| 406 | |
|
| 407 | 0 | String value = getConfigAttribute( checkerConfig, null, name, "" ); |
| 408 | |
|
| 409 | 0 | if ( "header".equals( name ) && ( "Header".equals( ruleName ) || "RegexpHeader".equals( ruleName ) ) ) |
| 410 | |
{ |
| 411 | 0 | List lines = stringSplit( value, "\\n" ); |
| 412 | 0 | int linenum = 1; |
| 413 | 0 | Iterator itl = lines.iterator(); |
| 414 | 0 | while ( itl.hasNext() ) |
| 415 | |
{ |
| 416 | 0 | String line = (String) itl.next(); |
| 417 | 0 | sink.lineBreak(); |
| 418 | 0 | sink.rawText( "<span style=\"color: gray\">" ); |
| 419 | 0 | sink.text( linenum + ":" ); |
| 420 | 0 | sink.rawText( "</span>" ); |
| 421 | 0 | sink.nonBreakingSpace(); |
| 422 | 0 | sink.monospaced(); |
| 423 | 0 | sink.text( line ); |
| 424 | 0 | sink.monospaced_(); |
| 425 | 0 | linenum++; |
| 426 | 0 | } |
| 427 | 0 | } |
| 428 | 0 | else if ( "headerFile".equals( name ) && "RegexpHeader".equals( ruleName ) ) |
| 429 | |
{ |
| 430 | 0 | sink.text( ": " ); |
| 431 | 0 | sink.monospaced(); |
| 432 | 0 | sink.text( "\"" ); |
| 433 | 0 | if ( basedir != null ) |
| 434 | |
{ |
| 435 | |
|
| 436 | 0 | String path = siteTool.getRelativePath( value, basedir.getAbsolutePath() ); |
| 437 | 0 | sink.text( path.replace( '\\', '/' ) ); |
| 438 | 0 | } |
| 439 | |
else |
| 440 | |
{ |
| 441 | 0 | sink.text( value ); |
| 442 | |
} |
| 443 | 0 | sink.text( "\"" ); |
| 444 | 0 | sink.monospaced_(); |
| 445 | |
} |
| 446 | |
else |
| 447 | |
{ |
| 448 | 0 | sink.text( ": " ); |
| 449 | 0 | sink.monospaced(); |
| 450 | 0 | sink.text( "\"" ); |
| 451 | 0 | sink.text( value ); |
| 452 | 0 | sink.text( "\"" ); |
| 453 | 0 | sink.monospaced_(); |
| 454 | |
} |
| 455 | 0 | sink.listItem_(); |
| 456 | 0 | } |
| 457 | 0 | sink.list_(); |
| 458 | |
} |
| 459 | |
|
| 460 | 0 | sink.tableCell_(); |
| 461 | |
|
| 462 | 0 | sink.tableCell(); |
| 463 | 0 | String fixedmessage = getConfigAttribute( checkerConfig, null, "message", null ); |
| 464 | |
|
| 465 | 0 | String configSeverity = getConfigAttribute( checkerConfig, null, "severity", null ); |
| 466 | 0 | sink.text( countRuleViolation( results.getFiles().values().iterator(), ruleName, fixedmessage, |
| 467 | |
configSeverity ) ); |
| 468 | 0 | sink.tableCell_(); |
| 469 | |
|
| 470 | 0 | sink.tableCell(); |
| 471 | |
|
| 472 | |
|
| 473 | 0 | configSeverity = getConfigAttribute( checkerConfig, parentConfigurations, "severity", "error" ); |
| 474 | 0 | iconSeverity( configSeverity ); |
| 475 | 0 | sink.nonBreakingSpace(); |
| 476 | 0 | sink.text( StringUtils.capitalise( configSeverity ) ); |
| 477 | 0 | sink.tableCell_(); |
| 478 | |
|
| 479 | 0 | sink.tableRow_(); |
| 480 | 0 | } |
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
private List stringSplit( String input, String delim ) |
| 490 | |
{ |
| 491 | 0 | List ret = new ArrayList(); |
| 492 | |
|
| 493 | 0 | int delimLen = delim.length(); |
| 494 | 0 | int offset = 0; |
| 495 | 0 | int lastOffset = 0; |
| 496 | |
String line; |
| 497 | |
|
| 498 | 0 | while ( ( offset = input.indexOf( delim, offset ) ) >= 0 ) |
| 499 | |
{ |
| 500 | 0 | line = input.substring( lastOffset, offset ); |
| 501 | 0 | ret.add( line ); |
| 502 | 0 | offset += delimLen; |
| 503 | 0 | lastOffset = offset; |
| 504 | |
} |
| 505 | |
|
| 506 | 0 | line = input.substring( lastOffset ); |
| 507 | 0 | ret.add( line ); |
| 508 | |
|
| 509 | 0 | return ret; |
| 510 | |
} |
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
private String countRuleViolation( Iterator files, String ruleName, String message, String severity ) |
| 522 | |
{ |
| 523 | 0 | long count = 0; |
| 524 | |
|
| 525 | 0 | while ( files.hasNext() ) |
| 526 | |
{ |
| 527 | 0 | List errors = (List) files.next(); |
| 528 | |
|
| 529 | 0 | for ( Iterator error = errors.iterator(); error.hasNext(); ) |
| 530 | |
{ |
| 531 | 0 | AuditEvent event = (AuditEvent) error.next(); |
| 532 | |
|
| 533 | 0 | String eventSrcName = event.getSourceName(); |
| 534 | 0 | if ( eventSrcName != null |
| 535 | |
&& ( eventSrcName.endsWith( ruleName ) |
| 536 | |
|| eventSrcName.endsWith( ruleName + "Check" ) ) ) |
| 537 | |
{ |
| 538 | |
|
| 539 | |
|
| 540 | 0 | if ( message != null ) |
| 541 | |
{ |
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | 0 | String msgWithoutSingleQuote = StringUtils.replace( message, "'", "" ); |
| 546 | 0 | if ( message.equals( event.getMessage() ) |
| 547 | |
|| msgWithoutSingleQuote.equals( event.getMessage() ) ) |
| 548 | |
{ |
| 549 | 0 | count++; |
| 550 | |
} |
| 551 | 0 | } |
| 552 | |
|
| 553 | |
|
| 554 | |
|
| 555 | |
|
| 556 | 0 | else if ( severity != null ) |
| 557 | |
{ |
| 558 | 0 | if ( severity.equals( event.getSeverityLevel().getName() ) ) |
| 559 | |
{ |
| 560 | 0 | count++; |
| 561 | |
} |
| 562 | |
} |
| 563 | |
else |
| 564 | |
{ |
| 565 | 0 | count++; |
| 566 | |
} |
| 567 | |
} |
| 568 | 0 | } |
| 569 | 0 | } |
| 570 | 0 | return String.valueOf( count ); |
| 571 | |
} |
| 572 | |
|
| 573 | |
private void doSeveritySummary( CheckstyleResults results ) |
| 574 | |
{ |
| 575 | 0 | sink.section1(); |
| 576 | 0 | sink.sectionTitle1(); |
| 577 | 0 | sink.text( bundle.getString( "report.checkstyle.summary" ) ); |
| 578 | 0 | sink.sectionTitle1_(); |
| 579 | |
|
| 580 | 0 | sink.table(); |
| 581 | |
|
| 582 | 0 | sink.tableRow(); |
| 583 | 0 | sink.tableHeaderCell(); |
| 584 | 0 | sink.text( bundle.getString( "report.checkstyle.files" ) ); |
| 585 | 0 | sink.tableHeaderCell_(); |
| 586 | |
|
| 587 | 0 | sink.tableHeaderCell(); |
| 588 | 0 | sink.text( bundle.getString( "report.checkstyle.infos" ) ); |
| 589 | 0 | sink.nonBreakingSpace(); |
| 590 | 0 | iconInfo(); |
| 591 | 0 | sink.tableHeaderCell_(); |
| 592 | |
|
| 593 | 0 | sink.tableHeaderCell(); |
| 594 | 0 | sink.text( bundle.getString( "report.checkstyle.warnings" ) ); |
| 595 | 0 | sink.nonBreakingSpace(); |
| 596 | 0 | iconWarning(); |
| 597 | 0 | sink.tableHeaderCell_(); |
| 598 | |
|
| 599 | 0 | sink.tableHeaderCell(); |
| 600 | 0 | sink.text( bundle.getString( "report.checkstyle.errors" ) ); |
| 601 | 0 | sink.nonBreakingSpace(); |
| 602 | 0 | iconError(); |
| 603 | 0 | sink.tableHeaderCell_(); |
| 604 | 0 | sink.tableRow_(); |
| 605 | |
|
| 606 | 0 | sink.tableRow(); |
| 607 | 0 | sink.tableCell(); |
| 608 | 0 | sink.text( String.valueOf( results.getFileCount() ) ); |
| 609 | 0 | sink.tableCell_(); |
| 610 | 0 | sink.tableCell(); |
| 611 | 0 | sink.text( String.valueOf( results.getSeverityCount( SeverityLevel.INFO ) ) ); |
| 612 | 0 | sink.tableCell_(); |
| 613 | 0 | sink.tableCell(); |
| 614 | 0 | sink.text( String.valueOf( results.getSeverityCount( SeverityLevel.WARNING ) ) ); |
| 615 | 0 | sink.tableCell_(); |
| 616 | 0 | sink.tableCell(); |
| 617 | 0 | sink.text( String.valueOf( results.getSeverityCount( SeverityLevel.ERROR ) ) ); |
| 618 | 0 | sink.tableCell_(); |
| 619 | 0 | sink.tableRow_(); |
| 620 | |
|
| 621 | 0 | sink.table_(); |
| 622 | |
|
| 623 | 0 | sink.section1_(); |
| 624 | 0 | } |
| 625 | |
|
| 626 | |
private void doFilesSummary( CheckstyleResults results ) |
| 627 | |
{ |
| 628 | 0 | sink.section1(); |
| 629 | 0 | sink.sectionTitle1(); |
| 630 | 0 | sink.text( bundle.getString( "report.checkstyle.files" ) ); |
| 631 | 0 | sink.sectionTitle1_(); |
| 632 | |
|
| 633 | 0 | sink.table(); |
| 634 | |
|
| 635 | 0 | sink.tableRow(); |
| 636 | 0 | sink.tableHeaderCell(); |
| 637 | 0 | sink.text( bundle.getString( "report.checkstyle.files" ) ); |
| 638 | 0 | sink.tableHeaderCell_(); |
| 639 | 0 | sink.tableHeaderCell(); |
| 640 | 0 | sink.text( bundle.getString( "report.checkstyle.infos.abbrev" ) ); |
| 641 | 0 | sink.nonBreakingSpace(); |
| 642 | 0 | iconInfo(); |
| 643 | 0 | sink.tableHeaderCell_(); |
| 644 | 0 | sink.tableHeaderCell(); |
| 645 | 0 | sink.text( bundle.getString( "report.checkstyle.warnings.abbrev" ) ); |
| 646 | 0 | sink.nonBreakingSpace(); |
| 647 | 0 | iconWarning(); |
| 648 | 0 | sink.tableHeaderCell_(); |
| 649 | 0 | sink.tableHeaderCell(); |
| 650 | 0 | sink.text( bundle.getString( "report.checkstyle.errors.abbrev" ) ); |
| 651 | 0 | sink.nonBreakingSpace(); |
| 652 | 0 | iconError(); |
| 653 | 0 | sink.tableHeaderCell_(); |
| 654 | 0 | sink.tableRow_(); |
| 655 | |
|
| 656 | |
|
| 657 | 0 | ArrayList fileList = new ArrayList( results.getFiles().keySet() ); |
| 658 | 0 | Collections.sort( fileList ); |
| 659 | |
|
| 660 | 0 | for ( Iterator files = fileList.iterator(); files.hasNext(); ) |
| 661 | |
{ |
| 662 | 0 | String filename = (String) files.next(); |
| 663 | 0 | List violations = results.getFileViolations( filename ); |
| 664 | 0 | if ( violations.isEmpty() ) |
| 665 | |
{ |
| 666 | |
|
| 667 | 0 | continue; |
| 668 | |
} |
| 669 | |
|
| 670 | 0 | sink.tableRow(); |
| 671 | |
|
| 672 | 0 | sink.tableCell(); |
| 673 | 0 | sink.link( "#" + filename.replace( '/', '.' ) ); |
| 674 | 0 | sink.text( filename ); |
| 675 | 0 | sink.link_(); |
| 676 | 0 | sink.tableCell_(); |
| 677 | |
|
| 678 | 0 | sink.tableCell(); |
| 679 | 0 | sink.text( String.valueOf( results.getSeverityCount( violations, SeverityLevel.INFO ) ) ); |
| 680 | 0 | sink.tableCell_(); |
| 681 | |
|
| 682 | 0 | sink.tableCell(); |
| 683 | 0 | sink.text( String.valueOf( results.getSeverityCount( violations, SeverityLevel.WARNING ) ) ); |
| 684 | 0 | sink.tableCell_(); |
| 685 | |
|
| 686 | 0 | sink.tableCell(); |
| 687 | 0 | sink.text( String.valueOf( results.getSeverityCount( violations, SeverityLevel.ERROR ) ) ); |
| 688 | 0 | sink.tableCell_(); |
| 689 | |
|
| 690 | 0 | sink.tableRow_(); |
| 691 | 0 | } |
| 692 | |
|
| 693 | 0 | sink.table_(); |
| 694 | 0 | sink.section1_(); |
| 695 | 0 | } |
| 696 | |
|
| 697 | |
private void doDetails( CheckstyleResults results ) |
| 698 | |
{ |
| 699 | |
|
| 700 | 0 | sink.section1(); |
| 701 | 0 | sink.sectionTitle1(); |
| 702 | 0 | sink.text( bundle.getString( "report.checkstyle.details" ) ); |
| 703 | 0 | sink.sectionTitle1_(); |
| 704 | |
|
| 705 | |
|
| 706 | 0 | ArrayList fileList = new ArrayList( results.getFiles().keySet() ); |
| 707 | 0 | Collections.sort( fileList ); |
| 708 | 0 | Iterator files = fileList.iterator(); |
| 709 | |
|
| 710 | 0 | while ( files.hasNext() ) |
| 711 | |
{ |
| 712 | 0 | String file = (String) files.next(); |
| 713 | 0 | List violations = results.getFileViolations( file ); |
| 714 | |
|
| 715 | 0 | if ( violations.isEmpty() ) |
| 716 | |
{ |
| 717 | |
|
| 718 | 0 | continue; |
| 719 | |
} |
| 720 | |
|
| 721 | 0 | sink.section2(); |
| 722 | 0 | sink.sectionTitle2(); |
| 723 | 0 | sink.text( file ); |
| 724 | 0 | sink.sectionTitle2_(); |
| 725 | |
|
| 726 | 0 | sink.anchor( file.replace( '/', '.' ) ); |
| 727 | 0 | sink.anchor_(); |
| 728 | |
|
| 729 | 0 | sink.table(); |
| 730 | 0 | sink.tableRow(); |
| 731 | 0 | sink.tableHeaderCell(); |
| 732 | 0 | sink.text( bundle.getString( "report.checkstyle.column.violation" ) ); |
| 733 | 0 | sink.tableHeaderCell_(); |
| 734 | 0 | sink.tableHeaderCell(); |
| 735 | 0 | sink.text( bundle.getString( "report.checkstyle.column.message" ) ); |
| 736 | 0 | sink.tableHeaderCell_(); |
| 737 | 0 | sink.tableHeaderCell(); |
| 738 | 0 | sink.text( bundle.getString( "report.checkstyle.column.line" ) ); |
| 739 | 0 | sink.tableHeaderCell_(); |
| 740 | 0 | sink.tableRow_(); |
| 741 | |
|
| 742 | 0 | doFileEvents( violations, file ); |
| 743 | |
|
| 744 | 0 | sink.table_(); |
| 745 | 0 | sink.section2_(); |
| 746 | 0 | } |
| 747 | |
|
| 748 | 0 | sink.section1_(); |
| 749 | 0 | } |
| 750 | |
|
| 751 | |
private void doFileEvents( List eventList, String filename ) |
| 752 | |
{ |
| 753 | 0 | Iterator events = eventList.iterator(); |
| 754 | 0 | while ( events.hasNext() ) |
| 755 | |
{ |
| 756 | 0 | AuditEvent event = (AuditEvent) events.next(); |
| 757 | 0 | SeverityLevel level = event.getSeverityLevel(); |
| 758 | |
|
| 759 | 0 | if ( ( getSeverityLevel() != null ) && !getSeverityLevel().equals( level ) ) |
| 760 | |
{ |
| 761 | 0 | continue; |
| 762 | |
} |
| 763 | |
|
| 764 | 0 | sink.tableRow(); |
| 765 | |
|
| 766 | 0 | sink.tableCell(); |
| 767 | |
|
| 768 | 0 | if ( SeverityLevel.INFO.equals( level ) ) |
| 769 | |
{ |
| 770 | 0 | iconInfo(); |
| 771 | |
} |
| 772 | 0 | else if ( SeverityLevel.WARNING.equals( level ) ) |
| 773 | |
{ |
| 774 | 0 | iconWarning(); |
| 775 | |
} |
| 776 | 0 | else if ( SeverityLevel.ERROR.equals( level ) ) |
| 777 | |
{ |
| 778 | 0 | iconError(); |
| 779 | |
} |
| 780 | |
|
| 781 | 0 | sink.tableCell_(); |
| 782 | |
|
| 783 | 0 | sink.tableCell(); |
| 784 | 0 | sink.text( event.getMessage() ); |
| 785 | 0 | sink.tableCell_(); |
| 786 | |
|
| 787 | 0 | sink.tableCell(); |
| 788 | 0 | if ( getXrefLocation() != null ) |
| 789 | |
{ |
| 790 | 0 | sink |
| 791 | |
.link( |
| 792 | |
getXrefLocation() + "/" + filename.replaceAll( "\\.java$", ".html" ) + "#" + event.getLine() ); |
| 793 | |
} |
| 794 | 0 | sink.text( String.valueOf( event.getLine() ) ); |
| 795 | 0 | if ( getXrefLocation() != null ) |
| 796 | |
{ |
| 797 | 0 | sink.link_(); |
| 798 | |
} |
| 799 | 0 | sink.tableCell_(); |
| 800 | |
|
| 801 | 0 | sink.tableRow_(); |
| 802 | 0 | } |
| 803 | 0 | } |
| 804 | |
|
| 805 | |
public SeverityLevel getSeverityLevel() |
| 806 | |
{ |
| 807 | 0 | return severityLevel; |
| 808 | |
} |
| 809 | |
|
| 810 | |
public void setSeverityLevel( SeverityLevel severityLevel ) |
| 811 | |
{ |
| 812 | 0 | this.severityLevel = severityLevel; |
| 813 | 0 | } |
| 814 | |
|
| 815 | |
public boolean isEnableRulesSummary() |
| 816 | |
{ |
| 817 | 0 | return enableRulesSummary; |
| 818 | |
} |
| 819 | |
|
| 820 | |
public void setEnableRulesSummary( boolean enableRulesSummary ) |
| 821 | |
{ |
| 822 | 0 | this.enableRulesSummary = enableRulesSummary; |
| 823 | 0 | } |
| 824 | |
|
| 825 | |
public boolean isEnableSeveritySummary() |
| 826 | |
{ |
| 827 | 0 | return enableSeveritySummary; |
| 828 | |
} |
| 829 | |
|
| 830 | |
public void setEnableSeveritySummary( boolean enableSeveritySummary ) |
| 831 | |
{ |
| 832 | 0 | this.enableSeveritySummary = enableSeveritySummary; |
| 833 | 0 | } |
| 834 | |
|
| 835 | |
public boolean isEnableFilesSummary() |
| 836 | |
{ |
| 837 | 0 | return enableFilesSummary; |
| 838 | |
} |
| 839 | |
|
| 840 | |
public void setEnableFilesSummary( boolean enableFilesSummary ) |
| 841 | |
{ |
| 842 | 0 | this.enableFilesSummary = enableFilesSummary; |
| 843 | 0 | } |
| 844 | |
|
| 845 | |
public boolean isEnableRSS() |
| 846 | |
{ |
| 847 | 0 | return enableRSS; |
| 848 | |
} |
| 849 | |
|
| 850 | |
public void setEnableRSS( boolean enableRSS ) |
| 851 | |
{ |
| 852 | 0 | this.enableRSS = enableRSS; |
| 853 | 0 | } |
| 854 | |
|
| 855 | |
public String getXrefLocation() |
| 856 | |
{ |
| 857 | 0 | return xrefLocation; |
| 858 | |
} |
| 859 | |
|
| 860 | |
public void setXrefLocation( String xrefLocation ) |
| 861 | |
{ |
| 862 | 0 | this.xrefLocation = xrefLocation; |
| 863 | 0 | } |
| 864 | |
|
| 865 | |
public Configuration getCheckstyleConfig() |
| 866 | |
{ |
| 867 | 0 | return checkstyleConfig; |
| 868 | |
} |
| 869 | |
|
| 870 | |
public void setCheckstyleConfig( Configuration config ) |
| 871 | |
{ |
| 872 | 0 | this.checkstyleConfig = config; |
| 873 | 0 | } |
| 874 | |
|
| 875 | |
} |