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