Fix UT coverage not being reported in Sonar 32/9732/5
authorRobert Varga <rovarga@cisco.com>
Wed, 6 Aug 2014 04:57:59 +0000 (06:57 +0200)
committerRobert Varga <rovarga@cisco.com>
Wed, 6 Aug 2014 06:56:42 +0000 (08:56 +0200)
Makes sure jacoco is run and points sonar the right way.

Change-Id: Ica97f4635e83d66133ebcaae479d6987f7b7794d
Signed-off-by: Robert Varga <rovarga@cisco.com>
commons/parent/pom.xml

index e097c771dbc3fa9a6c2633b6202c306cd4a6f972..1e3c70fd9a09a9a3e30197170d6eedcc6f8981df 100644 (file)
 
         <!-- TCP-MD5 artifacts -->
         <tcpmd5.version>1.0.0-SNAPSHOT</tcpmd5.version>
+
+        <!-- Sonar config -->
+        <sonar-jacoco-listeners.version>2.4</sonar-jacoco-listeners.version>
+        <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
+        <sonar.jacoco.reportPath>target/code-coverage/jacoco.exec</sonar.jacoco.reportPath>
+        <sonar.jacoco.itReportPath>target/code-coverage/jacoco-it.exec</sonar.jacoco.itReportPath>
     </properties>
 
     <dependencyManagement>
             <artifactId>logback-classic</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <!-- Sonar -->
+        <dependency>
+            <groupId>org.codehaus.sonar-plugins.java</groupId>
+            <artifactId>sonar-jacoco-listeners</artifactId>
+            <version>${sonar-jacoco-listeners.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <reporting>
                     <perCoreThreadCount>true</perCoreThreadCount-->
                     <runOrder>alphabetical</runOrder>
                     <threadCount>1</threadCount>
+                    <!-- Specific to generate mapping between tests and covered code -->
+                    <properties>
+                        <property>
+                            <name>listener</name>
+                            <value>org.sonar.java.jacoco.JUnitListener</value>
+                        </property>
+                    </properties>
                 </configuration>
             </plugin>
 
                 </execution>
               </executions>
             </plugin>
+            <plugin>
+                <groupId>org.jacoco</groupId>
+                <artifactId>jacoco-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>prepare-ut-agent</id>
+                        <phase>process-test-classes</phase>
+                        <goals>
+                            <goal>prepare-agent</goal>
+                        </goals>
+                        <configuration>
+                            <destFile>${sonar.jacoco.reportPath}</destFile>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>prepare-it-agent</id>
+                        <phase>pre-integration-test</phase>
+                        <goals>
+                            <goal>prepare-agent</goal>
+                        </goals>
+                        <configuration>
+                            <destFile>${sonar.jacoco.itReportPath}</destFile>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
+
         <pluginManagement>
             <plugins>
                 <plugin>
                                         <ignore />
                                     </action>
                                 </pluginExecution>
+                                <pluginExecution>
+                                   <pluginExecutionFilter>
+                                       <groupId>org.jacoco</groupId>
+                                       <artifactId>jacoco-maven-plugin</artifactId>
+                                       <versionRange>[0.6,)</versionRange>
+                                       <goals>
+                                           <goal>prepare-agent</goal>
+                                       </goals>
+                                    </pluginExecutionFilter>
+                                    <action>
+                                        <ignore/>
+                                    </action>
+                                </pluginExecution>
                             </pluginExecutions>
                         </lifecycleMappingMetadata>
                     </configuration>