Created
August 29, 2012 21:02
-
-
Save marchof/3518923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin.test/it/it-recursive-merge/pom.xml | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-recursive-merge/pom.xml Thu Jan 26 08:41:51 2012 -0500 | |
@@ -0,0 +1,70 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<!-- | |
+ 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 - 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/xsd/maven-4.0.0.xsd"> | |
+ <modelVersion>4.0.0</modelVersion> | |
+ | |
+ <parent> | |
+ <groupId>jacoco</groupId> | |
+ <artifactId>setup-parent</artifactId> | |
+ <version>1.0-SNAPSHOT</version> | |
+ </parent> | |
+ | |
+ <artifactId>it-includes-excludes</artifactId> | |
+ | |
+ <build> | |
+ <plugins> | |
+ <plugin> | |
+ <groupId>@project.groupId@</groupId> | |
+ <artifactId>jacoco-maven-plugin</artifactId> | |
+ <executions> | |
+ <execution> | |
+ <id>only-db</id> | |
+ <goals> | |
+ <goal>prepare-agent</goal> | |
+ </goals> | |
+ <configuration> | |
+ <excludes> | |
+ <exclude>**/FileUtil*</exclude> | |
+ <exclude>**/TestUtil*</exclude> | |
+ </excludes> | |
+ <destFile>${project.build.directory}/jacoco/jacoco_db.exec</destFile> | |
+ </configuration> | |
+ </execution> | |
+ <execution> | |
+ <id>only-file</id> | |
+ <goals> | |
+ <goal>prepare-agent</goal> | |
+ </goals> | |
+ <configuration> | |
+ <excludes> | |
+ <exclude>**/DatabaseUtil*</exclude> | |
+ <exclude>**/TestUtil*</exclude> | |
+ </excludes> | |
+ <destFile>${project.build.directory}/jacoco/jacoco_file.exec</destFile> | |
+ </configuration> | |
+ </execution> | |
+ <execution> | |
+ <id>report</id> | |
+ <phase>prepare-package</phase> | |
+ <goals> | |
+ <goal>report</goal> | |
+ </goals> | |
+ <configuration> | |
+ <dataFile>${project.build.directory}/jacoco</dataFile> | |
+ </configuration> | |
+ </execution> | |
+ </executions> | |
+ </plugin> | |
+ </plugins> | |
+ </build> | |
+</project> | |
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin.test/it/it-recursive-merge/src/main/java/org/project/DatabaseUtil.java | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-recursive-merge/src/main/java/org/project/DatabaseUtil.java Thu Jan 26 08:41:51 2012 -0500 | |
@@ -0,0 +1,19 @@ | |
+/******************************************************************************* | |
+ * 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 - initial API and implementation | |
+ * | |
+ *******************************************************************************/ | |
+package org.project; | |
+ | |
+ | |
+public class DatabaseUtil { | |
+ public void doStuff() { | |
+ System.out.println("Do DatabaseUtil Stuff"); | |
+ } | |
+} | |
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin.test/it/it-recursive-merge/src/main/java/org/project/FileUtil.java | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-recursive-merge/src/main/java/org/project/FileUtil.java Thu Jan 26 08:41:51 2012 -0500 | |
@@ -0,0 +1,19 @@ | |
+/******************************************************************************* | |
+ * 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 - initial API and implementation | |
+ * | |
+ *******************************************************************************/ | |
+package org.project; | |
+ | |
+ | |
+public class FileUtil { | |
+ public void doStuff() { | |
+ System.out.println("Do FileUtil Stuff"); | |
+ } | |
+} | |
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin.test/it/it-recursive-merge/src/main/java/org/project/TestUtil.java | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-recursive-merge/src/main/java/org/project/TestUtil.java Thu Jan 26 08:41:51 2012 -0500 | |
@@ -0,0 +1,19 @@ | |
+/******************************************************************************* | |
+ * 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 - initial API and implementation | |
+ * | |
+ *******************************************************************************/ | |
+package org.project; | |
+ | |
+ | |
+public class TestUtil { | |
+ public void doStuff() { | |
+ System.out.println("Do TestUtil Stuff"); | |
+ } | |
+} | |
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin.test/it/it-recursive-merge/src/test/java/org/project/TestDatabaseUtil.java | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-recursive-merge/src/test/java/org/project/TestDatabaseUtil.java Thu Jan 26 08:41:51 2012 -0500 | |
@@ -0,0 +1,21 @@ | |
+/******************************************************************************* | |
+ * 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 - initial API and implementation | |
+ * | |
+ *******************************************************************************/ | |
+package org.project; | |
+ | |
+import org.junit.Test; | |
+ | |
+public class TestDatabaseUtil { | |
+ @Test | |
+ public void testDoStuff() { | |
+ new DatabaseUtil().doStuff(); | |
+ } | |
+} | |
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin.test/it/it-recursive-merge/src/test/java/org/project/TestFileUtil.java | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-recursive-merge/src/test/java/org/project/TestFileUtil.java Thu Jan 26 08:41:51 2012 -0500 | |
@@ -0,0 +1,21 @@ | |
+/******************************************************************************* | |
+ * 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 - initial API and implementation | |
+ * | |
+ *******************************************************************************/ | |
+package org.project; | |
+ | |
+import org.junit.Test; | |
+ | |
+public class TestFileUtil { | |
+ @Test | |
+ public void testDoStuff() { | |
+ new FileUtil().doStuff(); | |
+ } | |
+} | |
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin.test/it/it-recursive-merge/verify.bsh | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-recursive-merge/verify.bsh Thu Jan 26 08:41:51 2012 -0500 | |
@@ -0,0 +1,97 @@ | |
+/******************************************************************************* | |
+ * 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 - initial API and implementation | |
+ * | |
+ *******************************************************************************/ | |
+import java.io.*; | |
+import org.codehaus.plexus.util.*; | |
+ | |
+String agentOptions = "excludes=**/FileUtil*:**/TestUtil*"; | |
+ | |
+String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) ); | |
+if ( buildLog.indexOf( agentOptions ) < 0 ) { | |
+ throw new RuntimeException("Include/Exclude was not configured correct" ); | |
+} | |
+ | |
+File databaseUtilReportFile = new File( basedir, "target/site/jacoco/org.project/DatabaseUtil.html" ); | |
+if ( !databaseUtilReportFile.isFile() ) | |
+{ | |
+ throw new FileNotFoundException( "DatabaseUtil should NOT be excluded from report: " + databaseUtilReportFile ); | |
+} | |
+ | |
+File fileUtilReportFile = new File( basedir, "target/site/jacoco/org.project/FileUtil.html" ); | |
+if ( !fileUtilReportFile.isFile() ) | |
+{ | |
+ throw new FileNotFoundException( "FileUtil should NOT be excluded from report: " + fileUtilReportFile ); | |
+} | |
+ | |
+File testUtilReportFile = new File( basedir, "target/site/jacoco/org.project/TestUtil.html" ); | |
+if ( !testUtilReportFile.isFile() ) | |
+{ | |
+ throw new FileNotFoundException( "TestUtil should NOT be excluded from report: " + testUtilReportFile ); | |
+} | |
+ | |
+/** | |
+ * Check CSVs for proper results. | |
+ */ | |
+File testReportCSV = new File( basedir, "target/site/jacoco/jacoco.csv" ); | |
+if ( !testReportCSV.isFile() ) | |
+{ | |
+ throw new FileNotFoundException( "CSV report generation required to verify recursive merge feature: " + testReportCSV ); | |
+} | |
+ | |
+LineNumberReader lnr = new LineNumberReader( new FileReader( testReportCSV ) ); | |
+lnr.readLine(); //skip the header | |
+ | |
+boolean sawFile = false; | |
+boolean sawDatabase = false; | |
+boolean sawTest = false; | |
+ | |
+for ( int i = 0; i < 3; i++ ) | |
+{ | |
+ String line = lnr.readLine(); | |
+ String[] values = line.split( "\\," ); | |
+ String clazz = values[2]; | |
+ int missed = Integer.parseInt( values[3] ); | |
+ int covered = Integer.parseInt( values[4] ); | |
+ | |
+ if ( "FileUtil".equals( clazz ) ) | |
+ { | |
+ sawFile = true; | |
+ if ( 0 != missed ) | |
+ { | |
+ throw new RuntimeException( "FileUtil should be 100% covered, missed: " + missed ); | |
+ } | |
+ } | |
+ else if ( "DatabaseUtil".equals( clazz ) ) | |
+ { | |
+ sawDatabase = true; | |
+ if ( 0 != missed ) | |
+ { | |
+ throw new RuntimeException( "DatabaseUtil should be 100% covered, missed: " + missed ); | |
+ } | |
+ } | |
+ else if ( "TestUtil".equals( clazz ) ) | |
+ { | |
+ sawTest = true; | |
+ if ( 0 != covered ) | |
+ { | |
+ throw new RuntimeException( "TestUtil should be 100% missed, covered: " + covered ); | |
+ } | |
+ } | |
+ else | |
+ { | |
+ throw new RuntimeException( "Unknown covered class: ", clazz ); | |
+ } | |
+} | |
+ | |
+if ( ! ( sawFile && sawDatabase && sawTest ) ) | |
+{ | |
+ throw new RuntimeException( "Did not observe results for all classes." ); | |
+} | |
\ No newline at end of file | |
diff -r c003a108330b -r 7dbcf07be63b jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java | |
--- a/jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java Mon Jan 23 23:39:12 2012 +0000 | |
+++ b/jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java Thu Jan 26 08:41:51 2012 -0500 | |
@@ -72,7 +72,9 @@ | |
private String sourceEncoding; | |
/** | |
- * File with execution data. | |
+ * File with execution data, or a directory. | |
+ * In the case of a directory, it will be searched recursively for all files. Every file will | |
+ * be assumed to be a JaCoCo execution data file. | |
* | |
* @parameter default-value="${project.build.directory}/jacoco.exec" | |
*/ | |
@@ -222,24 +224,43 @@ | |
getLog().error("Error while creating report: " + e.getMessage(), e); | |
} | |
} | |
+ | |
+ private void instantiateStores() { | |
+ if (sessionInfoStore == null) { | |
+ sessionInfoStore = new SessionInfoStore(); | |
+ } | |
+ | |
+ if (executionDataStore == null) { | |
+ executionDataStore = new ExecutionDataStore(); | |
+ } | |
+ } | |
private void loadExecutionData() throws IOException { | |
- sessionInfoStore = new SessionInfoStore(); | |
- executionDataStore = new ExecutionDataStore(); | |
- FileInputStream in = null; | |
- try { | |
- in = new FileInputStream(dataFile); | |
- final ExecutionDataReader reader = new ExecutionDataReader(in); | |
- reader.setSessionInfoVisitor(sessionInfoStore); | |
- reader.setExecutionDataVisitor(executionDataStore); | |
- reader.read(); | |
- } finally { | |
- if (in != null) { | |
- in.close(); | |
+ instantiateStores(); | |
+ loadExecutionData(dataFile); | |
+ } | |
+ | |
+ private void loadExecutionData(File f) throws IOException { | |
+ if (f.isDirectory()) { | |
+ for (File child : f.listFiles()) { | |
+ loadExecutionData(child); | |
+ } | |
+ } else { | |
+ FileInputStream in = null; | |
+ try { | |
+ in = new FileInputStream(f); | |
+ final ExecutionDataReader reader = new ExecutionDataReader(in); | |
+ reader.setSessionInfoVisitor(sessionInfoStore); | |
+ reader.setExecutionDataVisitor(executionDataStore); | |
+ reader.read(); | |
+ } finally { | |
+ if (in != null) { | |
+ in.close(); | |
+ } | |
} | |
} | |
} | |
- | |
+ | |
private void createReport(final IReportGroupVisitor visitor) | |
throws IOException { | |
final IBundleCoverage bundle = createBundle(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment