Skip to content

Commit

Permalink
fix: allow lazy loading of maxViolations (refs #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 9, 2024
1 parent 67f1d0f commit 0362591
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
./gradlew clean cE eclipse build publishToMavenLocal || exit 1
./gradlew publishToMavenLocal -Pversion=latest-SNAPSHOT || exit 1
cd violations-gradle-plugin-example

./gradlew violations violationsMaxAsProperty
./gradlew violations
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
#Thu Nov 07 16:53:40 CET 2024
#Sat Nov 09 05:57:23 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.0
version=2.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ public class ViolationsTask extends DefaultTask {
public File violationsFile;
public ViolationsLogger violationsLogger;

public void setMaxViolations(final Integer maxViolations) {
this.maxViolations.set(maxViolations);
}

@TaskAction
public void violationsPluginTasks() throws Exception {
this.violationsLogger =
Expand Down
28 changes: 17 additions & 11 deletions violations-gradle-plugin-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,23 @@ task violations(type: se.bjurr.violations.gradle.plugin.ViolationsTask) {
]
}

/**
* Test lazy loaded value.
*/
interface ViolationsTestExtension {
Property<Integer> getMaxViolations()
}

task violationsMaxAsProperty(type: se.bjurr.violations.gradle.plugin.ViolationsTask) {
// Lazy loading
maxViolations = 99999999
def extension = project.extensions.create("violationsTestExtension", ViolationsTestExtension)
extension.maxViolations.convention(Integer.MAX_VALUE)

violations = [
[
"FINDBUGS",
projectDir.path,
".*/findbugs/.*\\.xml\$",
"Findbugs"
]
]
task violationsWithTestExtension(type: se.bjurr.violations.gradle.plugin.ViolationsTask) {
maxViolations = extension.maxViolations.get()
}

/**
* Run all tests on build
*/
project.tasks.withType(se.bjurr.violations.gradle.plugin.ViolationsTask) { vt ->
build.dependsOn vt
}

0 comments on commit 0362591

Please sign in to comment.