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 IViolationsOutputChecks that the code coverage metrics are being met.- Since:
- 0.6.1
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCHECK_FAILEDprivate static java.lang.StringCHECK_SUCCESSprivate java.io.FiledataFileFile with execution data.private java.util.List<java.lang.String>excludesA list of class files to exclude from analysis.private booleanhaltOnFailureHalt the build if any of the checks fail.private java.util.List<java.lang.String>includesA list of class files to include into analysis.private static java.lang.StringMSG_SKIPPINGprivate java.util.List<RuleConfiguration>rulesCheck configuration used to specify rules on element types (BUNDLE, PACKAGE, CLASS, SOURCEFILE or METHOD) with a list of limits.private booleanviolations
-
Constructor Summary
Constructors Constructor Description CheckMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancanCheckCoverage()private voidexecuteCheck()voidexecuteMojo()Executes Mojo.voidonViolation(ICoverageNode node, Rule rule, Limit limit, java.lang.String message)Called for every rule violation.-
Methods inherited from class org.jacoco.maven.AbstractJacocoMojo
execute, getProject, skipMojo
-
-
-
-
Field Detail
-
MSG_SKIPPING
private static final java.lang.String MSG_SKIPPING
- See Also:
- Constant Field Values
-
CHECK_SUCCESS
private static final java.lang.String CHECK_SUCCESS
- See Also:
- Constant Field Values
-
CHECK_FAILED
private static final java.lang.String CHECK_FAILED
- See Also:
- Constant Field Values
-
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 haltOnFailureHalt the build if any of the checks fail.
-
dataFile
@Parameter(defaultValue="${project.build.directory}/jacoco.exec") private java.io.File dataFileFile 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
-
-
Method Detail
-
canCheckCoverage
private boolean canCheckCoverage()
-
executeMojo
public void executeMojo() throws org.apache.maven.plugin.MojoExecutionExceptionDescription copied from class:AbstractJacocoMojoExecutes Mojo.- Specified by:
executeMojoin classAbstractJacocoMojo- 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:IViolationsOutputCalled for every rule violation.- Specified by:
onViolationin interfaceIViolationsOutput- Parameters:
node- node which violates a rulerule- rule which is violatedlimit- limit which is violatedmessage- readable message describing this violation
-
-