美文网首页自动化测试/CI测试
Mac下Sonar Swift的配置使用

Mac下Sonar Swift的配置使用

作者: colacola | 来源:发表于2018-02-05 08:14 被阅读134次

    SonarQube安装

    准备工作

    1、已安装JAVA环境
    (Download Java for Mac OS X https://www.java.com/en/download/mac_download.jsp
    http://www.oracle.com/technetwork/java/javase/downloads/index.html

    2、下载SonarQube与SonarQube Runner

    下载地址:

    SonarQube

    SonarQube Scanner

    3、运行sonar

    • 解压sonarqube-6.7.1.zip
    • 通过终端命令行cd到sonarqube解压目录下的/bin/macosx-universal-64文件夹
    • 执行./sonar.sh startar-scanner
    • 浏览器访问http://localhost:9000
    • 出现以下页面,表示安装成功


      about

    SonarQube使用

    sonarqube默认支持的语言插件,在sonarqube-6.7.1/extensions/plugins 这个文件夹里可以看到。

    plugins
    其中的backelite-sonar-swift-plugin-0.3.5.jar是从这里下载的。

    关于Open source Swift plugin for SonarQube的开源文件

    具体操作步骤:
    • 拷贝backelite-sonar-swift-plugin-0.3.5.jar文件到sonarqube-6.7.1/extensions/plugins里
    • 下载run-sonar-swift.sh 文夹拷贝到swift项目的根目录下(和你的projext.xcodeproj 文件同级)
    • 下载sonar-project.properties文件拷贝到swift项目的根目录下(和你的projext.xcodeproj 文件同级)
    • 编辑sonar-project.properties文件,根据swift项目修改其中的参数
      sonar-project.properties文件
    ##########################
    # Required configuration #
    ##########################
    
    # Project key will also be used for binary file 
    sonar.projectKey=prjKey
    sonar.projectName=prjName
    sonar.projectVersion=1.0
    # Comment if you have a project with mixed ObjC / Swift
    sonar.language=swift
    
    # Project description
    sonar.projectDescription=prjDescription
    
    # Path to source directories
    # 修改为swift的路径
    sonar.sources=SourceDir
    # Path to test directories (comment if no test)
    sonar.tests=TestDir
    
    # Destination Simulator to run tests
    # 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 6,OS=9.2
    
    # 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
    #指定 xcodeproj 或 xcodeproj + xcworkspace
    #sonar.swift.project=MyPrj.xcodeproj
    #sonar.swift.workspace=MyWrkSpc.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=myApp
    
    # Scheme to build your application
    sonar.swift.appScheme=MyScheme
    
    # Configuration to use for your scheme. if you do not specify that the default will be Debug
    sonar.swift.appConfiguration=MyConfiguration
    
    # Encoding of the source code
    sonar.sourceEncoding=UTF-8
    
    sonar.swift.excludedPathsFromCoverage=.*Tests.*
    
    sonar.swift.tailor.config=--max-line-length=100 --max-file-length=500 --max-name-length=40 --max-name-length=40 --min-name-length=4
    
    • 终端命令行打开swift项目,执行sonar-scanner
    • 分析结束后,终端会显示比如INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/Kickstarter,打开提示的地址,可以看到分析结果。
    report

    参考文章

    Backelite/sonar-swift

    Analyzing with SonarQube Scanner

    Sonar Swift实践

    相关文章

      网友评论

        本文标题:Mac下Sonar Swift的配置使用

        本文链接:https://www.haomeiwen.com/subject/rscbzxtx.html