-
Notifications
You must be signed in to change notification settings - Fork 134
Java compilation warnings and errors are no longer limited to the first 100 #1890
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| type: improvement | ||
| improvement: | ||
| description: Java compilation warnings and errors are no longer limited to the first | ||
| 100 | ||
| links: | ||
| - https://github.com/palantir/gradle-baseline/pull/1890 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...e-java/src/main/groovy/com/palantir/baseline/plugins/BaselineJavaCompilerDiagnostics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * (c) Copyright 2019 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.List; | ||
| import org.gradle.api.Plugin; | ||
| import org.gradle.api.Project; | ||
| import org.gradle.api.tasks.compile.JavaCompile; | ||
|
|
||
| /** | ||
| * Applies the {@code -Xmaxwarns} and {@code -Xmaxerrs} compiler options with a very large | ||
| * limit to avoid truncating failure info. | ||
| */ | ||
| public final class BaselineJavaCompilerDiagnostics implements Plugin<Project> { | ||
|
|
||
| // Default maxwarns/maxerrs is only 100, which often makes it difficult to debug | ||
| // annotation processing issues. | ||
| private static final String MANY = "10000"; | ||
|
|
||
| private static final String MAX_WARNINGS_ARG = "-Xmaxwarns"; | ||
| private static final String MAX_ERRORS_ARG = "-Xmaxerrs"; | ||
|
|
||
| @Override | ||
| public void apply(Project project) { | ||
| project.getTasks().withType(JavaCompile.class).configureEach(javaCompileTask -> { | ||
| List<String> compilerArgs = javaCompileTask.getOptions().getCompilerArgs(); | ||
| // Avoid overriding options that have already been set | ||
| if (!compilerArgs.contains(MAX_WARNINGS_ARG)) { | ||
| compilerArgs.add(MAX_WARNINGS_ARG); | ||
| compilerArgs.add(MANY); | ||
| } | ||
| if (!compilerArgs.contains(MAX_ERRORS_ARG)) { | ||
| compilerArgs.add(MAX_ERRORS_ARG); | ||
| compilerArgs.add(MANY); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1
...ources/META-INF/gradle-plugins/com.palantir.baseline-java-compiler-diagnostics.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| implementation-class=com.palantir.baseline.plugins.BaselineJavaCompilerDiagnostics |
72 changes: 72 additions & 0 deletions
72
...ine-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * (c) Copyright 2018 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 | ||
|
|
||
| import com.palantir.baseline.plugins.BaselineJavaCompilerDiagnostics | ||
| import org.gradle.api.tasks.compile.JavaCompile | ||
| import org.gradle.testfixtures.ProjectBuilder | ||
| import spock.lang.Specification | ||
|
|
||
| class BaselineJavaCompilerDiagnosticsTest extends Specification { | ||
|
|
||
| def testDefault() { | ||
| when: | ||
| def project = ProjectBuilder.builder().build() | ||
| project.buildscript { | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
| } | ||
| project.plugins.apply 'java' | ||
| project.plugins.apply BaselineJavaCompilerDiagnostics | ||
| project.evaluate() | ||
|
|
||
| then: | ||
| JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) | ||
| List<String> allJvmArgs = compileTask.allJvmArgs | ||
| allJvmArgs.stream().filter('-Xmaxerrs'::equals).count() == 1 | ||
| allJvmArgs.get(allJvmArgs.indexOf('-Xmaxerrs') + 1) == '1000' | ||
| allJvmArgs.stream().filter('-Xmaxwarns'::equals).count() == 1 | ||
| allJvmArgs.get(allJvmArgs.indexOf('-Xmaxerrs') + 1) == '1000' | ||
| } | ||
|
|
||
| def testOverridden() { | ||
| when: | ||
| def project = ProjectBuilder.builder().build() | ||
| project.buildscript { | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
| } | ||
| project.plugins.apply 'java' | ||
| tasks.withType(JavaCompile) { | ||
| options.compilerArgs += [ | ||
| '-Xmaxerrs', '1000' | ||
| ] | ||
| } | ||
| project.plugins.apply BaselineJavaCompilerDiagnostics | ||
| project.evaluate() | ||
|
|
||
| then: | ||
| project.tasks.type | ||
| JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) | ||
| List<String> allJvmArgs = compileTask.allJvmArgs | ||
| allJvmArgs.stream().filter('-Xmaxerrs'::equals).count() == 1 | ||
| allJvmArgs.get(allJvmArgs.indexOf("-Xmaxerrs") + 1) == '1000' | ||
| allJvmArgs.stream().filter('-Xmaxwarns'::equals).count() == 1 | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we want this to work if people override after applying the plugin too? If so, we'd probably want to put this in a
project.afterEvaluateto run after people have had a chance to change it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does, but only due to the fact later arguments take precedence over earlier instances. The afterEvaluate will be cleaner :-)
Note that the same potential duplication can occur if commandlineargumentproviders are used because I'm not checking those, we take advantage of knowing they're applied after the fixed args. I figured we don't want to evaluate providers unnecessarily as part of this check due to potential side-effects given the worst case result still has the desired behavior.