Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarQube dashboard always showing "The main branch has no lines of code." (and run-sonar-swift.sh always exclude *.swift files) #308

Open
Bawenang opened this issue Nov 15, 2023 · 0 comments

Comments

@Bawenang
Copy link

New Issue Checklist

Issue Description

I'm trying to implement SonarQube in my iOS project. I'm doing it on an M2 Macbook Pro running Ventura 13.2.1 and Xcode 14.3.1. I am using SonarScanner to help do it. I have tried creating the coverage report manually using Slather and it can actually work and show the code coverage. However I can't seem to send it to SonarQube dashboard. It always shows the message "The main branch has no lines of code." This is the sonar-project.properties file:

    #
    # Swift SonarQube Plugin - Enables analysis of Swift and Objective-C projects into SonarQube.
    # Copyright © 2015 Backelite (${email})
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Lesser General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Lesser General Public License for more details.
    #
    # You should have received a copy of the GNU Lesser General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    #
    
    # Sonar Server details
    sonar.host.url=http://43.218.84.199:9000
    sonar.login=xxxxxx
    sonar.password=yyyyyyy
    
    # Project Details
    sonar.projectKey=bimb-bia-ios
    sonar.projectName=BIMB Authenticator for iOS
    sonar.projectDescription=This is the Sonar for BIMB Authenticator iOS
    
    # Comment if you have a project with mixed ObjC / Swift
    sonar.language=swift
    
    # Path to source directories
    # sonar.sources=SonarDemo,SonarDemoTests,SonarDemoUITests
    sonar.sources=bimb-authenticate-ios
    sonar.tests=bimb-authenticate-iosTests
    
    # Exclude directories
    sonar.test.inclusions=**/*Test*/**
    sonar.inclusions=**/*.swift
    sonar.exclusions=**/*.xml,Pods/**/*,Reports/**/*,Talsec/**/*,**/Swinject/**
    
    # Path to test directories (comment if no test)
    sonar.tests=bimb-authenticate-iosTests,bimb-authenticate-iosUITests
    
    # Destination Simulator to run surefire
    # As string expected in destination argument of xcodebuild command
    # Example = sonar.swift.simulator=platform=iOS Simulator,name=iPhone 6,OS=9.2
    # sonar.swift.simulator=platform=iOS Simulator,name=iPhone 7,OS=12.0
    sonar.swift.simulator=platform=iOS Simulator,name=iPhone 14 Pro,OS=16.4
    
    # Xcode project configuration (.xcodeproj)
    # and use the later to specify which project(s) to include in the analysis (comma separated list)
    # Specify either xcodeproj or xcodeproj + xcworkspace
    sonar.swift.project=bimb-authenticate-ios.xcodeproj
    sonar.swift.workspace=bimb-authenticate-ios.xcworkspace
    
    # Specify your appname.
    # This will be something like "myApp"
    # Use when basename is different from targeted scheme. 
    # Or when slather fails with 'No product binary found'
    sonar.swift.appName=bimb-authenticate-ios
    
    # Scheme to build your application
    sonar.swift.appScheme=bimb-authenticate-ios
    
    # Configuration to use for your scheme. if you do not specify that the default will be Debug
    sonar.swift.appConfiguration=Debug
    
    ##########################
    # Optional configuration #
    ##########################
    
    # Encoding of the source code
    sonar.sourceEncoding=UTF-8
    
    # SCM
    # sonar.scm.enabled=true
    # sonar.scm.url=scm:git:http://xxx
    
    # JUnit report generated by run-sonar.sh is stored in sonar-reports/TEST-report.xml
    # Change it only if you generate the file on your own
    # The XML files have to be prefixed by TEST- otherwise they are not processed
    sonar.junit.reportsPath=sonar-reports/TEST-report.xml
    
    # Cobertura report generated by run-sonar.sh is stored in sonar-reports/coverage-swift.xml
    # Change it only if you generate the file on your own
    sonar.swift.coverage.reportPattern=sonar-reports/coverage-swift*.xml
    #sonar.swift.coverage.reportPattern=sonar-reports/cobertura.xml
    
    # OCLint report generated by run-sonar.sh is stored in sonar-reports/oclint.xml
    # Change it only if you generate the file on your own
    sonar.swift.swiftlint.report=sonar-reports/*swiftlint.txt
    
    # Change it only if you generate the file on your own
    sonar.swift.tailor.report=sonar-reports/*tailor.txt
    
    # Paths to exclude from coverage report (surefire, 3rd party libraries etc.)
    # sonar.swift.excludedPathsFromCoverage=pattern1,pattern2
    # sonar.swift.excludedPathsFromCoverage=.*Tests.*,
    
    ##########################
    # Tailor configuration #
    ##########################
    # Tailor configuration
    # -l,--max-line-length=<0-999>                  maximum Line length (in characters)
    #    --list-files                               display Swift source files to be analyzed
    #    --max-class-length=<0-999>                 maximum Class length (in lines)
    #    --max-closure-length=<0-999>               maximum Closure length (in lines)
    #    --max-file-length=<0-999>                  maximum File length (in lines)
    #    --max-function-length=<0-999>              maximum Function length (in lines)
    #    --max-name-length=<0-999>                  maximum Identifier name length (in characters)
    #    --max-severity=<error|warning (default)>   maximum severity
    #    --max-struct-length=<0-999>                maximum Struct length (in lines)
    #    --min-name-length=<1-999>                  minimum Identifier name length (in characters)
    
    sonar.swift.tailor.config=--no-color --max-line-length=100 --max-file-length=500 --max-name-length=40 --max-name-length=40 --min-name-length=4

This is the verbose log from Sonar:

As you can see, I'm not sure why but **/*Test*/** and **/*.swift are excluded even though I cannot see them in the exclusions. Can you guys help me?

