sonar swift plugin exception

332 views
Skip to first unread message

Wilson Lai

unread,
Jan 31, 2018, 2:12:42 AM1/31/18
to SonarQube
I'm using SonarQube and SonarSwift and try to upload coverage report generated by Xcode 9.2  and got an error when trying to access the generated profdata file

My implementation
  1. Use Fastlane to build and run the unit tests 
  2.  Run sonar-scanner 
And I got the following error messages 

ERROR: Can't parse coverage report file (fastlane/report/Coverage.profdata). No coverage information will be saved.

java.lang.IllegalStateException: Can not parse line: HƢF _T0SS17iOS_TemplateTestsE11isValidatedSbAA10ValidationO10validation_tF.k(_T09Alamofire12TaskDelegateC10urlSessionySo10URLSessionC_So0fB0C4taskySo11InputStreamCSgc011needNewBodyI0t36K2@_T09Alamofire14SessionManagerC5retrySbAA7RequestC383JZ8_T09Alamofire7AFErrorO31ResponseValidationFailureReasonO22acceptableContentTypesSaySSGSgf6(WN(_T010Foundation10URLRequestV9AlamofireE5adaptAcD14RequestAdapter_pSg5using_tK9({S(_T09Alamofire11DataRequestC8validateACXDx11contentType_ts8SequenceRzSS7ElementRtzl=h7h0_T09Alamofire15SessionDelegateC03urlB0ySo10URLSessionC_So0E12DownloadTaskC08downloadG010Foundation3URLV22didFinishDownloadingTot>c|x| _T09Alamofire15SessionDelegateC40streamTaskDidBecomeInputAndOutputStreamsySo10URLSessionC_So0l6StreamE0CSo0hM0CSo0jM0CtcSgfAL=8Q_T09Alamofire7AFErrorO30MultipartEncodingFailureReasonO20localizedDescriptionSSfB$}Ϙ _T09Alamofire8downloadAA15DownloadRequestCAA14URLConvertible_p_AA10HTTPMethodO6methods10DictionaryVySSypGSg10parametersAA17ParameterEncoding_p8encodingAJyS2SGSg7headers10Foundation3URLV011destinationO0_AD0C7OptionsV7optionstAU_So15HTTPURLResponseCtcSg2totBu+A _T012iOS_Template19LoginViewControllerCACSgSo7NSCoderC5coder_tcfL@yU< _T09Alamofire15DownloadRequestC0B7OptionsVAESu8rawValue_tcfM._T09Alamofire7RequestC18cURLRepresentationSSyMӡh8_T09Alamofire7AFErrorO34ResponseSerializationFailureReasonO20failedStringEncodingSS10FoundationE0I0VSgfNi濷^mH_T09Alamofire15DownloadRequestC24stringResponseSerializerAA0beF0VySSGSS10FoundationE8EncodingVSg8encoding_tFR= _T09Alamofire6streamAA13StreamRequestCSo10NetServiceC4with_tTШ

                  Ny0_T010Foundation10URLRequestV9AlamofireEAcD14URLConvertible_p3url_AD10HTTPMethodO6methods10DictionaryVyS2SGSg7headerstKcfUDj6 /Users/wilson.k.lai/Documents/GitHub/demo-ios/Pods/Alamofire/Source/ParameterEncoding.swift:_T0So8NSNumberC9AlamofireE6isBool33_07E29AB6DA2856B846193FCC509DA12DLLSbfV0F;3, _T09Alamofire7RequestC16debugDescriptionSSfW4&.P_T09Alamofire7AFErrorO16errorDescriptionSSSgf^3nXMvQ _T09Alamofire14SessionManagerC6streamAA13StreamRequestCSS12withHostName_Si4portt_o  8_T09Alamofire6ResultO6unwrapxyK`dx:@/Users/wilson.k.lai/Documents/GitHub/demo-ios/Pods/Alamofire/Source/SessionManager.swift:_T09Alamofire14SessionManagerC8download33_83E574FCF6E88D5939C6CCAC18E76758LLAA15DownloadRequestCAG12DownloadableOSg_10Foundation3URLV011destinationP0_AG0L7OptionsV7optionstAM_So15HTTPURLResponseCtcSg2tos5Error_p10failedWitht`hCm8/Users/wilson.k.lai/Documents/GitHub/demo-ios/Pods/Alamofire/Source/SessionManager.swift:_T09Alamofire14SessionManagerC6stream33_83E574FCF6E88D5939C6CCAC18E76758LLAA13StreamRequestCAG10StreamableOcս-TP8_T09Alamofire7RequestC21serializeResponseDataAA6ResultOy10Foundation0E0VGSo15HTTPURLResponseCSg8response_AISg4datas5Error_pSg5errortFeخ

at com.sonar.swift.plugin.B.A(Unknown Source)

at com.sonar.swift.plugin.B.A(Unknown Source)

at java.util.Optional.ifPresent(Optional.java:159)

at com.sonar.swift.plugin.B.A(Unknown Source)

at com.sonar.swift.plugin.B.A(Unknown Source)

at com.sonar.swift.plugin.B.A(Unknown Source)

at com.sonar.swift.plugin.D.A(Unknown Source)

at com.sonar.swift.plugin.D.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:180)

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:288)

at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:283)

at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:261)

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.executeTask(Batch.java:111)

at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)

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:233)

