Skip to content

Commit

Permalink
Exclude generated sources from error-prone (#1571)
Browse files Browse the repository at this point in the history
Exclude generated sources from error-prone
  • Loading branch information
schlosna authored Nov 27, 2020
1 parent c8de883 commit 44682aa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1571.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Exclude generated sources from error-prone
links:
- https://github.com/palantir/gradle-baseline/pull/1571
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -292,6 +286,12 @@ public Iterable<String> 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<Stream<String>> getSpecificErrorProneChecks(Project project) {
return Optional.ofNullable(project.findProperty(PROP_ERROR_PRONE_APPLY))
.map(Objects::toString)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
}
}

0 comments on commit 44682aa

Please sign in to comment.