2015-04-28 20 views
8

Tôi đang theo dõi this bài viết để tích hợp SonarQube với Xcode và phân tích mã Mục tiêu-C. Mặc dù thiết lập có chức năng và không nhận được lỗi/cảnh báo sau khi chạy tập lệnh shell, không có vi phạm nào được hiển thị trong Trang tổng quan. Tất cả những gì tôi thấy là các chỉ số cơ bản như không. của các dòng mã, không. của các tệp, v.v. Có ai đã thử điều này và hướng dẫn thêm cho tôi không. enter image description hereSử dụng Sonarqube với Xcode

Trả lời

0

Bạn nên dùng thử phiên bản cũ hơn của SonarQube (< 4.0 thường hoạt động).

9

Ngoài bài viết bạn đã chỉ định ở trên, tôi có một vài bổ sung cho điều đó. Bạn có thể làm theo các bước dưới đây,

Điều kiện tiên quyết:

  • Sonar
  • Sonar-Á hậu
  • SonarQube Objective-C plugin (được cấp phép)
  • XCTool
  • OCLint (vi phạm) và gcovr (mã vùng)
  • MySql và JDK

Lắp đặt bước:

  • Tải về và cài đặt MySql dmg. Và sau đó khởi động máy chủ MySQL từ System Preferences hoặc thông qua dòng lệnh hoặc nếu khởi động lại nó phải là dòng lệnh.
  • Để bắt đầu - sudo /usr/local/mysql/support-files/mysql.server start
  • Để khởi động lại - sudo /usr/local/mysql/support-files/mysql.server restart
  • Để dừng - sudo /usr/local/mysql/support-files/mysql.server stop

  • Tải về và cài đặt phiên bản JDK mới nhất.

  • Đi tới thiết bị đầu cuối và nhập các lệnh sau để cài đặt các điều kiện tiên quyết . (Homebrew là gói hệ thống quản lý cho Hệ điều hành Mac.để cài đặt homebrew, nhập lệnh -

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)") 
    
  • Sonar - brew install sonar

  • Sonar-Á hậu - brew install sonar-runner
  • XCTool - brew install xctool
  • OCLint - brew install oclint hoặc

    brew install https://gist.githubusercontent.com/TonyAnhTran/e1522b93853c5a456b74/raw/157549c7a77261e906fb88bc5606afd8bd727a73/oclint.rb for version 0.8.1(updated)) 
    
  • gcovr - brew install gcovr

Cấu hình:

- Set con đường môi trường của Sonar:

export SONAR_HOME=/usr/local/Cellar/sonar-runner/2.4/libexec 
export SONAR=$SONAR_HOME/bin 
export PATH=$SONAR:$PATH 

cuối cùng là lệnh echo $SONAR_HOME nên quay lại con đường - /usr/local/Cellar/sonar-runner/2.4/libexec

- Set lên MySql DB:

export PATH=${PATH}:/usr/local/mysql/bin 
mysql -u root; 
CREATE DATABASE sonar_firstdb; 
CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'sonar’; 
GRANT ALL PRIVILEGES ON sonar_firstdb.* TO 'sonar'@'localhost’; 
FLUSH PRIVILEGES; 
exit 

- thiết lập cấu hình Set Sonar:

vi /usr/local/Cellar/sonar/5.1.2/libexec/conf/sonar.properties 

Bạn có thể nhận xét ra hầu hết các tùy chọn ngoại trừ thông tin và mysql và chắc chắn rằng bạn nhập tên cơ sở dữ liệu chính xác.

ví dụ:

sonar.jdbc.url=jdbc:mysql://localhost:3306/**sonar_firstdb**?useUnicode=true&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true 
vi /usr/local/Cellar/sonar-runner/2.4/libexec/conf/sonar-runner.properties 

Bạn có thể nhận xét ra hầu hết các tùy chọn ngoại trừ thông tin và mysql và chắc chắn rằng bạn nhập tên cơ sở dữ liệu chính xác.

ví dụ:

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar_firstdb?useUnicode=true&amp;characterEncoding=utf8 
  • Bắt đầu sonar sử dụng lệnh -

    sonar start 
    

Lệnh sẽ ra mắt sonar để điều hướng đến http://localhost:9000 trong trình duyệt của bạn lựa chọn . Đăng nhập (admin/admin) và có một cái nhìn xung quanh.

  • Bây giờ bạn phải cài đặt plugin Objective-C hoặc Swift.

Di chuyển đến Cài đặt -> Hệ thống -> Trung tâm cập nhật -> Plugins có sẵn (cài đặt plugin bắt buộc).

Bạn phải khởi động lại sonar để hoàn tất cài đặt sau khi thêm tiền tố và thêm khóa cấp phép sau khi plugin được cài đặt.

  • thông qua thiết bị đầu cuối đi vào thư mục gốc của một dự án bạn muốn sonar để kiểm tra, và tạo một dự án nộp các thuộc tính cụ thể với các lệnh sau:

    vi sonar-project.properties 
    

Thêm dự án cụ thể sau các thuộc tính và chỉnh sửa các phần được in đậm theo dự án của bạn.

// Required configuration 

sonar.projectKey=**com.payoda.wordsudoku** 
sonar.projectName=**DragDrop** 
sonar.projectVersion=**1.0** 
sonar.language=**objc** 

// Project description 
sonar.projectDescription=**Sample description** 

// Path to source directories 
sonar.sources=**~/path to your project** 
// Path to test directories (comment if no test) 
//sonar.tests=testSrcDir 


// Xcode project configuration (.xcodeproj or .xcworkspace) 
// -> If you have a project: configure only sonar.objectivec.project 
// -> If you have a workspace: configure sonar.objectivec.workspace and sonar.objectivec.project 
// and use the later to specify which project(s) to include in the analysis (comma separated list) 
sonar.objectivec.project=**DragDrop.xcodeproj** 
// sonar.objectivec.workspace=myApplication.xcworkspace 

// Scheme to build your application 
sonar.objectivec.appScheme=**DragDrop** 
// Scheme to build and run your tests (comment following line of you don't have any tests) 
//sonar.objectivec.testScheme=myApplicationTests 

///////////////////////// 
// Optional configuration 


// Encoding of the source code 
sonar.sourceEncoding=**UTF-8** 

// 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 
// 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/ 

// Cobertura report generated by run-sonar.sh is stored in sonar-reports/coverage.xml 

// Change it only if you generate the file on your own 
// sonar.objectivec.coverage.reportPattern=sonar-reports/coverage*.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.objectivec.oclint.report=sonar-reports/oclint.xml 

// Paths to exclude from coverage report (tests, 3rd party libraries etc.) 
// sonar.objectivec.excludedPathsFromCoverage=pattern1,pattern2 
sonar.objectivec.excludedPathsFromCoverage=.*Tests.* 

// Project SCM settings 
// sonar.scm.enabled=true 
// sonar.scm.url=scm:git:https://... 
  • Lưu tập tin và bạn có thể tái sử dụng như nhau đối với các dự án khác.
  • Trong thư mục gốc của dự án, hãy chạy lệnh - sonar-runner
+0

Điều này có giải quyết được sự cố không? – electricSunny

+0

Vâng, điều này đang hoạt động tốt ..Tôi có cố gắng làm điều này không ?? –

+0

Có - Tôi đã làm theo chính xác điều này, tôi vẫn không thấy bất kỳ số liệu nào cho sự sao chép phức tạp. – electricSunny