AbstractCoverageTask.java

    1/*******************************************************************************
    2 * Copyright (c) 2009 Mountainminds GmbH & Co. KG and others
    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 * $Id: $
   12 *******************************************************************************/
   13package org.jacoco.ant;
   14
   15import java.io.File;
   16
   17import org.apache.tools.ant.Task;
   18import org.jacoco.core.runtime.AgentOptions;
   19
   20/**
   21 * Base class for all coverage tasks that require agent options
   22 * 
   23 * @author Brock Janiczak
   24 * @version $Revision: $
   25 */
   26public class AbstractCoverageTask extends Task {
   27
   28    private final AgentOptions agentOptions;
   29
   30    /**
   31     * Create default agent options
   32     */
   33    protected AbstractCoverageTask() {
   34        agentOptions = new AgentOptions();
   35    }
   36
   37    /**
   38     * Gets the currently configured agent options for this task
   39     * 
   40     * @return Configured agent options
   41     */
   42    public AgentOptions getAgentOptions() {
   43        return agentOptions;
   44    }
   45
   46    /**
   47     * Sets the location to write coverage execution data
   48     * 
   49     * @ant.not-required Default is current working directory
   50     * @param file
   51     *            Location to write coverage execution data
   52     */
   53    public void setFile(final File file) {
   54        agentOptions.setFile(file.getAbsolutePath());
   55    }
   56
   57    /**
   58     * Merge execution coverage data if a coverage file is already present
   59     * 
   60     * @ant.not-required Default is true
   61     * @param merge
   62     *            <code>true</code> to merge execution data
   63     */
   64    public void setMerge(final boolean merge) {
   65        agentOptions.setMerge(merge);
   66    }
   67
   68    /**
   69     * List of wildcard patterns classes to include for instrumentation.
   70     * 
   71     * @ant.not-required Default is *
   72     * @param includes
   73     *            Wildcard pattern of included classes
   74     */
   75    public void setIncludes(final String includes) {
   76        agentOptions.setIncludes(includes);
   77    }
   78
   79    /**
   80     * List of wildcard patterns classes to exclude from instrumentation.
   81     * 
   82     * @ant.not-required Default is the empty string, no classes excluded
   83     * @param excludes
   84     *            Wildcard pattern of excluded classes
   85     */
   86    public void setExcludes(final String excludes) {
   87        agentOptions.setExcludes(excludes);
   88    }
   89
   90    /**
   91     * List of wildcard patterns for classloaders that JaCoCo will not
   92     * instrument classes from.
   93     * 
   94     * @ant.not-required Default is sun.reflect.DelegatingClassLoader
   95     * @param exclClassLoader
   96     *            Wildcard pattern of class loaders to exclude
   97     */
   98    public void setExclClassLoader(final String exclClassLoader) {
   99        agentOptions.setExclClassloader(exclClassLoader);
  100    }
  101
  102}