├── README.md └── XiayuQualityDemo ├── .gitignore ├── .idea ├── compiler.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── qaplug_profiles.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── xiayu │ │ └── xiayuqualitydemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── xiayu │ │ │ └── xiayuqualitydemo │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── xiayu │ └── xiayuqualitydemo │ └── ExampleUnitTest.java ├── build.gradle ├── config ├── quality.gradle └── quality │ ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml │ ├── findbugs │ └── findbugs-filter.xml │ ├── lint │ └── lint.xml │ └── pmd │ └── pmd-ruleset.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | #1.前言: 2 | 在我们平时项目开发中,经常会写一些不严谨的代码或者一些比较低级的错误代码,但是这些错误往往很难被发现,这样就导致了我们的项目中会隐藏了很多影响性能甚至是导致闪退的错误代码,于是许多响应的检测工具就出现了.在这里我就介绍一下我比较常用的几个检测工具吧 3 | 4 | #[项目DEMO源码](https://github.com/yulyu2008/QualityDemo) 5 | 6 | #2.FindBugs 7 | 顾名思义,FindBugs是一个寻找bug的工具,更具体的说FindBugs是一个静态检测java代码的工具,可以找到代码中的一些潜在bug,比如说NullPointerException,或者是一些流或者数据库没有关闭的问题. 8 | 9 | ##2.1作用 10 | 检测范围 : 11 | 12 | - 常见代码错误,序列化错误 13 | - 可能导致错误的代码,如空指针引用 14 | - 国际化相关问题:如错误的字符串转换 15 | - 可能受到的恶意攻击,如访问权限修饰符的定义等 16 | - 多线程的正确性:如多线程编程时常见的同步,线程调度问题。 17 | - 运行时性能问题:如由变量定义,方法调用导致的代码低效问题 18 | ##2.2使用方法 19 | #####FindBugs在Android studio里面有个插件 正常安卓即可(不会安装插件的自己google) 20 | 21 | ![install](http://img.blog.csdn.net/20170210201511659) 22 | 23 | 24 | #####安装好插件之后重启一下Android studio,在底部会有个红色的图标(不同版本可能位置不同),如果你出现了这个图标,那么恭喜你完成了第一步 25 | ![这里写图片描述](http://img.blog.csdn.net/20170210170643524?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 26 | 27 | #####点击左侧第五个按钮可以开始检测 28 | 29 | ![这里写图片描述](http://img.blog.csdn.net/20170210170925244?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 30 | 31 | 32 | 33 | #####检测结果显示如下 34 | 35 | - 当创建流的时候发生了异常 那么inputStream就可能为空 接下来直接调用inputStream就可能产生空指针异常 36 | ![这里写图片描述](http://img.blog.csdn.net/20170210172157593?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 37 | 38 | - 这里使用了io流,但是没有做释放 39 | ![这里写图片描述](http://img.blog.csdn.net/20170210192533233?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 40 | 41 | 42 | ##2.3设置 43 | #####在setting里面还可以对FindBugs做一些设置(这里就不做详细的介绍了) 44 | ![image](http://img.blog.csdn.net/20170210192721918?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 45 | 46 | ##2.4自定义规则 47 | #####FindBugs可以在gradle里面做自定义任务 48 | #####(注意需要在gradle里面添加 apply plugin:'findbugs') 49 | ![这里写图片描述](http://img.blog.csdn.net/20170210193228154?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 50 | ![这里写图片描述](http://img.blog.csdn.net/20170210193347371?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 51 | 52 | 53 | #####在这里配置了规则findbugs-filter.xml 以及报告生成的路径findbugs.xml 54 | 55 | task findbugs(type: FindBugs, dependsOn: "assembleDebug") { 56 | ignoreFailures = false 57 | effort = "max" 58 | reportLevel = "high" 59 | excludeFilter = new File("$configDir/findbugs/findbugs-filter.xml")//这里是自定义的规则 60 | classes = files("${project.rootDir}/app/build/intermediates/classes") 61 | 62 | source 'src' 63 | include '**/*.java' 64 | exclude '**/gen/**' 65 | 66 | reports { 67 | xml.enabled = false 68 | html.enabled = true 69 | xml { 70 | destination "$reportsDir/findbugs/findbugs.xml" //这里是报告产生的路径 71 | } 72 | html { 73 | destination "$reportsDir/findbugs/findbugs.html" //这里是报告产生的路径 74 | } 75 | } 76 | 77 | classpath = files() 78 | } 79 | 80 | #####运行自定义任务(找到任务,双击即可) 81 | ![](http://img.blog.csdn.net/20170210201726191) 82 | 83 | 84 | 85 | #3.PMD 86 | #####PMD和FindBugs的作用差不多,但是他们俩的检测方法不同,所以同时使用能达到互补. 87 | ##3.1作用 88 | #####检测范围 : 89 | 90 | - 可能的bug——空的try/catch/finally/switch块。 91 | - 无用代码(Dead code):无用的本地变量,方法参数和私有方法。 92 | - 空的if/while语句。 93 | - 过度复杂的表达式——不必要的if语句,本来可以用while循环但是却用了for循环。 94 | - 可优化的代码:浪费性能的String/StringBuffer的使用。 95 | 96 | ##3.2使用方法 97 | #####PMD在Android studio也有个插件,直接安装即可(注意搜索的关键字用QAPlug - PMD) 98 | ![这里写图片描述](http://img.blog.csdn.net/20170210193941974?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 99 | 100 | ##3.2自定义规则 101 | #####(注意需要在gradle里面添加 apply plugin: 'pmd') 102 | ![这里写图片描述](http://img.blog.csdn.net/20170210193228154?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 103 | 104 | 105 | 106 | task pmd(type: Pmd) { 107 | ignoreFailures = false 108 | ruleSetFiles = files("$configDir/pmd/pmd-ruleset.xml") //这里是自定义的规则 109 | ruleSets = [] 110 | 111 | source 'src' 112 | include '**/*.java' 113 | exclude '**/gen/**' 114 | 115 | reports { 116 | xml.enabled = false 117 | html.enabled = true 118 | xml { 119 | destination "$reportsDir/pmd/pmd.xml" //这里是报告产生的路径 120 | } 121 | html { 122 | destination "$reportsDir/pmd/pmd.html" //这里是报告产生的路径 123 | } 124 | } 125 | } 126 | #####在这里配置了规则pmd-ruleset.xml 以及报告生成的路径 pmd.html 127 | 128 | ![这里写图片描述](http://img.blog.csdn.net/20170210194154925) 129 | 130 | 131 | 132 | #####运行自定义任务(跟FindBugs一样,找到任务,双击即可) 133 | 134 | ![这里写图片描述](http://img.blog.csdn.net/20170210194323332) 135 | 136 | 137 | 138 | 139 | #4.CheckStyles 140 | 141 | #####CheckStyles是用来检测java代码规范性的 142 | 143 | ##4.1作用 144 | #####检测范围 : 145 | 146 | - 注解 147 | - javadoc注释 148 | - 命名规范 149 | - 文件头 150 | - 导入包规范 151 | - 尺寸设置 152 | - 空格 153 | - 正则表达式 154 | - 修饰符 155 | - 代码块 156 | - 编码问题 157 | - 类设计问题 158 | - 重复、度量以及一些杂项 159 | 160 | ##4.2使用方法 161 | #####安装插件 CheckStyles 162 | ![这里写图片描述](http://img.blog.csdn.net/20170210194537521) 163 | 164 | ##4.3设置 165 | ![这里写图片描述](http://img.blog.csdn.net/20170210194607927) 166 | 167 | **TreatCheckstyle errors as warnings 如果勾上的话,检测到错误时只是会以警告的形式提示** 168 | 169 | **下面是勾上时的提示方式(以警告的形式)** 170 | 171 | ![这里写图片描述](http://img.blog.csdn.net/20170210194737288) 172 | 173 | **下面是不勾时的提示方式(以报错的形式)** 174 | ![这里写图片描述](http://img.blog.csdn.net/20170210194935473) 175 | 176 | 177 | 178 | **下面是选择官方默认的检测规则(也可以自己定义,具体这里就不做详解了)** 179 | ![这里写图片描述](http://img.blog.csdn.net/20170210195148867) 180 | 181 | 182 | ##4.4通过gradle运行 183 | #####(注意需要在gradle里面添加 apply plugin: 'checkstyle') 184 | ![这里写图片描述](http://img.blog.csdn.net/20170210193228154?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVseXU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 185 | 186 | task checkstyle(type: Checkstyle) { 187 | configFile file("$configDir/checkstyle/checkstyle.xml") //这里是自定义的规则 188 | configProperties.checkstyleSuppressionsPath = file("$configDir/checkstyle/suppressions.xml").absolutePath //这里是自定义的规则 189 | source 'src' 190 | include '**/*.java' 191 | exclude '**/gen/**' 192 | classpath = files() 193 | } 194 | 195 | ![这里写图片描述](http://img.blog.csdn.net/20170210195248899) 196 | 197 | 198 | 199 | #5.Demo源码 200 | ##[Demo链接](https://github.com/yulyu2008/QualityDemo) 201 | ## https://github.com/yulyu2008/QualityDemo 202 | 203 | **注意Demo里面的task都抽取到了config目录下的quality.gradle中,所以需要在项目的build.gradle添加** 204 | 205 | **apply from: '../config/quality.gradle'** 206 | 207 | 208 | Demo是在他人的基础上修改的,由于已经无法找到源头,所以在这里声明一下 209 | 210 | -------------------------------------------------------------------------------- /XiayuQualityDemo/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /XiayuQualityDemo/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /XiayuQualityDemo/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /XiayuQualityDemo/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 | 29 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 56 | 57 | 59 | 60 | 61 | 62 | 63 | 1.8 64 | 65 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /XiayuQualityDemo/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /XiayuQualityDemo/.idea/qaplug_profiles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 289 | -------------------------------------------------------------------------------- /XiayuQualityDemo/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply from: '../config/quality.gradle' 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.xiayu.gradledemo" 8 | minSdkVersion 17 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.1.0' 28 | testCompile 'junit:junit:4.12' 29 | } 30 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/androidTest/java/com/xiayu/xiayuqualitydemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.xiayu.xiayuqualitydemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.xiayu.xiayuqualitydemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/java/com/xiayu/xiayuqualitydemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.xiayu.xiayuqualitydemo; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import java.io.File; 7 | import java.io.FileInputStream; 8 | import java.io.FileNotFoundException; 9 | import java.io.IOException; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | public static final String s_aa = ""; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | getData("xiayu"); 19 | } 20 | 21 | private void getData(String xiayu) { 22 | File file =new File(xiayu); 23 | FileInputStream inputStream =null; 24 | try { 25 | inputStream =new FileInputStream(file); 26 | } catch (FileNotFoundException e) { 27 | e.printStackTrace(); 28 | } 29 | try { 30 | int read = inputStream.read(); 31 | } catch (IOException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yulyu2008/QualityDemo/b7bd6e11c392d129eff02c3906e29f235634fd06/XiayuQualityDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yulyu2008/QualityDemo/b7bd6e11c392d129eff02c3906e29f235634fd06/XiayuQualityDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yulyu2008/QualityDemo/b7bd6e11c392d129eff02c3906e29f235634fd06/XiayuQualityDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yulyu2008/QualityDemo/b7bd6e11c392d129eff02c3906e29f235634fd06/XiayuQualityDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yulyu2008/QualityDemo/b7bd6e11c392d129eff02c3906e29f235634fd06/XiayuQualityDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | XiayuQualityDemo 3 | 4 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /XiayuQualityDemo/app/src/test/java/com/xiayu/xiayuqualitydemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.xiayu.xiayuqualitydemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /XiayuQualityDemo/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /XiayuQualityDemo/config/quality.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'checkstyle' 2 | apply plugin: 'findbugs' 3 | apply plugin: 'pmd' 4 | 5 | /* 6 | * Copyright 2015 Vincent Brison. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | // Add checkstyle, findbugs, pmd and lint to the check task. 22 | check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint' 23 | 24 | def configDir = "${project.rootDir}/config/quality" 25 | def reportsDir = "${project.buildDir}/reports" 26 | 27 | task checkstyle(type: Checkstyle) { 28 | configFile file("$configDir/checkstyle/checkstyle.xml") //这里是自定义的规则 29 | configProperties.checkstyleSuppressionsPath = file("$configDir/checkstyle/suppressions.xml").absolutePath //这里是自定义的规则 30 | source 'src' 31 | include '**/*.java' 32 | exclude '**/gen/**' 33 | classpath = files() 34 | } 35 | 36 | task findbugs(type: FindBugs, dependsOn: "assembleDebug") { 37 | ignoreFailures = false 38 | effort = "max" 39 | reportLevel = "high" 40 | excludeFilter = new File("$configDir/findbugs/findbugs-filter.xml")//这里是自定义的规则 41 | classes = files("${project.rootDir}/app/build/intermediates/classes") 42 | 43 | source 'src' 44 | include '**/*.java' 45 | exclude '**/gen/**' 46 | 47 | reports { 48 | xml.enabled = false 49 | html.enabled = true 50 | xml { 51 | destination "$reportsDir/findbugs/findbugs.xml" //这里是报告产生的路径 52 | } 53 | html { 54 | destination "$reportsDir/findbugs/findbugs.html" //这里是报告产生的路径 55 | } 56 | } 57 | 58 | classpath = files() 59 | } 60 | 61 | task pmd(type: Pmd) { 62 | ignoreFailures = false 63 | ruleSetFiles = files("$configDir/pmd/pmd-ruleset.xml") //这里是自定义的规则 64 | ruleSets = [] 65 | 66 | source 'src' 67 | include '**/*.java' 68 | exclude '**/gen/**' 69 | 70 | reports { 71 | xml.enabled = false 72 | html.enabled = true 73 | xml { 74 | destination "$reportsDir/pmd/pmd.xml" //这里是报告产生的路径 75 | } 76 | html { 77 | destination "$reportsDir/pmd/pmd.html" //这里是报告产生的路径 78 | } 79 | } 80 | } 81 | 82 | android { 83 | lintOptions { 84 | abortOnError true 85 | xmlReport false 86 | htmlReport true 87 | lintConfig file("$configDir/lint/lint.xml") 88 | htmlOutput file("$reportsDir/lint/lint-result.html") 89 | xmlOutput file("$reportsDir/lint/lint-result.xml") 90 | } 91 | } 92 | 93 | task detectInfer(type: Exec) { 94 | commandLine 'command' 95 | args = ['-v', 'infer'] 96 | 97 | // Hide output if infer is present 98 | standardOutput new ByteArrayOutputStream() 99 | 100 | // Inform user if infer not present 101 | ignoreExitValue true 102 | doLast { 103 | if(execResult.getExitValue() != 0) { 104 | throw new GradleException("Infer seems not installed. Please refer to http://fbinfer.com/docs/getting-started.html") 105 | } 106 | } 107 | } 108 | 109 | task infer(type: Exec, dependsOn: [clean, detectInfer]) { 110 | workingDir "${project.rootDir}" 111 | commandLine 'infer' 112 | args = ['--', './gradlew', 'build'] 113 | } 114 | -------------------------------------------------------------------------------- /XiayuQualityDemo/config/quality/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 278 | 279 | 280 | 281 | 282 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 424 | 425 | 426 | 427 | 428 | 429 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | -------------------------------------------------------------------------------- /XiayuQualityDemo/config/quality/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /XiayuQualityDemo/config/quality/findbugs/findbugs-filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /XiayuQualityDemo/config/quality/lint/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /XiayuQualityDemo/config/quality/pmd/pmd-ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | Custom ruleset for Android application 24 | 25 | .*/R.java 26 | .*/gen/.* 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /XiayuQualityDemo/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /XiayuQualityDemo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yulyu2008/QualityDemo/b7bd6e11c392d129eff02c3906e29f235634fd06/XiayuQualityDemo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /XiayuQualityDemo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /XiayuQualityDemo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /XiayuQualityDemo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /XiayuQualityDemo/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------