aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.ant/src/org/jacoco/ant/AgentTask.java
blob: a02b809dbf80b2dff09386041e776b07f62db924 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*******************************************************************************
 * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Brock Janiczak - initial API and implementation
 *    
 *******************************************************************************/
package org.jacoco.ant;

import org.apache.tools.ant.BuildException;

/**
 * Ant task that will unpack the coverage agent jar and generate the JVM options
 * required to use it
 */
public class AgentTask extends AbstractCoverageTask {

	private String property;

	/**
	 * Sets the name of the property to hold the agent JVM options
	 * 
	 * @param property
	 *            Name of the property to be populated
	 */
	public void setProperty(final String property) {
		this.property = property;
	}

	/**
	 * Unpacks a private copy of the JaCoCo agent and populates
	 * <code>property</code> with the JVM arguments required to use it. The
	 * value set into the property is only valid for the lifetime of the current
	 * JVM. The agent jar will be removed on termination of the JVM.
	 */
	@Override
	public void execute() throws BuildException {
		if (property == null || property.length() == 0) {
			throw new BuildException("Property is mandatory", getLocation());
		}
		final String jvmArg = isEnabled() ? getLaunchingArgument() : "";

		getProject().setNewProperty(property, jvmArg);
	}
}