├── settings.gradle ├── qualityChecks ├── settings.gradle ├── src │ ├── main │ │ ├── resources │ │ │ ├── findbugs-exclude.xml │ │ │ ├── pmd-ruleset.xml │ │ │ └── checkstyle.xml │ │ └── kotlin │ │ │ └── info │ │ │ └── adavis │ │ │ └── qualitychecks │ │ │ ├── QualityChecksExtension.kt │ │ │ ├── tasks │ │ │ ├── CheckstyleTask.kt │ │ │ ├── PmdTask.kt │ │ │ ├── FindBugsTask.kt │ │ │ └── WriteConfigFileTask.kt │ │ │ └── QualityChecksPlugin.kt │ ├── test │ │ └── kotlin │ │ │ └── info │ │ │ └── adavis │ │ │ └── qualitychecks │ │ │ ├── tasks │ │ │ ├── PmdTaskTest.kt │ │ │ ├── FindBugsTaskTest.kt │ │ │ ├── CheckstyleTaskTest.kt │ │ │ └── WriteConfigFileTaskTest.kt │ │ │ └── QualityChecksPluginTest.kt │ └── functionalTest │ │ └── kotlin │ │ └── info │ │ └── adavis │ │ └── qualitychecks │ │ └── QualityChecksPluginFunctionalTest.kt └── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── gradlew.bat └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':qualityChecks' 2 | 3 | -------------------------------------------------------------------------------- /qualityChecks/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'qualityChecks' -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adavis/quality-checks/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build/ 4 | 5 | *.iml 6 | 7 | # Ignore Gradle GUI config 8 | gradle-app.setting 9 | 10 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 11 | !gradle-wrapper.jar -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | before_cache: 5 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 6 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 7 | cache: 8 | directories: 9 | - $HOME/.gradle/caches/ 10 | - $HOME/.gradle/wrapper/ -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun May 21 19:40:58 EDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://repo.gradle.org/gradle/dist-snapshots/gradle-script-kotlin-4.0-20170518042627+0000-all.zip 7 | -------------------------------------------------------------------------------- /qualityChecks/src/main/resources/findbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /qualityChecks/src/main/kotlin/info/adavis/qualitychecks/QualityChecksExtension.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks 2 | 3 | import info.adavis.qualitychecks.QualityChecksPlugin.Companion.CHECKSTYLE_FILE_NAME 4 | import info.adavis.qualitychecks.QualityChecksPlugin.Companion.FINDBUGS_FILE_NAME 5 | import info.adavis.qualitychecks.QualityChecksPlugin.Companion.PMD_FILE_NAME 6 | 7 | open class QualityChecksExtension(var pmdConfigFile: String = "quality-checks/$PMD_FILE_NAME", 8 | var checkstyleConfigFile: String = "quality-checks/$CHECKSTYLE_FILE_NAME", 9 | var findBugsExclusionFile: String = "quality-checks/$FINDBUGS_FILE_NAME") 10 | -------------------------------------------------------------------------------- /qualityChecks/src/test/kotlin/info/adavis/qualitychecks/tasks/PmdTaskTest.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksExtension 4 | import info.adavis.qualitychecks.QualityChecksPlugin 5 | import org.gradle.testfixtures.ProjectBuilder 6 | import org.junit.Assert.* 7 | import org.junit.Test 8 | 9 | import java.io.File 10 | 11 | class PmdTaskTest { 12 | 13 | @Test 14 | fun `should create pmd task`() { 15 | val project = ProjectBuilder.builder().build() 16 | 17 | with(project) { 18 | extensions.create("qualityChecks", QualityChecksExtension::class.java) 19 | extensions.findByType(QualityChecksExtension::class.java).pmdConfigFile = File.createTempFile("temp", ".xml").path 20 | 21 | val pmdTask = tasks.create("pmd", PmdTask::class.java) 22 | 23 | assertNotNull(pmdTask) 24 | assertEquals(QualityChecksPlugin.VERIFICATION_GROUP, pmdTask.group) 25 | assertTrue(pmdTask.ruleSetFiles.first().name.startsWith("temp")) 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /qualityChecks/src/test/kotlin/info/adavis/qualitychecks/tasks/FindBugsTaskTest.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksExtension 4 | import info.adavis.qualitychecks.QualityChecksPlugin 5 | import org.gradle.testfixtures.ProjectBuilder 6 | import org.junit.Assert.* 7 | import org.junit.Test 8 | import java.io.File 9 | 10 | class FindBugsTaskTest { 11 | 12 | @Test 13 | fun `should create findBugs task`() { 14 | val project = ProjectBuilder.builder().build() 15 | 16 | with(project) { 17 | extensions.create("qualityChecks", QualityChecksExtension::class.java) 18 | extensions.findByType(QualityChecksExtension::class.java).findBugsExclusionFile = File.createTempFile("temp", ".xml").path 19 | 20 | val findbugsTask = tasks.create("findbugs", FindBugsTask::class.java) 21 | 22 | assertNotNull(findbugsTask) 23 | assertEquals(QualityChecksPlugin.VERIFICATION_GROUP, findbugsTask.group) 24 | assertTrue(findbugsTask.excludeFilter.name.startsWith("temp")) 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /qualityChecks/src/test/kotlin/info/adavis/qualitychecks/tasks/CheckstyleTaskTest.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksExtension 4 | import info.adavis.qualitychecks.QualityChecksPlugin 5 | import org.gradle.testfixtures.ProjectBuilder 6 | import org.junit.Assert.* 7 | import org.junit.Test 8 | import java.io.File 9 | 10 | class CheckstyleTaskTest { 11 | 12 | @Test 13 | fun `should create checkstyle task`() { 14 | val project = ProjectBuilder.builder().build() 15 | 16 | with(project) { 17 | extensions.create("qualityChecks", QualityChecksExtension::class.java) 18 | extensions.findByType(QualityChecksExtension::class.java).checkstyleConfigFile = File.createTempFile("temp", ".xml").path 19 | 20 | val checkstyleTask = tasks.create("checkstyle", CheckstyleTask::class.java) 21 | 22 | assertNotNull(checkstyleTask) 23 | assertEquals(QualityChecksPlugin.VERIFICATION_GROUP, checkstyleTask.group) 24 | assertTrue(checkstyleTask.configFile.name.startsWith("temp")) 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Annyce D. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /qualityChecks/src/main/kotlin/info/adavis/qualitychecks/tasks/CheckstyleTask.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksExtension 4 | import info.adavis.qualitychecks.QualityChecksPlugin.Companion.VERIFICATION_GROUP 5 | import org.gradle.api.plugins.quality.Checkstyle 6 | import org.gradle.api.plugins.quality.CheckstylePlugin 7 | import org.gradle.api.tasks.Input 8 | import java.io.File 9 | 10 | open class CheckstyleTask : Checkstyle() { 11 | 12 | init { 13 | project.plugins.apply(CheckstylePlugin::class.java) 14 | 15 | description = "Run Checkstyle" 16 | group = VERIFICATION_GROUP 17 | 18 | configFile = checkstyleConfigFile 19 | classpath = project.files() 20 | ignoreFailures = false 21 | includes.add("**/*.java") 22 | excludes.add("**/gen/**") 23 | source.add("src") 24 | } 25 | 26 | val checkstyleConfigFile: File 27 | @Input get() { 28 | val extension = project?.extensions?.findByType(QualityChecksExtension::class.java) 29 | return project.file(extension?.checkstyleConfigFile) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /qualityChecks/src/main/kotlin/info/adavis/qualitychecks/tasks/PmdTask.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksExtension 4 | import info.adavis.qualitychecks.QualityChecksPlugin.Companion.VERIFICATION_GROUP 5 | import org.gradle.api.file.FileCollection 6 | import org.gradle.api.plugins.quality.Pmd 7 | import org.gradle.api.plugins.quality.PmdPlugin 8 | import org.gradle.api.tasks.Input 9 | 10 | open class PmdTask : Pmd() { 11 | 12 | init { 13 | project.plugins.apply(PmdPlugin::class.java) 14 | 15 | description = "Run Pmd" 16 | group = VERIFICATION_GROUP 17 | 18 | ruleSetFiles = pmdConfigFiles 19 | ruleSets = emptyList() 20 | ignoreFailures = true 21 | 22 | reports.xml.isEnabled = true 23 | reports.html.isEnabled = true 24 | 25 | includes.add("**/*.java") 26 | excludes.add("**/gen/**") 27 | source.add("src") 28 | } 29 | 30 | val pmdConfigFiles: FileCollection 31 | @Input get() { 32 | val extension = project?.extensions?.findByType(QualityChecksExtension::class.java) 33 | return project.files(extension?.pmdConfigFile) 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /qualityChecks/src/main/kotlin/info/adavis/qualitychecks/tasks/FindBugsTask.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksExtension 4 | import info.adavis.qualitychecks.QualityChecksPlugin.Companion.VERIFICATION_GROUP 5 | import org.gradle.api.plugins.quality.FindBugs 6 | import org.gradle.api.plugins.quality.FindBugsPlugin 7 | import org.gradle.api.tasks.Input 8 | import java.io.File 9 | 10 | open class FindBugsTask : FindBugs() { 11 | 12 | init { 13 | project.plugins.apply(FindBugsPlugin::class.java) 14 | 15 | description = "Run FindBugs" 16 | group = VERIFICATION_GROUP 17 | 18 | classes = project.files("$project.buildDir/intermediates/classes") 19 | classpath = project.files() 20 | effort = "max" 21 | 22 | excludeFilter = findBugsExclusionFile 23 | ignoreFailures = true 24 | 25 | reports.xml.isEnabled = true 26 | reports.html.isEnabled = false 27 | 28 | source.add("src") 29 | } 30 | 31 | val findBugsExclusionFile: File 32 | @Input get() { 33 | val extension = project?.extensions?.findByType(QualityChecksExtension::class.java) 34 | return project.file(extension?.findBugsExclusionFile) 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /qualityChecks/src/test/kotlin/info/adavis/qualitychecks/QualityChecksPluginTest.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks 2 | 3 | import org.gradle.api.GradleException 4 | import org.gradle.api.plugins.ApplicationPlugin 5 | import org.gradle.testfixtures.ProjectBuilder 6 | import org.junit.Assert.assertNotNull 7 | import org.junit.Test 8 | 9 | class QualityChecksPluginTest { 10 | 11 | @Test(expected = GradleException::class) 12 | fun `plugin should throw exception when app plugin unavailable`() { 13 | val project = ProjectBuilder.builder().build() 14 | 15 | project.pluginManager.apply(QualityChecksPlugin::class.java) 16 | } 17 | 18 | @Test 19 | fun `plugin should add tasks when applied`() { 20 | val project = ProjectBuilder.builder().build() 21 | 22 | with(project) { 23 | pluginManager.apply(ApplicationPlugin::class.java) 24 | pluginManager.apply(QualityChecksPlugin::class.java) 25 | 26 | assertNotNull(tasks.findByName(QualityChecksPlugin.WRITE_CHECK_STYLE_CONFIG_FILE_TASK)) 27 | assertNotNull(tasks.findByName(QualityChecksPlugin.WRITE_FIND_BUGS_EXCLUSION_FILE_TASK)) 28 | assertNotNull(tasks.findByName(QualityChecksPlugin.WRITE_PMD_CONFIG_FILE_TASK)) 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /qualityChecks/src/main/resources/pmd-ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Custom ruleset for Android application 8 | 9 | .*/R.java 10 | .*/gen/.* 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/adavis/quality-checks.svg?branch=master)](https://travis-ci.org/adavis/quality-checks) 2 | 3 | Android Quality Checks Plugin 4 | ====== 5 | 6 | This plugin allows you to include Checkstyle, FindBugs, and PMD static code analysis tools to your Android Gradle build. 7 | It copies basic xml configuration files to a new directory `quality-checks` which is in the same directory of the `build.gradle` file. 8 | 9 | Installation 10 | ------------ 11 | 12 | Add the following to your `build.gradle`: 13 | 14 | ```gradle 15 | buildscript { 16 | repositories { 17 | maven { url 'https://plugins.gradle.org/m2/' } 18 | } 19 | dependencies { 20 | classpath 'gradle.plugin.info.adavis:qualityChecks:0.2.+' 21 | } 22 | } 23 | 24 | apply plugin: 'info.adavis.qualitychecks' 25 | ``` 26 | 27 | Usage 28 | ----- 29 | 30 | You can optionally define the location of the Checkstyle, FindBugs and PMD configuration files you would prefer to use: 31 | 32 | ```gradle 33 | qualityChecks { 34 | pmdConfigFile = '/pmd-ruleset.xml' 35 | checkstyleConfigFile = '/checkstyle.xml' 36 | findBugsExclusionFile = '/findbugs-exclude.xml' 37 | } 38 | ``` 39 | 40 | Then you can use the following commands to run the checks: 41 | 42 | ```gradle 43 | gradle pmd 44 | gradle findbugs 45 | gradle checkstyle 46 | ``` -------------------------------------------------------------------------------- /qualityChecks/src/main/kotlin/info/adavis/qualitychecks/tasks/WriteConfigFileTask.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksPlugin 4 | import org.gradle.api.DefaultTask 5 | import org.gradle.api.tasks.Input 6 | import org.gradle.api.tasks.Optional 7 | import org.gradle.api.tasks.OutputFile 8 | import org.gradle.api.tasks.TaskAction 9 | import java.io.File 10 | 11 | open class WriteConfigFileTask : DefaultTask() { 12 | 13 | @OutputFile 14 | @Optional 15 | var configFile: File? = null 16 | 17 | @Input 18 | @Optional 19 | var fileName: String? = null 20 | 21 | init { 22 | group = QualityChecksPlugin.VERIFICATION_GROUP 23 | 24 | onlyIf { 25 | configFile != null 26 | } 27 | } 28 | 29 | @TaskAction 30 | fun writeConfigFile() { 31 | description = "Write config file for quality checks task" 32 | 33 | configFile?.let { 34 | logger.info("Copying the file contents from $fileName") 35 | copyConfigFile(fileName, configFile) 36 | } 37 | } 38 | 39 | companion object { 40 | 41 | fun copyConfigFile(fileName: String?, configFile: File?) { 42 | ClassLoader.getSystemResourceAsStream(fileName).use { inputStream -> 43 | configFile?.outputStream()?.use { inputStream?.copyTo(it) } 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /qualityChecks/src/test/kotlin/info/adavis/qualitychecks/tasks/WriteConfigFileTaskTest.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks.tasks 2 | 3 | import info.adavis.qualitychecks.QualityChecksPlugin 4 | import org.gradle.api.Project 5 | import org.gradle.testfixtures.ProjectBuilder 6 | import org.junit.Assert.* 7 | import org.junit.Before 8 | import org.junit.Rule 9 | import org.junit.Test 10 | import org.junit.rules.TemporaryFolder 11 | import java.io.File 12 | 13 | class WriteConfigFileTaskTest { 14 | 15 | @Rule @JvmField 16 | val temporaryFolder = TemporaryFolder() 17 | 18 | lateinit var projectDir: File 19 | lateinit var project: Project 20 | lateinit var task: WriteConfigFileTask 21 | 22 | @Before 23 | fun setUp() { 24 | projectDir = temporaryFolder.root 25 | projectDir.mkdirs() 26 | 27 | project = ProjectBuilder.builder().withProjectDir(projectDir).build() 28 | task = project.tasks.create("writeConfigFile", WriteConfigFileTask::class.java) 29 | } 30 | 31 | @Test 32 | fun `should be able to create task`() { 33 | assertTrue(task is WriteConfigFileTask) 34 | } 35 | 36 | @Test 37 | fun `should not write file when already provided`() { 38 | with(task) { 39 | configFile = File.createTempFile("temp", ".xml") 40 | fileName = "pmd-ruleset.xml" 41 | 42 | writeConfigFile() 43 | 44 | configFile?.name?.startsWith("temp")?.let(::assertTrue) 45 | } 46 | } 47 | 48 | @Test 49 | fun `should not write file if null`() { 50 | with(task) { 51 | writeConfigFile() 52 | 53 | assertNull(configFile) 54 | } 55 | } 56 | 57 | @Test 58 | fun `should write default file contents if file exists`() { 59 | with(task) { 60 | configFile = temporaryFolder.newFile("pmd-ruleset.xml") 61 | fileName = QualityChecksPlugin.PMD_FILE_NAME 62 | 63 | writeConfigFile() 64 | 65 | val file = File(projectDir, "pmd-ruleset.xml") 66 | 67 | assertTrue(file.exists()) 68 | assertEquals(QualityChecksPlugin.PMD_FILE_NAME, task.configFile?.name) 69 | assertTrue(file.readText().contains("Custom ruleset for Android application")) 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /qualityChecks/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.gradle.api.tasks.testing.Test 2 | import org.gradle.plugin.devel.GradlePluginDevelopmentExtension 3 | import com.gradle.publish.PluginBundleExtension 4 | 5 | buildscript { 6 | repositories { 7 | jcenter() 8 | gradleScriptKotlin() 9 | maven { setUrl("https://plugins.gradle.org/m2/") } 10 | } 11 | dependencies { 12 | classpath(kotlinModule("gradle-plugin")) 13 | classpath("com.gradle.publish:plugin-publish-plugin:0.9.7") 14 | } 15 | } 16 | 17 | apply { 18 | plugin("kotlin") 19 | plugin("org.gradle.java-gradle-plugin") 20 | plugin("com.gradle.plugin-publish") 21 | } 22 | 23 | repositories { 24 | jcenter() 25 | } 26 | 27 | dependencies { 28 | compile(kotlinModule("stdlib", "1.1.2-2")) 29 | compile(gradleScriptKotlinApi()) 30 | testCompile("junit:junit:4.12") 31 | } 32 | 33 | val sourceSets = the().sourceSets 34 | 35 | sourceSets { 36 | "functionalTest" { 37 | compileClasspath += sourceSets["main"].output + configurations.testRuntime 38 | runtimeClasspath += output + compileClasspath 39 | } 40 | } 41 | 42 | task("functionalTest") { 43 | group = "verification" 44 | testClassesDir = sourceSets["functionalTest"].output.classesDir 45 | classpath = sourceSets["functionalTest"].runtimeClasspath 46 | } 47 | 48 | tasks { 49 | withType(Test::class.java) { 50 | testLogging { 51 | events("passed", "skipped", "failed") 52 | } 53 | } 54 | 55 | "check" { 56 | dependsOn("functionalTest") 57 | } 58 | } 59 | 60 | version = "0.2.4" 61 | group = "info.adavis" 62 | 63 | val gradlePlugin = configure { 64 | testSourceSets(sourceSets["functionalTest"]) 65 | 66 | (plugins) { 67 | "qualityChecksPlugin" { 68 | id = "info.adavis.qualitychecks" 69 | implementationClass = "info.adavis.qualitychecks.QualityChecksPlugin" 70 | } 71 | } 72 | } 73 | 74 | configure { 75 | website = "https://github.com/adavis/quality-checks" 76 | vcsUrl = "https://github.com/adavis/quality-checks.git" 77 | description = "Simple Gradle Plugin for including Checkstyle, FindBugs, and PMD in your Android project." 78 | tags = listOf("Checkstyle", "FindBugs", "PMD", "Android") 79 | 80 | this.plugins { 81 | "qualityChecksPlugin" { 82 | id = "info.adavis.qualitychecks" 83 | displayName = "Quality Checks Android Plugin" 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /qualityChecks/src/main/resources/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 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 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows 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 | -------------------------------------------------------------------------------- /qualityChecks/src/functionalTest/kotlin/info/adavis/qualitychecks/QualityChecksPluginFunctionalTest.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks 2 | 3 | import org.gradle.testkit.runner.BuildResult 4 | import org.gradle.testkit.runner.GradleRunner 5 | import org.gradle.testkit.runner.UnexpectedBuildFailure 6 | import org.junit.Assert.assertTrue 7 | import org.junit.Before 8 | import org.junit.Rule 9 | import org.junit.Test 10 | import org.junit.rules.TemporaryFolder 11 | import java.io.File 12 | 13 | class QualityChecksPluginFunctionalTest { 14 | 15 | @get:Rule val testProjectDir: TemporaryFolder = TemporaryFolder() 16 | 17 | lateinit var buildFile: File 18 | 19 | @Before 20 | fun setup() { 21 | buildFile = testProjectDir.newFile("build.gradle") 22 | } 23 | 24 | @Test(expected = UnexpectedBuildFailure::class) 25 | fun `when application plugin not available should throw exception`() { 26 | buildFile.appendText(""" 27 | plugins { 28 | id 'info.adavis.qualitychecks' 29 | } 30 | """) 31 | 32 | GradleRunner.create() 33 | .withProjectDir(testProjectDir.root) 34 | .withPluginClasspath() 35 | .build() 36 | } 37 | 38 | @Test 39 | fun `when plugin applied build should succeed and create files`() { 40 | buildFile.appendText(""" 41 | plugins { 42 | id 'application' 43 | id 'info.adavis.qualitychecks' 44 | } 45 | """) 46 | 47 | val result: BuildResult = GradleRunner.create() 48 | .withProjectDir(testProjectDir.root) 49 | .withPluginClasspath() 50 | .build() 51 | 52 | assertTrue(result.output.contains("BUILD SUCCESSFUL")) 53 | 54 | val qualityChecksDir = File(buildFile.parentFile, "quality-checks") 55 | assertTrue(qualityChecksDir.exists()) 56 | assertTrue(File(qualityChecksDir, QualityChecksPlugin.PMD_FILE_NAME).exists()) 57 | assertTrue(File(qualityChecksDir, QualityChecksPlugin.CHECKSTYLE_FILE_NAME).exists()) 58 | assertTrue(File(qualityChecksDir, QualityChecksPlugin.FINDBUGS_FILE_NAME).exists()) 59 | } 60 | 61 | @Test 62 | fun `when executed checkstyle should succeed`() { 63 | buildFile.appendText(""" 64 | plugins { 65 | id 'application' 66 | id 'info.adavis.qualitychecks' 67 | } 68 | """) 69 | 70 | val result: BuildResult = GradleRunner.create() 71 | .withProjectDir(testProjectDir.root) 72 | .withArguments("checkstyle", "--info") 73 | .withPluginClasspath() 74 | .build() 75 | 76 | println(result.output) 77 | assertTrue(result.output.contains("BUILD SUCCESSFUL")) 78 | } 79 | } -------------------------------------------------------------------------------- /qualityChecks/src/main/kotlin/info/adavis/qualitychecks/QualityChecksPlugin.kt: -------------------------------------------------------------------------------- 1 | package info.adavis.qualitychecks 2 | 3 | import info.adavis.qualitychecks.tasks.CheckstyleTask 4 | import info.adavis.qualitychecks.tasks.FindBugsTask 5 | import info.adavis.qualitychecks.tasks.PmdTask 6 | import info.adavis.qualitychecks.tasks.WriteConfigFileTask 7 | import org.gradle.api.GradleException 8 | import org.gradle.api.Plugin 9 | import org.gradle.api.Project 10 | import org.gradle.api.plugins.ApplicationPlugin 11 | import java.io.File 12 | 13 | class QualityChecksPlugin : Plugin { 14 | 15 | companion object { 16 | const val PMD_FILE_NAME = "pmd-ruleset.xml" 17 | const val CHECKSTYLE_FILE_NAME = "checkstyle.xml" 18 | const val FINDBUGS_FILE_NAME = "findbugs-exclude.xml" 19 | const val WRITE_PMD_CONFIG_FILE_TASK = "writePmdConfigFile" 20 | const val WRITE_CHECK_STYLE_CONFIG_FILE_TASK = "writeCheckStyleConfigFile" 21 | const val WRITE_FIND_BUGS_EXCLUSION_FILE_TASK = "writeFindBugsExclusionFile" 22 | const val VERIFICATION_GROUP = "verification" 23 | const val PLUGIN_EXTENSION_NAME = "qualityChecks" 24 | } 25 | 26 | lateinit var project: Project 27 | 28 | var pmdConfigFile: File? = null 29 | var checkStyleConfigFile: File? = null 30 | var findBugsExclusionFile: File? = null 31 | 32 | override fun apply(target: Project?) { 33 | target?.let { 34 | project = target 35 | if (project.plugins?.withType(ApplicationPlugin::class.java)?.isNotEmpty()!!) { 36 | project.extensions?.create(PLUGIN_EXTENSION_NAME, QualityChecksExtension::class.java) 37 | 38 | createConfigFilesIfNeeded() 39 | createConfigFileTasks() 40 | createQualityChecksTasks() 41 | } 42 | else { 43 | throw GradleException("You must apply the Android plugin before using this plugin.") 44 | } 45 | } 46 | } 47 | 48 | private fun createConfigFilesIfNeeded() { 49 | val qualityChecksDir = File(project.buildFile?.parentFile, "quality-checks") 50 | if (!qualityChecksDir.exists()) { 51 | qualityChecksDir.mkdirs() 52 | 53 | project.logger.info("created the `quality-checks` directory") 54 | } 55 | 56 | pmdConfigFile = createConfigFile(qualityChecksDir, PMD_FILE_NAME) 57 | checkStyleConfigFile = createConfigFile(qualityChecksDir, CHECKSTYLE_FILE_NAME) 58 | findBugsExclusionFile = createConfigFile(qualityChecksDir, FINDBUGS_FILE_NAME) 59 | } 60 | 61 | private fun createConfigFile(qualityChecksDir:File, fileName: String): File? { 62 | return File(qualityChecksDir, fileName).apply { 63 | createNewFile() 64 | WriteConfigFileTask.copyConfigFile(fileName, this) 65 | 66 | project.logger.info("created the $fileName file with default content") 67 | } 68 | } 69 | 70 | private fun createConfigFileTasks() { 71 | project.tasks?.let { 72 | it.create(WRITE_PMD_CONFIG_FILE_TASK, WriteConfigFileTask::class.java).apply { 73 | configFile = pmdConfigFile 74 | fileName = PMD_FILE_NAME 75 | } 76 | 77 | it.create(WRITE_CHECK_STYLE_CONFIG_FILE_TASK, WriteConfigFileTask::class.java).apply { 78 | configFile = checkStyleConfigFile 79 | fileName = CHECKSTYLE_FILE_NAME 80 | } 81 | 82 | it.create(WRITE_FIND_BUGS_EXCLUSION_FILE_TASK, WriteConfigFileTask::class.java).apply { 83 | configFile = findBugsExclusionFile 84 | fileName = FINDBUGS_FILE_NAME 85 | } 86 | } 87 | } 88 | 89 | private fun createQualityChecksTasks() { 90 | project.tasks?.let { 91 | it.create("pmd", PmdTask::class.java) 92 | it.create("findbugs", FindBugsTask::class.java) 93 | it.create("checkstyle", CheckstyleTask::class.java) 94 | 95 | project.logger.info("created the static code analysis tasks") 96 | } 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | --------------------------------------------------------------------------------