-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[MNG-8081] interpolate available properties during default profile selection (Maven 4.x) #1446
Conversation
6f3dfe9
to
739cba8
Compare
maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
Outdated
Show resolved
Hide resolved
...n-model-builder/src/test/java/org/apache/maven/model/profile/DefaultProfileSelectorTest.java
Outdated
Show resolved
Hide resolved
maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java
Outdated
Show resolved
Hide resolved
Second iteration:
|
The code looks good. However, what's the real use case for that ? It seems actually unrelated to MNG-5235, in a sense that the behaviour on this project is not modified by this PR. My understanding is that the use case for MNG-5235 is to activate profile based on project properties, while this PR is about interpolating activation property values (but not based on project properties). Also note that properties defined from activated external profiles are already taken into account, see MNG-2276. |
My use case is to be able to compare environment variables. Specifically, with GitLab CI, if |
Not sure how you'll model that with the limited support we have right now, do you ?
At some point, it may be easier to provide a custom Maven extension that would compute a system property based on those two variables so you can easily activate a profile based on the computed property. Maven 4 added |
Hmm, my approach was, e.g.:
...which seems fine to me 🤷 |
personally i do it in the sh part of the yaml:
No assumption needed all is detected in the build pipeline (where it belongs) and project itself just enables to activate it or not. |
@rmannibucau but your pipeline has to know/hope that the project has such a |
Yes, obviously that'll work 😊 |
@@ -76,16 +85,24 @@ public List<org.apache.maven.api.model.Profile> getActiveProfilesV4( | |||
@Override | |||
public List<Profile> getActiveProfiles( | |||
Collection<Profile> profiles, ProfileActivationContext context, ModelProblemCollector problems) { | |||
|
|||
if (profiles.stream().map(Profile::getId).distinct().count() < profiles.size()) { |
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.
What is this test about ? That seems unrelated to this PR. Should this be rather validated (with a warning printed) earlier in the process ? During settings validation and project validation ?
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.
What I found during testing was that deliberately failing test cases where the same id
was specified on multiple profiles seemed to reach this code, and break my collect-to-map, prior to failing the whole build due to the illegal profile duplication. So my thinking was that since we know at this point that we're in an illegal situation, we can just assume no profiles may be activated and the usual mechanisms will fail the build in due course (of course I am approaching all this as a superficial contributor with an incomplete understanding of Maven's guts).
@mbenson see it the other way, |
@rmannibucau I think it's okay if different users want to interact with Maven in different ways. Your preference does not invalidate mine. |
@mbenson well a mini language got rejected multiple times on the list - this is where this sh solution comes from. ultimately I'm for having a multipass filtering to filter as much as we can but my personal preference would be to do it on the full model and not specifically for profiles. That said, while v4 has the exact same code than v3.9 I'm happy. |
It seems it can be solved really easily though: |
That makes we wonder if this PR targets the wrong location. Should we modify the |
That was what I originally considered, but I quickly came to the opinion that as soon as we did it that way, someone would want to use some such property to match a Java version, etc., and that this would be a generally applicable way to solve a broad cross section of similar use cases. |
How could that (solving similar use cases) be considered a bad thing ? |
That's what I wanted to know 😮 |
From email thread: Guillaume Nodet [email protected] wrote:
I hadn't noted the discussion when it took place before, but fwiw I also lean in the direction that an embedded language might be going too far. At the same time EL, as in the extension you mentioned, seems a fine choice, but feels fine to leave that as an extension. Matt |
@mbenson I just spotted that the model builder performs some interpolation for file base activation in maven/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java Lines 896 to 943 in 5029cc2
Would it make sense to move this code in this block to interpolate ? It seems more intuitive that the two interpolations would actually be performed at the same time... |
That is possible, sure. I'll take a look in a bit. UPDATE: Yes, if there is already an "interpolate activations" activity taking place in the model builder, I agree it makes sense to add the expanded functionality there. In an early iteration of this work I encountered test failures relating to file paths when I allowed the interpolations to remain in the model, but reviewing this section of the code I see that that probably related to the relative path computation that's being done for file activations, so hopefully by taking that into consideration I can avoid such issues this time around. |
ffe2dd6
to
2982758
Compare
Here is the version that enhances |
maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
Outdated
Show resolved
Hide resolved
By way of [some] testing, I went ahead and expanded the profile activation model validation to consider the whole activation, similarly to how we are now interpolating the whole activation. Here I could be construed as misusing the |
Thanks @gnodet and @rmannibucau for the approvals! What is the next step? |
I'm nearly done with http://github.com/apache/maven/pull/1457, so as soon as that one is merged, we'll be able to port this PR to the new model builder easily. |
@gnodet do you have any thoughts on the best way to backport this feature to Maven 3? #1447 is my original PR, but a wildly divergent implementation may cause headaches in future. I wonder if it would make sense [from a future merge perspective] to stabilize the v3 impl and include the same commit in this branch prior to being replaced by the actual v4 implementation. 🤔 |
@mbenson I've rebased the PR and ported it to the new v4 model builder, please have a look |
hi @gnodet ... so with the implementation having been largely duplicated from model-builder into api-impl, would the similar code remain in both places indefinitely, or will the model-builder code eventually point directly to api-impl? |
The code in model-builder should be deprecated, it will be kept for compatibility with 3.x plugins for some time, and then removed. Not sure about the exact dates though. The point is that model-builder is not really used anymore in beta-1. |
maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java
Show resolved
Hide resolved
maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
Outdated
Show resolved
Hide resolved
Incorporated |
@gnodet again, thanks! |
Evaluate profile activations after having interpolated embedded property constructs.
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MNG-XXX] SUMMARY
,where you replace
MNG-XXX
andSUMMARY
with the appropriate JIRA issue.[MNG-XXX] SUMMARY
.Best practice is to use the JIRA issue title in both the pull request title and in the first line of the commit message.
mvn clean verify
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.
ICLA on file