violations gradle plugin
v3.0.2
Este é um plugin gradle para violações lib. Há também um plug -in maven para isso.
| Versão | Versão Java |
|---|---|
| Versão <2.0.0 | 8 |
| 2.0.0 <= versão | 11 |
Publicado para plugins.gradle.org.
Pode analisar os resultados da análise de código estático e:
Você também pode fazer isso com uma ferramenta de linha de comando.
Um trecho da saída pode ser assim:
...
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 ║
╚════════════╧══════╧══════╧═══════╧═══════╝Exemplo de relatórios suportados estão disponíveis aqui.
Vários analisadores foram implementados. Alguns analisadores podem analisar a produção de vários repórteres .
| Repórter | Analisador | Notas |
|---|---|---|
| ARM-GCC | CLANG | |
| Androidlint | ANDROIDLINT | |
| Ansible-later | ANSIBLELATER | Com formato json |
| Ansiblelint | FLAKE8 | Com -p |
| Bandido | CLANG | Com bandit -r examples/ -f custom -o bandit.out --msg-template "{abspath}:{line}: {severity}: {test_id}: {msg}" |
| Clang | CLANG | |
| CPD | CPD | |
| Cppcheck | CPPCHECK | Com cppcheck test.cpp --output-file=cppcheck.xml --xml |
| Cpplint | CPPLINT | |
| Csslint | CSSLINT | |
| Checkstyle | CHECKSTYLE | |
| CloudFormation Linter | JUNIT | cfn-lint . -f junit --output-file report-junit.xml |
| Codeclimate | CODECLIMATE | |
| CodENARC | CODENARC | |
| Cobertura | COVERITY | |
| Dardo | MACHINE | Com dart analyze --format=machine |
| Verificação de dependência | SARIF | Usando --format SARIF |
| Detekt | CHECKSTYLE | Com --output-format xml . |
| Docfx | DOCFX | |
| Doxygen | CLANG | |
| Erb | CLANG | Com 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 | Com format: 'checkstyle' . |
| FindBugs | FINDBUGS | |
| Flake8 | FLAKE8 | |
| FXCOP | FXCOP | |
| GCC | CLANG | |
| GHS | GHS | |
| Gendarme | GENDARME | |
| Repórter genérico | GENERIC | Criará uma única violação com todo o conteúdo como mensagem. |
| Golint | GOLINT | |
| Govet | GOLINT | Mesmo formato que Golint. |
| Golangci-lint | CHECKSTYLE | Com --out-format=checkstyle . |
| GoogleErrorProne | GOOGLEERRORPRONE | |
| Hadolint | CHECKSTYLE | Com -f checkstyle |
| IAR | IAR | Com --no_wrap_diagnostics |
| Inferir | PMD | Facebook inferir. Com --pmd-xml . |
| Jacoco | JACOCO | |
| Jcreport | JCREPORT | |
| Jshint | JSLINT | Com --reporter=jslint ou o analisador de estilo de seleção com --reporter=checkstyle |
| Junit | JUNIT | Ele contém apenas as falhas. |
| Ktlint | CHECKSTYLE | |
| Klocwork | KLOCWORK | |
| Kotlingradle | KOTLINGRADLE | Saída do plug -in Kotlin Gradle. |
| KotlinMaven | KOTLINMAVEN | Saída do plug -in Kotlin Maven. |
| Fia | LINT | Um formato XML comum, usado por diferentes linhentes. |
| Msbuildlog | MSBULDLOG | -fl -flp:logfile=MyProjectOutput.log;verbosity=diagnostic -fileLogger uso .*msbuild\.log$ |
| MSCPP | MSCPP | |
| McCabe | FLAKE8 | |
| Mypy | MYPY | |
| Nullaway | GOOGLEERRORPRONE | Mesmo formato que o erro do Google propenso. |
| PCLINT | PCLINT | PC-LINT usando o mesmo formato de saída que o plugin Jenkins Warnings, detalhes aqui |
| PHPCs | CHECKSTYLE | Com phpcs api.php --report=checkstyle . |
| Phppmd | PMD | Com phpmd api.php xml ruleset.xml . |
| PMD | PMD | |
| Pep8 | FLAKE8 | |
| Perlcrítico | PERLCRITIC | |
| Pitest | PITEST | |
| Protolint | PROTOLINT | |
| Puppet-lint | CLANG | Com -log-format %{fullpath}:%{line}:%{column}: %{kind}: %{message} |
| Pydocstyle | PYDOCSTYLE | |
| Pyflakes | FLAKE8 | |
| Pylint | PYLINT | Com pylint --output-format=parseable . |
| Resharper | RESHARPER | |
| Rubycop | CLANG | Com rubycop -f clang file.rb |
| Sarif | SARIF | v2.x. Microsoft Visual C# pode gerá -lo com ErrorLog="BuildErrors.sarif,version=2" . |
| SBTSCALAC | SBTSCALAC | |
| Scalastyle | CHECKSTYLE | |
| Sêmep | SEMGREP | Com --json . |
| Simian | SIMIAN | |
| Sonar | SONAR | Com mvn sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json . Removido em 7.7, consulte Sonar-11670, mas pode ser recuperado com: curl --silent 'http://sonar-server/api/issues/search?componentKeys=unique-key&resolved=false' | jq -f sonar-report-builder.jq > sonar-report.json . |
| Spotbugs | FINDBUGS | |
| Stylecop | STYLECOP | |
| Swiftlint | CHECKSTYLE | Com --reporter checkstyle . |
| Tslint | CHECKSTYLE | Com -t checkstyle |
| Valgrind | VALGRIND | Com --xml=yes . |
| Xmllint | XMLLINT | |
| Xunit | XUNIT | Ele contém apenas as falhas. |
| Yamllint | YAMLLINT | Com -f parsable |
| Zptlint | ZPTLINT |
52 analisadores e 79 repórteres.
Faltando um formato? Abra um problema aqui!
Há um exemplo em execução aqui.
Ter o seguinte no script de construção fará com que o plug -in seja executado com ./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