From 44682aac6fd66d6620f5c0371aac0af63928bc19 Mon Sep 17 00:00:00 2001 From: David Schlosnagle Date: Fri, 27 Nov 2020 12:01:33 -0500 Subject: [PATCH] Exclude generated sources from error-prone (#1571) Exclude generated sources from error-prone --- changelog/@unreleased/pr-1571.v2.yml | 5 +++ .../baseline/plugins/BaselineErrorProne.java | 14 ++++---- .../plugins/BaselineErrorProneTest.groovy | 34 +++++++++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 changelog/@unreleased/pr-1571.v2.yml create mode 100644 gradle-baseline-java/src/test/groovy/com/palantir/baseline/plugins/BaselineErrorProneTest.groovy diff --git a/changelog/@unreleased/pr-1571.v2.yml b/changelog/@unreleased/pr-1571.v2.yml new file mode 100644 index 000000000..be693be89 --- /dev/null +++ b/changelog/@unreleased/pr-1571.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Exclude generated sources from error-prone + links: + - https://github.com/palantir/gradle-baseline/pull/1571 diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineErrorProne.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineErrorProne.java index ac0aedbc2..9ae455fe9 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineErrorProne.java +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineErrorProne.java @@ -201,13 +201,7 @@ private static void configureErrorProneOptions( } errorProneOptions.getDisableWarningsInGeneratedCode().set(true); - // don't want backslashes on windows to break our regex - String separator = File.separatorChar == '\\' ? Pattern.quote("\\") : File.separator; - errorProneOptions - .getExcludedPaths() - .set(String.format( - ".*(build%sgenerated%ssources|src%sgenerated.*)%s.*", - separator, separator, separator, separator)); + errorProneOptions.getExcludedPaths().set(excludedPathsRegex()); // FallThrough does not currently work with switch expressions // See https://github.com/google/error-prone/issues/1649 @@ -292,6 +286,12 @@ public Iterable asArguments() { } } + static String excludedPathsRegex() { + // don't want backslashes on windows to break our regex + String separator = File.separator.contains("\\") ? Pattern.quote("\\") : File.separator; + return String.format(".*%s(build|generated_.*[sS]rc|src%sgenerated.*)%s.*", separator, separator, separator); + } + private static Optional> getSpecificErrorProneChecks(Project project) { return Optional.ofNullable(project.findProperty(PROP_ERROR_PRONE_APPLY)) .map(Objects::toString) diff --git a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/plugins/BaselineErrorProneTest.groovy b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/plugins/BaselineErrorProneTest.groovy new file mode 100644 index 000000000..72e14e4e4 --- /dev/null +++ b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/plugins/BaselineErrorProneTest.groovy @@ -0,0 +1,34 @@ +/* + * (c) Copyright 2020 Palantir Technologies Inc. All rights reserved. + * + * 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.palantir.baseline.plugins + +import java.util.regex.Pattern +import spock.lang.Specification + +class BaselineErrorProneTest extends Specification { + void testExcludedPaths() { + when: + String excludedPaths = BaselineErrorProne.excludedPathsRegex() + def predicate = Pattern.compile(excludedPaths).asPredicate() + + then: + predicate.test 'tritium-core/build/metricSchema/generated_src' + predicate.test 'tritium-registry/generated_src/com/palantir/tritium/metrics/registry/ImmutableMetricName.java' + predicate.test 'tritium-metrics/build/metricSchema/generated_src/com/palantir/tritium/metrics/TlsMetrics.java' + predicate.test 'tritium-jmh/generated_testSrc/com/palantir/tritium/microbenchmarks/generated/ProxyBenchmark_jmhType.java' + } +}