Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty metrics in sonar for web and javascript projects

Initial post

I use several tools for my Continuous Integration :

  • Maven 3.0.4
  • Sonar 3.3
  • Sonar Web Plugin 1.2
  • Sonar Javascript Plugin 1.1
  • Jenkins 1.486

Everything works fine for Java projects and XML projects.

I'm having trouble with Javascript and web projects. Projects are created in Sonar but they are empty.

Here is a sample of stacktrace for a javascript project

[INFO] --- sonar-maven-plugin:2.0-beta-2:sonar (default-cli) @ MyProject ---

[INFO] Sonar version: 3.3

[INFO] [15:59:24.937] Create JDBC datasource for jdbc:mysql://sonar-02:3306/sonar

[INFO] [15:59:41.190] Initializing Hibernate

[INFO] [15:59:43.318] ------------- Analyzing MyProject JS

[INFO] [15:59:43.573] Quality profile : [name=myProfileJavascript,language=js]

[INFO] [15:59:43.612] Configure maven plugins...

[INFO] [15:59:43.653] Compare to previous analysis (2013-02-08)

[INFO] [15:59:43.672] Compare over 5 days (2013-02-03, analysis of 2013-02-07 12:29:08.0)

[INFO] [15:59:43.682] Compare over 30 days (2013-01-09, analysis of 2013-02-07 12:29:08.0)

[INFO] [15:59:43.877] Initializer ProjectFileSystemLogger...

[INFO] [15:59:43.878] Excluded tests: [**/package-info.java]

[INFO] [15:59:43.881] Source directories:

[INFO] [15:59:43.881]
C:\Work\Workspaces\Intellij\MyProject\src\main\java

[INFO] [15:59:43.881] Test directories:

[INFO] [15:59:43.882]
C:\Work\Workspaces\Intellij\MyProject\src\test\java

[INFO] [15:59:43.882] Initializer ProjectFileSystemLogger done: 5 ms

[INFO] [15:59:43.882] Initializer MavenInitializer...

[INFO] [15:59:43.884] Java source version: 1.6

[INFO] [15:59:43.884] Java target version: 1.6

[INFO] [15:59:43.884] Initializer MavenInitializer done: 2 ms

[INFO] [15:59:44.183] Sensor JavaScriptSourceImporter...

[INFO] [15:59:44.335] Sensor JavaScriptSourceImporter done: 152 ms

[INFO] [15:59:44.335] Sensor JavaScriptSquidSensor...

[INFO] [15:59:44.520] Sensor JavaScriptSquidSensor done: 185 ms

[INFO] [15:59:44.520] Sensor JsTestDriverSurefireSensor...

[INFO] [15:59:44.526] Sensor JsTestDriverSurefireSensor done: 6 ms

[INFO] [15:59:44.526] Sensor JsTestDriverCoverageSensor...

[INFO] [15:59:44.584] Sensor JsTestDriverCoverageSensor done: 58 ms

[INFO] [15:59:44.584] Sensor CpdSensor...

[INFO] [15:59:44.585] SonarBridgeEngine is used

[INFO] [15:59:44.642] Sensor CpdSensor done: 58 ms

[INFO] [15:59:44.642] Sensor ProfileSensor...

[INFO] [15:59:44.725] Sensor ProfileSensor done: 83 ms

[INFO] [15:59:44.725] Sensor ProfileEventsSensor...

[INFO] [15:59:44.752] Sensor ProfileEventsSensor done: 27 ms

[INFO] [15:59:44.753] Sensor ProjectLinksSensor...

[INFO] [15:59:44.791] Sensor ProjectLinksSensor done: 38 ms

[INFO] [15:59:44.791] Sensor VersionEventsSensor...

[INFO] [15:59:44.820] Sensor VersionEventsSensor done: 29 ms

[INFO] [15:59:44.820] Sensor Maven dependencies...

[INFO] [15:59:48.148] Sensor Maven dependencies done: 3328 ms

[INFO] [15:59:48.517] Execute decorators...

[INFO] [15:59:48.856] ANALYSIS SUCCESSFUL, you can browse http://sonarServer:9000

[INFO] [15:59:48.857] Executing post-job class org.sonar.plugins.core.batch.IndexProjectPostJob

[INFO] [15:59:49.140] Executing post-job class org.sonar.plugins.dbcleaner.ProjectPurgePostJob

[INFO] [15:59:49.154] -> Keep one snapshot per day between 2013-01-11 and 2013-02-07

