Created
August 29, 2012 21:07
-
-
Save marchof/3518974 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 4b507047d942 jacoco-maven-plugin.test/it/it-multi-report-merge/pom.xml | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-multi-report-merge/pom.xml Fri Jan 27 10:41:46 2012 -0500 | |
@@ -0,0 +1,73 @@ | |
+<?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-multi-report-merge</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> | |
+ <dataFiles> | |
+ <dataFile>${project.build.directory}/jacoco/jacoco_db.exec</dataFile> | |
+ <dataFile>${project.build.directory}/jacoco/jacoco_file.exec</dataFile> | |
+ </dataFiles> | |
+ </configuration> | |
+ </execution> | |
+ </executions> | |
+ </plugin> | |
+ </plugins> | |
+ </build> | |
+</project> | |
diff -r c003a108330b -r 4b507047d942 jacoco-maven-plugin.test/it/it-multi-report-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-multi-report-merge/src/main/java/org/project/DatabaseUtil.java Fri Jan 27 10:41:46 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 4b507047d942 jacoco-maven-plugin.test/it/it-multi-report-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-multi-report-merge/src/main/java/org/project/FileUtil.java Fri Jan 27 10:41:46 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 4b507047d942 jacoco-maven-plugin.test/it/it-multi-report-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-multi-report-merge/src/main/java/org/project/TestUtil.java Fri Jan 27 10:41:46 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 4b507047d942 jacoco-maven-plugin.test/it/it-multi-report-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-multi-report-merge/src/test/java/org/project/TestDatabaseUtil.java Fri Jan 27 10:41:46 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 4b507047d942 jacoco-maven-plugin.test/it/it-multi-report-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-multi-report-merge/src/test/java/org/project/TestFileUtil.java Fri Jan 27 10:41:46 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 4b507047d942 jacoco-maven-plugin.test/it/it-multi-report-merge/verify.bsh | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/jacoco-maven-plugin.test/it/it-multi-report-merge/verify.bsh Fri Jan 27 10:41:46 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 multi-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 4b507047d942 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 Fri Jan 27 10:41:46 2012 -0500 | |
@@ -75,8 +75,17 @@ | |
* File with execution data. | |
* | |
* @parameter default-value="${project.build.directory}/jacoco.exec" | |
+ * @deprecated Use 'dataFiles' parameter instead. | |
*/ | |
private File dataFile; | |
+ | |
+ /** | |
+ * Files with execution data. | |
+ * In the case of multiple files, all will be merged together. | |
+ * | |
+ * @parameter | |
+ */ | |
+ private List<File> dataFiles; | |
/** | |
* A list of class files to include in instrumentation/analysis/reports. May | |
@@ -222,24 +231,49 @@ | |
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(); | |
+ | |
+ if (dataFiles == null) { | |
+ dataFiles = new ArrayList<File>(); | |
+ } | |
+ | |
+ // cannot set default values on collection types for Maven parameters | |
+ if (dataFiles.isEmpty()) { | |
+ dataFiles.add(dataFile); | |
+ } | |
+ | |
+ loadExecutionData(dataFiles); | |
+ } | |
+ | |
+ private void loadExecutionData(List<File> files) throws IOException { | |
+ for (File f : files) { | |
+ 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