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

[MNG-7851] Improve error message when modelVersion is 4.0 #1210

Merged
merged 1 commit into from Aug 29, 2023

Conversation

candrews
Copy link
Contributor

MNG-7851 Improve error message when modelVersion is 4.0

Improve DefaultModelValidator.compareModelVersions to be able to compare versions which different numbers of segments, allowing it to compare "4", "4.0", and "4.0.0" to each other for example.


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.

Improve DefaultModelValidator.compareModelVersions to be able to compare
versions which different numbers of segments, allowing it to compare
"4", "4.0", and "4.0.0" to each other for example.

Signed-off-by: Craig Andrews <candrews@integralblue.com>
@michael-o
Copy link
Member

This will very likely violate the generated XML Schema. Moreover, the validator prints a hard version. I consider this change wrong.

@candrews
Copy link
Contributor Author

This will very likely violate the generated XML Schema.

How does it violate the schema? Can you point me to something?

The result of this change is only that the error message changes - no other behavior changes.
With <modelVersion>4.0.0</modelVersion>:
Before:
'modelVersion' of '4.0' is newer than the versions supported by this version of Maven: [4.0.0]. Building this project requires a newer version of Maven.
With this PR:
'modelVersion' must be one of [4.0.0] but is '4.0'.

In this PR, I added a unit test that demonstrates this change in error messaging behavior for this situation.

Moreover, the validator prints a hard version. I consider this change wrong.

I'm sorry, I don't understand... Can you please clarify, perhaps with an example?

@michael-o
Copy link
Member

Just checked, the schema does not enforce the model version...weird. I'd say that it should be fixed literal 4.0.0. For me, this is similar to an XML namespace, if you change a single char then you change the entire namespace.
@gnodet @cstamas @hboutemy WDYT?

@candrews
Copy link
Contributor Author

I'd say that it should be fixed literal 4.0.0.

Currently, Maven does require it to be the literal 4.0.0:
https://github.com/apache/maven/blob/maven-3.9.4/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java#L138
https://github.com/apache/maven/blob/maven-3.9.4/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java#L1433

This PR adjusts the error message that is returned when attempts to use non-4.0.0 values are made.

@michael-o
Copy link
Member

michael-o commented Jul 26, 2023

I take my first comment back. Thanks for this clarification.

@cstamas
Copy link
Member

cstamas commented Jul 26, 2023

allowing it to compare "4", "4.0", and "4.0.0" to each other for example.

And to do what? I don't see where is the error message adjusted... what do i miss?

@candrews
Copy link
Contributor Author

And to do what? I don't see where is the error message adjusted... what do i miss?

The new test case at

demonstrates how the message changes. Before this PR, the message in this case is 'modelVersion' of '4.0' is newer than the versions supported by this version of Maven: [4.0.0]. Building this project requires a newer version of Maven. And with this PR, as this test case proves, the error message is 'modelVersion' must be one of [4.0.0] but is '4.0'..

@cstamas
Copy link
Member

cstamas commented Aug 1, 2023

LGTM

@michael-o
Copy link
Member

LGTM

then please approve

Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

If we're going litteral, shouldn't we simply check that the version in the model is one of the supported version. The validateModelVersion could be simplified to just check the version is supported or thrown an exception without having to check for newer / older versions.

@cstamas
Copy link
Member

cstamas commented Aug 3, 2023

The "version comparing"-like code is there (and was) only for "meaningful" error message: newer -> you need newer maven. But i agree, to me this looks overly complicated as well (or just use Version class instead?)

@gnodet
Copy link
Contributor

gnodet commented Aug 22, 2023

If we're going litteral, shouldn't we simply check that the version in the model is one of the supported version. The validateModelVersion could be simplified to just check the version is supported or thrown an exception without having to check for newer / older versions.

@candrews could you simplify the code for the validateModelVersion method so that it simply checks if the version is in the provided set instead (third branch of the tests) instead of comparing with all other versions ?

Copy link
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

I changed my mind... LGTM

@gnodet gnodet merged commit c482de8 into apache:maven-3.9.x Aug 29, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants