Return-Path: X-Original-To: apmail-maven-commits-archive@www.apache.org Delivered-To: apmail-maven-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09AABC441 for ; Tue, 8 May 2012 13:54:40 +0000 (UTC) Received: (qmail 86432 invoked by uid 500); 8 May 2012 13:54:39 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 86364 invoked by uid 500); 8 May 2012 13:54:39 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 86356 invoked by uid 99); 8 May 2012 13:54:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 May 2012 13:54:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 May 2012 13:54:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6B46C2388C6D for ; Tue, 8 May 2012 13:52:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r816652 [8/21] - in /websites/production/maventest/content/plugins/maven-checkstyle-plugin-latest: ./ apidocs/ apidocs/org/apache/maven/plugin/checkstyle/ apidocs/org/apache/maven/plugin/checkstyle/class-use/ cobertura/ css/ examples/ image... Date: Tue, 08 May 2012 13:52:36 -0000 To: commits@maven.apache.org From: hboutemy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120508135245.6B46C2388C6D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: websites/production/maventest/content/plugins/maven-checkstyle-plugin-latest/cobertura/org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.html ============================================================================== --- websites/production/maventest/content/plugins/maven-checkstyle-plugin-latest/cobertura/org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.html (original) +++ websites/production/maventest/content/plugins/maven-checkstyle-plugin-latest/cobertura/org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo.html Tue May 8 13:52:31 2012 @@ -12,7 +12,7 @@
 
- +
Classes in this File Line Coverage Branch Coverage Complexity
CheckstyleViolationCheckMojo
76%
28/37
50%
18/36
7,667
CheckstyleViolationCheckMojo
65%
36/55
55%
24/44
8,667
 
@@ -66,308 +66,368 @@  24  
 import org.apache.maven.plugin.MojoFailureException;
 25   -
 import org.codehaus.plexus.util.xml.pull.MXParser;
+
 import org.codehaus.plexus.util.ReaderFactory;
 26   -
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+
 import org.codehaus.plexus.util.xml.pull.MXParser;
 27   -
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 28   -
 
+
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 29   -
 import java.io.BufferedReader;
+
 
 30   -
 import java.io.File;
+
 import java.io.BufferedReader;
 31   -
 import java.io.FileInputStream;
+
 import java.io.File;
 32  
 import java.io.IOException;
 33   -
 import java.io.InputStreamReader;
-  34  
 import java.io.Reader;
-  35   +  34  
 
-  36   +  35  
 /**
-  37   +  36  
  * Perform a violation check against the last Checkstyle run to see if there are
-  38   +  37  
  * any violations. It reads the Checkstyle output file, counts the number of
-  39   +  38  
  * violations found and displays it on the console.
-  40   +  39  
  *
-  41   +  40  
  * @author <a href="mailto:joakim@erdfelt.net">Joakim Erdfelt</a>
-  42   +  41  
  * @goal check
-  43   +  42  
  * @phase verify
-  44   +  43  
  * @execute goal="checkstyle"
-  45   +  44  
  * @requiresDependencyResolution compile
-  46   +  45  
  */
-  47  8
 public class CheckstyleViolationCheckMojo
-  48   +  46  4
 public class CheckstyleViolationCheckMojo
+  47  
     extends AbstractMojo
