• 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  *    Brock Janiczak - initial API and implementation
11  *
12  *******************************************************************************/
13 package org.jacoco.ant;
14 
15 import org.apache.tools.ant.BuildException;
16 
17 /**
18  * Ant task that will unpack the coverage agent jar and generate the JVM options
19  * required to use it
20  */
21 public class AgentTask extends AbstractCoverageTask {
22 
23 	private String property;
24 
25 	/**
26 	 * Sets the name of the property to hold the agent JVM options
27 	 *
28 	 * @param property
29 	 *            Name of the property to be populated
30 	 */
setProperty(final String property)31 	public void setProperty(final String property) {
32 		this.property = property;
33 	}
34 
35 	/**
36 	 * Unpacks a private copy of the JaCoCo agent and populates
37 	 * <code>property</code> with the JVM arguments required to use it. The
38 	 * value set into the property is only valid for the lifetime of the current
39 	 * JVM. The agent jar will be removed on termination of the JVM.
40 	 */
41 	@Override
execute()42 	public void execute() throws BuildException {
43 		if (property == null || property.length() == 0) {
44 			throw new BuildException("Property is mandatory", getLocation());
45 		}
46 		final String jvmArg = isEnabled() ? getLaunchingArgument() : "";
47 
48 		getProject().setNewProperty(property, jvmArg);
49 	}
50 }
51