SonarQube 6.7 Error Same Measure Twice After Running Sonar-Scanner in iOS project (Mixed Objective C & Swift)

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

SonarQube 6.7

SonarQube Scanner 3.3.0.1492

  • what are you trying to achieve

Get code coverage for ios project with mixed Objective C and Swift

  • what have you tried so far to achieve this

We enabled plugin for Swift & Objective C at server side, as ObjectiveC.png and Swift.png
Then i format sonar-project.properties as:

sonar.projectKey=iOSProjectKey

sonar.projectName=iOSProjectName

sonar.projectVersion=4.5.0

sonar.c.file.suffixes=

sonar.objc.file.suffixes=.h,.m

sonar.swift.file.suffixes=.swift

sonar.sources=iOSProject

sonar.sourceEncoding=UTF-8

sonar.cfamily.build-wrapper-output=OurBuildFolderAtSamePlaceWithSonarProjectPropertiesFile

We also attached two images ObjectiveC.png & Swift.png to show the configuration at our Sonar Server now.

After running sonar-scanner command, the output has error as below:

13:43:15.861 ERROR: Lizard Report not found <ProjectPath>/sonar-reports/lizard-report.xml
java.io.FileNotFoundException: <ProjectPath>/sonar-reports/lizard-report.xml (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at java.io.FileInputStream.<init>(FileInputStream.java:93)
	at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
	at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:623)
	at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:148)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:805)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205)
	at com.backelite.sonarqube.swift.complexity.LizardReportParser.parseReport(LizardReportParser.java:67)
	at com.backelite.sonarqube.swift.complexity.LizardSensor.execute(LizardSensor.java:63)
	at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
	at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:177)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:291)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:286)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:264)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
	at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

13:43:15.861 INFO: Sensor Lizard [backelitesonarswiftplugin] (done) | time=19ms
13:43:15.861 INFO: Sensor JavaXmlSensor [java]
13:43:15.872 INFO: Sensor JavaXmlSensor [java] (done) | time=11ms
13:43:15.872 INFO: Sensor HTML [web]
13:43:15.909 DEBUG: '< ProjectPath>/SupportingFiles/personal_info.html' generated metadata  with charset 'UTF-8'
13:43:15.990 DEBUG: HtmlSensor: <ProjectPath>/SupportingFiles/personal_info.html: 0,0,1
13:43:16.018 INFO: Sensor HTML [web] (done) | time=146ms
13:43:16.018 INFO: Sensor SonarSwift [swift]
13:43:16.031 INFO: 27 source files to be analyzed
13:43:17.041 DEBUG: '<ProjectFolder_Path>/Extension.swift' generated metadata  with charset 'UTF-8'
13:43:17.283 INFO: ------------------------------------------------------------------------
13:43:17.283 INFO: EXECUTION FAILURE
13:43:17.283 INFO: ------------------------------------------------------------------------
13:43:17.283 INFO: Total time: 12.628s
13:43:17.393 INFO: Final Memory: 29M/525M
13:43:17.393 INFO: ------------------------------------------------------------------------
13:43:17.394 ERROR: Error during SonarQube Scanner execution
java.lang.UnsupportedOperationException: Can not add the same measure twice on <ProjectPath >/Extension.swift: DefaultMeasure[component=<ProjectPath >/Extension.swift,metric=Metric[id=<null>,key=ncloc,description=Non commenting lines of code,type=INT,direction=-1,domain=Size,name=Lines of Code,qualitative=false,userManaged=false,enabled=true,worstValue=<null>,bestValue=<null>,optimizedBestValue=false,hidden=false,deleteHistoricalData=false,decimalScale=<null>],value=123,fromCore=false]
	at org.sonar.scanner.sensor.DefaultSensorStorage.saveMeasure(DefaultSensorStorage.java:268)
	at org.sonar.scanner.sensor.DefaultSensorStorage.store(DefaultSensorStorage.java:212)
	at org.sonar.api.batch.sensor.measure.internal.DefaultMeasure.doSave(DefaultMeasure.java:95)
	at org.sonar.api.batch.sensor.internal.DefaultStorable.save(DefaultStorable.java:45)
	at com.sonar.swift.plugin.H.A(Unknown Source)
	at com.sonar.swift.plugin.H.D(Unknown Source)
	at com.sonar.swift.plugin.H.A(Unknown Source)
	at com.sonar.swift.plugin.E.A(Unknown Source)
	at com.sonar.swift.plugin.E.A(Unknown Source)
	at com.sonar.swift.plugin.E.execute(Unknown Source)
	at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
	at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:177)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:291)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:286)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:264)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
	at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

From the error messages above, beside the error of “Can not add the same measure twice on .swift”, it also display error for lizard reports too.
But from the attached image, we have just enabled Objective C & Swift only. Why does SonarScanner need to display lizard report ?
Besides that, we tried to remove swift file which display error message to another folder, then rerun sonar-scanner again. This time, Sonar display the same error message to new swift file.

