Daniel Raap | 10 Jun 09:14 2011
Picon

Analyse multi-modules project with ant task 1.1

Hello list,

 

i’ve tried to analyze our ant build software with sonar. Because it consists of different parts which are separate eclipse projects I wanted to use the new multi-modules feature of the sonar ant task 1.1. But for me it doesn’t work and always complains about “SonarException: Can not add twice the same measure on …”.

 

I think the problem is, that the workdir already contains results of that sensor. At the moment it fails for the second module at “Sensor ProfileSensor...” because I created an empty quality profile. Else it was failing at “Squid extraction...” with quality profile “Sonar way”.

 

Here are the build.xml snippets according to the example in the wiki (http://docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task#AnalysewithAntTask-Analysemultimodulesproject):

Parent:

                <target name="sonar">

                               <property name="sonar.jdbc.url" value="…" />

                               <property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" />

                               <property name="sonar.jdbc.username" value="…" />

                               <property name="sonar.jdbc.password" value="…" />

                               <property name="sonar.host.url" value="http://sonar:80" />

 

                               <property name="sonar.modules" value="Child1/build.xml,Child2/build.xml,Child3/build.xml,Child4/build.xml" />

 

                               <sonar:sonar key="com.example:Parent" version="1.0" xmlns:sonar="antlib:org.sonar.ant"/>

                </target>

 

Child1 and Child2 have these properties global in the build.xml (directly underneath the <project> tag):

  <property name="sonar.projectKey" value="com.example:Child1" />

  <property name="sonar.sources" value="${src.dir}" />

  <property name="sonar.binaries" value="${compiled.classes}" />

  <property name="sonar.libraries" value="${lib.dir}" />

  <property name="sonar.profile" value="Empty" />

  <property name="sonar.dynamicAnalysis" value="false" />           

 

Find the ant output attached.

 

Is there a property that has to be defined where to place the reports or is the multi-module functionality not yet working properly?

 

 

Best regards
Daniel Raap

sonar:
     [echo]  _
     [echo]  **********************************************
     [echo]  Collecting Sonar data
     [echo]  **********************************************
     [echo]
[sonar:sonar] Apache Ant version 1.8.1 compiled on April 30 2010
[sonar:sonar] Sonar Ant Task version: 1.1
[sonar:sonar] Loaded from: file:/C:/temp/BuildTest/sonar-ant-task-1.1.jar
[sonar:sonar] Sonar work directory: C:\temp\BuildTest\.sonar
[sonar:sonar] Sonar server: http://sonar:80
[sonar:sonar] Sonar version: 2.8
[sonar:sonar] [INFO]  Database dialect class org.sonar.jpa.dialect.MySql
[sonar:sonar] [INFO]  Initializing Hibernate
[sonar:sonar] [INFO]  Execution environment: Ant Apache Ant version 1.8.1 compiled on April 30 2010
[sonar:sonar] [INFO]  -------------  Analyzing Child1
[sonar:sonar] [INFO]  Selected quality profile : [name=Empty,language=java]
[sonar:sonar] [INFO]  Compare over 5 days (2011-06-05)
[sonar:sonar] [INFO]  Compare over 30 days (2011-05-11)
[sonar:sonar] [INFO]  Configure maven plugins...
[sonar:sonar] [INFO]  Sensor AsynchronousMeasuresSensor...
[sonar:sonar] [INFO]  Sensor AsynchronousMeasuresSensor done: 16 ms
[sonar:sonar] [INFO]  Sensor JavaSourceImporter...
[sonar:sonar] [INFO]  Sensor JavaSourceImporter done: 0 ms
[sonar:sonar] [INFO]  Sensor SquidSensor...
[sonar:sonar] [INFO]  Java Squid scan...
[sonar:sonar] [INFO]  Java Squid scan done: 0 ms
[sonar:sonar] [INFO]  Sensor SquidSensor done: 15 ms
[sonar:sonar] [INFO]  Sensor CpdSensor...
[sonar:sonar] [INFO]  Sensor CpdSensor done: 16 ms
[sonar:sonar] [INFO]  Sensor ProfileSensor...
[sonar:sonar] [INFO]  Sensor ProfileSensor done: 0 ms
[sonar:sonar] [INFO]  Sensor VersionEventsSensor...
[sonar:sonar] [INFO]  Sensor VersionEventsSensor done: 0 ms
[sonar:sonar] [INFO]  Execute decorators...
[sonar:sonar] [INFO]  -------------  Analyzing Child2
[sonar:sonar] [INFO]  Selected quality profile : [name=Empty,language=java]
[sonar:sonar] [INFO]  Compare over 5 days (2011-06-05)
[sonar:sonar] [INFO]  Compare over 30 days (2011-05-11)
[sonar:sonar] [INFO]  Configure maven plugins...
[sonar:sonar] [INFO]  Sensor AsynchronousMeasuresSensor...
[sonar:sonar] [INFO]  Sensor AsynchronousMeasuresSensor done: 0 ms
[sonar:sonar] [INFO]  Sensor JavaSourceImporter...
[sonar:sonar] [INFO]  Sensor JavaSourceImporter done: 0 ms
[sonar:sonar] [INFO]  Sensor SquidSensor...
[sonar:sonar] [INFO]  Java Squid scan...
[sonar:sonar] [INFO]  Java Squid scan done: 0 ms
[sonar:sonar] [INFO]  Sensor SquidSensor done: 0 ms
[sonar:sonar] [INFO]  Sensor CpdSensor...
[sonar:sonar] [INFO]  Sensor CpdSensor done: 0 ms
[sonar:sonar] [INFO]  Sensor ProfileSensor...

BUILD FAILED
C:\temp\BuildTest\build.xml:88: org.sonar.api.utils.SonarException: Can not add twice the same
measure on org.sonar.api.resources.Project <at> 19
6a753[id=8131,key=ch.totemo.development:${name},qualifier=BRC]: org.sonar.api.measures.Measure <at> 1be87a0[id=<null>,metricKey=profile,metric=org.sonar.ap
i.measures.Metric <at> 7ae747[key=profile,name=Profile,type=DATA,enabled=true,qualitative=false,direction=0,domain=General,worstValue=<null>,bestValue=<nul
l>,optimizedBestValue=false,hidden=false],value=5.0,data=Parent,description=<null>,alertStatus=<null>,alertText=<null>,tendency=<null>,date=<null>
,variation1=<null>,variation2=<null>,variation3=<null>,variation4=<null>,variation5=<null>,url=<null>,characteristic=<null>,persistenceMode=FULL]
        at org.sonar.batch.index.Bucket.addMeasure(Bucket.java:101)
        at org.sonar.batch.index.DefaultIndex.addMeasure(DefaultIndex.java:184)
        at org.sonar.batch.DefaultSensorContext.saveMeasure(DefaultSensorContext.java:84)
        at org.sonar.plugins.core.sensors.ProfileSensor.analyse(ProfileSensor.java:47)
        at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:58)
        at org.sonar.batch.phases.Phases.execute(Phases.java:80)
        at org.sonar.batch.ProjectBatch.execute(ProjectBatch.java:59)
        at org.sonar.batch.Batch.analyzeModule(Batch.java:164)
        at org.sonar.batch.Batch.analyzeModule(Batch.java:155)
        at org.sonar.batch.Batch.analyzeModules(Batch.java:82)
        at org.sonar.batch.Batch.execute(Batch.java:62)
        at org.sonar.ant.Launcher.executeBatch(Launcher.java:184)
        at org.sonar.ant.Launcher.execute(Launcher.java:64)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.sonar.ant.SonarTask.delegateExecution(SonarTask.java:205)
        at org.sonar.ant.SonarTask.execute(SonarTask.java:189)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1249)
        at org.apache.tools.ant.Main.runBuild(Main.java:801)
        at org.apache.tools.ant.Main.startAnt(Main.java:218)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 24 seconds
