1 /******************************************************************************* 2 * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Evgeny Mandrikov - initial API and implementation 10 * 11 *******************************************************************************/ 12 package org.jacoco.maven; 13 14 import org.apache.maven.plugin.AbstractMojo; 15 import org.apache.maven.plugin.MojoExecutionException; 16 import org.apache.maven.plugin.MojoFailureException; 17 import org.apache.maven.plugins.annotations.Parameter; 18 import org.apache.maven.project.MavenProject; 19 20 /** 21 * Base class for JaCoCo Mojos. 22 */ 23 public abstract class AbstractJacocoMojo extends AbstractMojo { 24 25 /** 26 * Maven project. 27 */ 28 @Parameter(property = "project", readonly = true) 29 private MavenProject project; 30 31 /** 32 * Flag used to suppress execution. 33 */ 34 @Parameter(property = "jacoco.skip", defaultValue = "false") 35 private boolean skip; 36 execute()37 public final void execute() throws MojoExecutionException, 38 MojoFailureException { 39 if (skip) { 40 getLog().info( 41 "Skipping JaCoCo execution because property jacoco.skip is set."); 42 skipMojo(); 43 return; 44 } 45 executeMojo(); 46 } 47 48 /** 49 * Executes Mojo. 50 * 51 * @throws MojoExecutionException 52 * if an unexpected problem occurs. Throwing this exception 53 * causes a "BUILD ERROR" message to be displayed. 54 * @throws MojoFailureException 55 * if an expected problem (such as a compilation failure) 56 * occurs. Throwing this exception causes a "BUILD FAILURE" 57 * message to be displayed. 58 */ executeMojo()59 protected abstract void executeMojo() throws MojoExecutionException, 60 MojoFailureException; 61 62 /** 63 * Skips Mojo. 64 */ skipMojo()65 protected void skipMojo() { 66 } 67 68 /** 69 * @return Maven project 70 */ getProject()71 protected final MavenProject getProject() { 72 return project; 73 } 74 75 } 76