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 java.io.File;
15 
16 import org.apache.maven.plugins.annotations.LifecyclePhase;
17 import org.apache.maven.plugins.annotations.Mojo;
18 import org.apache.maven.plugins.annotations.Parameter;
19 import org.apache.maven.plugins.annotations.ResolutionScope;
20 
21 /**
22  * <p>
23  * Prepares a property pointing to the JaCoCo runtime agent that can be passed
24  * as a VM argument to the application under test. Depending on the project
25  * packaging type by default a property with the following name is set:
26  * </p>
27  *
28  * <ul>
29  * <li>tycho.testArgLine for packaging type eclipse-test-plugin and</li>
30  * <li>argLine otherwise.</li>
31  * </ul>
32  *
33  * <p>
34  * If your project already defines VM arguments for test execution, be sure that
35  * they will include property defined by JaCoCo.
36  * </p>
37  *
38  * <p>
39  * One of the ways to do this in case of maven-surefire-plugin - is to use
40  * syntax for <a href="http://maven.apache.org/surefire/maven-surefire-plugin/faq.html#late-property-evaluation">late property evaluation</a>:
41  * </p>
42  *
43  * <pre>
44  *   &lt;plugin&gt;
45  *     &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
46  *     &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
47  *     &lt;configuration&gt;
48  *       &lt;argLine&gt;@{argLine} -your -extra -arguments&lt;/argLine&gt;
49  *     &lt;/configuration&gt;
50  *   &lt;/plugin&gt;
51  * </pre>
52  *
53  * <p>
54  * You can define empty property to avoid JVM startup error <code>Could not find or load main class @{argLine}</code>
55  * when using late property evaluation and jacoco-maven-plugin not executed.
56  * </p>
57  *
58  * <p>
59  * Another way is to define "argLine" as a Maven property rather than
60  * as part of the configuration of maven-surefire-plugin:
61  * </p>
62  *
63  * <pre>
64  *   &lt;properties&gt;
65  *     &lt;argLine&gt;-your -extra -arguments&lt;/argLine&gt;
66  *   &lt;/properties&gt;
67  *   ...
68  *   &lt;plugin&gt;
69  *     &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
70  *     &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
71  *     &lt;configuration&gt;
72  *       &lt;!-- no argLine here --&gt;
73  *     &lt;/configuration&gt;
74  *   &lt;/plugin&gt;
75  * </pre>
76  *
77  * <p>
78  * Resulting coverage information is collected during execution and by default
79  * written to a file when the process terminates.
80  * </p>
81  *
82  * @since 0.5.3
83  */
84 @Mojo(name = "prepare-agent", defaultPhase = LifecyclePhase.INITIALIZE, requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
85 public class AgentMojo extends AbstractAgentMojo {
86 
87 	/**
88 	 * Path to the output file for execution data.
89 	 */
90 	@Parameter(property = "jacoco.destFile", defaultValue = "${project.build.directory}/jacoco.exec")
91 	private File destFile;
92 
93 	/**
94 	 * @return the destFile
95 	 */
96 	@Override
getDestFile()97 	File getDestFile() {
98 		return destFile;
99 	}
100 
101 }
102