Class CheckMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.jacoco.maven.AbstractJacocoMojo
org.jacoco.maven.CheckMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo, IViolationsOutput

@Mojo(name="check", defaultPhase=VERIFY, threadSafe=true) public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput
Checks that the code coverage metrics are being met.
Since:
0.6.1
  • Field Details

    • MSG_SKIPPING

      private static final String MSG_SKIPPING
      See Also:
    • CHECK_SUCCESS

      private static final String CHECK_SUCCESS
      See Also:
    • CHECK_FAILED

      private static final String CHECK_FAILED
      See Also:
    • rules

      @Parameter(required=true) private List<RuleConfiguration> rules

      Check configuration used to specify rules on element types (BUNDLE, PACKAGE, CLASS, SOURCEFILE or METHOD) with a list of limits. Each limit applies to a certain counter (INSTRUCTION, LINE, BRANCH, COMPLEXITY, METHOD, CLASS) and defines a minimum or maximum for the corresponding value (TOTALCOUNT, COVEREDCOUNT, MISSEDCOUNT, COVEREDRATIO, MISSEDRATIO). If a limit refers to a ratio it must be in the range from 0.0 to 1.0 where the number of decimal places will also determine the precision in error messages. A limit ratio may optionally be declared as a percentage where 0.80 and 80% represent the same value.

      If not specified the following defaults are assumed:

      • rule element: BUNDLE
      • limit counter: INSTRUCTION
      • limit value: COVEREDRATIO

      This example requires an overall instruction coverage of 80% and no class must be missed:

       
       <rules>
         <rule>
           <element>BUNDLE</element>
           <limits>
             <limit>
               <counter>INSTRUCTION</counter>
               <value>COVEREDRATIO</value>
               <minimum>0.80</minimum>
             </limit>
             <limit>
               <counter>CLASS</counter>
               <value>MISSEDCOUNT</value>
               <maximum>0</maximum>
             </limit>
           </limits>
         </rule>
       </rules>
       

      This example requires a line coverage minimum of 50% for every class except test classes:

       
       <rules>
         <rule>
           <element>CLASS</element>
           <excludes>
             <exclude>*Test</exclude>
           </excludes>
           <limits>
             <limit>
               <counter>LINE</counter>
               <value>COVEREDRATIO</value>
               <minimum>50%</minimum>
             </limit>
           </limits>
         </rule>
       </rules>
       
    • haltOnFailure

      @Parameter(property="jacoco.haltOnFailure", defaultValue="true", required=true) private boolean haltOnFailure
      Halt the build if any of the checks fail.
    • dataFile

      @Parameter(defaultValue="${project.build.directory}/jacoco.exec") private File dataFile
      File with execution data.
    • includes

      @Parameter private List<String> includes
      A list of class files to include into analysis. May use wildcard characters (* and ?). When not specified everything will be included.
    • excludes

      @Parameter private List<String> excludes
      A list of class files to exclude from analysis. May use wildcard characters (* and ?). When not specified nothing will be excluded.
    • violations

      private boolean violations
  • Constructor Details

    • CheckMojo

      public CheckMojo()
  • Method Details

    • canCheckCoverage

      private boolean canCheckCoverage()
    • executeMojo

      public void executeMojo() throws org.apache.maven.plugin.MojoExecutionException
      Description copied from class: AbstractJacocoMojo
      Executes Mojo.
      Specified by:
      executeMojo in class AbstractJacocoMojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if an unexpected problem occurs. Throwing this exception causes a "BUILD ERROR" message to be displayed.
    • executeCheck

      private void executeCheck() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • onViolation

      public void onViolation(ICoverageNode node, Rule rule, Limit limit, String message)
      Description copied from interface: IViolationsOutput
      Called for every rule violation.
      Specified by:
      onViolation in interface IViolationsOutput
      Parameters:
      node - node which violates a rule
      rule - rule which is violated
      limit - limit which is violated
      message - readable message describing this violation