/******************************************************************************* * Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Evgeny Mandrikov - initial API and implementation * Kyle Lieber - implementation of CheckMojo * Marc Hoffmann - redesign using report APIs * *******************************************************************************/ package org.jacoco.maven; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.maven.plugin.MojoExecutionException; import org.jacoco.core.analysis.ICoverageNode; import org.jacoco.report.IReportVisitor; import org.jacoco.report.check.IViolationsOutput; import org.jacoco.report.check.Limit; import org.jacoco.report.check.Rule; /** * Checks that the code coverage metrics are being met. * * @goal check * @phase verify * @requiresProject true * @threadSafe * @since 0.6.1 */ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput { private static final String MSG_SKIPPING = "Skipping JaCoCo execution due to missing execution data file:"; private static final String CHECK_SUCCESS = "All coverage checks have been met."; private static final String CHECK_FAILED = "Coverage checks have not been met. See log for details."; /** *
* 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. *
* ** If not specified the following defaults are assumed: *
* ** Note that you must use implementation hints for * rule and limit when using Maven 2, with Maven 3 you do * not need to specify the attributes. *
* ** This example requires an overall instruction coverage of 80% and no class * must be missed: *
* ** {@code ** ** } ** *BUNDLE ** ** *INSTRUCTION *COVEREDRATIO *0.80 ** *CLASS *MISSEDCOUNT *0 *
* This example requires a line coverage minimum of 50% for every class * except test classes: *
* ** {@code ** * @parameter * @required */ private List* } ** *CLASS ** **Test ** ** *LINE *COVEREDRATIO *0.50 *