Skip to content

Commit

Permalink
fix(maven): Implement latest fix of the Maven versions (#22288)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed May 17, 2023
1 parent 5207da4 commit 42e2b27
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
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
3 changes: 2 additions & 1 deletion lib/modules/versioning/maven/index.spec.ts
Expand Up @@ -112,12 +112,13 @@ describe('modules/versioning/maven/index', () => {
${'1'} | ${'(,1),(1,)'} | ${false}
${'1'} | ${'(0,1),(1,2)'} | ${false}
${'1.0.0.RC9.2'} | ${'(,1.0.0.RC9.2),(1.0.0.RC9.2,)'} | ${false}
${'1.0.0-RC14'} | ${'(,1.0.0.RC9.2),(1.0.0.RC9.2,)'} | ${true}
${'1.0.0.RC14'} | ${'(,1.0.0.RC9.2),(1.0.0.RC9.2,)'} | ${true}
${'0'} | ${''} | ${false}
${'1'} | ${'1'} | ${true}
${'1'} | ${'(1'} | ${false}
${'2.4.2'} | ${'2.4.2'} | ${true}
${'2.4.2'} | ${'= 2.4.2'} | ${false}
${'1.2.3'} | ${'[1,2],[3,4]'} | ${true}
`(
'matches("$version", "$range") === $expected',
({ version, range, expected }) => {
Expand Down

0 comments on commit 42e2b27

Please sign in to comment.