at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)

at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)

at org.sonarsource.scanner.cli.Main.execute(Main.java:77)

at org.sonarsource.scanner.cli.Main.main(Main.java:61)


INFO: Sensor Swift Squid Sensor [swift] (done) | time=1278ms

INFO: Sensor Zero Coverage Sensor

INFO: Sensor Zero Coverage Sensor (done) | time=31ms



Which it looks like it can't parse the file generated from XCode 9.2 somehow

Elena Vilchik

unread,
Jan 31, 2018, 11:39:30 AM1/31/18
to SonarQube
Hi,

Your report should have following format: 

/absolute/path/to/file.swift:
    1|       |//
    2|       |//  
    3|       |// 
    4|       |//
    5|       |//  
    6|       |// 
    7|       |//
    8|       |
    9|       |import Cocoa
   10|       |
   11|       |@NSApplicationMain
   12|       |class AppDelegate: NSObject, NSApplicationDelegate {
   13|       |
   14|       |    @IBOutlet weak var window: NSWindow!
   15|       |
   16|       |
   17|      0|    func applicationDidFinishLaunching(aNotification: NSNotification) {
   18|      0|        // Insert code here to initialize your application
   19|      0|    }
   20|       |
   21|      0|    func applicationWillTerminate(aNotification: NSNotification) {
   22|      0|        // Insert code here to tear down your application
   23|      0|    }
   24|       |
   25|       |
   26|       |}
   27|       |
   28|       |class A {
   29|      1|    func foo(){
   30|      0|        if (1 > 2) {
   31|      0|            print("hello")
   32|      1|        } else {
   33|      1|            print("Bye")
   34|      1|        }
   35|      1|    }
   36|       |}


Judging by exception message it doesn't. Try to play around the way you generate it.

Regards,
Elena

Wilson Lai

unread,
Feb 1, 2018, 4:08:29 AM2/1/18
to SonarQube
Hi,

Checked the report is fine. By runing xcrun llmv-cov report it shows following results 

Filename                                       Regions    Missed Regions     Cover   Functions  Missed Functions  Executed  Instantiations   Missed Insts.  Executed       Lines      Missed Lines     Cover

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

AppDelegate.swift                                    6                 4    33.33%           6                 4    33.33%               6               4    33.33%          21                14    33.33%

module/login/LoginViewController.swift              13                12     7.69%           4                 3    25.00%               4               3    25.00%          32                27    15.62%