-  49   +  48  
 {
-  50   +  49  
     /**
-  51   +  50  
      * Specifies the path and filename to save the Checkstyle output. The format
-  52   +  51  
      * of the output file is determined by the <code>outputFileFormat</code>
-  53   +  52  
      * parameter.
-  54   +  53  
      *
-  55   +  54  
      * @parameter expression="${checkstyle.output.file}"
-  56   +  55  
      *            default-value="${project.build.directory}/checkstyle-result.xml"
-  57   +  56  
      */
-  58   +  57  
     private File outputFile;
-  59   +  58  
 
-  60   +  59  
     /**
-  61   +  60  
      * Specifies the format of the output to be used when writing to the output
-  62   +  61  
      * file. Valid values are "plain" and "xml".
-  63   +  62  
      *
-  64   +  63  
      * @parameter expression="${checkstyle.output.format}" default-value="xml"
-  65   +  64  
      */
-  66   +  65  
     private String outputFileFormat;
-  67   +  66  
 
-  68   +  67  
     /**
-  69   +  68  
      * Do we fail the build on a violation?
-  70   +  69  
      *
-  71   +  70  
      * @parameter expression="${checkstyle.failOnViolation}"
-  72   +  71  
      *            default-value="true"
-  73   +  72  
      */
-  74   +  73  
     private boolean failOnViolation;
-  75   +  74  
 
-  76   +  75  
     /**
+  76   +
      * The maximum number of allowed violations. The execution fails only if the
 77   -
      * The lowest severity level that is considered a violation.
+
      * number of violations is above this limit.
 78   -
      * Valid values are "error", "warning" and "info".
-  79  
      *
+  79   +
      * @parameter expression="${checkstyle.maxAllowedViolations}" default-value="0"
 80   -
      * @parameter expression="${checkstyle.violationSeverity}" default-value="error"
+
      * @since 2.3
 81   -
      * @since 2.2
-  82  
      */
-  83  8
     private String violationSeverity = "error";
-  84   +  82  4
     private int maxAllowedViolations = 0;
+  83  
 
-  85   +  84  
     /**
+  85   +
      * The lowest severity level that is considered a violation.
 86   -
      * Skip entire check.
+
      * Valid values are "error", "warning" and "info".
 87  
      *
 88   -
      * @parameter expression="${checkstyle.skip}" default-value="false"
+
      * @parameter expression="${checkstyle.violationSeverity}" default-value="error"
 89  
      * @since 2.2
 90  
      */
-  91   -
     private boolean skip;
+  91  4
     private String violationSeverity = "error";
 92  
 
 93  
     /**
 94   -
      * @see org.apache.maven.plugin.Mojo#execute()
+
      * Skip entire check.
 95   -
      */
+
      *
 96   -
     public void execute()
+
      * @parameter expression="${checkstyle.skip}" default-value="false"
 97   -
         throws MojoExecutionException, MojoFailureException
+
      * @since 2.2
 98   -
     {
-  99  8
         if ( !skip )
+
      */
+  99   +
     private boolean skip;
 100   -
         {
-  101  8
             if ( !"xml".equals( outputFileFormat ) )
+
 
+  101   +
     /**
 102   -
             {
-  103  2
                 throw new MojoExecutionException( "Output format is '" + outputFileFormat
+
      * Output the detected violations to the console.
+  103   +
      *
 104   -
                     + "', checkstyle:check requires format to be 'xml'." );
+
      * @parameter expression="${checkstyle.console}" default-value="false"
 105   -
             }
+
      * @since 2.3
 106   -
 
-  107  6
             if ( !outputFile.exists() )
+
      */
+  107   +
     private boolean logViolationsToConsole;
 108   -
             {
-  109  2
                 getLog().info(
+
 
+  109   +
     /**
 110   -
                                "Unable to perform checkstyle:check, "
+
      * @see org.apache.maven.plugin.Mojo#execute()
 111   -
                                    + "unable to find checkstyle:checkstyle outputFile." );
-  112  2
                 return;
+
      */
+  112   +
     public void execute()
 113   -
             }
+
         throws MojoExecutionException, MojoFailureException
 114   -
 
-  115   -
             try
+
     {
+  115  4
         if ( !skip )
 116   -
             {
-  117  4
                 XmlPullParser xpp = new MXParser();
+
         {
+  117  4
             if ( !"xml".equals( outputFileFormat ) )
 118   -
                 // TODO: use ReaderFactory.newXmlReader() when plexus-utils can be upgraded
-  119  4
                 Reader freader = new InputStreamReader( new FileInputStream( outputFile ), "UTF-8" );
-  120  4
                 BufferedReader breader = new BufferedReader( freader );
-  121  4
                 xpp.setInput( breader );
+
             {
+  119  1
                 throw new MojoExecutionException( "Output format is '" + outputFileFormat
+  120   +
                     + "', checkstyle:check requires format to be 'xml'." );
+  121   +
             }
 122  
 
-  123  4
                 int violations = countViolations( xpp );
-  124  4
                 if ( violations > 0 )
-  125   -
                 {
-  126  4
                     if ( failOnViolation )
+  123  3
             if ( !outputFile.exists() )
+  124   +
             {
+  125  1
                 getLog().info(
+  126   +
                                "Unable to perform checkstyle:check, "
 127   -
                     {
-  128  2
                         throw new MojoFailureException( "You have " + violations + " Checkstyle violation"
+
                                    + "unable to find checkstyle:checkstyle outputFile." );
+  128  1
                 return;
 129   -
                             + ( ( violations > 1 ) ? "s" : "" ) + "." );
+
             }
 130   -
                     }
+
 
 131   +
             try
+  132   +
             {
+  133  2
                 XmlPullParser xpp = new MXParser();
+  134  2
                 Reader freader = ReaderFactory.newXmlReader( outputFile );
+  135  2
                 BufferedReader breader = new BufferedReader( freader );
+  136  2
                 xpp.setInput( breader );
+  137   +
 
+  138  2
                 int violations = countViolations( xpp );
+  139  2
                 if ( violations > maxAllowedViolations )
+  140   +
                 {
+  141  2
                     if ( failOnViolation )
+  142   +
                     {
+  143  1
                         String msg = "You have " + violations + " Checkstyle violation"
+  144   +
                             + ( ( violations > 1 ) ? "s" : "" ) + ".";
+  145  1
                         if ( maxAllowedViolations > 0 )
+  146   +
                         {
+  147  0
                             msg += " The maximum number of allowed violations is " + maxAllowedViolations + ".";
+  148   +
                         }
+  149  1
                         throw new MojoFailureException( msg );
+  150   +
                     }
+  151  
 
-  132  2
                     getLog().warn( "checkstyle:check violations detected but failOnViolation set to false" );
-  133   +  152  1
                     getLog().warn( "checkstyle:check violations detected but failOnViolation set to false" );
+  153  
                 }
-  134   +  154  
             }
-  135  0
             catch ( IOException e )
-  136   +  155  0
             catch ( IOException e )
+  156  
             {
-  137  0
                 throw new MojoExecutionException( "Unable to read Checkstyle results xml: "
-  138   +  157  0
                 throw new MojoExecutionException( "Unable to read Checkstyle results xml: "
+  158  
                     + outputFile.getAbsolutePath(), e );
-  139   +  159  
             }
-  140  0
             catch ( XmlPullParserException e )
-  141   +  160  0
             catch ( XmlPullParserException e )
+  161  
             {
-  142  0
                 throw new MojoExecutionException( "Unable to read Checkstyle results xml: "
-  143   +  162  0
                 throw new MojoExecutionException( "Unable to read Checkstyle results xml: "
+  163  
                     + outputFile.getAbsolutePath(), e );
-  144  2
             }
-  145   +  164  1
             }
+  165  
         }
-  146  2
     }
-  147   +  166  1
     }
+  167  
 
-  148   +  168  
     private int countViolations( XmlPullParser xpp )
-  149   +  169  
         throws XmlPullParserException, IOException
-  150   +  170  
     {
-  151  4
         int count = 0;
-  152   +  171  2
         int count = 0;
+  172  
 
-  153  4
         int eventType = xpp.getEventType();
-  154  128
         while ( eventType != XmlPullParser.END_DOCUMENT )
-  155   +  173  2
         int eventType = xpp.getEventType();
+  174  2
         String file = "";
+  175  64
         while ( eventType != XmlPullParser.END_DOCUMENT )
+  176  
         {
-  156  124
             if ( eventType == XmlPullParser.START_TAG && "error".equals( xpp.getName() )
-  157   +  177  62
             if ( eventType == XmlPullParser.START_TAG && "file".equals( xpp.getName() ) )
+  178   +
             {
+  179  6
                 file = xpp.getAttributeValue( "", "name" );
+  180  6
                 file = file.substring( file.lastIndexOf( File.separatorChar ) + 1 );
+  181   +
             }
+  182   +
 
+  183  62
             if ( eventType == XmlPullParser.START_TAG && "error".equals( xpp.getName() )
+  184  
                 && isViolation( xpp.getAttributeValue( "", "severity" ) ) )
-  158   +  185  
             {
-  159  20
                 count++;
-  160   +  186  10
                 if ( logViolationsToConsole )
+  187   +
                 {
+  188  0
                     StringBuffer stb = new StringBuffer();
+  189  0
                     stb.append( file );
+  190  0
                     stb.append( '[' );
+  191  0
                     stb.append( xpp.getAttributeValue( "", "line" ) );
+  192  0
                     stb.append( ':' );
+  193  0
                     stb.append( xpp.getAttributeValue( "", "column" ) );
+  194  0
                     stb.append( "] " );
+  195  0
                     stb.append( xpp.getAttributeValue( "", "message" ) );
+  196  0
                     getLog().error( stb.toString() );
+  197   +
                 }
+  198  10
                 count++;
+  199  
             }
-  161  124
             eventType = xpp.next();
-  162   +  200  62
             eventType = xpp.next();
+  201  
         }
-  163   +  202  
 
-  164  4
         return count;
-  165   +  203  2
         return count;
+  204  
     }
-  166   +  205  
 
-  167   +  206  
     /**
-  168   +  207  
      * Checks if the given severity is considered a violation.
-  169   +  208  
      *
-  170   +  209  
      * @param severity The severity to check
-  171   +  210  
      * @return <code>true</code> if the given severity is a violation, otherwise <code>false</code>
-  172   +  211  
      */
-  173   +  212  
     private boolean isViolation( String severity )
-  174   +  213  
     {
-  175  20
         if ( "error".equals( severity ) )
-  176   +  214  10
         if ( "error".equals( severity ) )
+  215  
         {
-  177  20
             return "error".equals( violationSeverity ) || "warning".equals( violationSeverity )
-  178   +  216  10
             return "error".equals( violationSeverity ) || "warning".equals( violationSeverity )
+  217  
                 || "info".equals( violationSeverity );
-  179   +  218  
         }
-  180  0
         else if ( "warning".equals( severity ) )
-  181   +  219  0
         else if ( "warning".equals( severity ) )
+  220  
         {
-  182  0
             return "warning".equals( violationSeverity ) || "info".equals( violationSeverity );
-  183   +  221  0
             return "warning".equals( violationSeverity ) || "info".equals( violationSeverity );
+  222  
         }
-  184  0
         else if ( "info".equals( severity ) )
-  185   +  223  0
         else if ( "info".equals( severity ) )
+  224  
         {
-  186  0
             return "info".equals( violationSeverity );
-  187   +  225  0
             return "info".equals( violationSeverity );
+  226  
         }
-  188   +  227  
         else
-  189   +  228  
         {
-  190  0
             return false;
-  191   +  229  0
             return false;
+  230  
         }
-  192   +  231  
     }
-  193   +  232  
 }
- + \ No newline at end of file