SonarScanner ignoring coverage data of Swift files

I’ve set up an iOS project that has development pods. The analysis works fine i.e code smells and duplications are being detected and being shown on SonarQube server but coverage data gets ignored with the log showing this:

INFO: Parsing /Users/daniyal/MyApp/sonarqube-generic-coverage.xml
INFO: Imported coverage data for 0 files
INFO: Coverage data ignored for 4403 unknown files, including:
/Users/daniyal/MyApp/AccountStore/AccountStore/AccountProvider.swift

Sonar-project.properties looks like this

sonar.host.url=https://*******-engineering.com/
sonar.login=**********token*********
sonar.projectKey=MyApp
sonar.projectName=MyApp
sonar.language=swift
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-
sonar.sources=.
sonar.test.inclusions=**/*Test*/**
sonar.test.inclusions=*.swift
sonar.exclusions=**/*.xml,Pods/**/*,Reports/**/*
sonar.tests=AccountStore/AccountStoreTests
sonar.swift.simulator=platform=iOS Simulator,name=iPhone 8,OS=13.3
sonar.swift.project=MyApp/MyApp.xcodeproj
sonar.swift.workspace=MyApp.xcworkspace
sonar.swift.appName=MyApp
sonar.swift.appScheme=MyAppScheme
sonar.swift.appConfiguration=Debug
sonar.coverageReportPaths=sonarqube-generic-coverage.xml

Hi,

Welcome to the community!

Could you verify that this path actually points to an existing file: /Users/daniyal/MyApp/AccountStore/AccountStore/AccountProvider.swift. Also, are there any symlinks involved?

 
Ann

Thanks Ann,

You’re right the issue is actually due to the path.

What sonar qube is expecting is AccountStore/AccountStore/AccountProvider.swift and what’s being generated is /Users/daniyal/MyApp/AccountStore/AccountStore/AccountProvider.swift

I used the recommended script to generate XML.

Any idea how can I get the desired path?

Hi,

Sorry, no clue.

 
Ann

You can find and replace the paths with sed.
See my CI script as a reference:

    - 'xcodebuild clean test -workspace "${XC_WORKSPACE_FILE}" -scheme "${SCHEMA_BETA}" -destination "${TEST_PLATFORM_DESTINATION}" -enableCodeCoverage YES -derivedDataPath $PWD/output'
    - 'xccov-to-sonarqube-generic.sh $PWD/output/Logs/Test/*.xcresult/ > test.xml'
    - 'sed "s@$(pwd)/@@" test.xml > sonarqube-generic-coverage.xml'
1 Like