From d022b8307ef17b80344eba95d512d9295725bfd1 Mon Sep 17 00:00:00 2001 From: ldt-fweichert <147594401+ldt-fweichert@users.noreply.github.com> Date: Thu, 20 Feb 2025 15:04:35 +0100 Subject: [PATCH] feat(gradle): bump strategy (#33453) Co-authored-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Rhys Arkins <rhys@arkins.net> --- lib/modules/manager/gradle/parser.spec.ts | 4 ++++ lib/modules/manager/gradle/utils.spec.ts | 13 ++++++++++++- lib/modules/manager/gradle/utils.ts | 9 +++++++-- lib/modules/versioning/gradle/index.spec.ts | 11 +++++++++++ lib/modules/versioning/gradle/index.ts | 2 +- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/modules/manager/gradle/parser.spec.ts b/lib/modules/manager/gradle/parser.spec.ts index f114ff7ca6..365c20867b 100644 --- a/lib/modules/manager/gradle/parser.spec.ts +++ b/lib/modules/manager/gradle/parser.spec.ts @@ -360,8 +360,12 @@ describe('modules/manager/gradle/parser', () => { it.each` input | output ${'"foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} + ${'"foo:bar:1.2+"'} | ${{ depName: 'foo:bar', currentValue: '1.2+' }} ${'"foo:bar:1.2.3@zip"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', dataType: 'zip' }} ${'"foo:bar1:1"'} | ${{ depName: 'foo:bar1', currentValue: '1', managerData: { fileReplacePosition: 10 } }} + ${'"foo:bar:[1.2.3, )"'} | ${{ depName: 'foo:bar', currentValue: '[1.2.3, )', managerData: { fileReplacePosition: 9 } }} + ${'"foo:bar:[1.2.3, 1.2.4)"'} | ${{ depName: 'foo:bar', currentValue: '[1.2.3, 1.2.4)', managerData: { fileReplacePosition: 9 } }} + ${'"foo:bar:[,1.2.4)"'} | ${{ depName: 'foo:bar', currentValue: '[,1.2.4)', managerData: { fileReplacePosition: 9 } }} ${'"foo:bar:x86@x86"'} | ${{ depName: 'foo:bar', currentValue: 'x86', managerData: { fileReplacePosition: 9 } }} ${'foo.bar = "foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} `('$input', ({ input, output }) => { diff --git a/lib/modules/manager/gradle/utils.spec.ts b/lib/modules/manager/gradle/utils.spec.ts index d8879d0ebf..2d9b25c4d1 100644 --- a/lib/modules/manager/gradle/utils.spec.ts +++ b/lib/modules/manager/gradle/utils.spec.ts @@ -36,7 +36,14 @@ describe('modules/manager/gradle/utils', () => { }); it('returns null for invalid inputs', () => { - const inputs = ['', undefined, null, 'foobar', 'latest']; + const inputs = [ + '', + undefined, + null, + 'foobar', + 'latest', + '[1.6.0, ] , abc', + ]; for (const input of inputs) { expect(versionLikeSubstring(input)).toBeNull(); } @@ -53,6 +60,9 @@ describe('modules/manager/gradle/utils', () => { ${'foo:bar:1.2.3@zip'} | ${true} ${'foo:bar:x86@x86'} | ${true} ${'foo.bar:baz:1.2.+'} | ${true} + ${'foo.bar:baz:[1.6.0, ]'} | ${true} + ${'foo.bar:baz:[, 1.6.0)'} | ${true} + ${'foo.bar:baz:]1.6.0,]'} | ${true} ${'foo:bar:baz:qux'} | ${false} ${'foo:bar:baz:qux:quux'} | ${false} ${"foo:bar:1.2.3'"} | ${false} @@ -74,6 +84,7 @@ describe('modules/manager/gradle/utils', () => { ${'foo.foo:bar.bar:1.2.3'} | ${{ depName: 'foo.foo:bar.bar', currentValue: '1.2.3' }} ${'foo.bar:baz:1.2.3'} | ${{ depName: 'foo.bar:baz', currentValue: '1.2.3' }} ${'foo:bar:1.2.+'} | ${{ depName: 'foo:bar', currentValue: '1.2.+' }} + ${'foo.bar:baz:[1.6.0, ]'} | ${{ depName: 'foo.bar:baz', currentValue: '[1.6.0, ]' }} ${'foo:bar:1.2.3@zip'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', dataType: 'zip' }} ${'foo:bar:baz:qux'} | ${null} ${'foo:bar:baz:qux:quux'} | ${null} diff --git a/lib/modules/manager/gradle/utils.ts b/lib/modules/manager/gradle/utils.ts index 8b238247ec..58bd904678 100644 --- a/lib/modules/manager/gradle/utils.ts +++ b/lib/modules/manager/gradle/utils.ts @@ -1,5 +1,6 @@ import upath from 'upath'; import { regEx } from '../../../util/regex'; +import { api as gradleVersioning } from '../../versioning/gradle'; import type { PackageDependency } from '../types'; import type { GradleManagerData, @@ -11,7 +12,7 @@ const artifactRegex = regEx( '^[a-zA-Z][-_a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-_a-zA-Z0-9]*?)*$', ); -const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+]+)'); +const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+ ]+)'); // Extracts version-like and range-like strings from the beginning of input export function versionLikeSubstring( @@ -22,11 +23,15 @@ export function versionLikeSubstring( } const match = versionLikeRegex.exec(input); - const version = match?.groups?.version; + const version = match?.groups?.version?.trim(); if (!version || !regEx(/\d/).test(version)) { return null; } + if (!gradleVersioning.isValid(version)) { + return null; + } + return version; } diff --git a/lib/modules/versioning/gradle/index.spec.ts b/lib/modules/versioning/gradle/index.spec.ts index bd42d7fbf1..1b50818cc3 100644 --- a/lib/modules/versioning/gradle/index.spec.ts +++ b/lib/modules/versioning/gradle/index.spec.ts @@ -330,6 +330,17 @@ describe('modules/versioning/gradle/index', () => { ${'[1.0,1.2],[1.3,1.5['} | ${'pin'} | ${'1.0'} | ${'1.2.4'} | ${'1.2.4'} ${'[1.2.3,)'} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'} ${'[1.2.3,['} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'} + ${'[1.2.3]'} | ${'bump'} | ${'1.2.3'} | ${'1.2.4'} | ${'[1.2.4]'} + ${'[1.0.0,1.2.3]'} | ${'bump'} | ${'1.0.0'} | ${'1.2.4'} | ${'[1.0.0,1.2.4]'} + ${'[1.0.0,1.2.23]'} | ${'bump'} | ${'1.0.0'} | ${'1.2.23'} | ${'[1.0.0,1.2.23]'} + ${'(,1.0]'} | ${'bump'} | ${'0.0.1'} | ${'2.0'} | ${'(,2.0]'} + ${'],1.0]'} | ${'bump'} | ${'0.0.1'} | ${'2.0'} | ${'],2.0]'} + ${'(,1.0)'} | ${'bump'} | ${'0.1'} | ${'2.0'} | ${'(,3.0)'} + ${'],1.0['} | ${'bump'} | ${'2.0'} | ${'],2.0['} | ${'],1.0['} + ${'[1.0,1.2],[1.3,1.5)'} | ${'bump'} | ${'1.0'} | ${'1.2.4'} | ${'[1.0,1.2],[1.3,1.5)'} + ${'[1.0,1.2],[1.3,1.5['} | ${'bump'} | ${'1.0'} | ${'1.2.4'} | ${'[1.0,1.2],[1.3,1.5['} + ${'[1.2.3,)'} | ${'bump'} | ${'1.2.3'} | ${'1.2.4'} | ${'[1.2.4,)'} + ${'[1.2.3,['} | ${'bump'} | ${'1.2.3'} | ${'1.2.4'} | ${'[1.2.4,['} `( 'getNewValue($currentValue, $rangeStrategy, $currentVersion, $newVersion, $expected) === $expected', ({ diff --git a/lib/modules/versioning/gradle/index.ts b/lib/modules/versioning/gradle/index.ts index 6b17ca2a3a..e196a77efc 100644 --- a/lib/modules/versioning/gradle/index.ts +++ b/lib/modules/versioning/gradle/index.ts @@ -19,7 +19,7 @@ export const urls = [ 'https://docs.gradle.org/current/userguide/single_versions.html#version_ordering', ]; export const supportsRanges = true; -export const supportedRangeStrategies: RangeStrategy[] = ['pin']; +export const supportedRangeStrategies: RangeStrategy[] = ['pin', 'bump']; const equals = (a: string, b: string): boolean => compare(a, b) === 0; -- GitLab