From 906a904470d822a4246505d61b57db83b22d37b5 Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Thu, 14 Nov 2024 19:53:00 +0100 Subject: [PATCH 1/3] feat(maven): Use relocation information Fixes #5667 --- lib/modules/datasource/maven/index.spec.ts | 59 ++++++++++++++++++++++ lib/modules/datasource/maven/util.ts | 12 +++++ 2 files changed, 71 insertions(+) diff --git a/lib/modules/datasource/maven/index.spec.ts b/lib/modules/datasource/maven/index.spec.ts index eec203b2520c78..47dc14250e1182 100644 --- a/lib/modules/datasource/maven/index.spec.ts +++ b/lib/modules/datasource/maven/index.spec.ts @@ -353,6 +353,65 @@ describe('modules/datasource/maven/index', () => { expect(res?.sourceUrl).toBe('https://github.com/example/test'); }); + describe('supports relocation', () => { + it('with only groupId present', async () => { + const pom = ` + + + + io.example + + +`; + mockGenericPackage({ pom, html: null }); + + const res = await get(); + + expect(res?.replacementName).toBe('io.example:package'); + expect(res?.replacementVersion).toBe('2.0.0'); + expect(res?.deprecationMessage).toBeUndefined(); + }); + + it('with only artifactId present', async () => { + const pom = ` + + + + foo + + +`; + mockGenericPackage({ pom, html: null }); + + const res = await get(); + + expect(res?.replacementName).toBe('org.example:foo'); + expect(res?.replacementVersion).toBe('2.0.0'); + expect(res?.deprecationMessage).toBeUndefined(); + }); + + it('with all elments present', async () => { + const pom = ` + + + + io.example + foo + 1.2.3 + test relocation + + +`; + mockGenericPackage({ pom, html: null }); + + const res = await get(); + + expect(res?.replacementName).toBe('io.example:foo'); + expect(res?.replacementVersion).toBe('1.2.3'); + expect(res?.deprecationMessage).toBe('test relocation'); + }); + }); + it('removes authentication header after redirect', async () => { const frontendHost = 'frontend_for_private_s3_repository'; const frontendUrl = `https://${frontendHost}/maven2`; diff --git a/lib/modules/datasource/maven/util.ts b/lib/modules/datasource/maven/util.ts index b521b99d53ab1d..448c4f32df0d87 100644 --- a/lib/modules/datasource/maven/util.ts +++ b/lib/modules/datasource/maven/util.ts @@ -485,6 +485,18 @@ export async function getDependencyInfo( } } + const relocation = pomContent.descendantWithPath( + 'distributionManagement.relocation', + ); + if (relocation) { + const newGroup = relocation.valueWithPath('groupId') ?? dependency.group; + const newName = relocation.valueWithPath('artifactId') ?? dependency.name; + result.replacementName = newGroup + ':' + newName; + const relocationVersion = relocation.valueWithPath('version'); + result.replacementVersion = relocationVersion ?? version; + result.deprecationMessage = relocation.valueWithPath('message'); + } + const groupId = pomContent.valueWithPath('groupId'); if (groupId) { result.packageScope = groupId; From 4a69bac25fc9efc65478f1fb666f41a851d29631 Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Thu, 21 Nov 2024 22:24:52 +0100 Subject: [PATCH 2/3] Apply review suggestions --- lib/modules/datasource/maven/util.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/modules/datasource/maven/util.ts b/lib/modules/datasource/maven/util.ts index 448c4f32df0d87..b94c6199cb0c1d 100644 --- a/lib/modules/datasource/maven/util.ts +++ b/lib/modules/datasource/maven/util.ts @@ -489,9 +489,11 @@ export async function getDependencyInfo( 'distributionManagement.relocation', ); if (relocation) { - const newGroup = relocation.valueWithPath('groupId') ?? dependency.group; - const newName = relocation.valueWithPath('artifactId') ?? dependency.name; - result.replacementName = newGroup + ':' + newName; + const relocationGroup = + relocation.valueWithPath('groupId') ?? dependency.group; + const relocationName = + relocation.valueWithPath('artifactId') ?? dependency.name; + result.replacementName = relocationGroup + ':' + relocationName; const relocationVersion = relocation.valueWithPath('version'); result.replacementVersion = relocationVersion ?? version; result.deprecationMessage = relocation.valueWithPath('message'); From 3b3b7fd9c06226dde99d96e57466881e5011b01e Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Sun, 24 Nov 2024 15:56:41 +0100 Subject: [PATCH 3/3] Apply review suggestions --- lib/modules/datasource/maven/index.spec.ts | 73 ++++++++++++---------- lib/modules/datasource/maven/util.ts | 7 ++- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/lib/modules/datasource/maven/index.spec.ts b/lib/modules/datasource/maven/index.spec.ts index 47dc14250e1182..13fa0989447f0e 100644 --- a/lib/modules/datasource/maven/index.spec.ts +++ b/lib/modules/datasource/maven/index.spec.ts @@ -356,59 +356,66 @@ describe('modules/datasource/maven/index', () => { describe('supports relocation', () => { it('with only groupId present', async () => { const pom = ` - - - - io.example - - -`; + + + + io.example + + + + `; mockGenericPackage({ pom, html: null }); const res = await get(); - expect(res?.replacementName).toBe('io.example:package'); - expect(res?.replacementVersion).toBe('2.0.0'); - expect(res?.deprecationMessage).toBeUndefined(); + expect(res).toMatchObject({ + replacementName: 'io.example:package', + replacementVersion: '2.0.0', + }); }); it('with only artifactId present', async () => { const pom = ` - - - - foo - - -`; + + + + foo + + + + `; mockGenericPackage({ pom, html: null }); const res = await get(); - expect(res?.replacementName).toBe('org.example:foo'); - expect(res?.replacementVersion).toBe('2.0.0'); - expect(res?.deprecationMessage).toBeUndefined(); + expect(res).toMatchObject({ + replacementName: 'org.example:foo', + replacementVersion: '2.0.0', + }); }); it('with all elments present', async () => { const pom = ` - - - - io.example - foo - 1.2.3 - test relocation - - -`; + + + + io.example + foo + 1.2.3 + test relocation + + + + `; mockGenericPackage({ pom, html: null }); const res = await get(); - expect(res?.replacementName).toBe('io.example:foo'); - expect(res?.replacementVersion).toBe('1.2.3'); - expect(res?.deprecationMessage).toBe('test relocation'); + expect(res).toMatchObject({ + replacementName: 'io.example:foo', + replacementVersion: '1.2.3', + deprecationMessage: 'test relocation', + }); }); }); diff --git a/lib/modules/datasource/maven/util.ts b/lib/modules/datasource/maven/util.ts index b94c6199cb0c1d..6bcbdb95968a60 100644 --- a/lib/modules/datasource/maven/util.ts +++ b/lib/modules/datasource/maven/util.ts @@ -493,10 +493,13 @@ export async function getDependencyInfo( relocation.valueWithPath('groupId') ?? dependency.group; const relocationName = relocation.valueWithPath('artifactId') ?? dependency.name; - result.replacementName = relocationGroup + ':' + relocationName; + result.replacementName = `${relocationGroup}:${relocationName}`; const relocationVersion = relocation.valueWithPath('version'); result.replacementVersion = relocationVersion ?? version; - result.deprecationMessage = relocation.valueWithPath('message'); + const relocationMessage = relocation.valueWithPath('message'); + if (relocationMessage) { + result.deprecationMessage = relocationMessage; + } } const groupId = pomContent.valueWithPath('groupId');