Skip to content
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

[3.9.x][MNG-7795] IllegalArgumentException: 'other' has different root durin… #1128

Merged
merged 4 commits into from
Jun 1, 2023

Conversation

adangel
Copy link
Member

@adangel adangel commented May 25, 2023

…ing plugin validation

Checks the paths before relativizing them.

https://issues.apache.org/jira/browse/MNG-7795

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    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.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MNG-XXX] SUMMARY,
    where you replace MNG-XXX and SUMMARY with the appropriate JIRA issue.
  • Also format the first line of the commit message like [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.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the Core IT successfully.

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.

…g plugin validation

Checks the paths before relativizing them.
@@ -247,7 +247,11 @@ private String pluginOccurrence(MavenSession mavenSession) {
File currentPom = prj.getFile();
if (currentPom != null) {
File rootBasedir = mavenSession.getTopLevelProject().getBasedir();
result += " (" + rootBasedir.toPath().relativize(currentPom.toPath()) + ")";
if (currentPom.getPath().startsWith(rootBasedir.getPath())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the path should be absoluted / normalized. Also, this should be done against the new Session#getRootDirectory() imho:

            Path root = mavenSession.getRootDirectory();
            Path current = currentPom.toPath().toAbsolutePath().normalize();
            if (current.startsWith(root)) {
                current = root.relativize(current);
            }
            result += " (" + current + ")";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that rootDirectory always refer to the root of the project, while topDirectory refer to the current path (those may be different when building a subset of a project when using cd xxx && mvn ... or mvn -f xxx ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootDirectory seems to be available for maven 4 only...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 3.9.x, you could use session.getRequest().getMultiModuleProjectDirectory().

@cstamas what's your take on that ? would you rather keep poms relative to the top directory ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored the parts using your ideas (determine the relative path first before adding to the result string). The commits should probably be squashed before merged.

I've changed it also for pluginDeclaration(), to have consistent behavior.

Open question is now: Should I use session.getRequest().getMultiModuleProjectDirectory().toPath() instead of mavenSession.getTopLevelProject().getBasedir().toPath() for the root directory (for both pluginDeclaration() and pluginOccurrence()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be consistent with

File rootBasedir = session.getTopLevelProject().getBasedir();
logger.info(" from " + rootBasedir.toPath().relativize(currentPom.toPath()));

So better continue using the top directory. However, does the ExecutionEventLogger suffer from the same problem ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And can we make the local variable name consistent, i.e. name it topBasedir instead of rootBasedir ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And can we make the local variable name consistent, i.e. name it topBasedir instead of rootBasedir ?

Done.

I've also updated ExecutionEventLogger. It seems, this was the only other place, where Path::relativize is used.

@gnodet gnodet changed the title [MNG-7795] IllegalArgumentException: 'other' has different root durin… [3.9.x][MNG-7795] IllegalArgumentException: 'other' has different root durin… May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants