Misc. Coverage Fixes

- Collect coverage data for hyracks modules
- Generate aggregate coverage report for SonarQube

Change-Id: Ib44d8ed4fe81d2e26380e1bf6e02b7458910be0a
Reviewed-on: https://asterix-gerrit.ics.uci.edu/841
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>
diff --git a/asterixdb/asterix-coverage/pom.xml b/asterixdb/asterix-coverage/pom.xml
index 6cc00d3..3692fb2 100644
--- a/asterixdb/asterix-coverage/pom.xml
+++ b/asterixdb/asterix-coverage/pom.xml
@@ -29,106 +29,142 @@
     <version>0.8.9-SNAPSHOT</version>
   </parent>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-antrun-plugin</artifactId>
-        <version>1.8</version>
-        <executions>
-          <execution>
-            <phase>test</phase>
-            <goals>
-              <goal>run</goal>
-            </goals>
-            <configuration>
-              <target if="coverage" unless="skipTests">
-                <echo message="Generating JaCoCo Reports" />
-                <property name="asterix.dir" location="${basedir}/.."/>
-                <!-- special case for jenkins -->
-                <condition property="hyracks.dir" value="${asterix.dir}/hyracks">
-                  <available file="${asterix.dir}/hyracks/pom.xml"/>
-                </condition>
-                <pathconvert property="hyracks.dir">
-                  <first>
-                    <dirset dir="${asterix.dir}/..">
-                      <include name="*hyracks"/>
-                    </dirset>
-                  </first>
-                </pathconvert>
-                <!-- gather all of the source dirs -->
-                <pathconvert property="source.dirs" pathsep=",">
-                  <dirset dir="${asterix.dir}">
-                    <include name="**/src/main/java"/>
+  <profiles>
+    <profile>
+      <id>coverage</id>
+      <activation>
+        <property>
+          <name>coverage</name>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <version>1.8</version>
+            <executions>
+              <execution>
+                <phase>test</phase>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+                <configuration>
+                  <target if="coverage" unless="skipTests">
+                    <echo message="Generating JaCoCo Reports" />
+                    <property name="asterix.dir" location="${basedir}/.."/>
                     <!-- special case for jenkins -->
-                    <exclude name="hyracks/**"/>
-                  </dirset>
-                </pathconvert>
-                <pathconvert property="hyracks.source.dirs" pathsep=",">
-                  <dirset dir="${hyracks.dir}">
-                    <include name="**/src/main/java"/>
-                  </dirset>
-                </pathconvert>
-                <echo message="asterix dir: ${asterix.dir}/"/>
-                <echo message="hyracks dir: ${hyracks.dir}"/>
-                <echo message="asterix source dirs: ${source.dirs}/"/>
-                <echo message="hyracks source dirs: ${hyracks.source.dirs}/"/>
+                    <condition property="hyracks.dir" value="${asterix.dir}/hyracks">
+                      <available file="${asterix.dir}/hyracks/pom.xml"/>
+                    </condition>
+                    <pathconvert property="hyracks.dir">
+                      <first>
+                        <dirset dir="${asterix.dir}/..">
+                          <include name="*hyracks"/>
+                        </dirset>
+                      </first>
+                    </pathconvert>
+                    <!-- gather all of the source dirs -->
+                    <pathconvert property="source.dirs" pathsep=",">
+                      <dirset dir="${asterix.dir}">
+                        <include name="**/src/main/java"/>
+                        <!-- special case for jenkins -->
+                        <exclude name="hyracks/**"/>
+                      </dirset>
+                    </pathconvert>
+                    <pathconvert property="hyracks.source.dirs" pathsep=",">
+                      <dirset dir="${hyracks.dir}">
+                        <include name="**/src/main/java"/>
+                      </dirset>
+                    </pathconvert>
+                    <echo message="asterix dir: ${asterix.dir}/"/>
+                    <echo message="hyracks dir: ${hyracks.dir}"/>
+                    <echo message="asterix source dirs: ${source.dirs}/"/>
+                    <echo message="hyracks source dirs: ${hyracks.source.dirs}/"/>
 
-                <taskdef name="report" classname="org.jacoco.ant.ReportTask">
-                  <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar" />
-                </taskdef>
-                <mkdir dir="${basedir}/target/coverage-report" />
-                <report>
-                  <executiondata>
-                    <fileset dir="${asterix.dir}">
-                      <include name="**/jacoco.exec" />
-                    </fileset>
-                  </executiondata>
-                  <structure name="AsterixDB Coverage Project">
-                    <group name="AsterixDB">
-                      <classfiles>
+                    <taskdef name="report" classname="org.jacoco.ant.ReportTask">
+                      <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar" />
+                    </taskdef>
+                    <mkdir dir="${basedir}/target/coverage-report" />
+                    <report>
+                      <executiondata>
                         <fileset dir="${asterix.dir}">
-                          <include name="**/target/classes/**/*.class"/>
-                          <!-- special case for jenkins -->
-                          <exclude name="hyracks/**"/>
+                          <include name="**/jacoco.exec" />
                         </fileset>
-                      </classfiles>
-                      <sourcefiles encoding="UTF-8">
-                        <multirootfileset basedirs="${source.dirs}" type="file">
-                          <include name="**/*.java"/>
-                        </multirootfileset>
-                      </sourcefiles>
-                    </group>
-                    <group name="Hyracks">
-                      <classfiles>
-                        <fileset dir="${hyracks.dir}">
-                          <include name="**/target/classes/**/*.class"/>
-                          <exclude name="hyracks/hyracks-hdfs/hyracks-hdfs-1.x/**"/>
-                        </fileset>
-                      </classfiles>
-                      <sourcefiles encoding="UTF-8">
-                        <multirootfileset basedirs="${hyracks.source.dirs}" type="file">
-                          <include name="**/*.java"/>
-                        </multirootfileset>
-                      </sourcefiles>
-                    </group>
-                  </structure>
-                  <html destdir="${basedir}/target/coverage-report/html" />
-                  <xml destfile="${basedir}/target/coverage-report/coverage-report.xml" />
-                  <csv destfile="${basedir}/target/coverage-report/coverage-report.csv" />
-                </report>
-              </target>
-            </configuration>
-          </execution>
-        </executions>
-        <dependencies>
-          <dependency>
+                      </executiondata>
+                      <structure name="AsterixDB Coverage Project">
+                        <group name="AsterixDB">
+                          <classfiles>
+                            <fileset dir="${asterix.dir}">
+                              <include name="**/target/classes/**/*.class"/>
+                              <!-- special case for jenkins -->
+                              <exclude name="hyracks/**"/>
+                            </fileset>
+                          </classfiles>
+                          <sourcefiles encoding="UTF-8">
+                            <multirootfileset basedirs="${source.dirs}" type="file">
+                              <include name="**/*.java"/>
+                            </multirootfileset>
+                          </sourcefiles>
+                        </group>
+                        <group name="Hyracks">
+                          <classfiles>
+                            <fileset dir="${hyracks.dir}">
+                              <include name="**/target/classes/**/*.class"/>
+                              <exclude name="hyracks/hyracks-hdfs/hyracks-hdfs-1.x/**"/>
+                            </fileset>
+                          </classfiles>
+                          <sourcefiles encoding="UTF-8">
+                            <multirootfileset basedirs="${hyracks.source.dirs}" type="file">
+                              <include name="**/*.java"/>
+                            </multirootfileset>
+                          </sourcefiles>
+                        </group>
+                      </structure>
+                      <html destdir="${basedir}/target/coverage-report/html" />
+                      <xml destfile="${basedir}/target/coverage-report/coverage-report.xml" />
+                      <csv destfile="${basedir}/target/coverage-report/coverage-report.csv" />
+                    </report>
+                  </target>
+                </configuration>
+              </execution>
+            </executions>
+            <dependencies>
+              <dependency>
+                <groupId>org.jacoco</groupId>
+                <artifactId>org.jacoco.ant</artifactId>
+                <version>${jacoco.version}</version>
+              </dependency>
+            </dependencies>
+          </plugin>
+          <plugin>
             <groupId>org.jacoco</groupId>
-            <artifactId>org.jacoco.ant</artifactId>
+            <artifactId>jacoco-maven-plugin</artifactId>
             <version>${jacoco.version}</version>
