1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 09:35:50 +01:00

Static code analysis: run findbugs, pmd and lint at 'gradle check' #92

As a start, the build won't abort on any serious errors.
This commit is contained in:
cpfeiffer 2015-08-15 22:36:45 +02:00
parent a5e009b371
commit 3486b5ab69
3 changed files with 149 additions and 1 deletions

View File

@ -1,4 +1,8 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'findbugs'
apply plugin: 'pmd'
def ABORT_ON_CHECK_FAILURE=false
android { android {
compileSdkVersion 21 compileSdkVersion 21
@ -17,13 +21,22 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
lintOptions {
abortOnError ABORT_ON_CHECK_FAILURE
lintConfig file("${project.rootDir}/config/lint/lint.xml")
// if true, generate an HTML report (with issue explanations, sourcecode, etc)
htmlReport true
// optional path to report (default will be lint-results.html in the builddir)
htmlOutput file("$project.buildDir/reports/lint/lint.html")
}
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3' compile 'com.android.support:support-v4:21.0.3'
// compile 'com.noveogroup.android:android-logger:1.3.5'
compile 'com.github.tony19:logback-android-classic:1.1.1-3' compile 'com.github.tony19:logback-android-classic:1.1.1-3'
compile 'org.slf4j:slf4j-api:1.7.7' compile 'org.slf4j:slf4j-api:1.7.7'
compile 'com.github.PhilJay:MPAndroidChart:2.1.0' compile 'com.github.PhilJay:MPAndroidChart:2.1.0'
@ -32,3 +45,67 @@ dependencies {
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
// testCompile "org.mockito:mockito-core:1.9.5" // testCompile "org.mockito:mockito-core:1.9.5"
} }
check.dependsOn 'findbugs', 'pmd', 'lint'
task pmd(type: Pmd) {
ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml")
ignoreFailures = !ABORT_ON_CHECK_FAILURE
ruleSets = [
'java-android',
'java-basic',
'java-braces',
'java-clone',
'java-codesize',
'java-controversial',
'java-coupling',
'java-design',
'java-empty',
'java-finalizers',
'java-imports',
'java-junit',
'java-optimizations',
'java-strictexception',
'java-strings',
'java-sunsecure',
'java-typeresolution',
'java-unnecessary',
'java-unusedcode'
]
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"
}
}
}
task findbugs(type: FindBugs) {
ignoreFailures = !ABORT_ON_CHECK_FAILURE
effort = "default"
reportLevel = "medium"
excludeFilter = new File("${project.rootDir}/config/findbugs/findbugs-filter.xml")
classes = files("${project.rootDir}/app/build/intermediates/classes")
source = fileTree('src/main/java/')
classpath = files()
reports {
xml.enabled = false
html.enabled = true
xml {
destination "$project.buildDir/reports/findbugs/findbugs-output.xml"
}
html {
destination "$project.buildDir/reports/findbugs/findbugs-output.html"
}
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<!-- ignore all issues in resource generation -->
<Class name="~.*\.R\$.*"/>
</Match>
<Match>
<Class name="~.*\.Manifest\$.*"/>
</Match>
<!-- ignore all bugs in test classes, except for those bugs specifically relating to JUnit tests -->
<Match>
<Class name="~.*\.*Test" />
<!-- test classes are suffixed by 'Test' -->
<Not>
<Bug code="IJU" /> <!-- 'IJU' is the code for bugs related to JUnit test code -->
</Not>
</Match>
</FindBugsFilter>

View File

@ -0,0 +1,52 @@
<?xml version="1.0"?>
<!--
~ 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.
-->
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Custom ruleset for Android application</description>
<exclude-pattern>.*/R.java</exclude-pattern>
<exclude-pattern>.*/gen/.*</exclude-pattern>
<rule ref="rulesets/java/android.xml">
<!-- Config.LOGD deprecated in API level 4 !-->
<exclude name="ProtectLogD" />
<!-- Config.LOGV deprecated in API level 4 !-->
<exclude name="ProtectLogV" />
</rule>
<rule ref="rulesets/java/clone.xml" />
<rule ref="rulesets/java/finalizers.xml" />
<rule ref="rulesets/java/imports.xml">
<!-- Espresso is designed this way !-->
<exclude name="TooManyStaticImports" />
</rule>
<rule ref="rulesets/java/logging-java.xml" />
<rule ref="rulesets/java/braces.xml" />
<rule ref="rulesets/java/strings.xml" />
<rule ref="rulesets/java/basic.xml" />
<rule ref="rulesets/java/naming.xml">
<exclude name="AbstractNaming" />
<exclude name="LongVariable" />
<exclude name="LongMethodName" />
<exclude name="ShortMethodName" />
<exclude name="ShortVariable" />
<exclude name="VariableNamingConventions" />
</rule>
</ruleset>