With the increase of new business and the business of the old optimization, the project’s code has been is also increasing, when the amount of code to reach hundreds of thousands of lines, manual review as dues must be arduous, so a SonarQube code quality management platform, through configuration censorship rules, let the program help you to detect potential bugs in the code, let time-consuming operation through the machines, Save labor cost. Good nonsense not to say, to introduce the use of Sonar for ios projects.

Introduction of Sonar

Sonar is an open-source platform for code quality management, to manage the quality of the source code Through the plug-in form, can support including Java, C #, C/C + +, PL/SQL, Cobol, javascript, Groovy, oc of 20 kinds of programming language code quality management and inspection, And being able to use sonarQube with Jenkins what does it bring? Detect Bugs and Bugs in your code




Snapshot 2016-09-14 17.56.21.png

Bad smell detects potential errors in code




Snapshot 2016-09-14 17.56.40.png

Clearly the program contains a lot of copy-paste code is poor quality sonar can show the source code in the serious repetition




Snapshot 2016-09-14 17.56.56.png

4. Structure detects the number of lines of code, the composition of the code, and the percentage occupied




Snapshot 2016-09-14 17.57.11.png

5. Comment size Detects the amount of code comments




Screenshot 2016-09-14 17.27.30.png

6. Dependency project structure




Snapshot 2016-09-14 17.28.20.png

SonarQube installation

Prerequisites The JAVA environment has been installed. 2. The MySQL database has been installed

1. Download the sonar soanr software download address: www.sonarqube.org/downloads/ 2. Sonar: : Configure sonar download, unzip and drag the folder to /usr/local 3. Modify sonar. Properties to find

  /usr/local/sonar/conf/sonar.propertiesCopy the code

Modify the parameters

sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306 /sonar? useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformanceCopy the code

4. Start the sonar

sudo /usr/local/sonar/bin/macosx-universal-64/sonar.sh startCopy the code

5. Visit http://localhost:9000 when you visit the figure, congratulations on your successful soANr server configuration




Snapshot 2016-09-14 17.29.21.png

6.IOS engineering configuration Copy the two files to the. Xcodeproj directory of the project: run-sonar-sonar-project. properties pan.baidu.com/s/1pLpiNaz Configure the sonar-project.properties file




Snip20160914_1.png

7. Run the run-sonary. sh script to check that the code CD is executed in the project directory

   ./run-sonar.shCopy the code



Snip20160914_2.png

After the test is done




Snip20160914_4.png

Go to http://localhost:9000




Snapshot 2016-09-14 16.57.12.png