Skip to content

Commit

Permalink
GradleLintReportTask.groovy: use lazy apis
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Nov 14, 2023
1 parent f7535b1 commit e3bc4cd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ java {
}

tasks.withType(Test) {
maxHeapSize = '512m'
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(System.getenv("JDK_VERSION_FOR_TESTS")?.toInteger() ?: 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.plugins.quality.CodeNarcReports
import org.gradle.api.plugins.quality.internal.CodeNarcReportsImpl
import org.gradle.api.provider.Property
import org.gradle.api.reporting.Report
import org.gradle.api.reporting.Reporting
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.VerificationTask
Expand All @@ -48,20 +50,12 @@ abstract class GradleLintReportTask extends DefaultTask implements VerificationT

@Nested
private final CodeNarcReportsImpl reports

@Input
boolean reportOnlyFixableViolations
abstract Property<Boolean> getReportOnlyFixableViolations()

GradleLintReportTask() {
CodeNarcReportsImpl codeNarcReports
if (GradleVersion.version(project.gradle.gradleVersion).compareTo(GradleVersion.version('4.4.1')) > 0) {
codeNarcReports = project.objects.newInstance(CodeNarcReportsImpl.class, this)
} else {
//TODO: remove this once we don't have customers in Gradle 4.1
DeprecationLoggerUtils.whileDisabled() {
codeNarcReports = instantiator.newInstance(CodeNarcReportsImpl, this)
}
}
reports = codeNarcReports
reports = project.objects.newInstance(CodeNarcReportsImpl.class, this)
outputs.upToDateWhen { false }
group = 'lint'
}
Expand Down Expand Up @@ -133,7 +127,7 @@ abstract class GradleLintReportTask extends DefaultTask implements VerificationT
}

void filterOnlyFixableViolations(Results results) {
if (reportOnlyFixableViolations) {
if (reportOnlyFixableViolations.isPresent() && reportOnlyFixableViolations.get()) {
new GradleLintPatchAction(project).lintFinished(results.violations)
List<Violation> toRemove = results.violations.findAll {
it.fixes.size() == 0 || it.fixes.any { it.reasonForNotFixing != null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GradleSevenZeroLintPluginTaskConfigurer extends GradleLintPluginTaskConfig
new Action<GradleLintReportTask>() {
@Override
void execute(GradleLintReportTask gradleLintReportTask) {
gradleLintReportTask.reportOnlyFixableViolations = getReportOnlyFixableViolations(project, extension)
gradleLintReportTask.reportOnlyFixableViolations.set(getReportOnlyFixableViolations(project, extension))
gradleLintReportTask.reports.all { report ->
report.conventionMapping.with {
enabled = { report.name == getReportFormat(project, extension) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LintPluginTaskConfigurer extends GradleLintPluginTaskConfigurer {
new Action<GradleLintReportTask>() {
@Override
void execute(GradleLintReportTask gradleLintReportTask) {
gradleLintReportTask.reportOnlyFixableViolations = getReportOnlyFixableViolations(project, extension)
gradleLintReportTask.reportOnlyFixableViolations.set(getReportOnlyFixableViolations(project, extension))
gradleLintReportTask.reports.all { report ->
def fileSuffix = report.name == 'text' ? 'txt' : report.name
report.conventionMapping.with {
Expand Down

0 comments on commit e3bc4cd

Please sign in to comment.