From c635e428155f46470d155f9279c4159991d7b0fd Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 3 Feb 2023 13:25:20 -0800 Subject: [PATCH] Cleanup GradleLint task configurers and fix POM generation --- build.gradle | 6 +- gradle.lockfile | 39 ++++--- ...etween5And7LintPluginTaskConfigurer.groovy | 31 ----- .../lint/plugin/GradleLintPlugin.groovy | 12 +- ...egacyGradleLintPluginTaskConfigurer.groovy | 110 ------------------ ...groovy => LintPluginTaskConfigurer.groovy} | 2 +- 6 files changed, 26 insertions(+), 174 deletions(-) delete mode 100644 src/main/groovy/com/netflix/nebula/lint/plugin/GradleBetween5And7LintPluginTaskConfigurer.groovy delete mode 100644 src/main/groovy/com/netflix/nebula/lint/plugin/LegacyGradleLintPluginTaskConfigurer.groovy rename src/main/groovy/com/netflix/nebula/lint/plugin/{Gradle7AndHigherLintPluginTaskConfigurer.groovy => LintPluginTaskConfigurer.groovy} (90%) diff --git a/build.gradle b/build.gradle index 4c0ee92d..2f639555 100644 --- a/build.gradle +++ b/build.gradle @@ -58,9 +58,9 @@ configurations.all { dependencies { compileOnly 'dev.gradleplugins:gradle-api:7.6' - api 'com.netflix.nebula:nebula-gradle-interop:latest.release' - api 'org.apache.maven:maven-model-builder:3.8.3' - api 'org.codehaus.gpars:gpars:1.2.1' + shadow 'com.netflix.nebula:nebula-gradle-interop:latest.release' + shadow 'org.apache.maven:maven-model-builder:3.8.3' + shadow 'org.codehaus.gpars:gpars:1.2.1' plugin 'com.google.guava:guava:19.0' plugin('org.ow2.asm:asm:9.+') { version { diff --git a/gradle.lockfile b/gradle.lockfile index adb46a57..53af637e 100644 --- a/gradle.lockfile +++ b/gradle.lockfile @@ -15,7 +15,8 @@ com.jcraft:jsch:0.1.54=integTestRuntimeClasspath,testRuntimeClasspath com.jcraft:jzlib:1.1.2=integTestRuntimeClasspath,testRuntimeClasspath com.netflix.nebula:gradle-contacts-plugin:7.0.0=integTestRuntimeClasspath,testRuntimeClasspath com.netflix.nebula:gradle-info-plugin:12.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.netflix.nebula:nebula-gradle-interop:2.1.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.netflix.nebula:nebula-gradle-interop:2.0.0=integTestRuntimeClasspath,testRuntimeClasspath +com.netflix.nebula:nebula-gradle-interop:2.1.1=compileClasspath,shadow com.netflix.nebula:nebula-test:10.3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath com.perforce:p4java:2015.2.1365273=integTestRuntimeClasspath,testRuntimeClasspath com.trilead:trilead-ssh2:1.0.0-build220=integTestRuntimeClasspath,testRuntimeClasspath @@ -24,41 +25,41 @@ commons-lang:commons-lang:2.6=compileClasspath,runtimeClasspath,testCompileClass commons-logging:commons-logging:1.2=integTestRuntimeClasspath,testRuntimeClasspath de.regnis.q.sequence:sequence-library:1.0.3=integTestRuntimeClasspath,testRuntimeClasspath dev.gradleplugins:gradle-api:7.6=compileClasspath -javax.inject:javax.inject:1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +javax.inject:javax.inject:1=compileClasspath,shadow joda-time:joda-time:2.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath junit:junit:4.13.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath net.java.dev.jna:jna-platform:5.7.0=integTestRuntimeClasspath,testRuntimeClasspath net.java.dev.jna:jna:5.7.0=integTestRuntimeClasspath,testRuntimeClasspath net.java.dev.jna:platform:3.4.0=integTestRuntimeClasspath,testRuntimeClasspath org.antlr:antlr-runtime:3.4=integTestRuntimeClasspath,testRuntimeClasspath -org.apache.commons:commons-lang3:3.8.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.apache.commons:commons-lang3:3.8.1=compileClasspath,shadow org.apache.httpcomponents:httpclient:4.5.2=integTestRuntimeClasspath,testRuntimeClasspath org.apache.httpcomponents:httpcore:4.4.4=integTestRuntimeClasspath,testRuntimeClasspath -org.apache.maven:maven-artifact:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.apache.maven:maven-builder-support:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.apache.maven:maven-model-builder:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.apache.maven:maven-model:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.apache.maven:maven-artifact:3.8.3=compileClasspath,shadow +org.apache.maven:maven-builder-support:3.8.3=compileClasspath,shadow +org.apache.maven:maven-model-builder:3.8.3=compileClasspath,shadow +org.apache.maven:maven-model:3.8.3=compileClasspath,shadow org.apiguardian:apiguardian-api:1.1.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.codehaus.gpars:gpars:1.2.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.codehaus.gpars:gpars:1.2.1=compileClasspath,shadow org.codehaus.groovy:groovy:3.0.13=compileClasspath org.codehaus.groovy:groovy:3.0.9=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.codehaus.jsr166-mirror:jsr166y:1.7.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.codehaus.plexus:plexus-interpolation:1.26=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.codehaus.plexus:plexus-utils:3.3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.codehaus.jsr166-mirror:jsr166y:1.7.0=compileClasspath,shadow +org.codehaus.plexus:plexus-interpolation:1.26=compileClasspath,shadow +org.codehaus.plexus:plexus-utils:3.3.0=compileClasspath,shadow org.codenarc:CodeNarc:2.0.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.eclipse.jdt:core:3.1.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.eclipse.jgit:org.eclipse.jgit:5.0.1.201806211838-r=compileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.eclipse.sisu:org.eclipse.sisu.inject:0.3.5=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.eclipse.sisu:org.eclipse.sisu.inject:0.3.5=compileClasspath,shadow org.hamcrest:hamcrest-core:1.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.hamcrest:hamcrest:2.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains.kotlin:kotlin-stdlib:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath +org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,shadow,testCompileClasspath,testRuntimeClasspath org.junit.platform:junit-platform-commons:1.8.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.junit.platform:junit-platform-engine:1.8.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.multiverse:multiverse-core:0.7.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.multiverse:multiverse-core:0.7.0=compileClasspath,shadow org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath org.opentest4j:opentest4j:1.2.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.ow2.asm:asm-commons:9.4=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath @@ -72,4 +73,4 @@ org.spockframework:spock-core:2.1-M2-groovy-3.0=compileClasspath,integTestCompil org.spockframework:spock-junit4:2.1-M2-groovy-3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.tmatesoft.sqljet:sqljet:1.1.10=integTestRuntimeClasspath,testRuntimeClasspath org.tmatesoft.svnkit:svnkit:1.8.12=integTestRuntimeClasspath,testRuntimeClasspath -empty=annotationProcessor,compile,integTestAnnotationProcessor,integTestCompile,integTestCompileOnly,integTestRuntime,runtime,shadow,testAnnotationProcessor,testCompile,testCompileOnly,testRuntime +empty=annotationProcessor,compile,integTestAnnotationProcessor,integTestCompile,integTestCompileOnly,integTestRuntime,runtime,testAnnotationProcessor,testCompile,testCompileOnly,testRuntime diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleBetween5And7LintPluginTaskConfigurer.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleBetween5And7LintPluginTaskConfigurer.groovy deleted file mode 100644 index dac937a2..00000000 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleBetween5And7LintPluginTaskConfigurer.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 GradleBetween5And7LintPluginTaskConfigurer extends GradleLintPluginTaskConfigurer{ - @Override - Action configureReportAction(Project project, GradleLintExtension extension) { - new Action() { - @Override - void execute(GradleLintReportTask gradleLintReportTask) { - gradleLintReportTask.reportOnlyFixableViolations = 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.buildDir, "reports/gradleLint/${project.name}.$fileSuffix") - } - } - } - } - } - } -} 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 08a8580e..ee93ac36 100644 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy +++ b/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy @@ -15,7 +15,7 @@ */ 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 @@ -31,15 +31,7 @@ class GradleLintPlugin implements Plugin { } LintRuleRegistry.classLoader = getClass().classLoader - - // TODO: we need to retire this once we have folks in Gradle 7.x+ - if (GradleKt.versionCompareTo(project.gradle, '7.1') >= 0) { - new Gradle7AndHigherLintPluginTaskConfigurer().configure(project) - } else if (GradleKt.versionCompareTo(project.gradle, '5.0') >= 0) { - new GradleBetween5And7LintPluginTaskConfigurer().configure(project) - } else { - new LegacyGradleLintPluginTaskConfigurer().configure(project) - } + new LintPluginTaskConfigurer().configure(project) } protected static abstract class LintListener extends BuildAdapter implements TaskExecutionGraphListener {} diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/LegacyGradleLintPluginTaskConfigurer.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/LegacyGradleLintPluginTaskConfigurer.groovy deleted file mode 100644 index 46f54780..00000000 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/LegacyGradleLintPluginTaskConfigurer.groovy +++ /dev/null @@ -1,110 +0,0 @@ -package com.netflix.nebula.lint.plugin - -import org.gradle.BuildResult -import org.gradle.api.Action -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.execution.TaskExecutionGraph -import org.gradle.api.plugins.JavaBasePlugin -import org.gradle.api.tasks.compile.AbstractCompile - -/** - * Configure gradle lint tasks for gradle versions older than 5. - */ -class LegacyGradleLintPluginTaskConfigurer extends AbstractLintPluginTaskConfigurer { - - @Override - void createTasks(Project project, GradleLintExtension lintExt) { - if (project.rootProject == project) { - def autoLintTask = project.tasks.create(AUTO_LINT_GRADLE, LintGradleTask) - autoLintTask.listeners = lintExt.listeners - - def manualLintTask = project.tasks.create(LINT_GRADLE, LintGradleTask) - manualLintTask.group = LINT_GROUP - manualLintTask.failOnWarning = true - - def criticalLintTask = project.tasks.create(CRITICAL_LINT_GRADLE, LintGradleTask) - criticalLintTask.group = LINT_GROUP - criticalLintTask.onlyCriticalRules = true - - def fixTask = project.tasks.create(FIX_GRADLE_LINT, FixGradleLintTask) - fixTask.userDefinedListeners = lintExt.listeners - - def fixTask2 = project.tasks.create(FIX_LINT_GRADLE, FixGradleLintTask) - fixTask2.userDefinedListeners = lintExt.listeners - - List lintTasks = [fixTask, fixTask2, manualLintTask, autoLintTask] - - configureLegacyAutoLint(autoLintTask, project, lintExt, lintTasks, criticalLintTask) - - } - - configureReportTask(project, lintExt) - } - - - @Override - void wireJavaPlugin(Project project) { - project.plugins.withType(JavaBasePlugin) { - project.tasks.withType(AbstractCompile) { task -> - project.rootProject.tasks.getByName(FIX_GRADLE_LINT).dependsOn(task) - project.rootProject.tasks.getByName(LINT_GRADLE).dependsOn(task) - project.rootProject.tasks.getByName(FIX_LINT_GRADLE).dependsOn(task) - } - } - } - - /** - * Configures autoLint for build in old versions of Gradle - * This approach is not valid on new Gradle versions since lint can do configuration resolution and doing this in BuildListener is now considered un-managed thread and bad practice - * @param autoLintTask - * @param project - * @param lintExt - * @param lintTasks - * @param criticalLintTask - */ - private void configureLegacyAutoLint(LintGradleTask autoLintTask, Project project, GradleLintExtension lintExt, List lintTasks, Task criticalLintTask) { - project.gradle.addListener(new GradleLintPlugin.LintListener() { - List allTasks - - @Override - void graphPopulated(TaskExecutionGraph graph) { - allTasks = graph.allTasks - } - - @Override - void buildFinished(BuildResult result) { - def hasFailedTask = !lintExt.autoLintAfterFailure && allTasks.any { it.state.failure != null } - if(hasFailedTask || !hasValidTaskConfiguration(project, lintExt) || - hasExplicitLintTask(allTasks, lintTasks) || - hasFailedCriticalLintTask(allTasks, criticalLintTask)) { - return - } - autoLintTask.lint() - } - }) - } - - private void configureReportTask(Project project, GradleLintExtension extension) { - def task = project.tasks.create(GENERATE_GRADLE_LINT_REPORT, GradleLintReportTask, configureReportAction(project, extension)) - } - - @Override - Action configureReportAction(Project project, GradleLintExtension extension) { - new Action() { - @Override - void execute(GradleLintReportTask gradleLintReportTask) { - gradleLintReportTask.reportOnlyFixableViolations = 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.buildDir, "reports/gradleLint/${project.name}.$fileSuffix") - } - } - } - } - } - } -} diff --git a/src/main/groovy/com/netflix/nebula/lint/plugin/Gradle7AndHigherLintPluginTaskConfigurer.groovy b/src/main/groovy/com/netflix/nebula/lint/plugin/LintPluginTaskConfigurer.groovy similarity index 90% rename from src/main/groovy/com/netflix/nebula/lint/plugin/Gradle7AndHigherLintPluginTaskConfigurer.groovy rename to src/main/groovy/com/netflix/nebula/lint/plugin/LintPluginTaskConfigurer.groovy index cc971763..22ea210b 100644 --- a/src/main/groovy/com/netflix/nebula/lint/plugin/Gradle7AndHigherLintPluginTaskConfigurer.groovy +++ b/src/main/groovy/com/netflix/nebula/lint/plugin/LintPluginTaskConfigurer.groovy @@ -3,7 +3,7 @@ package com.netflix.nebula.lint.plugin import org.gradle.api.Action import org.gradle.api.Project -class Gradle7AndHigherLintPluginTaskConfigurer extends GradleBetween5And7LintPluginTaskConfigurer { +class LintPluginTaskConfigurer extends GradleLintPluginTaskConfigurer { @Override Action configureReportAction(Project project, GradleLintExtension extension) { new Action() {