diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy index de874b77..3765c111 100644 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy +++ b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 Netflix, Inc. + * Copyright 2015-2024 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,9 @@ package com.netflix.nebula.lint.plugin import com.netflix.nebula.interop.GradleKt -import org.gradle.BuildAdapter import org.gradle.api.BuildCancelledException import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.execution.TaskExecutionGraphListener class GradleLintPlugin implements Plugin { @Override @@ -31,14 +29,9 @@ class GradleLintPlugin implements Plugin { } LintRuleRegistry.classLoader = getClass().classLoader - - // TODO: we need to retire this once we have folks in Gradle 7.1+ - if (GradleKt.versionCompareTo(project.gradle, '7.1') >= 0) { - new GradleSevenOneAndHigherLintPluginTaskConfigurer().configure(project) - } else if (GradleKt.versionCompareTo(project.gradle, '7.0') >= 0) { - new GradleSevenZeroLintPluginTaskConfigurer().configure(project) + if (GradleKt.versionLessThan(project.gradle, '7.1')) { + throw new BuildCancelledException("Gradle Lint Plugin requires Gradle 7.1 or newer.") } + new GradleLintPluginTaskConfigurer().configure(project) } - - protected static abstract class LintListener extends BuildAdapter implements TaskExecutionGraphListener {} } diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginTaskConfigurer.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginTaskConfigurer.groovy index 7292b5d1..fd3f5cf2 100644 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginTaskConfigurer.groovy +++ b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPluginTaskConfigurer.groovy @@ -1,3 +1,18 @@ +/* + * Copyright 2015-2024 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netflix.nebula.lint.plugin import org.gradle.api.Action @@ -9,8 +24,25 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.TaskState import org.gradle.api.tasks.compile.AbstractCompile -abstract class GradleLintPluginTaskConfigurer extends AbstractLintPluginTaskConfigurer { - abstract Action configureReportAction(Project project, GradleLintExtension extension) +class GradleLintPluginTaskConfigurer extends AbstractLintPluginTaskConfigurer { + @Override + Action configureReportAction(Project project, GradleLintExtension extension) { + new Action() { + @Override + void execute(GradleLintReportTask gradleLintReportTask) { + gradleLintReportTask.reportOnlyFixableViolations = getReportOnlyFixableViolations(project, extension) + gradleLintReportTask.notCompatibleWithConfigurationCache("Gradle Lint Plugin is not compatible with configuration cache because it requires project model") + + gradleLintReportTask.reports.all { report -> + def fileSuffix = report.name == 'text' ? 'txt' : report.name + report.conventionMapping.with { + required.set(report.name == getReportFormat(project, extension)) + outputLocation.set(project.layout.buildDirectory.file("reports/gradleLint/${project.name}.$fileSuffix")) + } + } + } + } + } @Override void createTasks(Project project, GradleLintExtension lintExt) { diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleSevenOneAndHigherLintPluginTaskConfigurer.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleSevenOneAndHigherLintPluginTaskConfigurer.groovy deleted file mode 100644 index af261869..00000000 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleSevenOneAndHigherLintPluginTaskConfigurer.groovy +++ /dev/null @@ -1,25 +0,0 @@ -package com.netflix.nebula.lint.plugin - -import org.gradle.api.Action -import org.gradle.api.Project - -class GradleSevenOneAndHigherLintPluginTaskConfigurer extends GradleSevenZeroLintPluginTaskConfigurer { - @Override - Action configureReportAction(Project project, GradleLintExtension extension) { - new Action() { - @Override - void execute(GradleLintReportTask gradleLintReportTask) { - gradleLintReportTask.reportOnlyFixableViolations = getReportOnlyFixableViolations(project, extension) - gradleLintReportTask.notCompatibleWithConfigurationCache("Gradle Lint Plugin is not compatible with configuration cache because it requires project model") - - gradleLintReportTask.reports.all { report -> - def fileSuffix = report.name == 'text' ? 'txt' : report.name - report.conventionMapping.with { - required.set(report.name == getReportFormat(project, extension)) - outputLocation.set(project.layout.buildDirectory.file("reports/gradleLint/${project.name}.$fileSuffix")) - } - } - } - } - } -} diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleSevenZeroLintPluginTaskConfigurer.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleSevenZeroLintPluginTaskConfigurer.groovy deleted file mode 100644 index f5901b96..00000000 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleSevenZeroLintPluginTaskConfigurer.groovy +++ /dev/null @@ -1,31 +0,0 @@ -package com.netflix.nebula.lint.plugin - -import org.gradle.api.Action -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.execution.TaskExecutionListener -import org.gradle.api.plugins.JavaBasePlugin -import org.gradle.api.tasks.TaskProvider -import org.gradle.api.tasks.TaskState -import org.gradle.api.tasks.compile.AbstractCompile - -class GradleSevenZeroLintPluginTaskConfigurer extends GradleLintPluginTaskConfigurer{ - @Override - Action configureReportAction(Project project, GradleLintExtension extension) { - new Action() { - @Override - void execute(GradleLintReportTask gradleLintReportTask) { - gradleLintReportTask.reportOnlyFixableViolations.set(getReportOnlyFixableViolations(project, extension)) - gradleLintReportTask.reports.all { report -> - report.conventionMapping.with { - enabled = { report.name == getReportFormat(project, extension) } - destination = { - def fileSuffix = report.name == 'text' ? 'txt' : report.name - new File(project.layout.buildDirectory.asFile.get(), "reports/gradleLint/${project.name}.$fileSuffix") - } - } - } - } - } - } -} diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/LintPluginTaskConfigurer.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/LintPluginTaskConfigurer.groovy deleted file mode 100644 index 514fa3ad..00000000 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/LintPluginTaskConfigurer.groovy +++ /dev/null @@ -1,23 +0,0 @@ -package com.netflix.nebula.lint.plugin - -import org.gradle.api.Action -import org.gradle.api.Project - -class LintPluginTaskConfigurer extends GradleLintPluginTaskConfigurer { - @Override - Action configureReportAction(Project project, GradleLintExtension extension) { - new Action() { - @Override - void execute(GradleLintReportTask gradleLintReportTask) { - gradleLintReportTask.reportOnlyFixableViolations.set(getReportOnlyFixableViolations(project, extension)) - gradleLintReportTask.reports.all { report -> - def fileSuffix = report.name == 'text' ? 'txt' : report.name - report.conventionMapping.with { - required.set(report.name == getReportFormat(project, extension)) - outputLocation.set(project.layout.buildDirectory.file("reports/gradleLint/${project.name}.$fileSuffix")) - } - } - } - } - } -}