Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude generated sources from error-prone #1571

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamdanfox we might be able to remove build from regex here, or might want to constrain the pattern to avoid falsely matching say com/foo/build/Bar.java.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this feels a bit dangerous. I'd suggest we do something like build.*generated since almost all code-gen plugins I've seen put source files on a path with a generated component.

}

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'
}
}