Java static code analysis tool Infer, java static code infer

Source: Internet
Author: User
Tags ocaml

Java static code analysis tool Infer, java static code infer
Java static code analysis tool Infer

Author: chszs, reprinted with note. Blog homepage: http://blog.csdn.net/chszs

I. Introduction to Infer

Infer is Facebook's latest open-source static program analysis tool. It is used to analyze the code before publishing a mobile application and identify potential problems. Currently, Facebook uses this tool to analyze Facebook apps, including Android, iOS, Facebook Messenger, and Instagram.

Facebook said the tool helped it check hundreds of bugs in applications every month, such as null pointer access, resource and memory leaks. Infer supports C and Objective-C code of Android Java and iOS.

Infer home page on GitHub: https://github.com/facebook/infer

Ii. Infer use 1. Top-level commands 2. Auxiliary commands

InferJava: Binary program containing the Java frontend
InferClang: Binary program containing the Clang frontend
InferAnalyze: contains the binary program of the Infer backend (Execution analysis ).
InferPrint: the binary program that outputs the analysis result (for example, the list of detected bugs ).
InferJ: Command for running Java File Analysis
BuckAnalyze: An Analysis command for running a Java project compiled with Buck
Inferlib. py: other scripts in the Python Library
Utils. py: other scripts in the Python Library
Jwlib. py: other scripts in the Python Library

Iii. Infer Installation

The pre-compiled Infer tool is provided officially, but only supports Linux and MacOS platforms. If you are willing to use Infer, download and use it directly.
Otherwise, you need to download the source code and compile it yourself.

1. Download Infer

You can download the Infer command from the Git Repository:

git clone https://github.com/facebook/infer.git

Note: If you want to analyze C and Objective-C, Infer also needs clang and facebook-clang-plugin.
See https://github.com/facebook/facebook-clang-plugins for the facebook-clang-plugin plug-in
If you only want to analyze the Java/Android code, the above dependent libraries are not required.

2. Install Infer in Linux

Prerequisites: Python 2.7 or a later version is required.

Installation instructions:
(The following installation process is verified in Debian 7, Ubuntu 14.04, Ubuntu 12.04.4 LTS, and other systems)

1. Install OCaml Dependencies
# Sudo apt-get update # sudo apt-get upgrade # sudo apt-get install git openjdk-7-jdk m4 zlib1g-dev python-software-properties build-essential libgmp-dev libmp fr-dev libmp C-dev unzip # wget https://github.com/ocaml/opam/releases/download/1.2.2/opam-1.2.2-x86_64-Linux-O opam # chmod + x opam #. /opam init -- comp = 4.01.0 # Then press "y" # eval' In the last question '. /opam config env '#. /opam install sawja.1.5 atdgen.1.5.0 javalib.2.3 extlib.1.5.4 # Then press "y" in the case of the problem"
2. If you do not need to support Static Analysis of C and Objective-C code, continue with the following command:
# cd infer# make -C  infer java# export PATH=`pwd`/infer/bin:$PATH

Note: Java 8 is not supported.

3. If you need to support both Java code and C and Objective-C code, do not execute Step 1 above. Instead, execute Step 2 here.

Assume that GCC of version 4.7.2 and later is installed. (If the OS is Ubuntu 12.04.4 LTS, you have installed gcc 4.8 and g ++ 4.8.
Run the following command:

# sudo apt-get install python-software-properties# sudo add-apt-repository ppa:ubuntu-toolchain-r/test# sudo apt-get update# sudo apt-get install gcc-4.8 g++-4.8# sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
4. Continue
# cd infer# ./update-fcp.sh# ../facebook-clang-plugin/clang/setup.sh  # go have a coffee :)# ./compile-fcp.sh# make -C infer# export PATH=`pwd`/infer/bin:$PATH
4. Install Infer in another way. 1. Download

You can also download the binary distribution package directly.
Mac OS X version: https://github.com/facebook/infer/releases/download/v0.1.0/infer-osx-v0.1.0.tar.xz
Linux release package: https://github.com/facebook/infer/releases/download/v0.1.0/infer-linux64-v0.1.0.tar.xz

2. Installation

Decompress the binary distribution package

# tar xf infer-linux64-v0.1.0.tar.xz

The infer-linux64-v0.1.0 directory is created, and the main executable program of Infer is located in the infer-linux64-v0.1.0/infer/bin directory.

3. Add Infer to the path environment variable.
# cd infer-linux64-v0.1.0 &&# echo "export PATH=\"\$PATH:`pwd`/infer/infer/bin\"" \ >> ~/.bash_profile &&# source ~/.bash_profile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.