I'm working iOs app,which uses swift language.It's generating coverage.profdata successfully.But I would like to generate the same thing on SonarQube.
Please let me know if you have any ideas!!
I tried the below link
swift-sonar properties
The SonarQube Swift plugin does not have built-in support to import coverage results.
The only option (and the best one) for you is to use the Generic Coverage Plugin:
First you run your coverage tool to generate the coverage.profdata file
Then you manage to transform this file into the target format supported by the Generic Coverage Plugin
And finally you reference this new coverage file in your sonar-project.properties file (like explained in the documentation of the plugin)
Related
I am using following code to export test code coverage using Xcode11.4.
./xccov-to-sonarqube-generic.sh /DerivedData/MyApp-*/Logs/Test/*.xcresult/ > sonarqube-generic-coverage.xml
I am getting following error
This version of Xcode does not support opening result bundles created
with versions of Xcode and xcodebuild using the v1 API
Kindly help me with the proper way.
3 work arounds here for this as for as my research:
There is an update to xccov-to-sonarqube-generic.sh script for Xcode 11+. Try using this
https://github.com/SonarSource/sonar-scanning-examples/blob/master/swift-coverage/swift-coverage-example/xccov-to-sonarqube-generic.sh
Use Code Coverage Converter (cococo) utility to generate sonar's xml file format. Refer for more info:
https://medium.com/monsterculture/cococo-code-coverage-converter-from-xcode-11-to-sonarqube-7f48cff97b9b
Any shell script that is capable to convert Xocde 11+ *.xcresult file to sonar's xml file format
I have a requirement where we need to perform code analysis to find vulnerabilities like how sonarqube does for an iOS Project, not for the actual swift files but for .framework created using the swift files.
Is it possible to do this using sonarqube or swiftlint? Are there any code analysis tool available to analyse the .framework?
According to the docs, both the swift and Obj-C sonar scanners want code coverage data and in different ways (build-wrapper vs xccov). But this got me thinking, code coverage is for an entire target/project in xcode, not just files for a particular language. So for a mixed Obj-C and swift project, does SonarQube want the same entire-project-xcode-generated coverage data twice (once per scanner)? If not, how does it relate code coverage for a particular language in a sonar project, or does it not care at all?
Only asking this because again, and much to my surprise, the docs for the 2 scanners list different code coverage instructions, leading the user to wonder if each scanner doesn't expect the data to be mixed together like it is with xcode and a mixed obj-c swift project (i.e. its the same data)
Even i am facing same scanario. What we are currently doing is we setup build-wrapper utility as indicated at https://docs.sonarqube.org/latest/analysis/languages/cfamily/.
So, initially it worked fine for a month or so. Later, we start getting following error:
====================================================================================
02:36:25.658 INFO: ------------------------------------------------------------------------
02:36:25.658 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
* you are using the latest version of the build-wrapper and the SonarCFamily analyzer
* you are correctly invoking the scanner with correct configuration * your compiler is supported
* you are wrapping your build correctly
* you are wrapping a full/clean build
* you are providing the path to the correct build-wrapper output directory
====================================================================================
So, we have decide to install a backelite plug-in / jar (that handles sonar coverage reports for a mix of Swift and Objective-C) to our sonar server (Enterprise edition) , but, it led to the following error:
error message screenshot
So, basically you can set uo build wrapper utility and try performing the sonar scan. Make sure sonar-scanner is installed and you are passing relevant switches to the sonar-scanner command.
The code_build (https://pub.dartlang.org/packages/code_builde) package provides a solution to generate classes and constructors, field and methods for that class.
My ultimate goal is to generate Flutter (https://flutter.io) Widgets based on the json structure given, but I don't know how to do this with the code_build or another package.
So help would be appreciated!
The general way to write something which outputs Dart code is to wrap up the functionality in a Builder and to perform the code generation with build_runner
At a high level you'd write a Builder that:
Has buildExtensions of {".json": [".dart"]}.
Reads in the buildStep.inputId asset and parses the json.
Uses code_builder to build up a String and then write it to the output asset.
Then you'd configure the builder in build.yaml. And either apply it manually to your package, or if you'd like to publish it as a utility it can apply to dependencies.
Your package would have a dev_dependency on build_runner and then you can execute builds with flutter packages run build_runner build.
There are more docs at https://github.com/dart-lang/build/tree/master/docs
You can see an example of a package which does something similar - starts with yaml files and outputs Dart files using code_builder at https://github.com/natebosch/message_builder
There is now an online tool which will generate the Dart classes from a JSON payload if you're only looking to structure your model classes. It won't do it dynamically at runtime, but it's super helpful when you're first building your program.
https://javiercbk.github.io/json_to_dart/
Code coverage in Xcode is a testing option supported by LLVM. When you
enable code coverage, LLVM instruments the code to gather coverage
data based on the frequency that methods and functions are called. The
code coverage option can collect data to report on tests of
correctness and of performance, whether unit tests or UI tests.
I would like to generate a code-coverage report via Xcode.
I've looked at gcovr http://gcovr.com.
...or is it more prudent to generate a report via xcodebuild?
Is there a tutorial or guide to generating a report via Xcode 8+?
There is -enableCodeCoverage YES option for xcodebuild. You can easily see possibilities of xcodebuild command by typing xcodebuild --help.
Here are Apple guildelines on code coverage usage: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/07-code_coverage.html
You can even see the coverage report directly from Xcode.