Situation
I'm trying to get Sonar display the code coverage reports generated by FlexUnit from a Maven build job using Flex-Mojos but I'm not having any luck - all I ever get is a frustrating "-".
Build output
The result is that the dashboard always shows this (the left column):
(no, the unit tests don't run for over 90 minutes but rather 16 seconds; don't know what's off here)
The Sonar related console output is this:
So everything seems to work fine (no file-not-found errors other than the Cobertura one which I can't seem to get rid of in any way, no parse exceptions, etc).
Build setup
The pom.xml
used for building the project looks like this:
<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>foo</groupId>
<artifactId>parent</artifactId>
<version>1.0.3</version>
</parent>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>swc</packaging>
<name>Bar</name>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito</artifactId>
<version>1.4M5</version>
<type>swc</type>
<scope>external</scope>
</dependency>
<dependency>
<groupId>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId>
<version>4.1.0-8</version>
<classifier>flex</classifier>
<type>swc</type>
<scope>external</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/flash</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>4.2-beta</version>
<configuration>
<coverage>true</coverage>
<debug>false</debug>
<optimize>true</optimize>
<omitTraceStatements>true</omitTraceStatements>
<verboseStacktraces>false</verboseStacktraces>
<defines>
<property>
<name>CONFIG::BUILD</name>
<value>"${project.version}"</value>
</property>
</defines>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>asdoc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.build.directory}/asdoc/tempdita</directory>
<targetPath>docs</targetPath>
<includes>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>ASDoc_Config.xml</exclude>
<exclude>overviews.xml</exclude>
</excludes>
</resource>
</resources>
</build>
<properties>
<sonar.language>flex</sonar.language>
<sonar.sources>src/main/flash</sonar.sources>
<sonar.tests>src/test/flash</sonar.tests>
<sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
</properties>
</project>
I've tried several ways to run Sonar:
dynamicAnalysis=reuseReports
+mvn clean install
+mvn sonar:sonar
dynamicAnalysis=true
+mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true
dynamicAnalysis=true
+mvn clean install -DskipTests=true
+mvn sonar:sonar
(<-- doesn't work: for some reason in this scenario the unit tests fail to run with a NullPointerException during execution of Flex-Mojos'stest-run
goal).
Is there a way to make displaying the coverage results in the Sonar dashboard work? Do I need additional plugins for that (Emma, Clover, whatever) to get the coverage from the standard Surefire reports to show up? Is there a known issue that prevents this from working? Am I doing something wrong?
Update
I've tried running Sonar with the Sonar-Runner. Interestingly, the dashboard then completely drops the code coverage widget. Checking the console output of the runner shows that the runner doesn't execute the FlexSurefireSensor
(which the sonar:sonar
Maven goal does):
The sonar-project.properties
file contains:
sonar.projectKey=foo:bar
sonar.projectName=Bar
sonar.projectVersion=0.1.0-SNAPSHOT
sonar.language=flex
sources=src/main/flash
tests=src/test/flash
sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=target/surefire-reports
I'm running it with mvn clean install
followed by sonar-runner
.