-          </dependency>
-        </dependencies>
-      </plugin>
-    </plugins>
-  </build>
+            <executions>
+              <execution>
+                <goals>
+                  <goal>merge</goal>
+                </goals>
+                <phase>test</phase>
+                <configuration>
+                  <fileSets>
+                    <fileSet>
+                      <directory>${session.executionRootDirectory}</directory>
+                      <includes>
+                        <include>**/target/jacoco.exec</include>
+                        <include>**/target/jacoco-it.exec</include>
+                      </includes>
+                    </fileSet>
+                  </fileSets>
+                  <destFile>${session.executionRootDirectory}/target/jacoco-merged.exec</destFile>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+
 </project>
diff --git a/asterixdb/pom.xml b/asterixdb/pom.xml
index 4073247..d72b465 100644
--- a/asterixdb/pom.xml
+++ b/asterixdb/pom.xml
@@ -45,6 +45,7 @@
         <jdk.version>1.8</jdk.version>
         <runSlowAQLTests>false</runSlowAQLTests>
         <appendedResourcesDirectory>${basedir}/src/main/appended-resources</appendedResourcesDirectory>
+        <sonar.jacoco.reportPath>${env.PWD}/target/jacoco-merged.exec</sonar.jacoco.reportPath>
 
     <!-- Definition of tests in various categories which may be excluded -->
         <optimizer.tests>**/optimizer/**/*Test.java</optimizer.tests>
diff --git a/hyracks-fullstack/pom.xml b/hyracks-fullstack/pom.xml
index f2e0eea..54e7f34 100644
--- a/hyracks-fullstack/pom.xml
+++ b/hyracks-fullstack/pom.xml
@@ -45,6 +45,8 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <jdk.version>1.8</jdk.version>
         <jvm.extraargs/>
+        <sonar.jacoco.reportPath>${env.PWD}/target/jacoco-merged.exec</sonar.jacoco.reportPath>
+
         <!-- Definition of tests in various categories which may be excluded -->
         <hanging.pregelix.tests>**/pregelix/**/FailureRecovery*.java</hanging.pregelix.tests>
         <hivesterix.perf.tests>**/hivesterix/perf/PerfTestSuite.java</hivesterix.perf.tests>
@@ -55,6 +57,7 @@
         <hadoop.version>2.2.0</hadoop.version>
         <junit.version>4.8.1</junit.version>
         <commons.io.version>2.4</commons.io.version>
+        <jacoco.version>0.7.6.201602180812</jacoco.version>
     </properties>
     <dependencyManagement>
         <dependencies>
@@ -218,11 +221,14 @@
 	  <failIfNoTests>false</failIfNoTests>
 	  <forkCount>1</forkCount>
           <reuseForks>false</reuseForks>
-	  <argLine>-enableassertions -Xmx2048m
-	  -Dfile.encoding=UTF-8
-	  -Djava.util.logging.config.file=${user.home}/logging.properties
-	  -Xdebug
-	  -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n</argLine>
+    <argLine>
+      -enableassertions -Xmx2048m
+      -Dfile.encoding=UTF-8
+      -Djava.util.logging.config.file=${user.home}/logging.properties
+      -Xdebug
+      -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n
+      ${coverageArgLine}
+    </argLine>
 	  <includes>
 	    <include>${global.test.includes},${test.includes}</include>
 	  </includes>
@@ -385,6 +391,57 @@
       </build>
     </profile>
     <profile>
+      <id>coverage</id>
+      <activation>
+        <property>
+          <name>coverage</name>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.jacoco</groupId>
+            <artifactId>jacoco-maven-plugin</artifactId>
+            <version>${jacoco.version}</version>
+            <executions>
+              <execution>
+                <id>default-prepare-agent</id>
+                <goals>
+                  <goal>prepare-agent</goal>
+                </goals>
+                <configuration>
+                  <propertyName>coverageArgLine</propertyName>
+                </configuration>
+              </execution>
+              <execution>
+                <id>default-prepare-agent-integration</id>
+                <goals>
+                  <goal>prepare-agent-integration</goal>
+                </goals>
+                <configuration>
+                  <propertyName>coverageArgLine</propertyName>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+      <properties>
+        <coverage/>
+      </properties>
+    </profile>
+    <profile>
+      <id>no-coverage</id>
+      <activation>
+        <property>
+          <name>!coverage</name>
+        </property>
+      </activation>
+      <properties>
+        <coverageArgLine/>
+      </properties>
+    </profile>
+    <profile>
         <id>java8</id>
         <activation>
             <jdk>1.8</jdk>