Android 代码检查自动化

2020-04-14  本文已影响0人  游侠_6fb7

检查工具:Lint,FindBugs
任务配置:jenKins
任务配置gradle

gradle配置

配置gradle task
在build.gradle中配置:
apply from: 'xxxx/quality.gradle'
新建quality.gradle,避免gradle臃肿

apply plugin: 'checkstyle'
apply plugin: 'findbugs'
//apply plugin: 'pmd'

/*
 * Copyright 2015 Vincent Brison.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Add checkstyle, findbugs, pmd and lint to the check task.
//check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'

task checkstyle(type: Checkstyle) {
    def sourceroot = 'src';
    configFile file("${project.rootDir}/xxxx_module/checkconfig/quality/checkstyle/checkstyle.xml")
    configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/${project.name}/checkconfig/quality/checkstyle/suppressions.xml").absolutePath
    if (project.hasProperty('fileList')) {
        String string = String.valueOf(fileList)
        if (string == "") {
            return;
        }
        string = string.replace("'", "");
        String[] ss = string.split(",");
        int length = ss.length;
        for (int i = 0; i < length; i++) {
            String s = ss[i];
            int index = s.indexOf(sourceroot + "/");
            if (index < 0) {
                continue;
            }
            ss[i] = s.substring(index);
            print ss[i]
        }
        source ss
    } else {
        source sourceroot
        include '**/*.java'
    }
    classpath = files()
}

task findbugs(type: FindBugs, dependsOn: 'assembleDebug') {
    ignoreFailures = true
    effort = "max"
    reportLevel = "high"//"medium"
    excludeFilter = new File("${project.rootDir}/xxx_module/checkconfig/quality/findbugs/findbugs-filter.xml")
    classes = files("$project.buildDir/intermediates/javac")
//gradle tools3.4.1以上class文件移到javac文件夹中
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = false
        html.enabled = true
        xml {
            destination file("$project.buildDir/reports/findbugs/findbugs.xml")
        }
        html {
            destination file("$project.buildDir/reports/findbugs/findbugs.html")
        }
    }

    classpath = files()
}

android {
    lintOptions {
        abortOnError true
        xmlReport true
        htmlReport true
        lintConfig file("${project.rootDir}/${project.name}/checkconfig/quality/lint/lint.xml")
        htmlOutput file("$project.buildDir/reports/lint/lint-results.html")
        xmlOutput file("$project.buildDir/reports/lint/lint-results.xml")
    }
}

//剩下的一步步来,都会加进来
//
//
//task pmd(type: Pmd) {
//    ignoreFailures = false
//    ruleSetFiles = files("${project.rootDir}/config/quality/pmd/pmd-ruleset.xml")
//    ruleSets = []
//
//    source 'src'
//    include '**/*.java'
//    exclude '**/gen/**'
//
//    reports {
//        xml.enabled = false
//        html.enabled = true
//        xml {
//            destination "$project.buildDir/reports/pmd/pmd.xml"
//        }
//        html {
//            destination "$project.buildDir/reports/pmd/pmd.html"
//        }
//    }
//}
//
//}

jenkins配置

配置周一至周五执行代码检查


20200414142213.jpg

配置执行脚本
gradle lint
gradle findBugs

上一篇 下一篇

猜你喜欢

热点阅读