[INFO] [15:59:49.156] -> Keep one snapshot per week between 2012-12-14 and 2013-01-11

[INFO] [15:59:49.157] -> Keep one snapshot per month between 2011-04-08 and 2012-12-14

[INFO] [15:59:49.157] -> Delete data prior to: 2011-04-08

[INFO] [15:59:49.163] -> Clean MyProject JS [id=57524]

[INFO] [15:59:49.167] <- Clean snapshot 1690793

I can see that sonar is using C:\Work\Workspaces\Intellij\MyProject\src\main\java

In my pom I have tested several properties without changin sonar behaviour.

 <sonar.javascript.sources>src/main/webapp</sonar.javascript.sources>
 <sonar.sources>src/main/webapp</sonar.sources>
 <sources>src/main/webapp</sources>

It's the same problem with web projects.

Any Idea ?

Thank you in advance.

EDIT 11/02/2013 - After Fabrice - Sonar Team comment

I created a new pom (pom-web.xml) with the following informations

<properties>
    <sonar.branch>JS</sonar.branch>
    <sonar.language>web</sonar.language>
</properties>
<build>
    <sourceDirectory>src/main/webapp</sourceDirectory>
</build>

It seems that the sources directory changed but metrics are still empty.

[INFO] [12:11:54.486] Execute org.apache.maven.plugins:maven-surefire-plugin:2.9:test done: 545 ms

[INFO] [12:11:54.486] Execute maven plugin maven-surefire-plugin done: 545 ms

[INFO] [12:11:54.486] Initializer JacocoMavenInitializer...

[INFO] [12:11:54.486] Initializer JacocoMavenInitializer done: 0 ms

[INFO] [12:11:54.486] Initializer ProjectFileSystemLogger...

[INFO] [12:11:54.487] Excluded tests: [**/package-info.java]

[INFO] [12:11:54.487] Source directories:

[INFO] [12:11:54.487]
C:\Work\Workspaces\Intellij\MyProject\src\main\webapp

Same behavior with web and JS.

EDIT 11/02/2013 : Solution found

I needed to have one pom file. So I managed sonar properties thanks to profiles. As "sourceDirectory" is not re definable within profiles, I use a custom properties.

the property "sonar.branch" enables me to have several sonar entries for my project.

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.test</groupId>
<artifactId>MyMultiLanguageProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <ci.build.sourceDirectory>src/main/java</ci.build.sourceDirectory>
    <ci.build.testSourceDirectory>src/test/java</ci.build.testSourceDirectory>
</properties>

<build>
    <sourceDirectory>${ci.build.sourceDirectory}</sourceDirectory>
    <testSourceDirectory>${ci.build.testSourceDirectory}</testSourceDirectory>
</build>

<profiles>
    <profile>
        <id>CI-WEB</id>
        <properties>
            <sonar.branch>WEB</sonar.branch>
            <sonar.language>web</sonar.language>
            <sonar.sources>src</sonar.sources>
            <ci.build.sourceDirectory>src/main/webapp</ci.build.sourceDirectory>
            <ci.build.testSourceDirectory>src/test/webapp</ci.build.testSourceDirectory>
        </properties>
    </profile>
    <profile>
        <id>CI-JS</id>
        <properties>
            <sonar.branch>JS</sonar.branch>
            <sonar.language>js</sonar.language>
            <sonar.sources>src</sonar.sources>
            <ci.build.sourceDirectory>src/main/webapp</ci.build.sourceDirectory>
            <ci.build.testSourceDirectory>src/test/webapp</ci.build.testSourceDirectory>
        </properties>
    </profile>
</profiles>

like image 597
Wilhelm Peraud Avatar asked Feb 08 '13 15:02

Wilhelm Peraud


1 Answers

You currently have to create other POMs (or profile in your POM) if you want to analyse JS and Web projects. In those new POMs (or profiles), you will set the "sourceDirectory" tag to the correct folder, and you won't forget to specify "sonar.language" in the properties. Also, those new POMs/profiles should change the artifactId so that you have different projects in Sonar.

Then you can run "mvn clean sonar:sonar -f pom-javascript.xml" (new POM) or "mvn clean sonar:sonar -Pjavascript" (using a profile).

In a near future, Sonar will natively support multi-language projects. Until then, you have to use this hack.

like image 181
Fabrice - SonarSource Team Avatar answered Nov 14 '22 22:11

Fabrice - SonarSource Team