From ba700a4af6d5a3113e157b49ba40a70ee3d206ae Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:44:31 +0300 Subject: [PATCH] fix(gradle): Skip reason for composed version strings (#12128) --- lib/manager/gradle/shallow/extract.spec.ts | 29 ++++++++++++++++++++++ lib/manager/gradle/shallow/parser.ts | 24 ++++++++++-------- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/lib/manager/gradle/shallow/extract.spec.ts b/lib/manager/gradle/shallow/extract.spec.ts index 33678e57c8..951001c92c 100644 --- a/lib/manager/gradle/shallow/extract.spec.ts +++ b/lib/manager/gradle/shallow/extract.spec.ts @@ -1,5 +1,6 @@ import { extractAllPackageFiles } from '..'; import { fs, loadFixture } from '../../../../test/util'; +import { SkipReason } from '../../../types'; import type { ExtractConfig } from '../../types'; jest.mock('../../../util/fs'); @@ -108,6 +109,34 @@ describe('manager/gradle/shallow/extract', () => { ]); }); + it('skips versions composed from multiple variables', async () => { + mockFs({ + 'build.gradle': + 'foo = "1"; bar = "2"; baz = "3"; "foo:bar:$foo.$bar.$baz"', + }); + + const res = await extractAllPackageFiles({} as ExtractConfig, [ + 'build.gradle', + ]); + + expect(res).toMatchObject([ + { + packageFile: 'build.gradle', + deps: [ + { + depName: 'foo:bar', + currentValue: '1.2.3', + registryUrls: ['https://repo.maven.apache.org/maven2'], + skipReason: SkipReason.ContainsVariable, + managerData: { + packageFile: 'build.gradle', + }, + }, + ], + }, + ]); + }); + it('works with file-ext-var', async () => { mockFs({ 'gradle.properties': 'baz=1.2.3', diff --git a/lib/manager/gradle/shallow/parser.ts b/lib/manager/gradle/shallow/parser.ts index f684215c8e..6c913197f0 100644 --- a/lib/manager/gradle/shallow/parser.ts +++ b/lib/manager/gradle/shallow/parser.ts @@ -1,6 +1,7 @@ import * as url from 'url'; import is from '@sindresorhus/is'; import { logger } from '../../../logger'; +import { SkipReason } from '../../../types'; import { regEx } from '../../../util/regex'; import type { PackageDependency } from '../../types'; import type { GradleManagerData } from '../types'; @@ -147,20 +148,23 @@ function processDepInterpolation({ if (interpolationResult && isDependencyString(interpolationResult)) { const dep = parseDependencyString(interpolationResult); if (dep) { + let packageFile: string; + let fileReplacePosition: number; token.children.forEach((child) => { const variable = variables[child.value]; - if ( - child?.type === TokenType.Variable && - variable && - variable?.value === dep.currentValue - ) { - dep.managerData = { - fileReplacePosition: variable.fileReplacePosition, - packageFile: variable.packageFile, - }; - dep.groupName = variable.key; + if (child?.type === TokenType.Variable && variable) { + packageFile = variable.packageFile; + fileReplacePosition = variable.fileReplacePosition; + if (variable?.value === dep.currentValue) { + dep.managerData = { fileReplacePosition, packageFile }; + dep.groupName = variable.key; + } } }); + if (!dep.managerData) { + dep.managerData = { fileReplacePosition, packageFile }; + dep.skipReason = SkipReason.ContainsVariable; + } return { deps: [dep] }; } } -- GitLab