Fix unit test coverage not being reported
[openflowplugin.git] / pom.xml
diff --git a/pom.xml b/pom.xml
index 804a65372c567dc6bf43d0d2b58acaf1341a2ef2..99054e542843ec6d34097b8d19d7b5a14f85451c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <jmxGeneratorPath>src/main/yang-gen-config</jmxGeneratorPath>
       <salGeneratorPath>src/main/yang-gen-sal</salGeneratorPath>
       <exi.nagasena.version>0000.0002.0038.0</exi.nagasena.version>
-        <controller.distribution.version>0.1.2-SNAPSHOT</controller.distribution.version>
+      <controller.distribution.version>0.1.2-SNAPSHOT</controller.distribution.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>
+      <sonar.profile>Sonar way with Findbugs</sonar.profile>
     </properties>
 
     <dependencyManagement>
       </dependencies>
     </dependencyManagement>
 
+    <dependencies>
+        <!-- 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>
+
     <build>
         <plugins>
-          <plugin>
-             <groupId>org.codehaus.mojo</groupId>
-             <artifactId>build-helper-maven-plugin</artifactId>
-          </plugin>
+            <plugin>
+                 <groupId>org.codehaus.mojo</groupId>
+                 <artifactId>build-helper-maven-plugin</artifactId>
+            </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>
+                            <propertyName>jacoco.agent.ut.arg</propertyName>
+                        </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>
+                            <propertyName>jacoco.agent.it.arg</propertyName>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
         <pluginManagement>
           <plugins>
                 </lifecycleMappingMetadata>
               </configuration>
             </plugin>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-failsafe-plugin</artifactId>
+              <configuration>
+                <!-- Specific to generate mapping between tests and covered code -->
+                <argLine>${jacoco.agent.it.arg}</argLine>
+                <properties>
+                  <property>
+                    <name>listener</name>
+                    <value>org.sonar.java.jacoco.JUnitListener</value>
+                  </property>
+                </properties>
+                <!-- Let's put failsafe reports with surefire to have access to tests failures/success reports in sonar -->
+                <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
+              </configuration>
+            </plugin>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-surefire-plugin</artifactId>
+              <configuration>
+                <!-- Specific to generate mapping between tests and covered code -->
+                <argLine>${jacoco.agent.ut.arg}</argLine>
+                <properties>
+                  <property>
+                    <name>listener</name>
+                    <value>org.sonar.java.jacoco.JUnitListener</value>
+                  </property>
+                </properties>
+              </configuration>
+            </plugin>
           </plugins>
         </pluginManagement>
     </build>