Jenkins builds the use of findbugs for continuous integration of Android projects

Source: Internet
Author: User

Off Topic

This original and the previous series to be out, but because the intermediary company to release a version, to delay, today's work is done, and idle down. So we're going to continue Jenkins. Build the findbugs of the Continuous Integration series for Android projects.

FindBugs Introduction

About the introduction of FindBugs, you can Baidu under, paste the introduction of Baidu Encyclopedia. FindBugs is a static analysis tool that examines a class or JAR file to compare bytecode with a set of defect patterns to identify possible problems. This set of defect patterns is configurable and can be configured to filter out some issues that we do not want or need to detect.

Configuration of the findbugs in Gradle

The part of the theory is not much elaborated, we directly to see how to use FindBugs in the project.
First, introduce the FindBugs plugin in Build.gradle

‘findbugs‘

Then, add a task

task findbugs(type: FindBugs,dependsOn:"connectedAndroidTest"{//    true    "default"    "medium"    //这里填写项目classes目录    files("${project.rootDir}/andbase-core/build/intermediates/classes")    source = fileTree(‘src/main/java‘)    files()    reports {        //只能开启一个        false        true    }}

Note: All tasks are dependent on connectedandroidtest, they need to connect the simulator or the real machine, otherwise they will error

Here's what I build.gradle:

Apply plugin:' Com.android.library '//Code Coverage plug-inApply plugin:' Jacoco '//findbugsApply plugin:' FindBugs 'Android {Compilesdkversion ABuildtoolsversion' 22.0.1 'Defaultconfig {minsdkversion8Targetsdkversion AVersioncode1Versionname"1.0"} buildtypes {release {minifyenabledtrueProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '} debug{testcoverageenabledtrue}} lintoptions {Abortonerrorfalse} packagingoptions {Exclude' Meta-inf/notice 'Exclude' Meta-inf/license '} jacoco{version "0.7.4.201502262128"}}task FindBugs (Type:findbugs,dependson:"Connectedandroidtest"){//Ignorefailures =trueeffort ="Default"Reportlevel ="Medium"   //Fill in the Project classes directory hereClasses =Files("${project.rootdir}/andbase-core/build/intermediates/classes") Source = Filetree (' Src/main/java ') Classpath =Files() Reports {//can only open axml.enabled =falsehtml.enabled =true}}task Jacocotestreport (Type:jacocoreport){//,dependson: "Connectedandroidtest"Group ="Reporting"Description ="Generate Jacoco coverage reports after running tests."reports{xml.enabled =falsehtml.enabled =truecsv.enabled =false} classdirectories = Filetree (dir:"$buildDir/intermediates/classes/debug", excludes: [' **/*test.class ',' **/r.class ',' **/r$*.class ',' **/buildconfig.* ',' **/manifest*.* ']) def coveragesourcedirs = [' Src/main/java '] Additionalsourcedirs =Files(coveragesourcedirs) Sourcedirectories =Files(coveragesourcedirs) Additionalclassdirs =Files(coveragesourcedirs) Executiondata =Files("$buildDir/outputs/code-coverage/connected/coverage.ec")}dependencies {Compile Filetree (dir:' Libs ',include: [' *.jar ']) Compile' com.android.support:appcompat-v7:22.2.1 '}

Then enter the command in the terminal

gradlew findbugs

After successful execution, the findbugs.html file will be generated at the root of the project Build\reports\findbugs, Open is the bug results

Here you can see some of the overall warning situations.

But when you look down at specific questions, you'll find some r$anim or something.

While in Android, R files are automatically generated and we are not required to check the file for bugs. This is where filtering configuration comes in handy.

Findgbugs Filter Configuration

Create a new Findbug_filter.xml file under the project root directory, as follows

<?xml version= "1.0" encoding= "UTF-8"?><findbugsfilter>    <Match>        <!--Ignore All issues in resource generation --        <Class name="~.*\." r\$.* "/>    </Match>    <Match>        <Class name="~.*\." manifest\$.* "/>    </Match>    <Match>        <Class name="~.*\.*test" />        <!--test classes is suffixed by ' test ' --        <not >            <Bug Code="Iju" /> <!--' Iju ' is the code for bugs related to JUnit test code --        </not >    </Match></findbugsfilter>

The match to the above is to filter out, not to capture, so we filter out R files, manifest files and test case classes.
Accordingly, we need to modify the Gradle configuration so that the filter takes effect, and the task FindBugs is configured as follows:

Task FindBugs (Type:findbugs,dependson:"Connectedandroidtest"){//Ignorefailures =trueeffort ="Default"Reportlevel ="Medium"   //FilterExcludeFilter =NewFile ("${project.rootdir}/findbug_filter.xml")//Fill in the Project classes directory hereClasses =Files("${project.rootdir}/andbase-core/build/intermediates/classes") Source = Filetree (' Src/main/java ') Classpath =Files() Reports {//can only open axml.enabled =falsehtml.enabled =true}}

Then Gradlew findbugs in Teminal, re-view the report, the previous warnings about ' R $ ' are gone, the filter is in effect.
Furthermore, we may have such a requirement that each person's viewing report may have a different focus, so I think the report can be more personalized. In the same way, we can implement it according to the filter.

<?xml version= "1.0" encoding= "UTF-8"?><findbugsfilter>    <Match>        <!--Ignore All issues in resource generation --        <Class name="~.*\." r\$.* "/>    </Match>    <Match>        <Class name="~.*\." manifest\$.* "/>    </Match>    <Match>        <Class name="~.*\.*test" />        <!--test classes is suffixed by ' test ' --        <not >            <Bug Code="Iju" /> <!--' Iju ' is the code for bugs related to JUnit test code --        </not >    </Match>    <!--filter out some bug-->    <Match>        <!--1, performance issues --        <!--<bug category= "Performance"/>-->        <!--2, general correctness problems --        <!--<bug category= "correctness"/>-->        <!--3, multithreading correctness problems --        <!--<bug category= "mt_correctness"/>-->        <!--4, malicious code, it could be an attack point--        <!--<bug category= "Malicious_code"/>-->        <Or>            <!--Field names should start with a lower case letter-->            <bugcode name="Nm"/>            <!--method ignores exceptional return value or return value of method without side effect is ignored-->            <bugcode name="RV"/>            <!--International --            <bugcode name="Dm"/>        </Or>    </Match></findbugsfilter>

which

<Bug category="MT_CORRECTNESS" />

is to set the filter in a large category of bugs, what is the category value? There are performance (performance problems), correctness (general correctness problem), mt_correctness (multithreading correctness problem), Malicious_code (malicious code), these four categories.

<BugCode name="Dm"/>

And Bugcode is a subdivision under category category, and what are their name values, which can be viewed from the report:

Is the performance category,code column is the optional value for Bugcode name.
Through the configuration of the filter, we can personalize the report of the custom.

Jenkins Configuration FindBugs

Add post-Build action steps

Look at the description, the path configuration is to get the XML file, but, before we get to the HTML file, what to do? So, here we have to modify the Gradle configuration.

Task FindBugs (Type:findbugs,dependson:"Connectedandroidtest"){//Ignorefailures =trueeffort ="Default"Reportlevel ="Medium"   //FilterExcludeFilter =NewFile ("${project.rootdir}/findbug_filter.xml")//Fill in the Project classes directory hereClasses =Files("${project.rootdir}/andbase-core/build/intermediates/classes") Source = Filetree (' Src/main/java ') Classpath =Files() Reports {//can only open axml.enabled =truehtml.enabled =false}}

We set xml.enabled to true,html.enabled set to false.
The build command is then added findbugs

The mailbox also adds the FindBugs report accordingly

Save the configuration and build it now. If it works, you can see the following report

You can also view the report by opening the link from the mailbox content

Summarize

At this point, the series is almost finished. This set of continuous integration is used by our company, so the practicality is very high, with a lot of advantages, whether it is the development, testing has a great convenience, greatly improve the quality and controllability of the project. In large, it also provides a viable basis for agile development. The first time to write such a series, what is wrong or suggestions, I hope to see your proposed.

Look at the other articles:
1. Jenkins builds an introduction to the continuous integration of Android projects
2. Jenkins builds the installation of Jenkins for the continuous integration of the Android project
3. Jenkins builds the system configuration for the continuous integration of Android projects
4. Jenkins builds a project for continuous integration of Android projects
5, Jenkins build Android project continuous integration of unit testing and code coverage
6. The use of findbugs for the continuous integration of Jenkins to build Android projects

Jenkins builds the use of findbugs for continuous integration of Android projects

Related Article

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.