Skip to content

Commit

Permalink
breaking: enabling lazy loading of all configuration (refs #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 9, 2024
1 parent c5ea74d commit ad35cda
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 178 deletions.
139 changes: 66 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ Published to [plugins.gradle.org](https://plugins.gradle.org/plugin/se.bjurr.vio

It can parse results from static code analysis and:

* Report violations in the build log.
* Optionally fail the build depending on violations found.
- Report violations in the build log.
- Optionally fail the build depending on violations found.

You can also do this with a [command line tool](https://www.npmjs.com/package/violations-command-line).

A snippet of the output may look like this:
```

```sh
...
se/bjurr/violations/lib/example/OtherClass.java
╔══════════╤════════════╤══════════╤══════╤════════════════════════════════════════════════════╗
Expand Down Expand Up @@ -156,84 +157,76 @@ A number of **parsers** have been implemented. Some **parsers** can parse output
Missing a format? Open an issue [here](https://github.com/tomasbjerre/violations-lib/issues)!
## Usage
There is a running example [here](https://github.com/tomasbjerre/violations-gradle-plugin/tree/master/violations-gradle-plugin-example).
Having the following in the build script will make the plugin run with `./gradlew build`.
```gradle
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
jcenter()
}
dependencies {
classpath "se.bjurr.violations:violations-gradle-plugin:X"
}
}
apply plugin: "se.bjurr.violations.violations-gradle-plugin"
apply plugin: 'findbugs'
findbugs {
ignoreFailures = true
effort = "max"
showProgress = true
reportLevel = "low"
plugins {
id "se.bjurr.violations.violations-gradle-plugin" version "X"
}
task violations(type: se.bjurr.violations.gradle.plugin.ViolationsTask) {
//
// Optional config
//
maxReporterColumnWidth = 0 // 0 means "no limit"
maxRuleColumnWidth = 60
maxSeverityColumnWidth = 0
maxLineColumnWidth = 0
maxMessageColumnWidth = 50
codeClimateFile = file('gl-code-quality-report.json') // Will create a CodeClimate JSON report.
violationsFile = 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 = 'INFO' // INFO, WARN or ERROR
detailLevel = 'VERBOSE' // PER_FILE_COMPACT, COMPACT or VERBOSE
maxViolations = 99999999 // Will fail the build if total number of found violations is higher
printViolations = 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 -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 = project.properties.diffFrom // Can be empty (ignored), Git-commit or any Git-reference
diffTo = project.properties.diffTo // Same as above
diffMinSeverity = 'INFO' // INFO, WARN or ERROR
diffDetailLevel = 'VERBOSE' // PER_FILE_COMPACT, COMPACT or VERBOSE
diffMaxViolations = 99 // Will fail the build if number of violations, in the diff within from/to, is higher
diffPrintViolations = true // Will print violations found in diff
gitRepo = 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
violations = [
["FINDBUGS", buildDir.path, ".*/findbugs/.*\\.xml\$", "Findbugs"]
]
//
// 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")
violationConfig()
}
check.finalizedBy violations
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
#Sat Nov 09 05:57:23 CET 2024
#Sat Nov 09 06:33:49 CET 2024
description=Find report files from static code analysis, present and optionally fail the build.
group=se.bjurr.violations
implementationClass=se.bjurr.violations.gradle.plugin.ViolationsGradlePlugin
Expand All @@ -9,4 +9,4 @@ sourceCompatibility=11
stripGradlePluginSuffix=false
tags=violation,static code analysis,Checkstyle,CPPLint,CPPCheck,CSSLint,Findbugs,Flake8,PyLint,Pep8,Mccabe,PyFlakes,JSHint,Lint,PerlCritic,PMD,ReSharper,XMLLint
targetCompatibility=11
version=2.3.1
version=2.3.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package se.bjurr.violations.gradle.plugin;

import java.util.Objects;
import se.bjurr.violations.lib.reports.Parser;

public class ViolationConfig {
private String reporter;
private Parser parser;
private String folder;
private String pattern;

public ViolationConfig() {}

public String getReporter() {
return this.reporter;
}

public ViolationConfig setReporter(final String reporter) {
this.reporter = reporter;
return this;
}

public Parser getParser() {
return this.parser;
}

public ViolationConfig setParser(final Parser parser) {
this.parser = parser;
return this;
}

public String getFolder() {
return this.folder;
}

public ViolationConfig setFolder(final String folder) {
this.folder = folder;
return this;
}

public String getPattern() {
return this.pattern;
}

public ViolationConfig setPattern(final String pattern) {
this.pattern = pattern;
return this;
}

@Override
public int hashCode() {
return Objects.hash(this.folder, this.parser, this.pattern, this.reporter);
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final ViolationConfig other = (ViolationConfig) obj;
return Objects.equals(this.folder, other.folder)
&& this.parser == other.parser
&& Objects.equals(this.pattern, other.pattern)
&& Objects.equals(this.reporter, other.reporter);
}

@Override
public String toString() {
return "ViolationConfig [reporter="
+ this.reporter
+ ", parser="
+ this.parser
+ ", folder="
+ this.folder
+ ", pattern="
+ this.pattern
+ "]";
}
}
Loading

0 comments on commit ad35cda

Please sign in to comment.