Skip to main content

(CI) Jenkins PMD report for Objective-C with OCLint

OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code and looking for potential problems like:
  • Possible bugs - empty if/else/try/catch/finally statements
  • Unused code - unused local variables and parameters
  • Complicated code - high cyclomatic complexity, NPath complexity and high NCSS
  • Redundant code - redundant if statement and useless parentheses
  • Code smells - long method and long parameter list
  • Bad practices - inverted logic and parameter reassignment
  • ...

Installation:

  • Step 1: Download "oclint-0.x.x-x86_64-darwin-15.0.0.tar" from the downloads page. Unzip this file and see as below:

  • Step 2: Copying OCLint to System PATH. Open Terminal prompt, and input some commands lines as follows:
  • $ cd /Downloads/oclint-0.10.x
    $ cp bin/oclint* /usr/local/bin/
    $ cp -rp lib/* /usr/local/lib/
    Other option: Directly adding to PATH at here.
  • Checking installation: Open a new terminal prompt, and execute oclint directly from there and expect message similar to below:
  • $ oclint
    oclint: Not enough positional command line arguments specified!
    Must specify at least 1 positional arguments: See: oclint -help

Using OCLint with xcodebuild:

Suppose we have a project with the name as iOSDesignPatterns:

- Create a build script, as follows:
 #!/bin/sh
# Generate PMD reporter
# Step 1: Create xcodebuild.log
xcodebuild clean -project iOSDesignPatterns.xcodeproj/ -scheme 'iOSDesignPatterns' -configuration Debug
xcodebuild build -target iOSDesignPatterns -configuration Debug -scheme iOSDesignPatterns CLANG_ENABLE_MODULE_DEBUGGING=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | tee xcodebuild.log
# Step 2: Create compile_commands.json
oclint-xcodebuild

# Step 3: Create pmd_oclint.xml
oclint-json-compilation-database -- -report-type pmd -o pmd_oclint.xml

...and run it with:
$ sh build_pmd.sh

After run it successfully, as below:


Using OCLint with Jenkins:

Create a project on Jenkins and clone that project:
Configuring OCLint and PMD plugin:
- Open Configure page of a project on Jenkins CI.
- For execute a script:: Add a new build step and choose "Execute shell". Set up the command as above ("sh build_pmd.sh"). 
- For export PMD report: Add a new post-build action and choose "Publish PMD analysis result". Enter the output artifact name which is defined in the script ("pmd_oclint.xml").
- The result as below:
Build Jenkins CI: You will get an error as below:
If you want to build successful on Jenkins CI, you will need to add some arguments of oclint-json-compilation-database, as follows:
 # Step 3: Create pmd_oclint.xml
oclint-json-compilation-database -- -max-priority-1 '1' -max-priority-2 '50' -max-priority-3 '100' -report-type pmd -o pmd_oclint.xml

Save that script and build Jenkins CI again. The successful result as below:

Tools: XCode 7.x, OCLint 0.10.1
Ref documents:- OCLint.org

Comments

Popular posts from this blog

So sánh những framework hỗ trợ viết ứng dụng trên SmartPhone

Khi lập trình trên SmartPhone bạn không nhất thiết phải học những ngôn ngữ đặc thù trên từng loại hệ điều hành thì mới có thể lập trình được. Ví dụ như muốn lập trình trên iOS thì phải học ngôn ngữ Objective-C hay Swift, muốn lập trình được trên Android thì học ngôn ngữ Java, muốn lập trình trên WinPhone thì học ngôn ngữ C#. Hiện nay có rất nhiều những framework giúp đỡ cho các bạn rất nhiều khi các bạn muốn viết trên nhiều nền tảng smartphone bằng ngôn ngữ mà bạn yêu thích. Theo mình thấy thì hiện nay có 3 loại như: Native App, Hybrid Mobile App, Native Cross-Platform App. 1. Native App: là những ứng dụng sử dụng những framework và ngôn ngữ lập trình của hệ thống cung cấp sẵn. Ví dụ như bạn muốn lập trình iOS thì phải cài XCode, học ngôn ngữ Objective-C hay Swift, lập trình Android thì cài Android Studio và học ngôn ngữ Java. - Ưu điểm: Hiệu năng thực thi ứng dụng trên nền tảng nhanh và hiệu quả. Không bị phụ thuộc vào bên thứ 3. Khi phát hành ứng dụng trên những Mobile Store cũng dễ...

Hướng dẫn dùng Serverless sử dụng Lambda AWS

1. Lambda function là gì? AWS Lambda cho phép bạn chạy mã mà không cần cung cấp hay quản lý máy chủ. Bạn chỉ phải trả tiền cho thời gian xử lý thông tin đã sử dụng. Với Lambda, bạn có thể chạy mã cho gần như toàn bộ các loại ứng dụng hay dịch vụ backend – tất cả đều không cần quản trị. Chỉ cần tải đoạn mã của bạn lên và Lambda sẽ lo hết những gì cần làm để chạy và mở rộng mã của bạn với mức độ có sẵn cao. Bạn có thể thiết lập mã của bạn tự động kích hoạt từ các dịch vụ AWS khác, hoặc gọi trực tiếp từ bất cứ ứng dụng web hay di động nào. Chi phí chạy trên lambda function rẻ so với chi phí bạn mua 1 con server, duy trì và quản trị nó ( ví dụ như bạn phải xử lý bất đồng bộ những request, khi lượng user bạn tăng đột biến bạn phải có cơ chế auto scale, chứ không thì server bị sẽ bị treo, khi server bị treo bạn phải tự động khởi động lại sẽ mất thời gian,... ).

Hướng dẫn deploy 1 static web trên GitHub domain

Hiện tại GitHub đã hỗ trợ 1 tool gh-pages dùng để bạn publish 1 static web lên trên GitHub. Cái này rất tiện nếu bạn muốn làm những bản demo cho khách hàng xem và không muốn mua 1 con server riêng để deploy và mất phí duy trì. Bạn có thể xài account free của GitHub để làm việc này luôn. Để demo tool này cách xài như thế nào mình xin dùng 1 free template ' paper-dashboard-react ' bạn có thể dùng bất kỳ free template nào có sẵn trên mạng về xài và sửa chúng lại. Bạn mở terminal lên và di chuyển đến folder chứa file 'package.json', cài tool gh-pages theo chế độ development như sau: npm install gh-pages --save-dev Sau đó bạn mở file 'package.json' lên thêm giá trị 'homepage' và 2 đoạn script 'predeploy' và 'deploy' bằng gh-pages như hình sau: Bạn mở file public/index.html và sửa lại chỗ 'manifest': Sau khi sửa xong hết những chỗ này và giờ bạn muốn deploy thì chỉ cần chạy đoạn script sau: npm run deploy Khi bạn chạy lần đầu tiên ...