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

fix(maven): Implement latest fix of the Maven versions #22288

Merged
merged 2 commits into from May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/modules/versioning/maven/compare.spec.ts
Expand Up @@ -92,6 +92,8 @@ describe('modules/versioning/maven/compare', () => {
${'Hoxton.RELEASE'} | ${'hoxton'}
${'Hoxton.SR1'} | ${'hoxton.sr-1'}
${'1_5ea'} | ${'1.0_5ea'}
${'1.foo'} | ${'1-foo'}
${'1.x'} | ${'1-x'}
`('$x == $y', ({ x, y }) => {
expect(compare(x, y)).toBe(0);
expect(compare(y, x)).toBe(0);
Expand Down Expand Up @@ -164,7 +166,6 @@ describe('modules/versioning/maven/compare', () => {
${'1'} | ${'1-sp'}
${'1-foo2'} | ${'1-foo10'}
${'1-m1'} | ${'1-milestone-2'}
${'1.foo'} | ${'1-foo'}
${'1-foo'} | ${'1-1'}
${'1-alpha.1'} | ${'1-beta.1'}
${'1-1'} | ${'1.1'}
Expand Down Expand Up @@ -195,6 +196,30 @@ describe('modules/versioning/maven/compare', () => {
});
});

// @see https://issues.apache.org/jira/browse/MNG-7644
describe('MNG-7644', () => {
it.each`
qualifier
${'abc'}
${'alpha'}
${'a'}
${'beta'}
${'b'}
${'def'}
${'milestone'}
${'m'}
${'RC'}
`('$qualifier', ({ qualifier }: { qualifier: string }) => {
// 1.0.0.X1 < 1.0.0-X2 for any string x
expect(compare(`1.0.0.${qualifier}1`, `1.0.0-${qualifier}2`)).toBe(-1);

// 2.0.X == 2-X == 2.0.0.X for any string x
expect(compare(`2-${qualifier}`, `2.0.${qualifier}`)).toBe(0); // previously ordered, now equals
expect(compare(`2-${qualifier}`, `2.0.0.${qualifier}`)).toBe(0); // previously ordered, now equals
expect(compare(`2.0.${qualifier}`, `2.0.0.${qualifier}`)).toBe(0); // previously ordered, now equals
});
});

describe('Non-standard behavior', () => {
describe('equality', () => {
it.each`
Expand Down
7 changes: 2 additions & 5 deletions lib/modules/versioning/maven/compare.ts
Expand Up @@ -123,7 +123,7 @@ function tokenize(versionStr: string, preserveMinorZeroes = false): Token[] {
let result: Token[] = [];
let leadingZero = true;
iterateTokens(versionStr.toLowerCase().replace(regEx(/^v/i), ''), (token) => {
if (token.prefix === PREFIX_HYPHEN) {
if (token.prefix === PREFIX_HYPHEN || token.type === TYPE_QUALIFIER) {
buf = [];
}
buf.push(token);
Expand Down Expand Up @@ -154,10 +154,7 @@ function nullFor(token: Token): Token {
}

function commonOrder(token: Token): number {
if (token.prefix === PREFIX_DOT && token.type === TYPE_QUALIFIER) {
return 0;
}
if (token.prefix === PREFIX_HYPHEN && token.type === TYPE_QUALIFIER) {
if (token.type === TYPE_QUALIFIER) {
return 1;
}
if (token.prefix === PREFIX_HYPHEN && token.type === TYPE_NUMBER) {
Expand Down