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