violations gradle plugin
v3.0.2
这是用于违规lib的Gradle插件。还有一个Maven插件。
| 版本 | Java版本 |
|---|---|
| 版本<2.0.0 | 8 |
| 2.0.0 <=版本 | 11 |
发布到plugins.gradle.org。
它可以解析静态代码分析的结果,并且:
您也可以使用命令行工具执行此操作。
输出的片段看起来像这样:
...
se/bjurr/violations/lib/example/OtherClass.java
╔══════════╤════════════╤══════════╤══════╤════════════════════════════════════════════════════╗
║ Reporter │ Rule │ Severity │ Line │ Message ║
╠══════════╪════════════╪══════════╪══════╪════════════════════════════════════════════════════╣
║ Findbugs │ MS_SHOULD_ │ INFO │ 7 │ Field isn ' t final but should be ║
║ │ BE_FINAL │ │ │ ║
║ │ │ │ │ ║
║ │ │ │ │ <p> ║
║ │ │ │ │ This static field public but not final, and ║
║ │ │ │ │ could be changed by malicious code or ║
║ │ │ │ │ by accident from another package. ║
║ │ │ │ │ The field could be made final to avoid ║
║ │ │ │ │ this vulnerability.</p> ║
╟──────────┼────────────┼──────────┼──────┼────────────────────────────────────────────────────╢
║ Findbugs │ NM_FIELD_N │ INFO │ 6 │ Field names should start with a lower case letter ║
║ │ AMING_CONV │ │ │ ║
║ │ ENTION │ │ │ ║
║ │ │ │ │ <p> ║
║ │ │ │ │ Names of fields that are not final should be in mi ║
║ │ │ │ │ xed case with a lowercase first letter and the fir ║
║ │ │ │ │ st letters of subsequent words capitalized. ║
║ │ │ │ │ </p> ║
╚══════════╧════════════╧══════════╧══════╧════════════════════════════════════════════════════╝
Summary of se/bjurr/violations/lib/example/OtherClass.java
╔══════════╤══════╤══════╤═══════╤═══════╗
║ Reporter │ INFO │ WARN │ ERROR │ Total ║
╠══════════╪══════╪══════╪═══════╪═══════╣
║ Findbugs │ 2 │ 0 │ 0 │ 2 ║
╟──────────┼──────┼──────┼───────┼───────╢
║ │ 2 │ 0 │ 0 │ 2 ║
╚══════════╧══════╧══════╧═══════╧═══════╝
Summary
╔════════════╤══════╤══════╤═══════╤═══════╗
║ Reporter │ INFO │ WARN │ ERROR │ Total ║
╠════════════╪══════╪══════╪═══════╪═══════╣
║ Checkstyle │ 4 │ 1 │ 1 │ 6 ║
╟────────────┼──────┼──────┼───────┼───────╢
║ Findbugs │ 2 │ 2 │ 5 │ 9 ║
╟────────────┼──────┼──────┼───────┼───────╢
║ │ 6 │ 3 │ 6 │ 15 ║
╚════════════╧══════╧══════╧═══════╧═══════╝支持报告的示例在这里可用。
已经实施了许多解析器。一些解析器可以解析几个记者的输出。
| 记者 | 解析器 | 笔记 |
|---|---|---|
| ARM-GCC | CLANG | |
| Androidlint | ANDROIDLINT | |
| Ansible-Later | ANSIBLELATER | 使用json格式 |
| Ansiblelint | FLAKE8 | 与-p |
| 土匪 | CLANG | 使用bandit -r examples/ -f custom -o bandit.out --msg-template "{abspath}:{line}: {severity}: {test_id}: {msg}" |
| 铛 | CLANG | |
| CPD | CPD | |
| CPPCHECK | CPPCHECK | 使用cppcheck test.cpp --output-file=cppcheck.xml --xml |
| cpplint | CPPLINT | |
| csslint | CSSLINT | |
| checkstyle | CHECKSTYLE | |
| 云形式衬里 | JUNIT | cfn-lint . -f junit --output-file report-junit.xml |
| 编码气候 | CODECLIMATE | |
| 代号 | CODENARC | |
| 掩护 | COVERITY | |
| 镖 | MACHINE | 通过dart analyze --format=machine |
| 依赖性检查 | SARIF | 使用--format SARIF |
| detekt | CHECKSTYLE | 使用--output-format xml 。 |
| DOCFX | DOCFX | |
| doxygen | CLANG | |
| ERB | CLANG | 使用erb -P -x -T '-' "${it}" | ruby -c 2>&1 >/dev/null | grep '^-' | sed -E 's/^-([a-zA-Z0-9:]+)/${filename}1 ERROR:/p' > erbfiles.out 。 |
| eslint | CHECKSTYLE | 使用format: 'checkstyle' 。 |
| 查找bug | FINDBUGS | |
| Flake8 | FLAKE8 | |
| fxcop | FXCOP | |
| 海湾合作委员会 | CLANG | |
| GHS | GHS | |
| 宪兵 | GENDARME | |
| 通用记者 | GENERIC | 将创建一个单一的违规行为,所有内容作为消息。 |
| 戈林特 | GOLINT | |
| 政府 | GOLINT | 与Golint相同的格式。 |
| Golangci-lint | CHECKSTYLE | 带有--out-format=checkstyle 。 |
| Googleerrorprone | GOOGLEERRORPRONE | |
| Hadolint | CHECKSTYLE | 使用-f checkstyle |
| IAR | IAR | 与--no_wrap_diagnostics |
| 推断 | PMD | Facebook推断。使用--pmd-xml 。 |
| jacoco | JACOCO | |
| JCReport | JCREPORT | |
| Jshint | JSLINT | 使用--reporter=jslint或带有--reporter=checkstyle解析器 |
| 朱尼特 | JUNIT | 它仅包含故障。 |
| ktlint | CHECKSTYLE | |
| Klocwork | KLOCWORK | |
| Kotlingradle | KOTLINGRADLE | 来自Kotlin Gradle插件的输出。 |
| Kotlinmaven | KOTLINMAVEN | 来自Kotlin Maven插件的输出。 |
| 皮棉 | LINT | 一种常见的XML格式,由不同的Linter使用。 |
| msbuildlog | MSBULDLOG | 使用-fileLogger -fl -flp:logfile=MyProjectOutput.log;verbosity=diagnostic .*msbuild\.log$ |
| MSCPP | MSCPP | |
| 麦凯布 | FLAKE8 | |
| mypy | MYPY | |
| Nullaway | GOOGLEERRORPRONE | 与易于使用的Google错误相同。 |
| pclint | PCLINT | 使用与Jenkins警告插件相同的输出格式的PC-LINT,此处详细介绍 |
| phpcs | CHECKSTYLE | 使用phpcs api.php --report=checkstyle 。 |
| PHPPMD | PMD | 使用phpmd api.php xml ruleset.xml 。 |
| PMD | PMD | |
| pep8 | FLAKE8 | |
| perlcritic | PERLCRITIC | |
| 坑 | PITEST | |
| 原晶 | PROTOLINT | |
| 木偶薄荷 | CLANG | 带有-log-format %{fullpath}:%{line}:%{column}: %{kind}: %{message} |
| PydocStyle | PYDOCSTYLE | |
| 碎片 | FLAKE8 | |
| 皮层 | PYLINT | pylint --output-format=parseable 。 |
| 重击器 | RESHARPER | |
| 红宝石 | CLANG | 使用rubycop -f clang file.rb |
| 萨里夫 | SARIF | v2.x. Microsoft Visual C#可以使用ErrorLog="BuildErrors.sarif,version=2"生成它。 |
| sbtscalac | SBTSCALAC | |
| Scalastyle | CHECKSTYLE | |
| semgrep | SEMGREP | 与--json 。 |
| 猿人 | SIMIAN | |
| 声纳 | SONAR | 与mvn sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json 。在7.7中删除,请参见Sonar-11670,但可以检索: curl --silent 'http://sonar-server/api/issues/search?componentKeys=unique-key&resolved=false' | jq -f sonar-report-builder.jq > sonar-report.json 。 |
| 斑点 | FINDBUGS | |
| Stylecop | STYLECOP | |
| Swiftlint | CHECKSTYLE | 使用--reporter checkstyle 。 |
| tslint | CHECKSTYLE | 使用-t checkstyle |
| Valgrind | VALGRIND | 使用--xml=yes 。 |
| XMLLINT | XMLLINT | |
| Xunit | XUNIT | 它仅包含故障。 |
| Yamllint | YAMLLINT | 与-f parsable |
| zptlint | ZPTLINT |
52名解析器和79个记者。
缺少格式?在这里打开一个问题!
这里有一个运行示例。
在构建脚本中具有以下内容将使插件运行./gradlew build 。
plugins {
id " se.bjurr.violations.violations-gradle-plugin " version " X "
}
task violations ( type : se.bjurr.violations.gradle.plugin.ViolationsTask ) {
//
// Optional config
//
maxReporterColumnWidth . set( 0 ) // 0 is disabled
maxRuleColumnWidth . set( 10 )
maxSeverityColumnWidth . set( 0 )
maxLineColumnWidth . set( 0 )
maxMessageColumnWidth . set( 50 )
codeClimateFile . set(file( ' code-climate-file.json ' )) // Will create a CodeClimate JSON report.
violationsFile . set(file( ' violations-file.json ' )) // Will create a normalized JSON report.
//
// Global configuration, remove if you dont want to report violations for
// the entire repo.
//
minSeverity . set(se . bjurr . violations . lib . model . SEVERITY . INFO ) // INFO, WARN or ERROR
detailLevel . set( se.bjurr.violations.git.ViolationsReporterDetailLevel . VERBOSE ) // PER_FILE_COMPACT, COMPACT or VERBOSE
maxViolations . set( 99999999 ) // Will fail the build if total number of found violations is higher
printViolations . set( true ) // Will print violations found in diff
//
// Diff configuration, remove if you dont want to report violations for
// files changed between specific revisions.
//
// diff-properties can be supplied with something like:
//
// ./gradlew violations -i -PdiffFrom=e4de20e -PdiffTo=HEAD
//
// And in Travis, you could add:
//
// script:
// - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./gradlew check -PdiffFrom=$TRAVIS_PULL_REQUEST_BRANCH -PdiffTo=$TRAVIS_BRANCH ; fi'
//
diffFrom . set(project . properties . diffFrom) // Can be empty (ignored), Git-commit or any Git-reference
diffTo . set(project . properties . diffTo) // Same as above
diffMinSeverity . set(se . bjurr . violations . lib . model . SEVERITY . INFO ) // INFO, WARN or ERROR
diffDetailLevel . set( se.bjurr.violations.git.ViolationsReporterDetailLevel . VERBOSE ) // PER_FILE_COMPACT, COMPACT or VERBOSE
diffMaxViolations . set( 99 ) // Will fail the build if number of violations, in the diff within from/to, is higher
diffPrintViolations . set( true ) // Will print violations found in diff
gitRepo . set(file( ' . ' )) // Where to look for Git
//
// This is mandatory regardless of if you want to report violations between
// revisions or the entire repo.
//
// Many more formats available, see: https://github.com/tomasbjerre/violations-lib
violationConfig()
.setFolder(projectDir . path)
.setParser( se.bjurr.violations.lib.reports.Parser . FINDBUGS )
.setPattern( " .*/findbugs/.* \ .xml $ " )
.setReporter( " Findbugs " )
violationConfig()
.setFolder(projectDir . path)
.setParser( se.bjurr.violations.lib.reports.Parser . PMD )
.setPattern( " .*/pmd/.* \ .xml $ " )
.setReporter( " PMD " )
}
check . finalizedBy violations