We really need Sonar Development Team support this case OR you can give us the link to sample which config Sonar to scan project which is mixed Objective C and Swift code.

We are discussing with your Sale department to buy the SonarQube to show CodeCoverage in our current project. If we can not run SonarQube with source code mixed ObjectiveC and Swift, it is hard for us to persuade our director to buy Sonar license.

We are looking forward to receiving your support as soon as possible.

Best regards,

Note: I tried to upload ObjectiveC.png image but your Community site has just allowed me upload 1 image at current topic. So i will post it later via email, have Miss Sara Sharpless help to send these two images to your development team.

1 Like

Hi @thangdq,

what version of Swift and C/C++/Objective-C analyzers do you have installed?
Could you make sure you have the latest version of the two analyzers?
This is supposed to be fixed in the C/C++/Objective-C analyzer since a long time: CPP-1829.

Hi @mpaladin, I am facing similar issue with my iOS project.

Here is what my properties file includes-
sonar.projectKey=MyProject
sonar.language=swift
sonar.projectName= MyProject
sonar.projectVersion=1.0
sonar.sources= MyProjectFolder
sonar.swift.simulator=platform=iOS Simulator,name=iPad Air,OS=12.4
sonar.swift.project= MyProject.xcodeproj
sonar.swift.workspace= MyProject.xcworkspace
sonar.swift.appScheme= MyProject
sonar.exclusions=/Manged Objects/
sonar.verbose=true

I am using -
SonarQube Enterprise edition 8.0
SonarQube scanner 4.0.0

Please help us with this.

Thanks.

Hi @Manjunath_K,

what are these properties? These are not from the official SonarSource swift plugin. If you install such plugins you need to make sure the two analyzers don’t overlap each other which is probably the case for you and @thangdq.

Hello @mpaladin,

Thanks for the response.

I am new to Sonar and I am following steps mentioned here -

I would be glad if you could direct me to the exact steps to follow to scan the iOS project using Sonar and get the reports.

I have checked Sonar official site and unfortunately couldn’t find what I want.

I see many questions similar to this by different developers for iOS projects. Your answer could be helpful to them also. Please help me.

I have trail version enterprise SonarQube installed in our server.

Thanks.

Hi @Manjunath_K,

as you see in the article you shared you are installing a plugin which is overlapping with the default swift analyzer. Our swift analyzer doesn’t need special configuration, see the documentation page: https://docs.sonarqube.org/latest/analysis/languages/swift/.

Hi @mpaladin,

I guess, you are pointing at backelite-sonar-swift-plugin-0.4.5.jar plugin. With out this we cannot compile the code. We get below error -

Running run-sonar-swift.sh…

.Extracting Xcode project information… BUILD FAILED ****

The following build commands failed:

CompileC /Users/name/Library/Developer/Xcode/DerivedData/MyApp-cthezsyhnxbnqgdwqfympwmhcagc/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FirebaseCore.build/Objects-normal/x86_64/FIRErrors.o /Users/name/Apps/MyApp/Pods/FirebaseCore/Firebase/Core/FIRErrors.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler

(1 failure)

ERROR - Command ‘xcodebuild clean build -workspace MyApp.xcworkspace -scheme MyApp -destination platform=iOS Simulator,name=iPad Air,OS=12.4 -destination-timeout 360 COMPILER_INDEX_STORE_ENABLE=NO’ failed with error code: 65

Let me know if I am doing something wrong.

Hi @Manjunath_K,

yes, if you have troubles with this contact their support channel, we don’t support such plugin.

I doubt it is the cause of the compilation error.

Hi @mpaladin,

Thanks for response. I have decided to not to follow the steps provided in shared link.

Can you please help me with steps that we need to follow for executing sonar scan on an iOS project which has pods, unit tests, UI unit tests and has files written in both Objective C and Swift. Pointing to right link will also help.

I have seen many developers having issue in executing sonar scan on iOS projects.

Hi @Manjunath_K,

if your project contains Objective-C follow https://docs.sonarqube.org/latest/analysis/languages/cfamily/.

If it contains only swift files just launch sonar-scanner with sonar.sources pointing to your sources folder. For coverage you can find link on the documentation page: https://docs.sonarqube.org/latest/analysis/languages/swift/.

Hi @mpaladin,

I did try running after removing the plugin, but still ran into same issue.
I dont find much info in the links you provided.

We are using trial license which soon will expire and still not able to get any results.
Please help us with the right steps to execute scanner on our iOS projects having only Swift and also swift+objective-c code bases.

Thanks.

Hi @Manjunath_K,

if you want to analyze your swift project just get a clean SonarQube installation without installing any extra plugin and analyze your project with just these properties, nothing else required:

sonar.projectKey=MyProject
sonar.projectName=MyProject
sonar.sources=MyProjectFolder