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 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
-
Constructor Summary
Constructors Constructor Description CheckMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
canCheckCoverage()
private void
executeCheck()
void
executeMojo()
Executes Mojo.void
onViolation(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 the range is 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, the value must end with %.
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
-
-
Method Detail
-
canCheckCoverage
private boolean canCheckCoverage()
-
executeMojo
public void executeMojo() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoExecutionException
Description copied from class:AbstractJacocoMojo
Executes Mojo.- Specified by:
executeMojo
in 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:IViolationsOutput
Called for every rule violation.- Specified by:
onViolation
in interfaceIViolationsOutput
- Parameters:
node
- node which violates a rulerule
- rule which is violatedlimit
- limit which is violatedmessage
- readable message describing this violation
-
-