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

Fix input and output annotations #351

Closed
wants to merge 9 commits into from

Conversation

lptr
Copy link
Contributor

@lptr lptr commented Oct 24, 2019

With Gradle 6.0 we are starting to enforce annotations on all task getters. Non ad-hoc tasks should use annotations in place of the Task.getInputs() and getOutputs() APIs. Due to these changes with Gradle 6.0 the applying the Protobuf plugin results in the following deprecation warnings being displayed:

   > Warning: Type 'GenerateProtoTask': property 'buildType' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'builtins' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'descriptorPath' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'descriptorSetOptions' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'fileResolver' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'flavors' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'generateDescriptorSet' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'isTest' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'isTestVariant' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'outputSourceDirectorySet' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'plugins' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'sourceFiles' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'sourceSet' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'variant' is not annotated with an input or output annotation.
   > Warning: Type 'ProtobufExtract': property 'destDir' is not annotated with an input or output annotation.
   > Warning: Type 'ProtobufExtract': property 'isTest' is not annotated with an input or output annotation.

This PR fixes the problems and the warnings are removed.

I tried to figure out the role of each property as best I could based on the code alone, but I'm not sure I got everything right.

@@ -345,13 +386,12 @@ public class GenerateProtoTask extends DefaultTask {
public void addSourceFiles(FileCollection files) {
checkCanConfig()
sourceFiles.from(files)
// Register the files as input so that Gradle will check their changes for incremental build
inputs.files(files).withPathSensitivity(PathSensitivity.RELATIVE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason for these deletions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify: Gradle queries the annotated getters automatically before running the task to determine up-to-dateness and cache key.

@lptr lptr requested a review from zhangkun83 October 28, 2019 07:28
Copy link
Contributor

@wolfs wolfs left a comment

Choose a reason for hiding this comment

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

The changes are a good first step! I added some comments, my main concern is about backwards compatibility of registering files for ProtobufExtract. If that isn't an issue, then the PR is good as it is.

public boolean getIsTest() {
Preconditions.checkNotNull(isTest)
return isTest
}

@InputFiles
@PathSensitive(PathSensitivity.NAME_ONLY)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about the NAME_ONLY. Are you should or is RELATIVE safer?

It seems like the task is copying/extracing from the input files. Maybe it should have a copy-spec instead of plain input files instead?

It also seems like archives can be part of the inputFiles.

For now, using NAME_ONLY does not change the behavior, since that is what the plugin declared before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. Let's not change behavior where we don't have to for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a TODO here to revisit the correctness of PathSensitivity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@dcabasson
Copy link
Contributor

Looking forward to having the protobuf plugin leverage all the new features of Gradle 5+.

A good next step will be to make task configuration avoidance work because the plugin in its current form doesn't leverage that at all.

@jfbibeau
Copy link

Thank you for this PR! Will be nice to get the protobuf plugin more aligned with Gradle best practices 👍

@lptr
Copy link
Contributor Author

lptr commented Oct 29, 2019

@wolfs please take another look!

Copy link
Contributor

@wolfs wolfs left a comment

Choose a reason for hiding this comment

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

LGTM!

@lptr
Copy link
Contributor Author

lptr commented Nov 4, 2019

Hi, can someone from the Protobuf team take a look at this please?

@rpalcolea
Copy link
Contributor

Also #304 is relevant

@rpalcolea
Copy link
Contributor

Hi @zhangkun83 , any chance you could look at this PR? also #304 would be nice as we have seen this plugin creating several tasks in configuration phase that might not be needed unless the user intent is to run the proto tasks

@voidzcy voidzcy mentioned this pull request Nov 12, 2019
@@ -86,6 +99,7 @@ public class GenerateProtoTask extends DefaultTask {
*
* Default: false
*/
@Internal
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Attached to a task property to indicate that the property is not to be taken into account for up-to-date checking."
It probably should be taken into account for up-to-date checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a clarifying comment.

@Optional
@Nested
DescriptorSetOptions getDescriptorSetOptions() {
return generateDescriptorSet ? descriptorSetOptions : null
Copy link
Collaborator

Choose a reason for hiding this comment

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

If generateDescriptorSet == false and this property is accessed, throwing an exception explaining what went wrong would be more helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made this method protected as well and added a comment.

}

@Nested
protected Collection<PluginOptions> getPluginsInternal() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose these two getters for exposing the two containers as properties so that they can be validated, since there public equivalents cannot be called after configuration is finished. A comment to explain that would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added clarifying comments to both the methods and to the @Internal annotations.

public boolean getIsTest() {
Preconditions.checkNotNull(isTest)
return isTest
}

@InputFiles
@PathSensitive(PathSensitivity.NAME_ONLY)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a TODO here to revisit the correctness of PathSensitivity.

@lptr lptr requested a review from zhangkun83 November 18, 2019 12:49
@lptr
Copy link
Contributor Author

lptr commented Nov 28, 2019

@zhangkun83 Do you want me to do anything else before this can be merged?

*/
@Optional
@Nested
protected DescriptorSetOptions getDescriptorSetOptions() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is it not to be called directly? This is the public accessor for DescriptorSetOptions used in the example from README.

It seems that you cannot make it throw when generateDescriptorSet == false as I requested earlier, because Gradle will query this property unconditionally. This is a bit unfortunate as Gradle doesn't have an annotation for "this is public, but don't use it for up-to-date checks".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean by throw when generateDescriptorSet == false. I reverted to the origin public property being @Internal (that's Gradle's annotation for "this is public, but don't use it for up-to-date checks").

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we made accessing descriptorSetOptions throw when generateDescriptorSet == false, the user would get more meaningful error message (see getDescriptorPath()), compared to getting null for descriptorSetOptions and then NPE down the road.

I find @Internal on a public property to be confusing, especially when you add the auxiliary properties like getDescriptorSetOptionsInternal() that also have "Internal" in the name. Can you rename them to *ForUpToDateCheck()?

@lptr lptr requested a review from zhangkun83 December 3, 2019 09:46
@lptr
Copy link
Contributor Author

lptr commented Dec 11, 2019

Hi @zhangkun83!

The problem I'd like to address here is that the Protobuf plugin in its currently released form does not declare inputs and outputs for the tasks it creates correctly. I don't want to pressure you into any particular way wrt handling errors etc. Yet we seem to be locked in a cycle of you trying to explain to me how you want things to be which I then implement not to your liking. Considering the long round-trip times I feel this is not leading to the desired results.

Why don't we change this around, so you could add the annotations in a separate PR, and I can help review it? What matters for me is to wrap this up in a timely manner, so the many Gradle users that currently have issues with the plugin can be helped.

I'd like to invite you to the Gradle Community Slack workspace. Given the popularity of your plugin, it would be great if we had a more direct connection. Once we fixed the input/output handling there are other improvements that we'd like to discuss, too. Would you mind sending me your email address to [email protected] so that I can send an invite?

I'd also like to offer help face-to-face if that would work for you. I'm in the CET timezone, we can chat on Google Hangout or somesuch if you want.

@zhangkun83
Copy link
Collaborator

@lptr sorry for the slow turnaround. The team have gone through some changes and I have been taking vacations. You idea is good, so please review #364.

zhangkun83 added a commit that referenced this pull request Dec 12, 2019
With Gradle 6.0 we are starting to enforce annotations on all task getters. Non ad-hoc tasks should use annotations in place of the `Task.getInputs()` and `getOutputs()` APIs. Due to these changes with Gradle 6.0 the applying the Protobuf plugin results in the following deprecation warnings being displayed:

```text
   > Warning: Type 'GenerateProtoTask': property 'buildType' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'builtins' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'descriptorPath' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'descriptorSetOptions' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'fileResolver' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'flavors' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'generateDescriptorSet' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'isTest' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'isTestVariant' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'outputSourceDirectorySet' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'plugins' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'sourceFiles' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'sourceSet' is not annotated with an input or output annotation.
   > Warning: Type 'GenerateProtoTask': property 'variant' is not annotated with an input or output annotation.
   > Warning: Type 'ProtobufExtract': property 'destDir' is not annotated with an input or output annotation.
   > Warning: Type 'ProtobufExtract': property 'isTest' is not annotated with an input or output annotation.
```

This PR fixes the problems and the warnings are removed. This is based on #351 by @lptr
@lptr
Copy link
Contributor Author

lptr commented Dec 13, 2019

This has been taken care of via #364.

@lptr lptr closed this Dec 13, 2019
@lptr lptr deleted the gradle/fix-inputs-outputs branch December 13, 2019 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants