From ebcc60826aa51662a09b2e8784ce4d58c2e69115 Mon Sep 17 00:00:00 2001 From: Robert Munteanu Date: Thu, 21 Sep 2023 07:16:27 +0200 Subject: [PATCH] feat: mavenPropertyVersions regexManager (#24425) Co-authored-by: Michael Kriese Co-authored-by: Johannes Feichtner <343448+Churro@users.noreply.github.com> --- .../presets/internal/regex-managers.spec.ts | 48 +++++++++++++++++++ lib/config/presets/internal/regex-managers.ts | 15 ++++++ 2 files changed, 63 insertions(+) diff --git a/lib/config/presets/internal/regex-managers.spec.ts b/lib/config/presets/internal/regex-managers.spec.ts index 13a947bec990c3..f4464c5150f961 100644 --- a/lib/config/presets/internal/regex-managers.spec.ts +++ b/lib/config/presets/internal/regex-managers.spec.ts @@ -232,4 +232,52 @@ describe('config/presets/internal/regex-managers', () => { }); }); }); + + describe('finds dependencies in pom.xml properties', () => { + const regexManager = presets['mavenPropertyVersions'].regexManagers?.[0]; + + it(`find dependencies in file`, async () => { + const fileContent = codeBlock` + + 9.3 + + + 4.0.10 + + + 4.4.6 + `; + + const res = await extractPackageFile( + fileContent, + 'pom.xml', + regexManager! + ); + + expect(res?.deps).toMatchObject([ + { + currentValue: '9.3', + datasource: 'maven', + depName: 'org.ow2.asm:asm', + replaceString: + '\n9.3', + }, + { + currentValue: '4.0.10', + datasource: 'maven', + depName: 'org.codehaus.groovy:groovy', + replaceString: + '\n4.0.10', + versioning: 'semver', + }, + { + currentValue: '4.4.6', + datasource: 'docker', + depName: 'mongo', + replaceString: + '\n4.4.6', + }, + ]); + }); + }); }); diff --git a/lib/config/presets/internal/regex-managers.ts b/lib/config/presets/internal/regex-managers.ts index e50074ab597a80..ac9bff0f4369dd 100644 --- a/lib/config/presets/internal/regex-managers.ts +++ b/lib/config/presets/internal/regex-managers.ts @@ -44,6 +44,21 @@ export const presets: Record = { }, ], }, + mavenPropertyVersions: { + description: 'Update `*.version` properties in `pom.xml` files.', + regexManagers: [ + { + customType: 'regex', + datasourceTemplate: + '{{#if datasource}}{{{datasource}}}{{else}}maven{{/if}}', + fileMatch: ['^pom\\.xml$'], + matchStrings: [ + '\\s+<.+\\.version>(?.+)<\\/.+\\.version>', + ], + versioningTemplate: '{{#if versioning}}{{{versioning}}}{{/if}}', + }, + ], + }, tfvarsVersions: { description: 'Update `*_version` variables in `.tfvars` files.', regexManagers: [