Highlighted

SonarQube code coverage for AEM project

Debal-Das

13-04-2020

Hi All,

 

We are using separate Sonarqube server and integrated with our application. Using that we are able to receive the code vulnerabilities properly. But Generating the Code Coverage is having issues. Currently we have integrated with Jacoco Plugin with SonarQube for  Code Coverage and we have installed Sonarqube with AEM rules plugin version 1.0.

 

We have done below changes in POM file -

 

POM Changes

 

<properties>

        <sonar.exclusions>**/*.js,**/*.xml,lib/*,packages/*,ui.galen/*,**/*.json,ui.npm/*,content/*</sonar.exclusions>

        <sonar.junit.reportPaths>bundle/target/surfire-reports</sonar.junit.reportPaths>

        <sonar.jacoco.reportPaths>bundle/target/jacoco.exec</sonar.jacoco.reportPaths>

</properties>

<plugin>

<groupId>org.jacoco</groupId>

<artifactId>jacoco-maven-plugin</artifactId>

<version>0.7.9</version>

<executions>

              <execution>

                             <id>pre-unit-test</id>

                             <goals>

                                           <goal>prepare-agent</goal>

                             </goals>

                             <configuration>

                                           <!-- Sets the path to the file which contains the execution data. -->

                                           <destFile>bundle/target/jacoco.exec</destFile>

                                           <excludes>

                                                          <exclude>**/*.js</exclude>

                                                          <exclude>**/*.xml</exclude>

                                                          <exclude>lib/*</exclude>

                                                          <exclude>packages/*</exclude>

                                                          <exclude>ui.galen/*</exclude>

                                                          <exclude>**/*.json</exclude>

                                                          <exclude>ui.npm/*</exclude>

                                                          <exclude>content/*</exclude>

                                           </excludes>

                                           <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->

                                           <propertyName>surefireArgLine</propertyName>

                             </configuration>

              </execution>

              <!-- Ensures that the code coverage report for unit tests is created after unit tests have been run. -->

              <execution>

                             <id>post-unit-test</id>

                             <phase>test</phase>

                             <goals>

                                           <goal>report</goal>

                             </goals>

                             <configuration>

                                           <!-- Sets the path to the file which contains the execution data. -->

                                           <dataFile>bundle/target/jacoco.exec</dataFile>

                                           <!-- Sets the output directory for the code coverage report. -->

                                           <outputDirectory>bundle/target</outputDirectory>

                             </configuration>

              </execution>

              <execution>

                             <id>generate-code-coverage-report</id>

                             <phase>test</phase>

                             <goals>

                                             <goal>report</goal>

                             </goals>

              </execution>

</executions>

</plugin>

 

SONAR Command Used

 

mvn clean package sonar:sonar

 

With all these changes we are getting code coverage 0.0. So, please help me to resolve this issue.

 

Note: We are able to see the Code Coverage in IDE – Eclipse/IntelliJ. But not able to get the coverage report in sonarqube site. 

 

Thanks,

Debal

Replies

Highlighted

Theo_Pendle

MVP

13-04-2020

Hi,

What do you mean by "plugin" exactly? 

If you mean special rules for AEM projects, you can find those (and installation instructions) here: https://github.com/Cognifide/AEM-Rules-for-SonarQube

If you are talking about an IDE plugin that will do the same analysis, then you are looking for this: https://www.sonarlint.org/intellij/. You can install that plugin in IntelliJ for example and then connect to a remote SonarQube server to make sure you are using the same rules in the IDE as Sonar will during static analysis.

Highlighted

Debal-Das

13-04-2020

Hi ,

 

Apologize for the confusion.

 

Please allow me to provide details here.

 

We are using separate Sonarqube server and integrated with our application. Using that we are able to receive the code vulnerabilities properly. But Generating the Code Coverage is having issues. Currently we have integrated with Jacoco Plugin with SonarQube for  Code Coverage and we have installed Sonarqube with AEM rules plugin version 1.0.

 

We have done below changes in POM file -

 

POM Changes

 

<properties>

        <sonar.exclusions>**/*.js,**/*.xml,lib/*,packages/*,ui.galen/*,**/*.json,ui.npm/*,content/*</sonar.exclusions>

        <sonar.junit.reportPaths>bundle/target/surfire-reports</sonar.junit.reportPaths>

        <sonar.jacoco.reportPaths>bundle/target/jacoco.exec</sonar.jacoco.reportPaths>

</properties>

<plugin>

<groupId>org.jacoco</groupId>

<artifactId>jacoco-maven-plugin</artifactId>

<version>0.7.9</version>

<executions>

              <execution>

                             <id>pre-unit-test</id>

                             <goals>

                                           <goal>prepare-agent</goal>

                             </goals>

                             <configuration>

                                           <!-- Sets the path to the file which contains the execution data. -->

                                           <destFile>bundle/target/jacoco.exec</destFile>

                                           <excludes>

                                                          <exclude>**/*.js</exclude>

                                                          <exclude>**/*.xml</exclude>

                                                          <exclude>lib/*</exclude>

                                                          <exclude>packages/*</exclude>

                                                          <exclude>ui.galen/*</exclude>

                                                          <exclude>**/*.json</exclude>

                                                          <exclude>ui.npm/*</exclude>

                                                          <exclude>content/*</exclude>

                                           </excludes>

                                           <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->

                                           <propertyName>surefireArgLine</propertyName>

                             </configuration>

              </execution>

              <!-- Ensures that the code coverage report for unit tests is created after unit tests have been run. -->

              <execution>

                             <id>post-unit-test</id>

                             <phase>test</phase>

                             <goals>

                                           <goal>report</goal>

                             </goals>

                             <configuration>

                                           <!-- Sets the path to the file which contains the execution data. -->

                                           <dataFile>bundle/target/jacoco.exec</dataFile>

                                           <!-- Sets the output directory for the code coverage report. -->

                                           <outputDirectory>bundle/target</outputDirectory>

                             </configuration>

              </execution>

              <execution>

                             <id>generate-code-coverage-report</id>

                             <phase>test</phase>

                             <goals>

                                             <goal>report</goal>

                             </goals>

              </execution>

</executions>

</plugin>

 

SONAR Command Used

 

mvn clean package sonar:sonar

 

With all these changes we are getting code coverage 0.0. So, please help me to resolve this issue.

 

Thanks,

Debal