-
Notifications
You must be signed in to change notification settings - Fork 359
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
Added gradle recipe to remove enableFeaturePreview method #4191
Added gradle recipe to remove enableFeaturePreview method #4191
Conversation
bd0aabc
to
c972e34
Compare
c972e34
to
e1d2eca
Compare
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.
Left a few comments, but overall things look good.
nit: You might review your formatter options or we can clean this up once the PR is ready.
@Override | ||
public MethodInvocation visitMethodInvocation(MethodInvocation method, | ||
@NotNull ExecutionContext executionContext) { | ||
if (ENABLE_FEATURE_PREVIEW_METHOD_NAME.equals(method.getSimpleName())) { |
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.
If I recall correctly, the type information should be present such that this can be done with a MethodMatcher
.
MethodMatcher enableFeaturePreviewMatcher = new MethodMatcher("RewriteSettings enableFeaturePreview(String)");
if (enableFeaturePreviewMatcher.matches(m)) {
// do the thing
}
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.
The pattern above didn't work, but this one below did:
new MethodMatcher("org.gradle.api.initialization.Settings enableFeaturePreview(String)");
I debugged and constructed a MethodMatcher
by passing in the actual method object, then looked at the toString() and saw this. Let me know if I should do something different.
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.
That works, you could have also flipped the inheritance included parameter to true
as well. I forgot that in my example, but this does the same thing.
rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveEnableFeaturePreview.java
Outdated
Show resolved
Hide resolved
rewrite-gradle/src/main/java/org/openrewrite/gradle/RemoveEnableFeaturePreview.java
Outdated
Show resolved
Hide resolved
…leFeaturePreview.java Co-authored-by: Shannon Pamperl <[email protected]>
…leFeaturePreview.java Co-authored-by: Shannon Pamperl <[email protected]>
Looks like it needs a license. I can add one to the file if that's the process. |
Ah normally we have a bot to then give you helpful suggestions, but not yet on this project. A quick |
Don't merge this yet, I tested this locally and it didn't work. Not sure if it's my fault or not. I published to maven local, then ran it on a project, and it didn't make any changes. I added some logging statements and it seems the method matcher (or something else) isn't quite right. I'll look into it tomorrow. I added a failing test to try and keep it from getting merged. |
…ojects i tested against
public MethodInvocation visitMethodInvocation( | ||
MethodInvocation method, @NotNull ExecutionContext executionContext) { | ||
|
||
if (!"enableFeaturePreview".equals(method.getSimpleName())) { |
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 was using a method matcher, and it passed tests fine, but I manually ran this recipe against a few local gradle projects and it worked on 1 but on another it didn't match at all. The one it didn't work on, I debugged the LST and found that the method had a methodType of null for some reason. I dont' know if it's a bug in the parser or not, but I changed the logic here to just check the method name, check that there's exactly 1 argument, and check that the argument matches the @Option
passed in.
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 being flaky is a bit curious to me. My likely suspect though is that in the cases where it is not working, the type is missing from the Groovy AST -- coming out of the Groovy Compiler -- prior to it being mapped to the OpenRewrite Groovy LST.
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.
Added a bit of polish to minimize the implementation & better adhere to some project conventions that aren't automated on this particular project yet, but are in others.
Thanks a lot for the work done here! I'd say this is good to go as is, but will give Shannon a little time to respond if he sees anything still.
I was wondering if we should include any declarative Gradle upgrade recipes already for major versions that remove experimental features removed per major version. https://github.com/gradle/gradle/blob/v8.7.0/subprojects/core/src/main/java/org/gradle/api/internal/FeaturePreviews.java
https://github.com/gradle/gradle/blob/v7.2.0/subprojects/core/src/main/java/org/gradle/api/internal/FeaturePreviews.java
https://github.com/gradle/gradle/blob/v6.9.4/subprojects/core/src/main/java/org/gradle/api/internal/FeaturePreviews.java
https://github.com/gradle/gradle/blob/v5.6.4/subprojects/core/src/main/java/org/gradle/api/internal/FeaturePreviews.java
https://github.com/gradle/gradle/blob/v4.10.3/subprojects/core/src/main/java/org/gradle/api/internal/FeaturePreviews.java
|
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.
This looks good to me, @timtebeek. Just the one test that I kinda feel is valid from a testing standpoint, but invalid from a semantics standpoint.
rewrite-gradle/src/test/java/org/openrewrite/gradle/RemoveEnableFeaturePreviewTest.java
Outdated
Show resolved
Hide resolved
I do like the idea of starting some migration recipes for Gradle. We have enough of the low level components to make it work fairly well. |
…leFeaturePreviewTest.java Co-authored-by: Shannon Pamperl <[email protected]>
Great, then let's follow up with a declarative yaml recipe in a separate PR that uses the above recipe and list of feature flags in #4191 (comment), and adds in updating the Gradle wrapper too. |
What's changed?
Added a gradle recipe to remove the
enableFeaturePreview
method fromsettings.gradle
.Provide the feature to remove via a property.
A
rewrite.yml
file would include the recipe like this:It would remove the following line from
settings.gradle
What's your motivation?
I wrote this recipe for use at my company and was encouraged to contribute it here by @shanman190 and @timtebeek. Slack thread: https://rewriteoss.slack.com/archives/C01A843MWG5/p1715414946440599?thread_ts=1715381394.713129&cid=C01A843MWG5
Checklist