module/welcome/WelcomeViewController.swift           1                 1     0.00%           1                 1     0.00%               1               1     0.00%           4                 4     0.00%

util/Validation.swift                                3                 3     0.00%           3                 3     0.00%               3               3     0.00%           9                 9     0.00%

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

TOTAL                                               23                20    13.04%          14                11    21.43%              14              11    21.43%          66                54    18.18%



The problems looks like SonarSwift plugin cannot parse the reports generated from XCode 9+ ..


Wilson 


Elena Vilchik

unread,
Feb 1, 2018, 8:33:20 AM2/1/18
to Wilson Lai, SonarQube
Sorry if I misunderstood something, but you are saying 2 opposite things: "Checked the report is fine." and "looks like SonarSwift plugin cannot parse the reports generated from XCode 9+"
If report is fine it means it has the same format as I showed, then it would be parsed correctly:)

If you think that XCode9+'s report has different format, could you show what's different? 

For me XCode9 generated the same report format (while instrumented program executable has different location from older XCode versions) 


--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/ZkX6GRCx5ns/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/80a9ae56-1bd1-4419-b340-447132c3076d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Elena Vilchik | 
SonarSource
Language Team

Wilson Lai

unread,
Feb 1, 2018, 8:34:40 PM2/1/18
to Elena Vilchik, SonarQube
Hi Elena, 

Yeah I checked the report with Xcode command line (from XCode 9.2), below is the output after I run 

xcrun llvm-cov show -instr-profile Coverage.profdata from terminal. So I suspect that if SonarSwift plugin can read the .profdata file. Just to double confirm, the 'sonar.swift.coverage.reportPath' in sonar-project.properties should be pointed to Coverage.profdata file right? that's my current setting.  

...

sonar.swift.coverage.reportPath=DerivedData/Build/ProfileData/08860391-1C09-4156-89A1-FF7144622A79/Coverage.profdata


/path/to/file/WelcomeViewController.swift:

    1|       |//

    2|       |//  WelcomeViewController.swift

    3|       |//  iOS_Template

    4|       |//

    5|       |//  Created by Wilson on 24/12/2017.

    6|       |//  Copyright © 2017 Wilson. All rights reserved.

    7|       |//

    8|       |

    9|       |import UIKit

   10|       |

   11|       |class WelcomeViewController: UIViewController {

   12|       |

   13|       |    @IBOutlet weak var welcomeWords: UILabel!

   14|       |    

   15|       |    var userName = ""

   16|       |    

   17|       |}

   18|       |

   19|       |extension WelcomeViewController {

   20|       |    // MARK: Lifecycle

   21|      0|    override func viewWillAppear(_ animated: Bool) {

   22|      0|        super.viewWillAppear(animated)

   23|      0|        welcomeWords.text = "Hi! " + userName

   24|      0|    }

   25|       |}

 



To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.

Wilson Lai

unread,
Feb 2, 2018, 3:26:15 AM2/2/18
to Elena Vilchik, SonarQube
Hi Elena,

Finally I got it fixed. Just missed that there's a report generated by crun llvm-cov show -instr-profile command and when I change the sonarswift path to point to the report it just worked. 

Thanks for your help!

Elena Vilchik

unread,
Feb 2, 2018, 3:31:16 AM2/2/18
to Wilson Lai, SonarQube
Happy to hear that!

To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
--

Elena Vilchik | 
SonarSource
Language Team

dreddy...@gmail.com

unread,
Apr 17, 2018, 4:26:41 PM4/17/18
to SonarQube
I have created a Coverage.report in my xcode project and does any one know how do i see code coverage results in jenkins using sonarqube??

Elena Vilchik

unread,
Apr 18, 2018, 3:24:23 AM4/18/18
to SonarQube
Hello,

Please create a new thread with all details of your question

Regards,
Elena
Reply all
Reply to author
Forward
0 new messages