-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Convert PluginPropertiesExtension Groovy to Java #39605
Convert PluginPropertiesExtension Groovy to Java #39605
Conversation
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
Tried to convert the
I have paused working on |
Pinging @elastic/es-core-infra |
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.
Thank you for your contribution @rhamedy !
We prefer small PRs so this is even better than having the plugin converted too.
I left a few comments. Also would be kind enough and add tests for these classes ?
We want all the java code to have tests.
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
@atorok thank you for the review. I have addressed them in my recent I would definitely write tests! Is there a |
Thanks @rhamedy for the quick update. For tests I think you should look at @elasticmachine test this please |
@atorok I have addressed the code review comments as well as added some tests. I could not find a class that I could use as baseline to write tests probably because the tests are different in other classes and this is plugin. The test ensures tha the Please let me know if any changes to be made 👍 |
@elasticmachine test this please |
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.
Thanks for taking this on @rhamedy. I left a few comments.
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Show resolved
Hide resolved
@rjernst @atorok I pushed up my new changes taking into account the code review comments. I have removed the unecessary |
|
||
public PluginPropertiesExtension(Project project) { | ||
this.name = project.getName(); | ||
this.version = project.getVersion().toString(); |
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 just realized this now, this is a problem present in the old code as well.
The way we assign this default makes it prone to ordering.
If the extension is created before project.version
is assigned we won't pick it up.
We should have a null check in the getter instead and returnproject.version
if version
is null
This is fine also in a subsequent PR.
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 can update the PluginPropertiesExtension.getVersion()
to return project.getVersion().toString()
if version
is null 👍
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.
It is not possible for version to be null. VersionProperties statically loads the version. BuildPlugin is initialized before any PluginPropertiesExtension, since it is applied by PluginBuildPlugin, which extends BuildPlugin. Adding null checks all over for version will only make the code more complicated to understand with no actual additional safety.
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.
We do this early on in the root level build.gradle
allprojects {
group = 'org.elasticsearch'
version = VersionProperties.elasticsearch
description = "Elasticsearch subproject ${project.path}"
}
So indeed it's not possible for project.version
to be null in our build,
but all bets are off for external plugins, there's no guarantee that it won't be null.
We might not want to be lenient here and throw an exception if the version is null, but I still think we should do it rather than leave it be an NPE.
Alternatively, we could hard code this to VersionProperties.elasticsearch
as we only test building plugins where the version of build-tools matches that of elasticsearch.
External plugins can then have whatever project.version they like.
What do you think of this approach @rjernst
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesTask.java
Outdated
Show resolved
Hide resolved
@elasticmachine test this please |
@atorok @rjernst I have factored the changes requested and pushed the changes up. The tests that I have added are working 👍 however when running the command
I double checked the |
@elasticmachine test this please |
buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy
Outdated
Show resolved
Hide resolved
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.
LGTM no need to squash we do that on merge anyhow.
@elasticmachine test this please |
…sk, update the tests
…me hasNativeController to getHasNativeController
758a406
to
03fa92f
Compare
buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy
Outdated
Show resolved
Hide resolved
buildSrc/src/main/java/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.java
Outdated
Show resolved
Hide resolved
@elasticmachine test this please |
@atorok pushed my changes! 👍 |
@elasticmachine test this please |
@rhamedy looks like there are some failing tests |
@atorok the recent changes fix the test failures 👍 |
@elasticmachine test this please |
Sorry for the delay @rhamedy I'll see to merge this as soon as the PR checks pass |
Merge remote-tracking branch 'origin/master' into plugin-properties-task-tojava When the version is not set, use the project version bu do so lazily so we don't snapshot it at construction time
@atorok that would be awesome! 🙂 |
Contributes to #34459
Converted