Class 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 Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String CHECK_FAILED  
      private static java.lang.String CHECK_SUCCESS  
      private java.io.File dataFile
      File with execution data.
      private java.util.List<java.lang.String> excludes
      A list of class files to exclude from analysis.
      private boolean haltOnFailure
      Halt the build if any of the checks fail.
      private java.util.List<java.lang.String> includes
      A list of class files to include into analysis.
      private static java.lang.String MSG_SKIPPING  
      private java.util.List<RuleConfiguration> rules
      Check configuration used to specify rules on element types (BUNDLE, PACKAGE, CLASS, SOURCEFILE or METHOD) with a list of limits.
      private boolean violations  
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      CheckMojo()  
    • Field Detail

      • rules

        @Parameter(required=true)
        private java.util.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 java.io.File dataFile
        File with execution data.
      • includes

        @Parameter
        private java.util.List<java.lang.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 java.util.List<java.lang.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 Detail

      • CheckMojo

        public CheckMojo()
    • Method Detail

      • 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,
                                java.lang.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