Thanks.

Command executed

./run-sonar-swift.sh

Complete output when running fastlane, including the stack trace and command used
  [21:18:50]: ▸ INFO: Scanner configuration file: /opt/homebrew/Cellar/sonar-scanner/5.0.1.3006/libexec/conf/sonar-scanner.properties
   [21:18:50]: ▸ INFO: Project root configuration file: /Users/bawenang/Documents/bimb-auth-ios/authenticator-ios-app/sonar-project.properties
   [21:18:50]: ▸ INFO: SonarScanner 5.0.1.3006
   [21:18:50]: ▸ INFO: Java 21.0.1 Homebrew (64-bit)
   [21:18:50]: ▸ INFO: Mac OS X 13.2.1 aarch64
   [21:18:50]: ▸ INFO: User cache: /Users/bawenang/.sonar/cache
   [21:18:50]: ▸ INFO: Analyzing on SonarQube server 10.2.1.78527
   [21:18:50]: ▸ INFO: Default locale: "en_ID", source code encoding: "UTF-8"
   [21:18:51]: ▸ INFO: Load global settings
   [21:18:51]: ▸ INFO: Load global settings (done) | time=562ms
   [21:18:51]: ▸ INFO: Server id: 243B8A4D-AYtqBBf16o1Yqf4ORLpb
   [21:18:51]: ▸ INFO: User cache: /Users/bawenang/.sonar/cache
   [21:18:51]: ▸ INFO: Load/download plugins
   [21:18:51]: ▸ INFO: Load plugins index
   [21:18:52]: ▸ INFO: Load plugins index (done) | time=223ms
   [21:18:52]: ▸ INFO: Load/download plugins (done) | time=301ms
   [21:18:52]: ▸ INFO: Process project properties
   [21:18:52]: ▸ INFO: Process project properties (done) | time=4ms
   [21:18:52]: ▸ INFO: Execute project builders
   [21:18:52]: ▸ INFO: Execute project builders (done) | time=1ms
   [21:18:52]: ▸ INFO: Project key: bimb-bia-ios
   [21:18:52]: ▸ INFO: Base dir: /Users/bawenang/Documents/bimb-auth-ios/authenticator-ios-app
   [21:18:52]: ▸ INFO: Working dir: /Users/bawenang/Documents/bimb-auth-ios/authenticator-ios-app/.scannerwork
   [21:18:52]: ▸ INFO: Load project settings for component key: 'bimb-bia-ios'
   [21:18:52]: ▸ INFO: Load project settings for component key: 'bimb-bia-ios' (done) | time=335ms
   [21:18:52]: ▸ INFO: Load quality profiles
   [21:18:53]: ▸ INFO: Load quality profiles (done) | time=251ms
   [21:18:53]: ▸ INFO: Load active rules
   [21:19:00]: ▸ INFO: Load active rules (done) | time=7322ms
   [21:19:00]: ▸ INFO: Load analysis cache
   [21:19:00]: ▸ INFO: Load analysis cache (404) | time=172ms
   [21:19:00]: ▸ WARN: The properties 'sonar.login' and 'sonar.password' are deprecated and will be removed in the future. Please pass a token with the 'sonar.token' property instead.
   [21:19:00]: ▸ INFO: Load project repositories
   [21:19:00]: ▸ INFO: Load project repositories (done) | time=173ms
   [21:19:00]: ▸ INFO: Indexing files...
   [21:19:00]: ▸ INFO: Project configuration:
   [21:19:00]: ▸ INFO:   Included sources: **/*.swift
   [21:19:00]: ▸ INFO:   Excluded sources: **/*.xml, Pods/**/*, Reports/**/*, Talsec/**/*, **/Swinject/**, **/*Test*/**, **/*.swift
   [21:19:00]: ▸ INFO:   Included tests: **/*Test*/**
   [21:19:01]: ▸ INFO: 10 files indexed
   [21:19:01]: ▸ INFO: 254 files ignored because of inclusion/exclusion patterns
   [21:19:01]: ▸ INFO: 0 files ignored because of scm ignore settings
   [21:19:01]: ▸ INFO: ------------- Run sensors on module BIMB Authenticator for iOS
   [21:19:01]: ▸ INFO: Load metrics repository
   [21:19:01]: ▸ INFO: Load metrics repository (done) | time=225ms
   [21:19:02]: ▸ INFO: Sensor JaCoCo XML Report Importer [jacoco]
   [21:19:02]: ▸ INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
   [21:19:02]: ▸ INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
   [21:19:02]: ▸ INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1ms
   [21:19:02]: ▸ INFO: Sensor CSS Rules [javascript]
   [21:19:02]: ▸ INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
   [21:19:02]: ▸ INFO: Sensor CSS Rules [javascript] (done) | time=0ms
   [21:19:02]: ▸ INFO: Sensor C# Project Type Information [csharp]
   [21:19:02]: ▸ INFO: Sensor C# Project Type Information [csharp] (done) | time=0ms
   [21:19:02]: ▸ INFO: Sensor C# Analysis Log [csharp]
   [21:19:02]: ▸ INFO: Sensor C# Analysis Log [csharp] (done) | time=8ms
   [21:19:02]: ▸ INFO: Sensor C# Properties [csharp]
   [21:19:02]: ▸ INFO: Sensor C# Properties [csharp] (done) | time=0ms
   [21:19:02]: ▸ INFO: Sensor TextAndSecretsSensor [text]
   [21:19:02]: ▸ INFO: Sensor TextAndSecretsSensor [text] (done) | time=188ms
   [21:19:02]: ▸ INFO: Sensor VB.NET Project Type Information [vbnet]
   [21:19:02]: ▸ INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=0ms
   [21:19:02]: ▸ INFO: Sensor VB.NET Analysis Log [vbnet]
   [21:19:02]: ▸ INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=13ms
   [21:19:02]: ▸ INFO: Sensor VB.NET Properties [vbnet]
   [21:19:02]: ▸ INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
   [21:19:02]: ▸ INFO: Sensor IaC Docker Sensor [iac]
   [21:19:02]: ▸ INFO: 0 source files to be analyzed
   [21:19:02]: ▸ INFO: 0/0 source files have been analyzed
   [21:19:02]: ▸ INFO: Sensor IaC Docker Sensor [iac] (done) | time=40ms
   [21:19:02]: ▸ INFO: ------------- Run sensors on project
   [21:19:02]: ▸ INFO: Sensor Analysis Warnings import [csharp]
   [21:19:02]: ▸ INFO: Sensor Analysis Warnings import [csharp] (done) | time=0ms
   [21:19:02]: ▸ INFO: Sensor Zero Coverage Sensor
   [21:19:02]: ▸ INFO: Sensor Zero Coverage Sensor (done) | time=0ms
   [21:19:02]: ▸ INFO: CPD Executor Calculating CPD for 0 files
   [21:19:02]: ▸ INFO: CPD Executor CPD calculation finished (done) | time=0ms
   [21:19:02]: ▸ INFO: Analysis report generated in 40ms, dir size=136.9 kB
   [21:19:02]: ▸ INFO: Analysis report compressed in 9ms, zip size=16.3 kB
   [21:19:02]: ▸ INFO: Analysis report uploaded in 255ms
   [21:19:02]: ▸ INFO: ANALYSIS SUCCESSFUL, you can find the results at: http://43.218.84.199:9000/dashboard?id=bimb-bia-ios
   [21:19:02]: ▸ INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
   [21:19:02]: ▸ INFO: More about the report processing at http://43.218.84.199:9000/api/ce/task?id=AYu0c2MfoXOXg-m1xLOA
   [21:19:02]: ▸ INFO: Analysis total time: 10.675 s
   [21:19:02]: ▸ INFO: ------------------------------------------------------------------------
   [21:19:02]: ▸ INFO: EXECUTION SUCCESS
   [21:19:02]: ▸ INFO: ------------------------------------------------------------------------
   [21:19:02]: ▸ INFO: Total time: 12.161s
   [21:19:02]: ▸ INFO: Final Memory: 21M/80M
   [21:19:02]: ▸ INFO: ------------------------------------------------------------------------

From the log, I saw that there is somehting peculiar here:

  [21:19:00]: ▸ INFO: Project configuration:
   [21:19:00]: ▸ INFO:   Included sources: **/*.swift
   [21:19:00]: ▸ INFO:   Excluded sources: **/*.xml, Pods/**/*, Reports/**/*, Talsec/**/*, **/Swinject/**, **/*Test*/**, **/*.swift
   [21:19:00]: ▸ INFO:   Included tests: **/*Test*/**
   [21:19:01]: ▸ INFO: 10 files indexed
   [21:19:01]: ▸ INFO: 254 files ignored because of inclusion/exclusion patterns
   [21:19:01]: ▸ INFO: 0 files ignored because of scm ignore settings
The command can actually send to SonarQube. But it shows empty.

Environment

Rig: M1 Macbook Pro
MacOS: Ventura 13.2.1
Xcode: Xcode 14.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant