From 319223518661f52081c7921f7c8f7e81e9f681e4 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Wed, 8 Dec 2021 07:18:00 +0300 Subject: [PATCH] fix(gradle): Handle scala version interpolation (#12989) --- lib/manager/gradle/shallow/parser.spec.ts | 1 + lib/manager/gradle/shallow/parser.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/manager/gradle/shallow/parser.spec.ts b/lib/manager/gradle/shallow/parser.spec.ts index e828da74021093..d3b844772bbf73 100644 --- a/lib/manager/gradle/shallow/parser.spec.ts +++ b/lib/manager/gradle/shallow/parser.spec.ts @@ -50,6 +50,7 @@ describe('manager/gradle/shallow/parser', () => { ${'foo = "1.2.3"'} | ${'"foo:bar:$foo@@@"'} | ${null} ${'baz = "1.2.3"'} | ${'"foo:bar:$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }} ${'foo.bar = "1.2.3"'} | ${'"foo:bar:$foo.bar"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'foo.bar' }} + ${'foo = "1.2.3"'} | ${'"foo:bar_$foo:4.5.6"'} | ${{ depName: 'foo:bar_1.2.3', managerData: { fileReplacePosition: 28 } }} ${''} | ${'foo.bar = "foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }} ${'baz = "1.2.3"'} | ${'foobar = "foo:bar:$baz"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }} ${'baz = "1.2.3"'} | ${'group: "foo", name: "bar", version: baz'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }} diff --git a/lib/manager/gradle/shallow/parser.ts b/lib/manager/gradle/shallow/parser.ts index c906e834b8a2ca..f95b2443980fe3 100644 --- a/lib/manager/gradle/shallow/parser.ts +++ b/lib/manager/gradle/shallow/parser.ts @@ -160,6 +160,7 @@ function processDepString({ function processDepInterpolation({ tokenMap, variables, + packageFile: packageFileOrig, }: SyntaxHandlerInput): SyntaxHandlerOutput { const token = tokenMap.depInterpolation as StringInterpolation; const interpolationResult = interpolateString(token.children, variables); @@ -180,8 +181,18 @@ function processDepInterpolation({ } }); if (!dep.managerData) { + const lastToken = token.children[token.children.length - 1]; + if ( + lastToken.type === TokenType.String && + lastToken.value.startsWith(`:${dep.currentValue}`) + ) { + packageFile = packageFileOrig; + fileReplacePosition = lastToken.offset + 1; + delete dep.groupName; + } else { + dep.skipReason = SkipReason.ContainsVariable; + } dep.managerData = { fileReplacePosition, packageFile }; - dep.skipReason = SkipReason.ContainsVariable; } return { deps: [dep] }; }