1/*******************************************************************************
2 * Copyright (c) 2009, 2015 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 *******************************************************************************/
12package org.jacoco.maven;
13
14import java.util.List;
15
16import org.apache.maven.plugin.AbstractMojo;
17import org.apache.maven.plugin.MojoExecutionException;
18import org.apache.maven.plugin.MojoFailureException;
19import org.apache.maven.project.MavenProject;
20
21/**
22 * Base class for JaCoCo Mojos.
23 */
24public abstract class AbstractJacocoMojo extends AbstractMojo {
25
26	/**
27	 * Maven project.
28	 *
29	 * @parameter property="project"
30	 * @readonly
31	 */
32	private MavenProject project;
33
34	/**
35	 * A list of class files to include in instrumentation/analysis/reports. May
36	 * use wildcard characters (* and ?). When not specified everything will be
37	 * included.
38	 *
39	 * @parameter
40	 */
41	private List<String> includes;
42
43	/**
44	 * A list of class files to exclude from instrumentation/analysis/reports.
45	 * May use wildcard characters (* and ?). When not specified nothing will be
46	 * excluded.
47	 *
48	 * @parameter
49	 */
50	private List<String> excludes;
51
52	/**
53	 * Flag used to suppress execution.
54	 *
55	 * @parameter property="jacoco.skip" default-value="false"
56	 */
57	private boolean skip;
58
59	public final void execute() throws MojoExecutionException,
60			MojoFailureException {
61		if (skip) {
62			getLog().info(
63					"Skipping JaCoCo execution because property jacoco.skip is set.");
64			skipMojo();
65			return;
66		}
67		executeMojo();
68	}
69
70	/**
71	 * Executes Mojo.
72	 *
73	 * @throws MojoExecutionException
74	 *             if an unexpected problem occurs. Throwing this exception
75	 *             causes a "BUILD ERROR" message to be displayed.
76	 * @throws MojoFailureException
77	 *             if an expected problem (such as a compilation failure)
78	 *             occurs. Throwing this exception causes a "BUILD FAILURE"
79	 *             message to be displayed.
80	 */
81	protected abstract void executeMojo() throws MojoExecutionException,
82			MojoFailureException;
83
84	/**
85	 * Skips Mojo.
86	 */
87	protected void skipMojo() {
88	}
89
90	/**
91	 * @return Maven project
92	 */
93	protected final MavenProject getProject() {
94		return project;
95	}
96
97	/**
98	 * Returns the list of class files to include.
99	 *
100	 * @return class files to include, may contain wildcard characters
101	 */
102	protected List<String> getIncludes() {
103		return includes;
104	}
105
106	/**
107	 * Returns the list of class files to exclude.
108	 *
109	 * @return class files to exclude, may contain wildcard characters
110	 */
111	protected List<String> getExcludes() {
112		return excludes;
113	}
114
115}
116