From bf5fe995006346d5d4bf7345a81530f932cc0ca6 Mon Sep 17 00:00:00 2001 From: Callum Rogers Date: Tue, 12 Nov 2024 13:26:15 +0000 Subject: [PATCH] Support errorprone being enabled by setting `com.palantir.baseline-error-prone.disable=false` (#17) Ensure we match the behaviour of `com.palantir.baseline-error-prone.disable` from baseline. --- changelog/@unreleased/pr-17.v2.yml | 6 ++++++ .../SuppressibleErrorPronePlugin.java | 21 ++++++++++++------- ...ibleErrorPronePluginIntegrationTest.groovy | 8 +++++-- 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 changelog/@unreleased/pr-17.v2.yml diff --git a/changelog/@unreleased/pr-17.v2.yml b/changelog/@unreleased/pr-17.v2.yml new file mode 100644 index 0000000..c6a503a --- /dev/null +++ b/changelog/@unreleased/pr-17.v2.yml @@ -0,0 +1,6 @@ +type: fix +fix: + description: Ensure we match the behaviour of `com.palantir.baseline-error-prone.disable` + from baseline. + links: + - https://github.com/palantir/suppressible-error-prone/pull/17 diff --git a/gradle-suppressible-error-prone/src/main/java/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePlugin.java b/gradle-suppressible-error-prone/src/main/java/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePlugin.java index f5f11cd..e2d8494 100644 --- a/gradle-suppressible-error-prone/src/main/java/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePlugin.java +++ b/gradle-suppressible-error-prone/src/main/java/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePlugin.java @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; import net.ltgt.gradle.errorprone.CheckSeverity; @@ -40,10 +39,10 @@ public final class SuppressibleErrorPronePlugin implements Plugin { private static final String SUPPRESS_STAGE_ONE = "errorProneSuppressStage1"; private static final String SUPPRESS_STAGE_TWO = "errorProneSuppressStage2"; private static final String ERROR_PRONE_APPLY = "errorProneApply"; - private static final Set ERROR_PRONE_DISABLE = Set.of( - "errorProneDisable", - // This is only here for backcompat from when all the errorprone code lived in baseline - "com.palantir.baseline-error-prone.disable"); + private static final String ERROR_PRONE_DISABLE = "errorProneDisable"; + + // This is only here for backcompat from when all the errorprone code lived in baseline + private static final String ERROR_PRONE_BASELINE_DISABLE = "com.palantir.baseline-error-prone.disable"; @Override public void apply(Project project) { @@ -166,8 +165,11 @@ private void setupErrorProneOptions( JavaCompile javaCompile, ErrorProneOptions errorProneOptions) { - errorProneOptions.getEnabled().set(project.provider(() -> ERROR_PRONE_DISABLE.stream() - .noneMatch(project::hasProperty))); + errorProneOptions.getEnabled().set(project.provider(() -> { + boolean newDisable = project.hasProperty(ERROR_PRONE_DISABLE); + boolean oldDisable = isDisabledViaLegacyBaselineProperty(project); + return !(newDisable || oldDisable); + })); // This doesn't seem to do what you'd expect: disabling the checks in the generated code. But it was enabled // when this code lived in baseline, so we'll keep it enabled. @@ -285,4 +287,9 @@ static String excludedPathsRegex() { // language=RegExp return ".*/(build|generated_.*[sS]rc|src/generated.*)/.*"; } + + private static boolean isDisabledViaLegacyBaselineProperty(Project project) { + Object disable = project.findProperty(ERROR_PRONE_BASELINE_DISABLE); + return disable != null && !disable.equals("false"); + } } diff --git a/gradle-suppressible-error-prone/src/test/groovy/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePluginIntegrationTest.groovy b/gradle-suppressible-error-prone/src/test/groovy/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePluginIntegrationTest.groovy index 06e84f4..2eb8c34 100644 --- a/gradle-suppressible-error-prone/src/test/groovy/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePluginIntegrationTest.groovy +++ b/gradle-suppressible-error-prone/src/test/groovy/com/palantir/gradle/suppressibleerrorprone/SuppressibleErrorPronePluginIntegrationTest.groovy @@ -449,7 +449,7 @@ class SuppressibleErrorPronePluginIntegrationTest extends IntegrationSpec { } def 'can disable errorprone using property'() { - when: + when: 'there is java code some that will fail an errorprone during compilation' // language=Java writeJavaSourceFileToSourceSets ''' package app; @@ -460,9 +460,13 @@ class SuppressibleErrorPronePluginIntegrationTest extends IntegrationSpec { } '''.stripIndent(true) - then: + then: 'compilation succeeds when errorprone is disabled' runTasksSuccessfully('compileAllErrorProne', '-PerrorProneDisable') runTasksSuccessfully('compileAllErrorProne', '-Pcom.palantir.baseline-error-prone.disable') + runTasksSuccessfully('compileAllErrorProne', '-Pcom.palantir.baseline-error-prone.disable=true') + + then: 'compilation fails the legacy baseline errorprone disable property is set to false' + runTasksWithFailure('compileAllErrorProne', '-Pcom.palantir.baseline-error-prone.disable=false') } def 'should be able to refactor near usages of deprecated methods'() {