-
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-7432] Resolver session contains non-MavenWorkspaceReader #695
Conversation
FYI @famod @olamy @michael-o |
I'm using a delegation to the original |
6aea07d
to
3a72f60
Compare
I've just created a ticket for this: https://issues.apache.org/jira/browse/MNG-7432 |
Signed-off-by: Christoph Läubrich <christoph@laeubi-soft.de>
3a72f60
to
af9c75e
Compare
@michael-o do you like to review this? |
I need to understand the cause first because there seems to be some quirk, no? |
Not sure, at least this does restores the previous behavior.
The fix do the following:
this should fix all this issues. |
@olamy The regression introduced in Maven 3.8.5 in 6f14196, which is resolved in this unmerged and unreleased pull request, is causing all Jenkins core PR builds to fail. |
A more minimal (and therefore likely less controversial) alternative to the fix proposed in this PR is: diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
index 56a42b724..965345394 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -377,8 +377,15 @@ private void setupWorkspaceReader( MavenSession session, DefaultRepositorySystem
}
workspaceReaders.add( workspaceReader );
}
- WorkspaceReader[] readers = workspaceReaders.toArray( new WorkspaceReader[0] );
- repoSession.setWorkspaceReader( new ChainedWorkspaceReader( readers ) );
+ if ( workspaceReaders.size() == 1 )
+ {
+ repoSession.setWorkspaceReader( workspaceReaders.get( 0 ) );
+ }
+ else
+ {
+ WorkspaceReader[] readers = workspaceReaders.toArray( new WorkspaceReader[0] );
+ repoSession.setWorkspaceReader( new ChainedWorkspaceReader( readers ) );
+ }
} This fixes the problem for me by restoring the old behavior from Maven 3.8.4. |
but will instantly fail once another workspace reader is registered again ;-) |
I do not really know or care what a workspace reader is. I just want my builds to work again. |
You can use maven 3.8.4 in the meantime. |
I think that writing "restoring the old behavior from Maven 3.8.4" should have made it clear that I already knew that. |
Sure but if you simply "do not really care" the easiest and fastest way is using 3.8.4. For 3.8.5 support for additional Readers was added because there are people who care, and applying a fix that would only "restoring the old behavior" (that was already broken but probably never noticed) won't help much. I also don't see that the fix is controversial just that @michael-o want to better understand the cause, so if you can provide additional information why your build fails e.g. by providing a minimal reproducer, integration or unit test or you can confirm that it is the same problem described by @famod then it might help to make more progress here. |
Sorry, I lack the time and interest to pursue this further. I have already reverted back to Maven 3.8.4. |
I suppose maven/maven-core/src/main/java/org/apache/maven/internal/aether/MavenChainedWorkspaceReader.java Lines 99 to 102 in af9c75e
|
No, this is just a shorthand in case there is only one WSR. |
@michael-o just wondering inf we can proceed here? If its fine for 3.8.x I'll prepare PRs for 2.9.x and 4.x as well ... I also wonder if it would be suitable to release a 3.8.6 version or do we have to wait for 2.9.0? |
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.
Seems like a straightforward fix. If I understand correctly, one or both of
Lines 208 to 215 in b3d5c12
if ( workspace instanceof MavenWorkspaceReader ) | |
{ | |
model = ( (MavenWorkspaceReader) workspace ).findModel( pomArtifact ); | |
if ( model != null ) | |
{ | |
return model; | |
} | |
} |
maven/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
Lines 187 to 190 in 69d6c6d
if ( workspace instanceof MavenWorkspaceReader ) | |
{ | |
model = ( (MavenWorkspaceReader) workspace ).findModel( RepositoryUtils.toArtifact( artifact ) ); | |
} |
Exactly! |
Is there an IT for this? If there would be, I'd check this and add for 3.8.6+. |
The jira has a link to a reproducer maybe this could be integrated an in itest or give a hint how to create one? |
For reference, the Jenkins build error was at Line 302 in 3599d34
|
ITs are here: https://github.com/apache/maven-integration-testing |
public static WorkspaceReader of( Collection<WorkspaceReader> workspaceReaderCollection ) | ||
{ | ||
WorkspaceReader[] readers = workspaceReaderCollection.toArray( new WorkspaceReader[0] ); | ||
if ( readers.length == 1 ) |
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'd personally just remove this length check, and make it always wrapped (is simpler).
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 think the complexity is manageable given that in most cases there is only one WSP and we save useless loop calls in that case when it is used across the maven build.
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.
Still, the check could happen then on collection, not after conversion to array, no? nvm, am fine with it as it is
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.
Yes, I just used the "toArray" as we accept a collection and then getting the first element from collection requires to iterate over the collection, but if size is larger requires an toArray as well... in the end it dosn't make much a difference given that this only happens once per maven invocation.
Created UT that IMHO should cover the issue #706 |
This UT makes sure that DefaultMaven sets up proper type of WorkspaceReader in RepositorySystemSession. For example, this UT fails with current maven-3.8.x and maven-3.9.x branches.
@cstamas I have now fetched your test as well into this PR. |
@michael-o so what's blocking here? Should I take over? |
Feel free to take over the entire ticket handling with IT, etc. |
Ok, but IMHO no need for IT here, as UT covers nicely (again: when resolver runs "within maven", the session.workspaceReader MUST be instanceof MavenWorkspaceReader to get expected -- stuff from reactor -- result, that's all) |
So, you even wouldn't consider to absorb the reproducer as an IT? |
As I commented on JIRA, I consider the reproducer WRONG USECASE, and if we lift that into ITs we would put it in concrete... |
I go with that explanation |
As Resolver session contains non-MavenWorkspaceReader, the reactor models (already resolved w/ profiles applied) are re-built when using Resolver within Mojo, instead to get them via ReactorReader as expected. The rebuilt models will lack explicit (-P on CLI) profiles applied, as resolver itself is not maven aware, hence there is no way to "tell" resolver to apply them. Building reactor models w/ profiles applied is NOT done using resolver, but by Maven when loading up reactor, as profiles are NOT applied for downstream transitive dependencies (see discussion on MNG-1388 why). Signed-off-by: Christoph Läubrich <christoph@laeubi-soft.de> Co-authored-by: Christoph Läubrich <christoph@laeubi-soft.de> Co-authored-by: Tamas Cservenak <tamas@cservenak.net>
…#695) As Resolver session contains non-MavenWorkspaceReader, the reactor models (already resolved w/ profiles applied) are re-built when using Resolver within Mojo, instead to get them via ReactorReader as expected. The rebuilt models will lack explicit (-P on CLI) profiles applied, as resolver itself is not maven aware, hence there is no way to "tell" resolver to apply them. Building reactor models w/ profiles applied is NOT done using resolver, but by Maven when loading up reactor, as profiles are NOT applied for downstream transitive dependencies (see discussion on MNG-1388 why). Signed-off-by: Christoph Läubrich <christoph@laeubi-soft.de> Co-authored-by: Christoph Läubrich <christoph@laeubi-soft.de> Co-authored-by: Tamas Cservenak <tamas@cservenak.net>
Signed-off-by: Christoph Läubrich christoph@laeubi-soft.de
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 replaceMNG-XXX
and
SUMMARY
with the appropriate JIRA issue. Best practice is to use the JIRA issuetitle in 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.