aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--org.jacoco.build/pom.xml5
-rw-r--r--org.jacoco.examples.test/.classpath7
-rw-r--r--org.jacoco.examples.test/.gitignore2
-rw-r--r--org.jacoco.examples.test/.project35
-rw-r--r--org.jacoco.examples.test/META-INF/MANIFEST.MF12
-rw-r--r--org.jacoco.examples.test/about.html27
-rw-r--r--org.jacoco.examples.test/build.properties4
-rw-r--r--org.jacoco.examples.test/pom.xml41
-rw-r--r--org.jacoco.examples.test/src/org/jacoco/examples/ClassInfoTest.java57
-rw-r--r--org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java70
-rw-r--r--org.jacoco.examples.test/src/org/jacoco/examples/CoreTutorialTest.java38
-rw-r--r--org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java59
-rw-r--r--org.jacoco.examples/src/org/jacoco/examples/ClassInfo.java55
-rw-r--r--org.jacoco.examples/src/org/jacoco/examples/CoreTutorial.java80
-rw-r--r--org.jacoco.examples/src/org/jacoco/examples/ExecDump.java56
-rw-r--r--org.jacoco.tests/pom.xml6
16 files changed, 485 insertions, 69 deletions
diff --git a/org.jacoco.build/pom.xml b/org.jacoco.build/pom.xml
index 0c1fdc88..f03aad80 100644
--- a/org.jacoco.build/pom.xml
+++ b/org.jacoco.build/pom.xml
@@ -193,6 +193,11 @@
<classifier>nodeps</classifier>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.jacoco.examples</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- Third-party dependencies -->
<dependency>
<groupId>org.ow2.asm</groupId>
diff --git a/org.jacoco.examples.test/.classpath b/org.jacoco.examples.test/.classpath
new file mode 100644
index 00000000..64c5e31b
--- /dev/null
+++ b/org.jacoco.examples.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.jacoco.examples.test/.gitignore b/org.jacoco.examples.test/.gitignore
new file mode 100644
index 00000000..4dc00917
--- /dev/null
+++ b/org.jacoco.examples.test/.gitignore
@@ -0,0 +1,2 @@
+/target
+/bin
diff --git a/org.jacoco.examples.test/.project b/org.jacoco.examples.test/.project
new file mode 100644
index 00000000..56dd28db
--- /dev/null
+++ b/org.jacoco.examples.test/.project
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jacoco.examples.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>.settings</name>
+ <type>2</type>
+ <locationURI>PARENT-1-PROJECT_LOC/org.jacoco.core.test/.settings</locationURI>
+ </link>
+ </linkedResources>
+</projectDescription>
diff --git a/org.jacoco.examples.test/META-INF/MANIFEST.MF b/org.jacoco.examples.test/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..70691df3
--- /dev/null
+++ b/org.jacoco.examples.test/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: JaCoCo Examples Tests
+Bundle-SymbolicName: org.jacoco.examples.test
+Bundle-Version: 0.6.4.qualifier
+Bundle-Vendor: Mountainminds GmbH & Co. KG
+Fragment-Host: org.jacoco.examples
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.junit;version="[4.8.0,5.0.0)",
+ org.junit.matchers;version="[4.8.0,5.0.0)",
+ org.junit.rules;version="[4.8.0,5.0.0)"
+Require-Bundle: org.hamcrest.core;bundle-version="[1.1.0,2.0.0)"
diff --git a/org.jacoco.examples.test/about.html b/org.jacoco.examples.test/about.html
new file mode 100644
index 00000000..d31112db
--- /dev/null
+++ b/org.jacoco.examples.test/about.html
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<title>About</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>
+ @build.date@
+</p>
+
+<h3>License</h3>
+
+<p>
+ All Content in this plug-in is made available by Mountainminds GmbH &amp; Co.
+ KG, Munich. Unless otherwise indicated below, the Content is provided to you
+ under the terms and conditions of the Eclipse Public License Version 1.0
+ (&quot;EPL&quot;). A copy of the EPL is available at
+ <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+ For purposes of the EPL, "Program" will mean the Content.
+</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.jacoco.examples.test/build.properties b/org.jacoco.examples.test/build.properties
new file mode 100644
index 00000000..34d2e4d2
--- /dev/null
+++ b/org.jacoco.examples.test/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.jacoco.examples.test/pom.xml b/org.jacoco.examples.test/pom.xml
new file mode 100644
index 00000000..a2dbf9d3
--- /dev/null
+++ b/org.jacoco.examples.test/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2009, 2013 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 - initial API and implementation
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.tests</artifactId>
+ <version>0.6.4-SNAPSHOT</version>
+ <relativePath>../org.jacoco.tests</relativePath>
+ </parent>
+
+ <artifactId>org.jacoco.examples.test</artifactId>
+
+ <name>JaCoCo :: Test :: Examples</name>
+
+ <properties>
+ <jacoco.includes>org.jacoco.examples.*</jacoco.includes>
+ <jacoco.excludes>org.jacoco.examples.CoreTutorial$TestTarget</jacoco.excludes>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>org.jacoco.examples</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/org.jacoco.examples.test/src/org/jacoco/examples/ClassInfoTest.java b/org.jacoco.examples.test/src/org/jacoco/examples/ClassInfoTest.java
new file mode 100644
index 00000000..bd4c200e
--- /dev/null
+++ b/org.jacoco.examples.test/src/org/jacoco/examples/ClassInfoTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2013 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.examples;
+
+import static org.jacoco.examples.ConsoleOutput.containsLine;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests for {@link ClassInfo}.
+ */
+public class ClassInfoTest {
+
+ @Rule
+ public ConsoleOutput console = new ConsoleOutput();
+
+ @Test
+ public void testRunExample() throws Exception {
+
+ final String[] args = new String[] { createClassFile() };
+ new ClassInfo(console.stream).execute(args);
+
+ console.expect(containsLine("class name: org/jacoco/examples/ClassInfoTest"));
+ console.expect(containsLine("methods: 3"));
+ console.expect(containsLine("branches: 2"));
+ console.expect(containsLine("complexity: 4"));
+ }
+
+ private String createClassFile() throws IOException {
+ InputStream in = getClass().getResource(
+ getClass().getSimpleName() + ".class").openStream();
+ File f = File.createTempFile("Example", ".class");
+ FileOutputStream out = new FileOutputStream(f);
+ int b;
+ while ((b = in.read()) != -1) {
+ out.write(b);
+ }
+ in.close();
+ out.close();
+ return f.getPath();
+ }
+}
diff --git a/org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java b/org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java
new file mode 100644
index 00000000..40ab3d8e
--- /dev/null
+++ b/org.jacoco.examples.test/src/org/jacoco/examples/ConsoleOutput.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2013 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.examples;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+
+import org.hamcrest.Matcher;
+import org.junit.rules.ExternalResource;
+
+/**
+ * In-Memory buffer to assert console output.
+ */
+public class ConsoleOutput extends ExternalResource {
+
+ private final ByteArrayOutputStream buffer;
+
+ public final PrintStream stream;
+
+ public ConsoleOutput() {
+ this.buffer = new ByteArrayOutputStream();
+ try {
+ this.stream = new PrintStream(buffer, true, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e.getMessage());
+ }
+ }
+
+ @Override
+ protected void after() {
+ buffer.reset();
+ }
+
+ public static Matcher<String> containsLine(String line) {
+ return containsString(String.format("%s\n", line));
+ }
+
+ public static Matcher<String> isEmpty() {
+ return is("");
+ }
+
+ public String getContents() {
+ try {
+ return new String(buffer.toByteArray(), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ fail(e.getMessage());
+ return "";
+ }
+ }
+
+ public void expect(Matcher<String> matcher) {
+ assertThat(getContents(), matcher);
+ }
+
+}
diff --git a/org.jacoco.examples.test/src/org/jacoco/examples/CoreTutorialTest.java b/org.jacoco.examples.test/src/org/jacoco/examples/CoreTutorialTest.java
new file mode 100644
index 00000000..7fea0e4f
--- /dev/null
+++ b/org.jacoco.examples.test/src/org/jacoco/examples/CoreTutorialTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2013 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.examples;
+
+import static org.jacoco.examples.ConsoleOutput.containsLine;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests for {@link CoreTutorial}.
+ */
+public class CoreTutorialTest {
+
+ @Rule
+ public ConsoleOutput console = new ConsoleOutput();
+
+ @Test
+ public void testRunExample() throws Exception {
+ new CoreTutorial(console.stream).execute();
+
+ console.expect(containsLine("0 of 3 methods missed"));
+ console.expect(containsLine("1 of 5 complexity missed"));
+ console.expect(containsLine("Line 46: "));
+ console.expect(containsLine("Line 47: green"));
+ console.expect(containsLine("Line 48: yellow"));
+ console.expect(containsLine("Line 49: red"));
+ }
+}
diff --git a/org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java b/org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java
new file mode 100644
index 00000000..f35bf89b
--- /dev/null
+++ b/org.jacoco.examples.test/src/org/jacoco/examples/ExecDumpTest.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2013 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.examples;
+
+import static org.jacoco.examples.ConsoleOutput.containsLine;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.jacoco.core.data.ExecutionData;
+import org.jacoco.core.data.ExecutionDataWriter;
+import org.jacoco.core.data.SessionInfo;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests for {@link ExecDump}.
+ */
+public class ExecDumpTest {
+
+ @Rule
+ public ConsoleOutput console = new ConsoleOutput();
+
+ @Test
+ public void testRunExample() throws Exception {
+
+ final String file = createExecFile();
+ final String[] args = new String[] { file };
+ new ExecDump(console.stream).execute(args);
+
+ console.expect(containsLine("exec file: " + file));
+ console.expect(containsLine("CLASS ID HITS/PROBES CLASS NAME"));
+ console.expect(containsString("Session \"testid\":"));
+ console.expect(containsLine("0000000000001234 2 of 3 foo/MyClass"));
+ }
+
+ private String createExecFile() throws IOException {
+ File f = File.createTempFile("jacoco", ".exec");
+ final FileOutputStream out = new FileOutputStream(f);
+ final ExecutionDataWriter writer = new ExecutionDataWriter(out);
+ writer.visitSessionInfo(new SessionInfo("testid", 1, 2));
+ writer.visitClassExecution(new ExecutionData(0x1234, "foo/MyClass",
+ new boolean[] { false, true, true }));
+ writer.flush();
+ out.close();
+ return f.getPath();
+ }
+}
diff --git a/org.jacoco.examples/src/org/jacoco/examples/ClassInfo.java b/org.jacoco.examples/src/org/jacoco/examples/ClassInfo.java
index 21c2a588..30daf014 100644
--- a/org.jacoco.examples/src/org/jacoco/examples/ClassInfo.java
+++ b/org.jacoco.examples/src/org/jacoco/examples/ClassInfo.java
@@ -13,6 +13,7 @@ package org.jacoco.examples;
import java.io.File;
import java.io.IOException;
+import java.io.PrintStream;
import org.jacoco.core.analysis.Analyzer;
import org.jacoco.core.analysis.IClassCoverage;
@@ -20,50 +21,64 @@ import org.jacoco.core.analysis.ICoverageVisitor;
import org.jacoco.core.data.ExecutionDataStore;
/**
- * This example reads given Java class files, directories or JARs and dumps
- * information about the classes.
+ * This example reads Java class files, directories or JARs given as program
+ * arguments and dumps information about the classes.
*/
public final class ClassInfo implements ICoverageVisitor {
+ private final PrintStream out;
private final Analyzer analyzer;
- private ClassInfo() {
+ /**
+ * Creates a new example instance printing to the given stream.
+ *
+ * @param out
+ * stream for outputs
+ */
+ public ClassInfo(final PrintStream out) {
+ this.out = out;
analyzer = new Analyzer(new ExecutionDataStore(), this);
}
- private void dumpInfo(final String file) throws IOException {
- analyzer.analyzeAll(new File(file));
+ /**
+ * Run this example with the given parameters.
+ *
+ * @param args
+ * command line parameters
+ * @throws IOException
+ * in case of error reading a input file
+ */
+ public void execute(final String[] args) throws IOException {
+ for (final String file : args) {
+ analyzer.analyzeAll(new File(file));
+ }
}
public void visitCoverage(final IClassCoverage coverage) {
- System.out.printf("class name: %s%n", coverage.getName());
- System.out.printf("class id: %016x%n",
- Long.valueOf(coverage.getId()));
- System.out.printf("instructions: %s%n", Integer.valueOf(coverage
+ out.printf("class name: %s%n", coverage.getName());
+ out.printf("class id: %016x%n", Long.valueOf(coverage.getId()));
+ out.printf("instructions: %s%n", Integer.valueOf(coverage
.getInstructionCounter().getTotalCount()));
- System.out.printf("branches: %s%n",
+ out.printf("branches: %s%n",
Integer.valueOf(coverage.getBranchCounter().getTotalCount()));
- System.out.printf("lines: %s%n",
+ out.printf("lines: %s%n",
Integer.valueOf(coverage.getLineCounter().getTotalCount()));
- System.out.printf("methods: %s%n",
+ out.printf("methods: %s%n",
Integer.valueOf(coverage.getMethodCounter().getTotalCount()));
- System.out.printf("complexity: %s%n%n", Integer.valueOf(coverage
+ out.printf("complexity: %s%n%n", Integer.valueOf(coverage
.getComplexityCounter().getTotalCount()));
}
/**
- * Reads all class file specified as the arguments and dumps information
- * about it to <code>stdout</code>.
+ * Entry point to run this examples as a Java application.
*
* @param args
- * list of class files
+ * list of program arguments
* @throws IOException
+ * in case of errors executing the example
*/
public static void main(final String[] args) throws IOException {
- final ClassInfo info = new ClassInfo();
- for (final String file : args) {
- info.dumpInfo(file);
- }
+ new ClassInfo(System.out).execute(args);
}
}
diff --git a/org.jacoco.examples/src/org/jacoco/examples/CoreTutorial.java b/org.jacoco.examples/src/org/jacoco/examples/CoreTutorial.java
index 55fd6cf2..560eacd6 100644
--- a/org.jacoco.examples/src/org/jacoco/examples/CoreTutorial.java
+++ b/org.jacoco.examples/src/org/jacoco/examples/CoreTutorial.java
@@ -12,6 +12,7 @@
package org.jacoco.examples;
import java.io.InputStream;
+import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
@@ -39,9 +40,7 @@ public final class CoreTutorial {
public static class TestTarget implements Runnable {
public void run() {
- final int n = 7;
- final String status = isPrime(n) ? "prime" : "not prime";
- System.out.printf("%s is %s%n", Integer.valueOf(n), status);
+ isPrime(7);
}
private boolean isPrime(final int n) {
@@ -86,30 +85,25 @@ public final class CoreTutorial {
}
- private InputStream getTargetClass(final String name) {
- final String resource = '/' + name.replace('.', '/') + ".class";
- return getClass().getResourceAsStream(resource);
- }
+ private final PrintStream out;
- private void printCounter(final String unit, final ICounter counter) {
- final Integer missed = Integer.valueOf(counter.getMissedCount());
- final Integer total = Integer.valueOf(counter.getTotalCount());
- System.out.printf("%s of %s %s missed%n", missed, total, unit);
- }
-
- private String getColor(final int status) {
- switch (status) {
- case ICounter.NOT_COVERED:
- return "red";
- case ICounter.PARTLY_COVERED:
- return "yellow";
- case ICounter.FULLY_COVERED:
- return "green";
- }
- return "";
+ /**
+ * Creates a new example instance printing to the given stream.
+ *
+ * @param out
+ * stream for outputs
+ */
+ public CoreTutorial(final PrintStream out) {
+ this.out = out;
}
- private void runTutorial() throws Exception {
+ /**
+ * Run this example.
+ *
+ * @throws Exception
+ * in case of errors
+ */
+ public void execute() throws Exception {
final String targetName = TestTarget.class.getName();
// For instrumentation and runtime we need a IRuntime instance
@@ -152,7 +146,7 @@ public final class CoreTutorial {
// Let's dump some metrics and line coverage information:
for (final IClassCoverage cc : coverageBuilder.getClasses()) {
- System.out.printf("Coverage of class %s%n", cc.getName());
+ out.printf("Coverage of class %s%n", cc.getName());
printCounter("instructions", cc.getInstructionCounter());
printCounter("branches", cc.getBranchCounter());
@@ -161,23 +155,45 @@ public final class CoreTutorial {
printCounter("complexity", cc.getComplexityCounter());
for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) {
- System.out.printf("Line %s: %s%n", Integer.valueOf(i),
- getColor(cc.getLine(i).getStatus()));
+ out.printf("Line %s: %s%n", Integer.valueOf(i), getColor(cc
+ .getLine(i).getStatus()));
}
}
}
+ private InputStream getTargetClass(final String name) {
+ final String resource = '/' + name.replace('.', '/') + ".class";
+ return getClass().getResourceAsStream(resource);
+ }
+
+ private void printCounter(final String unit, final ICounter counter) {
+ final Integer missed = Integer.valueOf(counter.getMissedCount());
+ final Integer total = Integer.valueOf(counter.getTotalCount());
+ out.printf("%s of %s %s missed%n", missed, total, unit);
+ }
+
+ private String getColor(final int status) {
+ switch (status) {
+ case ICounter.NOT_COVERED:
+ return "red";
+ case ICounter.PARTLY_COVERED:
+ return "yellow";
+ case ICounter.FULLY_COVERED:
+ return "green";
+ }
+ return "";
+ }
+
/**
- * Execute the example.
+ * Entry point to run this examples as a Java application.
*
* @param args
+ * list of program arguments
* @throws Exception
+ * in case of errors
*/
public static void main(final String[] args) throws Exception {
- new CoreTutorial().runTutorial();
- }
-
- private CoreTutorial() {
+ new CoreTutorial(System.out).execute();
}
}
diff --git a/org.jacoco.examples/src/org/jacoco/examples/ExecDump.java b/org.jacoco.examples/src/org/jacoco/examples/ExecDump.java
index 3f28a1ab..30193314 100644
--- a/org.jacoco.examples/src/org/jacoco/examples/ExecDump.java
+++ b/org.jacoco.examples/src/org/jacoco/examples/ExecDump.java
@@ -13,6 +13,7 @@ package org.jacoco.examples;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.PrintStream;
import java.util.Date;
import org.jacoco.core.data.ExecutionData;
@@ -22,51 +23,65 @@ import org.jacoco.core.data.ISessionInfoVisitor;
import org.jacoco.core.data.SessionInfo;
/**
- * This example reads given execution data files and dumps their content.
+ * This example reads execution data files given as program arguments and dumps
+ * their content.
*/
public final class ExecDump {
+ private final PrintStream out;
+
/**
- * Reads all execution data files specified as the arguments and dumps the
- * content.
+ * Creates a new example instance printing to the given stream.
+ *
+ * @param out
+ * stream for outputs
+ */
+ public ExecDump(final PrintStream out) {
+ this.out = out;
+ }
+
+ /**
+ * Run this example with the given parameters.
*
* @param args
- * list of execution data files
+ * command line parameters
* @throws IOException
+ * in case of error reading a input file
*/
- public static void main(final String[] args) throws IOException {
+ public void execute(final String[] args) throws IOException {
for (final String file : args) {
- dumpContent(file);
+ dump(file);
}
}
- private static void dumpContent(final String file) throws IOException {
- System.out.printf("exec file: %s%n", file);
- System.out.println("CLASS ID HITS/PROBES CLASS NAME");
+ private void dump(final String file) throws IOException {
+ out.printf("exec file: %s%n", file);
+ out.println("CLASS ID HITS/PROBES CLASS NAME");
final FileInputStream in = new FileInputStream(file);
final ExecutionDataReader reader = new ExecutionDataReader(in);
reader.setSessionInfoVisitor(new ISessionInfoVisitor() {
public void visitSessionInfo(final SessionInfo info) {
- System.out.printf("Session \"%s\": %s - %s%n", info.getId(),
- new Date(info.getStartTimeStamp()),
+ out.printf("Session \"%s\": %s - %s%n", info.getId(), new Date(
+ info.getStartTimeStamp()),
new Date(info.getDumpTimeStamp()));
}
});
reader.setExecutionDataVisitor(new IExecutionDataVisitor() {
public void visitClassExecution(final ExecutionData data) {
- System.out.printf("%016x %3d of %3d %s%n",
+ out.printf("%016x %3d of %3d %s%n",
Long.valueOf(data.getId()),
Integer.valueOf(getHitCount(data.getProbes())),
- Integer.valueOf(data.getProbes().length), data.getName());
+ Integer.valueOf(data.getProbes().length),
+ data.getName());
}
});
reader.read();
in.close();
- System.out.println();
+ out.println();
}
- private static int getHitCount(final boolean[] data) {
+ private int getHitCount(final boolean[] data) {
int count = 0;
for (final boolean hit : data) {
if (hit) {
@@ -76,6 +91,15 @@ public final class ExecDump {
return count;
}
- private ExecDump() {
+ /**
+ * Entry point to run this examples as a Java application.
+ *
+ * @param args
+ * list of program arguments
+ * @throws IOException
+ * in case of errors executing the example
+ */
+ public static void main(final String[] args) throws IOException {
+ new ExecDump(System.out).execute(args);
}
}
diff --git a/org.jacoco.tests/pom.xml b/org.jacoco.tests/pom.xml
index 71b78ae7..e4cd5ddc 100644
--- a/org.jacoco.tests/pom.xml
+++ b/org.jacoco.tests/pom.xml
@@ -31,7 +31,8 @@
<module>../org.jacoco.agent.rt.test</module>
<module>../org.jacoco.agent.test</module>
<module>../org.jacoco.ant.test</module>
- <module>../jacoco-maven-plugin.test</module>
+ <!-- <module>../jacoco-maven-plugin.test</module> -->
+ <module>../org.jacoco.examples.test</module>
</modules>
<properties>
@@ -53,6 +54,9 @@
<includes>
<include>${jacoco.includes}</include>
</includes>
+ <excludes>
+ <exclude>${jacoco.excludes}</exclude>
+ </excludes>
</configuration>
<executions>
<execution>