diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-08-30 22:13:04 +0600 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-08-30 22:13:04 +0600 |
commit | e69ba4dbb015949c5d84ba7bbb0b53efac28bb23 (patch) | |
tree | 44cbe6d78216fcb3c37c0aca1dc7ed3fc09906fa /org.jacoco.ant | |
parent | a888d873ac20357a4a11029bc84c5c4b48e394a3 (diff) | |
download | jacoco-e69ba4dbb015949c5d84ba7bbb0b53efac28bb23.tar.gz |
Fix EOLs
Diffstat (limited to 'org.jacoco.ant')
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/AbstractCoverageTask.java | 430 | ||||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/AgentTask.java | 98 | ||||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/CoverageTask.java | 394 | ||||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/DumpTask.java | 352 | ||||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/MergeTask.java | 248 | ||||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/ReportTask.java | 990 | ||||
-rw-r--r-- | org.jacoco.ant/src/org/jacoco/ant/antlib.xml | 42 |
7 files changed, 1277 insertions, 1277 deletions
diff --git a/org.jacoco.ant/src/org/jacoco/ant/AbstractCoverageTask.java b/org.jacoco.ant/src/org/jacoco/ant/AbstractCoverageTask.java index 6c8d37c2..c9bd0f7d 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/AbstractCoverageTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/AbstractCoverageTask.java @@ -1,215 +1,215 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 java.io.File;
-import java.io.IOException;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.jacoco.agent.AgentJar;
-import org.jacoco.core.runtime.AgentOptions;
-
-/**
- * Base class for all coverage tasks that require agent options
- */
-public class AbstractCoverageTask extends Task {
-
- private final AgentOptions agentOptions;
-
- private boolean enabled;
-
- /**
- * Create default agent options
- */
- protected AbstractCoverageTask() {
- super();
- agentOptions = new AgentOptions();
- enabled = true;
- }
-
- /**
- * @return Whether or not the current task is enabled
- */
- public boolean isEnabled() {
- return enabled;
- }
-
- /**
- * Sets whether or not the current task is enabled
- *
- * @param enabled
- * Enablement state of the task
- */
- public void setEnabled(final boolean enabled) {
- this.enabled = enabled;
- }
-
- /**
- * Gets the currently configured agent options for this task
- *
- * @return Configured agent options
- */
- public AgentOptions getAgentOptions() {
- return agentOptions;
- }
-
- /**
- * Sets the location to write coverage execution data. Default is current
- * working directory
- *
- * @param file
- * Location to write coverage execution data
- */
- public void setDestfile(final File file) {
- agentOptions.setDestfile(file.getAbsolutePath());
- }
-
- /**
- * Append execution coverage data if a coverage file is already present.
- * Default is <code>true</code>
- *
- * @param append
- * <code>true</code> to append execution data to an existing file
- */
- public void setAppend(final boolean append) {
- agentOptions.setAppend(append);
- }
-
- /**
- * List of wildcard patterns classes to include for instrumentation. Default
- * is <code>*</code>
- *
- * @param includes
- * Wildcard pattern of included classes
- */
- public void setIncludes(final String includes) {
- agentOptions.setIncludes(includes);
- }
-
- /**
- * List of wildcard patterns classes to exclude from instrumentation.
- * Default is the empty string, no classes excluded
- *
- * @param excludes
- * Wildcard pattern of excluded classes
- */
- public void setExcludes(final String excludes) {
- agentOptions.setExcludes(excludes);
- }
-
- /**
- * List of wildcard patterns for classloaders that JaCoCo will not
- * instrument classes from. Default is
- * <code>sun.reflect.DelegatingClassLoader</code>
- *
- * @param exclClassLoader
- * Wildcard pattern of class loaders to exclude
- */
- public void setExclClassLoader(final String exclClassLoader) {
- agentOptions.setExclClassloader(exclClassLoader);
- }
-
- /**
- * Sets the session identifier. Default is a auto-generated id
- *
- * @param id
- * session identifier
- */
- public void setSessionId(final String id) {
- agentOptions.setSessionId(id);
- }
-
- /**
- * Dump coverage data on VM termination. Default is <code>true</code>
- *
- * @param dumpOnExit
- * <code>true</code> to write coverage data on VM termination
- */
- public void setDumpOnExit(final boolean dumpOnExit) {
- agentOptions.setDumpOnExit(dumpOnExit);
- }
-
- /**
- * Sets the output method. Default is <code>file</code>
- *
- * @param output
- * Output method
- */
- public void setOutput(final String output) {
- agentOptions.setOutput(output);
- }
-
- /**
- * Sets the IP address or hostname to bind to when output method is tcp
- * server or connect to when the output method is tcp client. Default is
- * <code>localhost</code>
- *
- * @param address
- * Address to bind or connect to
- */
- public void setAddress(final String address) {
- agentOptions.setAddress(address);
- }
-
- /**
- * Sets the Port to bind to when the output method is tcp server or connect
- * to when the output method is tcp client. Default is <code>6300</code>
- *
- * @param port
- */
- public void setPort(final int port) {
- agentOptions.setPort(port);
- }
-
- /**
- * Sets the directory where all class files seen by the agent should be
- * dumped to.
- *
- * @param dir
- * dump output location
- */
- public void setClassdumpdir(final File dir) {
- agentOptions.setClassDumpDir(dir.getAbsolutePath());
- }
-
- /**
- * Creates JVM argument to launch with the specified JaCoCo agent jar and
- * the current options
- *
- * @return JVM Argument to pass to new VM
- */
- protected String getLaunchingArgument() {
- return getAgentOptions().getVMArgument(getAgentFile());
- }
-
- private File getAgentFile() {
- try {
- File agentFile = null;
- final String agentFileLocation = getProject().getProperty(
- "_jacoco.agentFile");
- if (agentFileLocation != null) {
- agentFile = new File(agentFileLocation);
- } else {
- agentFile = AgentJar.extractToTempLocation();
- getProject().setProperty("_jacoco.agentFile",
- agentFile.toString());
- }
-
- return agentFile;
- } catch (final IOException e) {
- throw new BuildException("Unable to extract agent jar", e,
- getLocation());
- }
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.jacoco.agent.AgentJar; +import org.jacoco.core.runtime.AgentOptions; + +/** + * Base class for all coverage tasks that require agent options + */ +public class AbstractCoverageTask extends Task { + + private final AgentOptions agentOptions; + + private boolean enabled; + + /** + * Create default agent options + */ + protected AbstractCoverageTask() { + super(); + agentOptions = new AgentOptions(); + enabled = true; + } + + /** + * @return Whether or not the current task is enabled + */ + public boolean isEnabled() { + return enabled; + } + + /** + * Sets whether or not the current task is enabled + * + * @param enabled + * Enablement state of the task + */ + public void setEnabled(final boolean enabled) { + this.enabled = enabled; + } + + /** + * Gets the currently configured agent options for this task + * + * @return Configured agent options + */ + public AgentOptions getAgentOptions() { + return agentOptions; + } + + /** + * Sets the location to write coverage execution data. Default is current + * working directory + * + * @param file + * Location to write coverage execution data + */ + public void setDestfile(final File file) { + agentOptions.setDestfile(file.getAbsolutePath()); + } + + /** + * Append execution coverage data if a coverage file is already present. + * Default is <code>true</code> + * + * @param append + * <code>true</code> to append execution data to an existing file + */ + public void setAppend(final boolean append) { + agentOptions.setAppend(append); + } + + /** + * List of wildcard patterns classes to include for instrumentation. Default + * is <code>*</code> + * + * @param includes + * Wildcard pattern of included classes + */ + public void setIncludes(final String includes) { + agentOptions.setIncludes(includes); + } + + /** + * List of wildcard patterns classes to exclude from instrumentation. + * Default is the empty string, no classes excluded + * + * @param excludes + * Wildcard pattern of excluded classes + */ + public void setExcludes(final String excludes) { + agentOptions.setExcludes(excludes); + } + + /** + * List of wildcard patterns for classloaders that JaCoCo will not + * instrument classes from. Default is + * <code>sun.reflect.DelegatingClassLoader</code> + * + * @param exclClassLoader + * Wildcard pattern of class loaders to exclude + */ + public void setExclClassLoader(final String exclClassLoader) { + agentOptions.setExclClassloader(exclClassLoader); + } + + /** + * Sets the session identifier. Default is a auto-generated id + * + * @param id + * session identifier + */ + public void setSessionId(final String id) { + agentOptions.setSessionId(id); + } + + /** + * Dump coverage data on VM termination. Default is <code>true</code> + * + * @param dumpOnExit + * <code>true</code> to write coverage data on VM termination + */ + public void setDumpOnExit(final boolean dumpOnExit) { + agentOptions.setDumpOnExit(dumpOnExit); + } + + /** + * Sets the output method. Default is <code>file</code> + * + * @param output + * Output method + */ + public void setOutput(final String output) { + agentOptions.setOutput(output); + } + + /** + * Sets the IP address or hostname to bind to when output method is tcp + * server or connect to when the output method is tcp client. Default is + * <code>localhost</code> + * + * @param address + * Address to bind or connect to + */ + public void setAddress(final String address) { + agentOptions.setAddress(address); + } + + /** + * Sets the Port to bind to when the output method is tcp server or connect + * to when the output method is tcp client. Default is <code>6300</code> + * + * @param port + */ + public void setPort(final int port) { + agentOptions.setPort(port); + } + + /** + * Sets the directory where all class files seen by the agent should be + * dumped to. + * + * @param dir + * dump output location + */ + public void setClassdumpdir(final File dir) { + agentOptions.setClassDumpDir(dir.getAbsolutePath()); + } + + /** + * Creates JVM argument to launch with the specified JaCoCo agent jar and + * the current options + * + * @return JVM Argument to pass to new VM + */ + protected String getLaunchingArgument() { + return getAgentOptions().getVMArgument(getAgentFile()); + } + + private File getAgentFile() { + try { + File agentFile = null; + final String agentFileLocation = getProject().getProperty( + "_jacoco.agentFile"); + if (agentFileLocation != null) { + agentFile = new File(agentFileLocation); + } else { + agentFile = AgentJar.extractToTempLocation(); + getProject().setProperty("_jacoco.agentFile", + agentFile.toString()); + } + + return agentFile; + } catch (final IOException e) { + throw new BuildException("Unable to extract agent jar", e, + getLocation()); + } + } + +} diff --git a/org.jacoco.ant/src/org/jacoco/ant/AgentTask.java b/org.jacoco.ant/src/org/jacoco/ant/AgentTask.java index ed846f47..43190ac2 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/AgentTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/AgentTask.java @@ -1,49 +1,49 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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);
- }
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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); + } +} diff --git a/org.jacoco.ant/src/org/jacoco/ant/CoverageTask.java b/org.jacoco.ant/src/org/jacoco/ant/CoverageTask.java index 58d713ee..8aeee8f7 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/CoverageTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/CoverageTask.java @@ -1,197 +1,197 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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:
- * Evgeny Mandrikov - TestNG support
- * Brock Janiczak - initial API and implementation
- *
- *******************************************************************************/
-package org.jacoco.ant;
-
-import static java.lang.String.format;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.RuntimeConfigurable;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.TaskContainer;
-import org.apache.tools.ant.UnknownElement;
-
-/**
- * Container task to run Java/JUnit tasks with the JaCoCo agent jar. Coverage
- * will only be applied if all of the following are true:
- * <ul>
- * <li>Exactly one sub task may be present</li>
- * <li>Task must be either Java or JUnit</li>
- * <li>Task must be using a forked VM (so vm args can be passed)</li>
- * </ul>
- */
-public class CoverageTask extends AbstractCoverageTask implements TaskContainer {
-
- private final Collection<TaskEnhancer> taskEnhancers = new ArrayList<TaskEnhancer>();
- private Task childTask;
-
- /**
- * Creates a new default coverage task
- */
- public CoverageTask() {
- super();
- taskEnhancers.add(new JavaLikeTaskEnhancer("java"));
- taskEnhancers.add(new JavaLikeTaskEnhancer("junit"));
- taskEnhancers.add(new TestNGTaskEnhancer("testng"));
- }
-
- /**
- * Add child task to this container and reconfigure it to run with coverage
- * enabled
- */
- public void addTask(final Task task) {
- if (childTask != null) {
- throw new BuildException(
- "Only one child task can be supplied to the coverge task",
- getLocation());
- }
-
- this.childTask = task;
-
- final String subTaskTypeName = task.getTaskType();
-
- final TaskEnhancer enhancer = findEnhancerForTask(subTaskTypeName);
- if (enhancer == null) {
- throw new BuildException(format(
- "%s is not a valid child of the coverage task",
- subTaskTypeName), getLocation());
- }
-
- if (isEnabled()) {
- log(format("Enhancing %s with coverage", childTask.getTaskName()));
- enhancer.enhanceTask(task);
- }
-
- task.maybeConfigure();
- }
-
- private TaskEnhancer findEnhancerForTask(final String taskName) {
- for (final TaskEnhancer enhancer : taskEnhancers) {
- if (enhancer.supportsTask(taskName)) {
- return enhancer;
- }
- }
-
- return null;
- }
-
- /**
- * Executes subtask and performs any required cleanup
- */
- @Override
- public void execute() throws BuildException {
- if (childTask == null) {
- throw new BuildException(
- "A child task must be supplied for the coverage task",
- getLocation());
- }
-
- childTask.execute();
- }
-
- /**
- * Task enhancer for TestNG. TestNG task always run in a forked VM and has
- * nested jvmargs elements
- */
- private class TestNGTaskEnhancer extends JavaLikeTaskEnhancer {
-
- public TestNGTaskEnhancer(final String supportedTaskName) {
- super(supportedTaskName);
- }
-
- @Override
- public void enhanceTask(final Task task) {
- addJvmArgs(task);
- }
-
- }
-
- /**
- * Basic task enhancer that can handle all 'java like' tasks. That is, tasks
- * that have a top level fork attribute and nested jvmargs elements
- */
- private class JavaLikeTaskEnhancer implements TaskEnhancer {
-
- private final String supportedTaskName;
-
- public JavaLikeTaskEnhancer(final String supportedTaskName) {
- this.supportedTaskName = supportedTaskName;
- }
-
- public boolean supportsTask(final String taskname) {
- return taskname.equals(supportedTaskName);
- }
-
- public void enhanceTask(final Task task) {
- final RuntimeConfigurable configurableWrapper = task
- .getRuntimeConfigurableWrapper();
-
- final String forkValue = getProject().replaceProperties(
- (String) configurableWrapper.getAttributeMap().get("fork"));
-
- if (!Project.toBoolean(forkValue)) {
- throw new BuildException(
- "Coverage can only be applied on a forked VM",
- getLocation());
- }
-
- addJvmArgs(task);
- }
-
- public void addJvmArgs(final Task task) {
- final UnknownElement el = new UnknownElement("jvmarg");
- el.setTaskName("jvmarg");
- el.setQName("jvmarg");
-
- final RuntimeConfigurable runtimeConfigurableWrapper = el
- .getRuntimeConfigurableWrapper();
- runtimeConfigurableWrapper.setAttribute("value",
- getLaunchingArgument());
-
- task.getRuntimeConfigurableWrapper().addChild(
- runtimeConfigurableWrapper);
-
- ((UnknownElement) task).addChild(el);
- }
- }
-
- /**
- * The task enhancer is responsible for potentially reconfiguring a task to
- * support running with code coverage enabled
- */
- private interface TaskEnhancer {
- /**
- * @param taskname
- * Task type to enhance
- * @return <code>true</code> if this enhancer is capable of enhancing
- * the requested task type
- */
- public boolean supportsTask(String taskname);
-
- /**
- * Attempt to enhance the supplied task with coverage information. This
- * operation may fail if the task is being executed in the current VM
- *
- * @param task
- * Task instance to enhance (usually an
- * {@link UnknownElement})
- * @throws BuildException
- * Thrown if this enhancer can handle this type of task, but
- * this instance can not be enhanced for some reason.
- */
- public void enhanceTask(Task task) throws BuildException;
- }
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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: + * Evgeny Mandrikov - TestNG support + * Brock Janiczak - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.ant; + +import static java.lang.String.format; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.RuntimeConfigurable; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.TaskContainer; +import org.apache.tools.ant.UnknownElement; + +/** + * Container task to run Java/JUnit tasks with the JaCoCo agent jar. Coverage + * will only be applied if all of the following are true: + * <ul> + * <li>Exactly one sub task may be present</li> + * <li>Task must be either Java or JUnit</li> + * <li>Task must be using a forked VM (so vm args can be passed)</li> + * </ul> + */ +public class CoverageTask extends AbstractCoverageTask implements TaskContainer { + + private final Collection<TaskEnhancer> taskEnhancers = new ArrayList<TaskEnhancer>(); + private Task childTask; + + /** + * Creates a new default coverage task + */ + public CoverageTask() { + super(); + taskEnhancers.add(new JavaLikeTaskEnhancer("java")); + taskEnhancers.add(new JavaLikeTaskEnhancer("junit")); + taskEnhancers.add(new TestNGTaskEnhancer("testng")); + } + + /** + * Add child task to this container and reconfigure it to run with coverage + * enabled + */ + public void addTask(final Task task) { + if (childTask != null) { + throw new BuildException( + "Only one child task can be supplied to the coverge task", + getLocation()); + } + + this.childTask = task; + + final String subTaskTypeName = task.getTaskType(); + + final TaskEnhancer enhancer = findEnhancerForTask(subTaskTypeName); + if (enhancer == null) { + throw new BuildException(format( + "%s is not a valid child of the coverage task", + subTaskTypeName), getLocation()); + } + + if (isEnabled()) { + log(format("Enhancing %s with coverage", childTask.getTaskName())); + enhancer.enhanceTask(task); + } + + task.maybeConfigure(); + } + + private TaskEnhancer findEnhancerForTask(final String taskName) { + for (final TaskEnhancer enhancer : taskEnhancers) { + if (enhancer.supportsTask(taskName)) { + return enhancer; + } + } + + return null; + } + + /** + * Executes subtask and performs any required cleanup + */ + @Override + public void execute() throws BuildException { + if (childTask == null) { + throw new BuildException( + "A child task must be supplied for the coverage task", + getLocation()); + } + + childTask.execute(); + } + + /** + * Task enhancer for TestNG. TestNG task always run in a forked VM and has + * nested jvmargs elements + */ + private class TestNGTaskEnhancer extends JavaLikeTaskEnhancer { + + public TestNGTaskEnhancer(final String supportedTaskName) { + super(supportedTaskName); + } + + @Override + public void enhanceTask(final Task task) { + addJvmArgs(task); + } + + } + + /** + * Basic task enhancer that can handle all 'java like' tasks. That is, tasks + * that have a top level fork attribute and nested jvmargs elements + */ + private class JavaLikeTaskEnhancer implements TaskEnhancer { + + private final String supportedTaskName; + + public JavaLikeTaskEnhancer(final String supportedTaskName) { + this.supportedTaskName = supportedTaskName; + } + + public boolean supportsTask(final String taskname) { + return taskname.equals(supportedTaskName); + } + + public void enhanceTask(final Task task) { + final RuntimeConfigurable configurableWrapper = task + .getRuntimeConfigurableWrapper(); + + final String forkValue = getProject().replaceProperties( + (String) configurableWrapper.getAttributeMap().get("fork")); + + if (!Project.toBoolean(forkValue)) { + throw new BuildException( + "Coverage can only be applied on a forked VM", + getLocation()); + } + + addJvmArgs(task); + } + + public void addJvmArgs(final Task task) { + final UnknownElement el = new UnknownElement("jvmarg"); + el.setTaskName("jvmarg"); + el.setQName("jvmarg"); + + final RuntimeConfigurable runtimeConfigurableWrapper = el + .getRuntimeConfigurableWrapper(); + runtimeConfigurableWrapper.setAttribute("value", + getLaunchingArgument()); + + task.getRuntimeConfigurableWrapper().addChild( + runtimeConfigurableWrapper); + + ((UnknownElement) task).addChild(el); + } + } + + /** + * The task enhancer is responsible for potentially reconfiguring a task to + * support running with code coverage enabled + */ + private interface TaskEnhancer { + /** + * @param taskname + * Task type to enhance + * @return <code>true</code> if this enhancer is capable of enhancing + * the requested task type + */ + public boolean supportsTask(String taskname); + + /** + * Attempt to enhance the supplied task with coverage information. This + * operation may fail if the task is being executed in the current VM + * + * @param task + * Task instance to enhance (usually an + * {@link UnknownElement}) + * @throws BuildException + * Thrown if this enhancer can handle this type of task, but + * this instance can not be enhanced for some reason. + */ + public void enhanceTask(Task task) throws BuildException; + } +} diff --git a/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java b/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java index c6beeeca..645403e7 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/DumpTask.java @@ -1,176 +1,176 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 static java.lang.String.format;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.Socket;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.util.FileUtils;
-import org.jacoco.core.data.ExecutionDataWriter;
-import org.jacoco.core.runtime.AgentOptions;
-import org.jacoco.core.runtime.RemoteControlReader;
-import org.jacoco.core.runtime.RemoteControlWriter;
-
-/**
- * Ant task for remotely controlling an application that is running with the
- * tcpserver output mode
- */
-public class DumpTask extends Task {
-
- private static final OutputStream NUL = new OutputStream() {
- @Override
- public void write(final int b) throws IOException {
- // nothing to do
- }
- };
-
- private boolean dump = true;
- private boolean reset = false;
- private File destfile = null;
- private String address = AgentOptions.DEFAULT_ADDRESS;
- private int port = AgentOptions.DEFAULT_PORT;
- private boolean append = true;
-
- /**
- * Sets the location of the execution data file to write. This parameter is
- * required when dump is <code>true</code>. Default is
- * <code>jacoco.exec</code>
- *
- * @param destfile
- * Location to write execution data to
- */
- public void setDestfile(final File destfile) {
- this.destfile = destfile;
- }
-
- /**
- * IP Address or hostname to connect to. Defaults to <code>localhost</code>
- *
- * @param address
- * IP Address or hostname to connect to
- */
- public void setAddress(final String address) {
- this.address = address;
- }
-
- /**
- * Port number to connect to. Default is <code>6300</code>
- *
- * @param port
- * Port to connect to
- */
- public void setPort(final int port) {
- this.port = port;
- }
-
- /**
- * <code>true</code> if the destination file it to be appended to.
- * <code>false</code> if the file is to be overwritten
- *
- * @param append
- * <code>true</code> if the destination file should be appended
- * to
- */
- public void setAppend(final boolean append) {
- this.append = append;
- }
-
- /**
- * Sets whether execution data should be downloaded from the remote host.
- * Defaults to <code>false</code>
- *
- * @param dump
- * <code>true</code> to download execution data
- */
- public void setDump(final boolean dump) {
- this.dump = dump;
- }
-
- /**
- * Sets whether a reset command should be sent after the execution data has
- * been copied. Defaults to <code>false</code>
- *
- * @param reset
- * <code>true</code> to reset execution data
- */
- public void setReset(final boolean reset) {
- this.reset = reset;
- }
-
- @Override
- public void execute() throws BuildException {
-
- if (port <= 0) {
- throw new BuildException("Invalid port value", getLocation());
- }
- if (dump && destfile == null) {
- throw new BuildException(
- "Destination file is required when dumping execution data",
- getLocation());
- }
-
- OutputStream output = null;
-
- try {
-
- // 1. Open socket connection
- final Socket socket = new Socket(InetAddress.getByName(address),
- port);
- log(format("Connecting to %s", socket.getRemoteSocketAddress()));
- final RemoteControlWriter remoteWriter = new RemoteControlWriter(
- socket.getOutputStream());
- final RemoteControlReader remoteReader = new RemoteControlReader(
- socket.getInputStream());
-
- // 2. Open file output
- output = openOutputStream();
- final ExecutionDataWriter outputWriter = new ExecutionDataWriter(
- output);
- remoteReader.setSessionInfoVisitor(outputWriter);
- remoteReader.setExecutionDataVisitor(outputWriter);
-
- // 3. Request dump
- remoteWriter.visitDumpCommand(dump, reset);
- remoteReader.read();
-
- socket.close();
-
- } catch (final IOException e) {
- throw new BuildException("Unable to dump coverage data", e,
- getLocation());
- } finally {
- FileUtils.close(output);
- }
- }
-
- private OutputStream openOutputStream() throws IOException {
- OutputStream output;
- if (dump) {
- log(format("Dumping execution data to %s",
- destfile.getAbsolutePath()));
- FileUtils.getFileUtils().createNewFile(destfile, true);
- output = new FileOutputStream(destfile, append);
- } else {
- output = NUL;
- }
- return output;
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 static java.lang.String.format; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.Socket; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.util.FileUtils; +import org.jacoco.core.data.ExecutionDataWriter; +import org.jacoco.core.runtime.AgentOptions; +import org.jacoco.core.runtime.RemoteControlReader; +import org.jacoco.core.runtime.RemoteControlWriter; + +/** + * Ant task for remotely controlling an application that is running with the + * tcpserver output mode + */ +public class DumpTask extends Task { + + private static final OutputStream NUL = new OutputStream() { + @Override + public void write(final int b) throws IOException { + // nothing to do + } + }; + + private boolean dump = true; + private boolean reset = false; + private File destfile = null; + private String address = AgentOptions.DEFAULT_ADDRESS; + private int port = AgentOptions.DEFAULT_PORT; + private boolean append = true; + + /** + * Sets the location of the execution data file to write. This parameter is + * required when dump is <code>true</code>. Default is + * <code>jacoco.exec</code> + * + * @param destfile + * Location to write execution data to + */ + public void setDestfile(final File destfile) { + this.destfile = destfile; + } + + /** + * IP Address or hostname to connect to. Defaults to <code>localhost</code> + * + * @param address + * IP Address or hostname to connect to + */ + public void setAddress(final String address) { + this.address = address; + } + + /** + * Port number to connect to. Default is <code>6300</code> + * + * @param port + * Port to connect to + */ + public void setPort(final int port) { + this.port = port; + } + + /** + * <code>true</code> if the destination file it to be appended to. + * <code>false</code> if the file is to be overwritten + * + * @param append + * <code>true</code> if the destination file should be appended + * to + */ + public void setAppend(final boolean append) { + this.append = append; + } + + /** + * Sets whether execution data should be downloaded from the remote host. + * Defaults to <code>false</code> + * + * @param dump + * <code>true</code> to download execution data + */ + public void setDump(final boolean dump) { + this.dump = dump; + } + + /** + * Sets whether a reset command should be sent after the execution data has + * been copied. Defaults to <code>false</code> + * + * @param reset + * <code>true</code> to reset execution data + */ + public void setReset(final boolean reset) { + this.reset = reset; + } + + @Override + public void execute() throws BuildException { + + if (port <= 0) { + throw new BuildException("Invalid port value", getLocation()); + } + if (dump && destfile == null) { + throw new BuildException( + "Destination file is required when dumping execution data", + getLocation()); + } + + OutputStream output = null; + + try { + + // 1. Open socket connection + final Socket socket = new Socket(InetAddress.getByName(address), + port); + log(format("Connecting to %s", socket.getRemoteSocketAddress())); + final RemoteControlWriter remoteWriter = new RemoteControlWriter( + socket.getOutputStream()); + final RemoteControlReader remoteReader = new RemoteControlReader( + socket.getInputStream()); + + // 2. Open file output + output = openOutputStream(); + final ExecutionDataWriter outputWriter = new ExecutionDataWriter( + output); + remoteReader.setSessionInfoVisitor(outputWriter); + remoteReader.setExecutionDataVisitor(outputWriter); + + // 3. Request dump + remoteWriter.visitDumpCommand(dump, reset); + remoteReader.read(); + + socket.close(); + + } catch (final IOException e) { + throw new BuildException("Unable to dump coverage data", e, + getLocation()); + } finally { + FileUtils.close(output); + } + } + + private OutputStream openOutputStream() throws IOException { + OutputStream output; + if (dump) { + log(format("Dumping execution data to %s", + destfile.getAbsolutePath())); + FileUtils.getFileUtils().createNewFile(destfile, true); + output = new FileOutputStream(destfile, append); + } else { + output = NUL; + } + return output; + } + +} diff --git a/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java b/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java index 92f9b3e9..77dea180 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/MergeTask.java @@ -1,124 +1,124 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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 static java.lang.String.format;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Iterator;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.ResourceCollection;
-import org.apache.tools.ant.types.resources.Union;
-import org.apache.tools.ant.util.FileUtils;
-import org.jacoco.core.data.ExecutionDataReader;
-import org.jacoco.core.data.ExecutionDataStore;
-import org.jacoco.core.data.ExecutionDataWriter;
-import org.jacoco.core.data.SessionInfoStore;
-
-/**
- * Task for merging a set of execution data store files into a single file
- */
-public class MergeTask extends Task {
-
- private File destfile;
-
- private final Union files = new Union();
-
- /**
- * Sets the location of the merged data store
- *
- * @param destfile
- * Destination data store location
- */
- public void setDestfile(final File destfile) {
- this.destfile = destfile;
- }
-
- /**
- * This task accepts any number of execution data resources.
- *
- * @param resources
- * Execution data resources
- */
- public void addConfigured(final ResourceCollection resources) {
- files.add(resources);
- }
-
- @Override
- public void execute() throws BuildException {
- if (destfile == null) {
- throw new BuildException("Destination file must be supplied",
- getLocation());
- }
-
- final SessionInfoStore infoStore = new SessionInfoStore();
- final ExecutionDataStore dataStore = new ExecutionDataStore();
-
- loadSourceFiles(infoStore, dataStore);
-
- OutputStream outputStream = null;
- try {
- FileUtils.getFileUtils().createNewFile(destfile, true);
-
- outputStream = new BufferedOutputStream(new FileOutputStream(
- destfile));
- final ExecutionDataWriter dataWriter = new ExecutionDataWriter(
- outputStream);
- infoStore.accept(dataWriter);
- dataStore.accept(dataWriter);
- } catch (final IOException e) {
- throw new BuildException(format("Unable to write merged file %s",
- destfile.getAbsolutePath()), e, getLocation());
- } finally {
- FileUtils.close(outputStream);
- }
-
- }
-
- private void loadSourceFiles(final SessionInfoStore infoStore,
- final ExecutionDataStore dataStore) {
- final Iterator<?> resourceIterator = files.iterator();
- while (resourceIterator.hasNext()) {
- final Resource resource = (Resource) resourceIterator.next();
-
- if (resource.isDirectory()) {
- continue;
- }
-
- log(format("Loading execution data file %s", resource));
-
- InputStream resourceStream = null;
- try {
- resourceStream = resource.getInputStream();
- final ExecutionDataReader reader = new ExecutionDataReader(
- resourceStream);
- reader.setSessionInfoVisitor(infoStore);
- reader.setExecutionDataVisitor(dataStore);
- reader.read();
- } catch (final IOException e) {
- throw new BuildException(format("Unable to read %s", resource),
- e, getLocation());
- } finally {
- FileUtils.close(resourceStream);
- }
- }
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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 static java.lang.String.format; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Iterator; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.ResourceCollection; +import org.apache.tools.ant.types.resources.Union; +import org.apache.tools.ant.util.FileUtils; +import org.jacoco.core.data.ExecutionDataReader; +import org.jacoco.core.data.ExecutionDataStore; +import org.jacoco.core.data.ExecutionDataWriter; +import org.jacoco.core.data.SessionInfoStore; + +/** + * Task for merging a set of execution data store files into a single file + */ +public class MergeTask extends Task { + + private File destfile; + + private final Union files = new Union(); + + /** + * Sets the location of the merged data store + * + * @param destfile + * Destination data store location + */ + public void setDestfile(final File destfile) { + this.destfile = destfile; + } + + /** + * This task accepts any number of execution data resources. + * + * @param resources + * Execution data resources + */ + public void addConfigured(final ResourceCollection resources) { + files.add(resources); + } + + @Override + public void execute() throws BuildException { + if (destfile == null) { + throw new BuildException("Destination file must be supplied", + getLocation()); + } + + final SessionInfoStore infoStore = new SessionInfoStore(); + final ExecutionDataStore dataStore = new ExecutionDataStore(); + + loadSourceFiles(infoStore, dataStore); + + OutputStream outputStream = null; + try { + FileUtils.getFileUtils().createNewFile(destfile, true); + + outputStream = new BufferedOutputStream(new FileOutputStream( + destfile)); + final ExecutionDataWriter dataWriter = new ExecutionDataWriter( + outputStream); + infoStore.accept(dataWriter); + dataStore.accept(dataWriter); + } catch (final IOException e) { + throw new BuildException(format("Unable to write merged file %s", + destfile.getAbsolutePath()), e, getLocation()); + } finally { + FileUtils.close(outputStream); + } + + } + + private void loadSourceFiles(final SessionInfoStore infoStore, + final ExecutionDataStore dataStore) { + final Iterator<?> resourceIterator = files.iterator(); + while (resourceIterator.hasNext()) { + final Resource resource = (Resource) resourceIterator.next(); + + if (resource.isDirectory()) { + continue; + } + + log(format("Loading execution data file %s", resource)); + + InputStream resourceStream = null; + try { + resourceStream = resource.getInputStream(); + final ExecutionDataReader reader = new ExecutionDataReader( + resourceStream); + reader.setSessionInfoVisitor(infoStore); + reader.setExecutionDataVisitor(dataStore); + reader.read(); + } catch (final IOException e) { + throw new BuildException(format("Unable to read %s", resource), + e, getLocation()); + } finally { + FileUtils.close(resourceStream); + } + } + } + +} diff --git a/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java b/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java index c7593a47..dd458b21 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java +++ b/org.jacoco.ant/src/org/jacoco/ant/ReportTask.java @@ -1,495 +1,495 @@ -/*******************************************************************************
- * Copyright (c) 2009, 2012 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:
- * Marc R. Hoffmann - initial API and implementation
- *
- *******************************************************************************/
-package org.jacoco.ant;
-
-import static java.lang.String.format;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.resources.FileResource;
-import org.apache.tools.ant.types.resources.Union;
-import org.apache.tools.ant.util.FileUtils;
-import org.jacoco.core.analysis.Analyzer;
-import org.jacoco.core.analysis.CoverageBuilder;
-import org.jacoco.core.analysis.IBundleCoverage;
-import org.jacoco.core.analysis.ICoverageNode;
-import org.jacoco.core.data.ExecutionDataReader;
-import org.jacoco.core.data.ExecutionDataStore;
-import org.jacoco.core.data.SessionInfoStore;
-import org.jacoco.report.FileMultiReportOutput;
-import org.jacoco.report.IMultiReportOutput;
-import org.jacoco.report.IReportGroupVisitor;
-import org.jacoco.report.IReportVisitor;
-import org.jacoco.report.MultiReportVisitor;
-import org.jacoco.report.ZipMultiReportOutput;
-import org.jacoco.report.csv.CSVFormatter;
-import org.jacoco.report.html.HTMLFormatter;
-import org.jacoco.report.xml.XMLFormatter;
-
-/**
- * Task for coverage report generation. Experimental implementation that needs
- * refinement.
- */
-public class ReportTask extends Task {
-
- /**
- * The source files are specified in a resource collection with additional
- * attributes.
- */
- public static class SourceFilesElement extends Union {
-
- String encoding = null;
-
- int tabWidth = 4;
-
- /**
- * Defines the optional source file encoding. If not set the platform
- * default is used.
- *
- * @param encoding
- * source file encoding
- */
- public void setEncoding(final String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Sets the tab stop width for the source pages. Default value is 4.
- *
- * @param tabWidth
- * number of characters per tab stop
- */
- public void setTabwidth(final int tabWidth) {
- if (tabWidth <= 0) {
- throw new BuildException("Tab width must be greater than 0");
- }
- this.tabWidth = tabWidth;
- }
-
- }
-
- /**
- * Container element for class file groups.
- */
- public static class GroupElement {
-
- private final List<GroupElement> children = new ArrayList<GroupElement>();
-
- private final Union classfiles = new Union();
-
- private final SourceFilesElement sourcefiles = new SourceFilesElement();
-
- private String name;
-
- /**
- * Sets the name of the group.
- *
- * @param name
- * name of the group
- */
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
- * Creates a new child group.
- *
- * @return new child group
- */
- public GroupElement createGroup() {
- final GroupElement group = new GroupElement();
- children.add(group);
- return group;
- }
-
- /**
- * Returns the nested resource collection for class files.
- *
- * @return resource collection for class files
- */
- public Union createClassfiles() {
- return classfiles;
- }
-
- /**
- * Returns the nested resource collection for source files.
- *
- * @return resource collection for source files
- */
- public SourceFilesElement createSourcefiles() {
- return sourcefiles;
- }
-
- }
-
- /**
- * Interface for child elements that define formatters.
- */
- private interface IFormatterElement {
-
- IReportVisitor createVisitor() throws IOException;
-
- }
-
- /**
- * Formatter Element for HTML reports.
- */
- public class HTMLFormatterElement implements IFormatterElement {
-
- private File destdir;
-
- private File destfile;
-
- private String footer = "";
-
- private String encoding = "UTF-8";
-
- private Locale locale = Locale.getDefault();
-
- /**
- * Sets the output directory for the report.
- *
- * @param destdir
- * output directory
- */
- public void setDestdir(final File destdir) {
- this.destdir = destdir;
- }
-
- /**
- * Sets the Zip output file for the report.
- *
- * @param destfile
- * Zip output file
- */
- public void setDestfile(final File destfile) {
- this.destfile = destfile;
- }
-
- /**
- * Sets an optional footer text that will be displayed on every report
- * page.
- *
- * @param text
- * footer text
- */
- public void setFooter(final String text) {
- this.footer = text;
- }
-
- /**
- * Sets the output encoding for generated HTML files. Default is UTF-8.
- *
- * @param encoding
- * output encoding
- */
- public void setEncoding(final String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Sets the locale for generated text output. By default the platform
- * locale is used.
- *
- * @param locale
- * text locale
- */
- public void setLocale(final Locale locale) {
- this.locale = locale;
- }
-
- public IReportVisitor createVisitor() throws IOException {
- final IMultiReportOutput output;
- if (destfile != null) {
- if (destdir != null) {
- throw new BuildException(
- "Either destination directory or file must be supplied, not both",
- getLocation());
- }
- final FileOutputStream stream = new FileOutputStream(destfile);
- output = new ZipMultiReportOutput(stream);
-
- } else {
- if (destdir == null) {
- throw new BuildException(
- "Destination directory or file must be supplied for html report",
- getLocation());
- }
- output = new FileMultiReportOutput(destdir);
- }
- final HTMLFormatter formatter = new HTMLFormatter();
- formatter.setFooterText(footer);
- formatter.setOutputEncoding(encoding);
- formatter.setLocale(locale);
- return formatter.createVisitor(output);
- }
-
- }
-
- /**
- * Formatter Element for CSV reports.
- */
- public class CSVFormatterElement implements IFormatterElement {
-
- private File destfile;
-
- private String encoding = "UTF-8";
-
- /**
- * Sets the output file for the report.
- *
- * @param destfile
- * output file
- */
- public void setDestfile(final File destfile) {
- this.destfile = destfile;
- }
-
- public IReportVisitor createVisitor() throws IOException {
- if (destfile == null) {
- throw new BuildException(
- "Destination file must be supplied for csv report",
- getLocation());
- }
- final CSVFormatter formatter = new CSVFormatter();
- formatter.setOutputEncoding(encoding);
- return formatter.createVisitor(new FileOutputStream(destfile));
- }
-
- /**
- * Sets the output encoding for generated XML file. Default is UTF-8.
- *
- * @param encoding
- * output encoding
- */
- public void setEncoding(final String encoding) {
- this.encoding = encoding;
- }
-
- }
-
- /**
- * Formatter Element for XML reports.
- */
- public class XMLFormatterElement implements IFormatterElement {
-
- private File destfile;
-
- private String encoding = "UTF-8";
-
- /**
- * Sets the output file for the report.
- *
- * @param destfile
- * output file
- */
- public void setDestfile(final File destfile) {
- this.destfile = destfile;
- }
-
- /**
- * Sets the output encoding for generated XML file. Default is UTF-8.
- *
- * @param encoding
- * output encoding
- */
- public void setEncoding(final String encoding) {
- this.encoding = encoding;
- }
-
- public IReportVisitor createVisitor() throws IOException {
- if (destfile == null) {
- throw new BuildException(
- "Destination file must be supplied for xml report",
- getLocation());
- }
- final XMLFormatter formatter = new XMLFormatter();
- formatter.setOutputEncoding(encoding);
- return formatter.createVisitor(new FileOutputStream(destfile));
- }
-
- }
-
- private final Union executiondataElement = new Union();
-
- private SessionInfoStore sessionInfoStore;
-
- private ExecutionDataStore executionDataStore;
-
- private final GroupElement structure = new GroupElement();
-
- private final List<IFormatterElement> formatters = new ArrayList<IFormatterElement>();
-
- /**
- * Returns the nested resource collection for execution data files.
- *
- * @return resource collection for execution files
- */
- public Union createExecutiondata() {
- return executiondataElement;
- }
-
- /**
- * Returns the root group element that defines the report structure.
- *
- * @return root group element
- */
- public GroupElement createStructure() {
- return structure;
- }
-
- /**
- * Creates a new HTML report element.
- *
- * @return HTML report element
- */
- public HTMLFormatterElement createHtml() {
- final HTMLFormatterElement element = new HTMLFormatterElement();
- formatters.add(element);
- return element;
- }
-
- /**
- * Creates a new CSV report element.
- *
- * @return CSV report element
- */
- public CSVFormatterElement createCsv() {
- final CSVFormatterElement element = new CSVFormatterElement();
- formatters.add(element);
- return element;
- }
-
- /**
- * Creates a new XML report element.
- *
- * @return CSV report element
- */
- public XMLFormatterElement createXml() {
- final XMLFormatterElement element = new XMLFormatterElement();
- formatters.add(element);
- return element;
- }
-
- @Override
- public void execute() throws BuildException {
- loadExecutionData();
- try {
- final IReportVisitor visitor = createVisitor();
- visitor.visitInfo(sessionInfoStore.getInfos(),
- executionDataStore.getContents());
- createReport(visitor, structure);
- visitor.visitEnd();
- } catch (final IOException e) {
- throw new BuildException("Error while creating report", e,
- getLocation());
- }
- }
-
- private void loadExecutionData() {
- sessionInfoStore = new SessionInfoStore();
- executionDataStore = new ExecutionDataStore();
- for (final Iterator<?> i = executiondataElement.iterator(); i.hasNext();) {
- final Resource resource = (Resource) i.next();
- log(format("Loading execution data file %s", resource));
- InputStream in = null;
- try {
- in = new BufferedInputStream(resource.getInputStream());
- final ExecutionDataReader reader = new ExecutionDataReader(in);
- reader.setSessionInfoVisitor(sessionInfoStore);
- reader.setExecutionDataVisitor(executionDataStore);
- reader.read();
- } catch (final IOException e) {
- throw new BuildException(format(
- "Unable to read execution data file %s", resource), e,
- getLocation());
- } finally {
- FileUtils.close(in);
- }
- }
- }
-
- private IReportVisitor createVisitor() throws IOException {
- final List<IReportVisitor> visitors = new ArrayList<IReportVisitor>();
- for (final IFormatterElement f : formatters) {
- visitors.add(f.createVisitor());
- }
- return new MultiReportVisitor(visitors);
- }
-
- private void createReport(final IReportGroupVisitor visitor,
- final GroupElement group) throws IOException {
- if (group.name == null) {
- throw new BuildException("Group name must be supplied",
- getLocation());
- }
- if (group.children.size() > 0) {
- final IReportGroupVisitor groupVisitor = visitor
- .visitGroup(group.name);
- for (final GroupElement child : group.children) {
- createReport(groupVisitor, child);
- }
- } else {
- final IBundleCoverage bundle = createBundle(group);
- log(format("Writing group \"%s\" with %s classes",
- bundle.getName(),
- Integer.valueOf(bundle.getClassCounter().getTotalCount())));
- final SourceFilesElement sourcefiles = group.sourcefiles;
- final AntResourcesLocator locator = new AntResourcesLocator(
- sourcefiles.encoding, sourcefiles.tabWidth);
- locator.addAll(sourcefiles.iterator());
- if (!locator.isEmpty()) {
- checkForMissingDebugInformation(bundle);
- }
- visitor.visitBundle(bundle, locator);
- }
- }
-
- private IBundleCoverage createBundle(final GroupElement group)
- throws IOException {
- final CoverageBuilder builder = new CoverageBuilder();
- final Analyzer analyzer = new Analyzer(executionDataStore, builder);
- for (final Iterator<?> i = group.classfiles.iterator(); i.hasNext();) {
- final Resource resource = (Resource) i.next();
- if (resource.isDirectory() && resource instanceof FileResource) {
- analyzer.analyzeAll(((FileResource) resource).getFile());
- } else {
- final InputStream in = resource.getInputStream();
- analyzer.analyzeAll(in);
- in.close();
- }
- }
- return builder.getBundle(group.name);
- }
-
- private void checkForMissingDebugInformation(final ICoverageNode node) {
- if (node.getClassCounter().getTotalCount() > 0
- && node.getLineCounter().getTotalCount() == 0) {
- log(format(
- "To enable source code annotation class files for bundle '%s' have to be compiled with debug information",
- node.getName()), Project.MSG_WARN);
- }
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2009, 2012 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: + * Marc R. Hoffmann - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.ant; + +import static java.lang.String.format; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.resources.FileResource; +import org.apache.tools.ant.types.resources.Union; +import org.apache.tools.ant.util.FileUtils; +import org.jacoco.core.analysis.Analyzer; +import org.jacoco.core.analysis.CoverageBuilder; +import org.jacoco.core.analysis.IBundleCoverage; +import org.jacoco.core.analysis.ICoverageNode; +import org.jacoco.core.data.ExecutionDataReader; +import org.jacoco.core.data.ExecutionDataStore; +import org.jacoco.core.data.SessionInfoStore; +import org.jacoco.report.FileMultiReportOutput; +import org.jacoco.report.IMultiReportOutput; +import org.jacoco.report.IReportGroupVisitor; +import org.jacoco.report.IReportVisitor; +import org.jacoco.report.MultiReportVisitor; +import org.jacoco.report.ZipMultiReportOutput; +import org.jacoco.report.csv.CSVFormatter; +import org.jacoco.report.html.HTMLFormatter; +import org.jacoco.report.xml.XMLFormatter; + +/** + * Task for coverage report generation. Experimental implementation that needs + * refinement. + */ +public class ReportTask extends Task { + + /** + * The source files are specified in a resource collection with additional + * attributes. + */ + public static class SourceFilesElement extends Union { + + String encoding = null; + + int tabWidth = 4; + + /** + * Defines the optional source file encoding. If not set the platform + * default is used. + * + * @param encoding + * source file encoding + */ + public void setEncoding(final String encoding) { + this.encoding = encoding; + } + + /** + * Sets the tab stop width for the source pages. Default value is 4. + * + * @param tabWidth + * number of characters per tab stop + */ + public void setTabwidth(final int tabWidth) { + if (tabWidth <= 0) { + throw new BuildException("Tab width must be greater than 0"); + } + this.tabWidth = tabWidth; + } + + } + + /** + * Container element for class file groups. + */ + public static class GroupElement { + + private final List<GroupElement> children = new ArrayList<GroupElement>(); + + private final Union classfiles = new Union(); + + private final SourceFilesElement sourcefiles = new SourceFilesElement(); + + private String name; + + /** + * Sets the name of the group. + * + * @param name + * name of the group + */ + public void setName(final String name) { + this.name = name; + } + + /** + * Creates a new child group. + * + * @return new child group + */ + public GroupElement createGroup() { + final GroupElement group = new GroupElement(); + children.add(group); + return group; + } + + /** + * Returns the nested resource collection for class files. + * + * @return resource collection for class files + */ + public Union createClassfiles() { + return classfiles; + } + + /** + * Returns the nested resource collection for source files. + * + * @return resource collection for source files + */ + public SourceFilesElement createSourcefiles() { + return sourcefiles; + } + + } + + /** + * Interface for child elements that define formatters. + */ + private interface IFormatterElement { + + IReportVisitor createVisitor() throws IOException; + + } + + /** + * Formatter Element for HTML reports. + */ + public class HTMLFormatterElement implements IFormatterElement { + + private File destdir; + + private File destfile; + + private String footer = ""; + + private String encoding = "UTF-8"; + + private Locale locale = Locale.getDefault(); + + /** + * Sets the output directory for the report. + * + * @param destdir + * output directory + */ + public void setDestdir(final File destdir) { + this.destdir = destdir; + } + + /** + * Sets the Zip output file for the report. + * + * @param destfile + * Zip output file + */ + public void setDestfile(final File destfile) { + this.destfile = destfile; + } + + /** + * Sets an optional footer text that will be displayed on every report + * page. + * + * @param text + * footer text + */ + public void setFooter(final String text) { + this.footer = text; + } + + /** + * Sets the output encoding for generated HTML files. Default is UTF-8. + * + * @param encoding + * output encoding + */ + public void setEncoding(final String encoding) { + this.encoding = encoding; + } + + /** + * Sets the locale for generated text output. By default the platform + * locale is used. + * + * @param locale + * text locale + */ + public void setLocale(final Locale locale) { + this.locale = locale; + } + + public IReportVisitor createVisitor() throws IOException { + final IMultiReportOutput output; + if (destfile != null) { + if (destdir != null) { + throw new BuildException( + "Either destination directory or file must be supplied, not both", + getLocation()); + } + final FileOutputStream stream = new FileOutputStream(destfile); + output = new ZipMultiReportOutput(stream); + + } else { + if (destdir == null) { + throw new BuildException( + "Destination directory or file must be supplied for html report", + getLocation()); + } + output = new FileMultiReportOutput(destdir); + } + final HTMLFormatter formatter = new HTMLFormatter(); + formatter.setFooterText(footer); + formatter.setOutputEncoding(encoding); + formatter.setLocale(locale); + return formatter.createVisitor(output); + } + + } + + /** + * Formatter Element for CSV reports. + */ + public class CSVFormatterElement implements IFormatterElement { + + private File destfile; + + private String encoding = "UTF-8"; + + /** + * Sets the output file for the report. + * + * @param destfile + * output file + */ + public void setDestfile(final File destfile) { + this.destfile = destfile; + } + + public IReportVisitor createVisitor() throws IOException { + if (destfile == null) { + throw new BuildException( + "Destination file must be supplied for csv report", + getLocation()); + } + final CSVFormatter formatter = new CSVFormatter(); + formatter.setOutputEncoding(encoding); + return formatter.createVisitor(new FileOutputStream(destfile)); + } + + /** + * Sets the output encoding for generated XML file. Default is UTF-8. + * + * @param encoding + * output encoding + */ + public void setEncoding(final String encoding) { + this.encoding = encoding; + } + + } + + /** + * Formatter Element for XML reports. + */ + public class XMLFormatterElement implements IFormatterElement { + + private File destfile; + + private String encoding = "UTF-8"; + + /** + * Sets the output file for the report. + * + * @param destfile + * output file + */ + public void setDestfile(final File destfile) { + this.destfile = destfile; + } + + /** + * Sets the output encoding for generated XML file. Default is UTF-8. + * + * @param encoding + * output encoding + */ + public void setEncoding(final String encoding) { + this.encoding = encoding; + } + + public IReportVisitor createVisitor() throws IOException { + if (destfile == null) { + throw new BuildException( + "Destination file must be supplied for xml report", + getLocation()); + } + final XMLFormatter formatter = new XMLFormatter(); + formatter.setOutputEncoding(encoding); + return formatter.createVisitor(new FileOutputStream(destfile)); + } + + } + + private final Union executiondataElement = new Union(); + + private SessionInfoStore sessionInfoStore; + + private ExecutionDataStore executionDataStore; + + private final GroupElement structure = new GroupElement(); + + private final List<IFormatterElement> formatters = new ArrayList<IFormatterElement>(); + + /** + * Returns the nested resource collection for execution data files. + * + * @return resource collection for execution files + */ + public Union createExecutiondata() { + return executiondataElement; + } + + /** + * Returns the root group element that defines the report structure. + * + * @return root group element + */ + public GroupElement createStructure() { + return structure; + } + + /** + * Creates a new HTML report element. + * + * @return HTML report element + */ + public HTMLFormatterElement createHtml() { + final HTMLFormatterElement element = new HTMLFormatterElement(); + formatters.add(element); + return element; + } + + /** + * Creates a new CSV report element. + * + * @return CSV report element + */ + public CSVFormatterElement createCsv() { + final CSVFormatterElement element = new CSVFormatterElement(); + formatters.add(element); + return element; + } + + /** + * Creates a new XML report element. + * + * @return CSV report element + */ + public XMLFormatterElement createXml() { + final XMLFormatterElement element = new XMLFormatterElement(); + formatters.add(element); + return element; + } + + @Override + public void execute() throws BuildException { + loadExecutionData(); + try { + final IReportVisitor visitor = createVisitor(); + visitor.visitInfo(sessionInfoStore.getInfos(), + executionDataStore.getContents()); + createReport(visitor, structure); + visitor.visitEnd(); + } catch (final IOException e) { + throw new BuildException("Error while creating report", e, + getLocation()); + } + } + + private void loadExecutionData() { + sessionInfoStore = new SessionInfoStore(); + executionDataStore = new ExecutionDataStore(); + for (final Iterator<?> i = executiondataElement.iterator(); i.hasNext();) { + final Resource resource = (Resource) i.next(); + log(format("Loading execution data file %s", resource)); + InputStream in = null; + try { + in = new BufferedInputStream(resource.getInputStream()); + final ExecutionDataReader reader = new ExecutionDataReader(in); + reader.setSessionInfoVisitor(sessionInfoStore); + reader.setExecutionDataVisitor(executionDataStore); + reader.read(); + } catch (final IOException e) { + throw new BuildException(format( + "Unable to read execution data file %s", resource), e, + getLocation()); + } finally { + FileUtils.close(in); + } + } + } + + private IReportVisitor createVisitor() throws IOException { + final List<IReportVisitor> visitors = new ArrayList<IReportVisitor>(); + for (final IFormatterElement f : formatters) { + visitors.add(f.createVisitor()); + } + return new MultiReportVisitor(visitors); + } + + private void createReport(final IReportGroupVisitor visitor, + final GroupElement group) throws IOException { + if (group.name == null) { + throw new BuildException("Group name must be supplied", + getLocation()); + } + if (group.children.size() > 0) { + final IReportGroupVisitor groupVisitor = visitor + .visitGroup(group.name); + for (final GroupElement child : group.children) { + createReport(groupVisitor, child); + } + } else { + final IBundleCoverage bundle = createBundle(group); + log(format("Writing group \"%s\" with %s classes", + bundle.getName(), + Integer.valueOf(bundle.getClassCounter().getTotalCount()))); + final SourceFilesElement sourcefiles = group.sourcefiles; + final AntResourcesLocator locator = new AntResourcesLocator( + sourcefiles.encoding, sourcefiles.tabWidth); + locator.addAll(sourcefiles.iterator()); + if (!locator.isEmpty()) { + checkForMissingDebugInformation(bundle); + } + visitor.visitBundle(bundle, locator); + } + } + + private IBundleCoverage createBundle(final GroupElement group) + throws IOException { + final CoverageBuilder builder = new CoverageBuilder(); + final Analyzer analyzer = new Analyzer(executionDataStore, builder); + for (final Iterator<?> i = group.classfiles.iterator(); i.hasNext();) { + final Resource resource = (Resource) i.next(); + if (resource.isDirectory() && resource instanceof FileResource) { + analyzer.analyzeAll(((FileResource) resource).getFile()); + } else { + final InputStream in = resource.getInputStream(); + analyzer.analyzeAll(in); + in.close(); + } + } + return builder.getBundle(group.name); + } + + private void checkForMissingDebugInformation(final ICoverageNode node) { + if (node.getClassCounter().getTotalCount() > 0 + && node.getLineCounter().getTotalCount() == 0) { + log(format( + "To enable source code annotation class files for bundle '%s' have to be compiled with debug information", + node.getName()), Project.MSG_WARN); + } + } + +} diff --git a/org.jacoco.ant/src/org/jacoco/ant/antlib.xml b/org.jacoco.ant/src/org/jacoco/ant/antlib.xml index 0516b019..a2d7acef 100644 --- a/org.jacoco.ant/src/org/jacoco/ant/antlib.xml +++ b/org.jacoco.ant/src/org/jacoco/ant/antlib.xml @@ -1,22 +1,22 @@ -<?xml version="1.0"?>
-
-<!--
- Copyright (c) 2009, 2012 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
-
- $Id: $
--->
-
-<antlib>
- <taskdef name="coverage" classname="org.jacoco.ant.CoverageTask"/>
- <taskdef name="agent" classname="org.jacoco.ant.AgentTask"/>
- <taskdef name="report" classname="org.jacoco.ant.ReportTask"/>
- <taskdef name="merge" classname="org.jacoco.ant.MergeTask"/>
- <taskdef name="dump" classname="org.jacoco.ant.DumpTask"/>
+<?xml version="1.0"?> + +<!-- + Copyright (c) 2009, 2012 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 + + $Id: $ +--> + +<antlib> + <taskdef name="coverage" classname="org.jacoco.ant.CoverageTask"/> + <taskdef name="agent" classname="org.jacoco.ant.AgentTask"/> + <taskdef name="report" classname="org.jacoco.ant.ReportTask"/> + <taskdef name="merge" classname="org.jacoco.ant.MergeTask"/> + <taskdef name="dump" classname="org.jacoco.ant.DumpTask"/> </antlib>
\ No newline at end of file |