Attachment (smime.p7s): application/pkcs7-signature, 5167 bytes
Freddy Mallet | 13 Jun 15:48 2011

Re: Analyse multi-modules project with ant task 1.1

Hi Daniel,


According to your log file, there seems to be a bug on the way you define the Sonar module key on each module :

key=ch.totemo.development:${name} 

So I guess at least two modules have the same key because the property ${name} is not interpreted. 

Kind regards,
Freddy

----------------------------------------
Freddy Mallet
www.SonarSource.org
www.SonarSource.com
----------------------------------------


On Fri, Jun 10, 2011 at 9:14 AM, Daniel Raap <daniel.raap-4BUtOHJXg7LtRgLqZ5aouw@public.gmane.org> wrote:

Hello list,

 

i’ve tried to analyze our ant build software with sonar. Because it consists of different parts which are separate eclipse projects I wanted to use the new multi-modules feature of the sonar ant task 1.1. But for me it doesn’t work and always complains about “SonarException: Can not add twice the same measure on …”.

 

I think the problem is, that the workdir already contains results of that sensor. At the moment it fails for the second module at “Sensor ProfileSensor...” because I created an empty quality profile. Else it was failing at “Squid extraction...” with quality profile “Sonar way”.

 

Here are the build.xml snippets according to the example in the wiki (http://docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task#AnalysewithAntTask-Analysemultimodulesproject):

Parent:

                <target name="sonar">

                               <property name="sonar.jdbc.url" value="…" />

                               <property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" />

                               <property name="sonar.jdbc.username" value="…" />

                               <property name="sonar.jdbc.password" value="…" />

                               <property name="sonar.host.url" value="http://sonar:80" />

 

                               <property name="sonar.modules" value="Child1/build.xml,Child2/build.xml,Child3/build.xml,Child4/build.xml" />

 

                               <sonar:sonar key="com.example:Parent" version="1.0" xmlns:sonar="antlib:org.sonar.ant"/>

                </target>

 

Child1 and Child2 have these properties global in the build.xml (directly underneath the <project> tag):

  <property name="sonar.projectKey" value="com.example:Child1" />

  <property name="sonar.sources" value="${src.dir}" />

  <property name="sonar.binaries" value="${compiled.classes}" />

  <property name="sonar.libraries" value="${lib.dir}" />

  <property name="sonar.profile" value="Empty" />

  <property name="sonar.dynamicAnalysis" value="false" />           

 

Find the ant output attached.

 

Is there a property that has to be defined where to place the reports or is the multi-module functionality not yet working properly?

 

 

Best regards
Daniel Raap



Gmane