From 835d4e32f5254e6a79eb6a118a3e90bbc68d42db Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Wed, 5 Dec 2018 16:50:10 -0500 Subject: [PATCH] Issue #34: Add a way to enforce specific lints. Before this commits no lints would actually fail the build because we only checked for compatibility. After this commit apilint runs the lint twice: - Once with only the existing api as argument to check for lints (with an optional filter for lints). - Once with both existing and new API to check for compatibility. This adds a new configuration: `apiLint.lintFilters` which allows consumers to set a list of prefixes of lints that can fail the build. --- README.md | 5 ++++ .../org/mozilla/apilint/ApiLintPlugin.groovy | 26 +++++++++++++++---- .../apilint/ApiLintPluginExtension.groovy | 1 + apilint/src/main/resources/apilint.py | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d7774c1..39c8517 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ apiLint { currentApiRelativeFilePath = 'api.txt' jsonResultFileName = 'apilint-result.json' changelogFileName = null + lintFilters = null } ``` @@ -122,3 +123,7 @@ contains the result of apilint. changelogFileName Relative path to the changelog file, optional. See also [Changelog](#changelog). + +lintFilters List of lints that fail the build, by default +all lints can fail the build. Filters will match any error code that starts +with the string specified, e.g. `GV` will match `GV1`, `GV2`, ... diff --git a/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPlugin.groovy b/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPlugin.groovy index 7f45887..f06b5b3 100644 --- a/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPlugin.groovy +++ b/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPlugin.groovy @@ -45,20 +45,36 @@ class ApiLintPlugin implements Plugin { apiGenerate.dependsOn variant.javaCompile + def apiCompatLint = project.task("apiCompatLint${name}", type: PythonExec) { + description = "Runs API compatibility lint checks for variant ${name}" + workingDir '.' + scriptPath 'apilint.py' + args '--show-noticed' + args apiFile + args currentApiFile + args '--result-json' + args project.file( + "${variant.javaCompile.destinationDir}/${extension.jsonResultFileName}") + } + + apiCompatLint.dependsOn apiGenerate + def apiLint = project.task("apiLint${name}", type: PythonExec) { description = "Runs API lint checks for variant ${name}" group = 'Verification' workingDir '.' scriptPath 'apilint.py' - args '--show-noticed' - args apiFile args currentApiFile args '--result-json' args project.file( "${variant.javaCompile.destinationDir}/${extension.jsonResultFileName}") + if (extension.lintFilters != null) { + args '--filter-errors' + args extension.lintFilters + } } - apiLint.dependsOn apiGenerate + apiLint.dependsOn apiCompatLint project.tasks.check.dependsOn apiLint if (extension.changelogFileName) { @@ -74,7 +90,7 @@ class ApiLintPlugin implements Plugin { } apiChangelogCheck.dependsOn apiGenerate - apiLint.dependsOn apiChangelogCheck + apiCompatLint.dependsOn apiChangelogCheck } def apiDiff = project.task("apiDiff${name}", type: Exec) { @@ -107,7 +123,7 @@ class ApiLintPlugin implements Plugin { } apiLintHelp.dependsOn apiDiff - apiLint.finalizedBy apiLintHelp + apiCompatLint.finalizedBy apiLintHelp def apiUpdate = project.task("apiUpdateFile${name}", type: Copy) { description = "Updates the API file from the local one for variant ${name}" diff --git a/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPluginExtension.groovy b/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPluginExtension.groovy index 888d8cc..0031554 100644 --- a/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPluginExtension.groovy +++ b/apilint/src/main/groovy/org/mozilla/apilint/ApiLintPluginExtension.groovy @@ -8,4 +8,5 @@ class ApiLintPluginExtension { String currentApiRelativeFilePath = 'api.txt' String jsonResultFileName = 'apilint-result.json' String changelogFileName + List lintFilters } diff --git a/apilint/src/main/resources/apilint.py b/apilint/src/main/resources/apilint.py index 59364db..82b4c38 100644 --- a/apilint/src/main/resources/apilint.py +++ b/apilint/src/main/resources/apilint.py @@ -1651,7 +1651,8 @@ def matches_filter(filter_, failure): filtered_fail[p] = cur_fail[p] cur_fail = filtered_fail - dump_result_json(args, compat_fail, cur_noticed, cur_fail) + dump_result_json(args, compat_fail, + cur_noticed if args['show_noticed'] else [], cur_fail) if compat_fail and len(compat_fail) != 0: print("%s API compatibility issues %s\n" % ((format(fg=WHITE, bg=BLUE, bold=True), format(reset=True))))