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