Skip to content

Commit

Permalink
Support errorprone being enabled by setting `com.palantir.baseline-er…
Browse files Browse the repository at this point in the history
…ror-prone.disable=false` (#17)

Ensure we match the behaviour of `com.palantir.baseline-error-prone.disable` from baseline.
  • Loading branch information
CRogers authored Nov 12, 2024
1 parent 3874e58 commit bf5fe99
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-17.v2.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,10 +39,10 @@ public final class SuppressibleErrorPronePlugin implements Plugin<Project> {
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<String> 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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'() {
Expand Down

0 comments on commit bf5fe99

Please sign in to comment.