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