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

[improvement] Support auto-applying error-prone suggested fixes #660

Merged
merged 9 commits into from
Jun 24, 2019

Conversation

gatesn
Copy link
Contributor

@gatesn gatesn commented Jun 24, 2019

Before this PR

Error-prone compiler emits suggested fixes as log lines.

After this PR

Setting -PerrorProneApply=true will configure CompileJava to apply error-prone suggested fixes to the source.

.toFile();
javaCompile.getOutputs().file(patchFile);

// TODO(gatesn): How can we flag this on/off? It appears to come with a hefty perf hit
Copy link
Contributor

Choose a reason for hiding this comment

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

in tritium i use https://github.com/palantir/tritium/blob/develop/build.gradle#L110 and https://github.com/palantir/tritium/blob/develop/gradle.properties#L4 then when I want to generate a patch one can ./gradlew -DgenerateErrorPronePatch=true compileJava compileTestJava

errorProneOptions.getErrorproneArgumentProviders().add(() -> ImmutableList.of(
"-XepPatchChecks:" + Joiner.on(',')
.join(errorProneExtension.getPatchChecks().get()),
"-XepPatchLocation:" + patchFile.getParentFile().getAbsolutePath()));
Copy link
Contributor

Choose a reason for hiding this comment

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

could use in place application to directly apply fixes similar to spotlessApply

Suggested change
"-XepPatchLocation:" + patchFile.getParentFile().getAbsolutePath()));
"-XepPatchLocation:IN_PLACE"));

@gatesn gatesn marked this pull request as ready for review June 24, 2019 20:25
@gatesn gatesn requested a review from a team as a code owner June 24, 2019 20:25
.configure(ErrorProneOptions.class, errorProneOptions -> {
errorProneOptions.setEnabled(true);
errorProneOptions.setDisableWarningsInGeneratedCode(true);
errorProneOptions.check("EqualsHashCode", CheckSeverity.ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we read this from the extension?

@gatesn gatesn changed the title [improvement] Create tasks to apply error-prone suggested fixes [improvement] Support auto-applying error-prone suggested fixes Jun 24, 2019
file('src/main/java/test/Test.java') << inValidJavaFile

then:
BuildResult result = with('compileJava', "-P${BaselineErrorProne.PROP_ERROR_PRONE_APPLY}=true").build()
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of using the constant, could you hard code the value in the test? it helps prevent accidental changes to the flag

errorProneOptions.check("EqualsIncompatibleType", CheckSeverity.ERROR);
errorProneOptions.check("StreamResourceLeak", CheckSeverity.ERROR);

Optional.ofNullable(project.getProperties().get(PROP_ERROR_PRONE_APPLY)).ifPresent(x -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

project.hasProperty?

file('src/main/java/test/Test.java') << inValidJavaFile

then:
BuildResult result = with('compileJava', "-P${BaselineErrorProne.PROP_ERROR_PRONE_APPLY}=true").build()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd test the actual syntax we intend to use (without =true)

@dansanduleac
Copy link
Contributor

👍

@bulldozer-bot bulldozer-bot bot merged commit acda424 into develop Jun 24, 2019
@bulldozer-bot bulldozer-bot bot deleted the ngates/errorprone-apply branch June 24, 2019 20:50
@svc-autorelease
Copy link
Collaborator

Released 0.63.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants