-
Notifications
You must be signed in to change notification settings - Fork 354
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
Activated profiles should not always deactivate POM profiles that are active by default #4270
base: main
Are you sure you want to change the base?
Activated profiles should not always deactivate POM profiles that are active by default #4270
Conversation
rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java
Outdated
Show resolved
Hide resolved
@@ -1267,9 +1262,7 @@ void activeByDefault() { | |||
</profile> | |||
</profiles> | |||
</project> | |||
""", spec -> { | |||
((MavenParser.Builder) spec.getParser()).activeProfiles(activeProfile); |
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.
When you remove this, it no longer seems to mimic what I see when I really try to use rewrite in this scenario. In other words, the problematic code (or at least I think it's problematic:) is not exposed. I totally get what you did in this change, and it's what I first tried. However, when evaluation gets to where it determines if a profile is active, active profile is not foobar
. It's empty, which does not expose the issue.
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.
Ah sorry about that! Thanks for keeping a sharp eye out. What's the current status of this PR now then? As I see a todo comment and draft status. Anything you'd like feedback on or plan to continue? Just so I know what to review/merge, or wait for.
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.
Hi @timtebeek . I was kind of hoping you all would run with it, but I may be able to finish this up. I'm just back from vacation.
Is it safe to assume that your team agrees #4269 actually is a bug? :)
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 does indeed seem like we should have more profiles marked as active due to activeByDefault
, even if a settings.xml explicitly lists some profiles already. Hard to fully dive into this for me these past couple weeks, but that's what I'm getting from reading your issue & code changes here.
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! We plan to pick this back up soon.
Hi. We're back on this. Has there been any work on profile deactivation: I searched a bit in PRs and issues. 'profile deactivation', 'profile disabling', and 'deactivation' didn't turn up anything. |
@timtebeek I pinky promise not to sidetrack (far) on this, but got a quick solve for this (and in -java-17, -java-21)?
My skills, internet, AI, and colleagues have all failed so far. We're primarily a Maven shop. Trying to regress before pushing the changes. I did check your build guidance. |
8e78595
to
494402f
Compare
@@ -83,6 +84,29 @@ public MavenSettings(@Nullable String localRepository, @Nullable Profiles profil | |||
this.servers = servers; | |||
} | |||
|
|||
public List<Profile> activeProfiles(final Iterable<String> userSpecifiedProfiles) { |
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 made the code a little more production-ready. I did copy this, due to my ignorance with lombok, between the model meant for POM files and the model meant for Maven settings filesI need to add tests for the changes that deal with Maven settings.xml profiles, but am hoping to get a bit of feedback on this approach.
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.
@timtebeek I pushed one way to isolate code in f9bea1a. I'm far from happy with it. I'll gladly remove/revert that commit if you are OK with copying this activeProfiles
algorithm in 2 places. Just let me know.
Hi @crankydillo I've been traveling since Wednesday, getting home Sunday. I'll try to have a more detailed look next week. As for your IDE setup, one tip is to create a copy of this file to limit what modules are loaded. That could help speed up development as well. Lines 1 to 7 in 537d023
I don't recall any work towards explicit profile deactivation. What kind of usage patterns do you see there beyond what Maven already does for us when you execute the rewrite-maven-plugin with those profiles enabled/disabled? |
Sorry, I missed this question. It's probably best for me to just add a test for this. I'll get that done soon. I don't think I pushed it as part of this PR (because it currently fails:). Update: I have already pushed it. It's just |
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.
Some suggestions could not be made:
- rewrite-gradle/src/main/groovy/RewriteSettings.groovy
- lines 31-36
public boolean isActive(Iterable<String> activeProfiles) { | ||
return ProfileActivation.isActive(id, activeProfiles, activation); |
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.
In general we're fairly conservative with changes to any tree.*
classes, as these are also serialized, with a more high impact change for our users. Is there anything we can do to restore the old methods to minimize the impact?
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.
Sorry @timtebeek I didn't see this. Let me check!
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're talking about standard object serialization, right? I didn't think methods like the ones I removed/added played a role in that. I thought it was more about state.
Regardless, let me see what I can easily put back.
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's a little more involved, but ideally we minimize changes to the API where we can. Thanks for having a look!
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.
Makes sense. I should have thought about public API. I pushed some changes. Let me know what you think.
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.
Any ideas on how we can help with this? We have some workarounds, but they don't work quite as well as we thought.
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.
:bump :)
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.
Apologies for the delayed response; it's hard to get to everything these days. I think to start revert the implements WithProfiles
on the ..tree.*
classes here would help get this in a state that's closer to review & merge. Not sure about what the exact replacement should be, but that would help restart this, along with resolving the conflicts.
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 understand. I will see if I can get rid of the interface. I know I can if I just copy code around. I looked at Trait
, but if there's an obvious application here, I'm not seeing it. Seems oriented around a cursor, and that doesn't seem to be playing a role.
Let me see what I can come up with over the next few days.
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.
Ok, I pushed a change that does not involve interfaces. Unfortunately, I think Maven settings will still have an issue (the interface-approach tried to deal with that). However, I don't think that Maven settings problem affects us. I'll have to verify.
288f3ef
to
910f121
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.
Some suggestions could not be made:
- rewrite-gradle/src/main/groovy/RewriteSettings.groovy
- lines 31-36
Thanks for the fresh work on this @crankydillo ; let me know when this is ready for review, as currently it's still marked as a draft. |
I have it as draft, because there's still a bit of work (see here). I'll finish that up if you think the approach looks good. Update: I'll just go ahead and do that. Should have it out of draft by tomorrow! |
407616b
to
1db298d
Compare
rewrite-maven/src/main/java/org/openrewrite/maven/WithProfiles.java
Outdated
Show resolved
Hide resolved
00da607
to
0e58942
Compare
rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java
Outdated
Show resolved
Hide resolved
0e58942
to
5a40cf9
Compare
5a40cf9
to
1f36d4d
Compare
mavenCtx.setMavenSettings(settings); | ||
|
||
rewriteRun(recipeSpec -> recipeSpec.executionContext(mavenCtx), | ||
pomXml(""" |
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.
pomXml(""" | |
pomXml( | |
""" |
assertThat(err.getMessage()).contains("Problem parsing a/pom.xml"); // brittle:(, but class above is broad | ||
} | ||
|
||
@Issue("TODO: create issue") |
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 test is related to my understanding of this Maven doc. It is related, but not the same as what I've written up in #4269, so thinking about creating a new issue for it. If you think I've misunderstood something or this test is invalid, we can just remove. This is not a current use-case for us.
Thanks for the rework @crankydillo ! Much appreciate the narrower scope as that makes this easier to review. Quick headsup though that I'll be mostly out this coming week ahead of JFall, but hope to revisit the week after. |
:bump |
rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java
Outdated
Show resolved
Hide resolved
…est.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
These versions resolve with Maven. If I'm misuing the test APIs, I can create a sample project.