diff --git a/lib/modules/manager/gradle/__snapshots__/parser.spec.ts.snap b/lib/modules/manager/gradle/__snapshots__/parser.spec.ts.snap deleted file mode 100644 index 571951909582d3..00000000000000 --- a/lib/modules/manager/gradle/__snapshots__/parser.spec.ts.snap +++ /dev/null @@ -1,103 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`modules/manager/gradle/parser calculations parses fixture from "gradle" manager 1`] = ` -[ - { - "currentValue": "1.5.2.RELEASE", - "depName": "org.springframework.boot:spring-boot-gradle-plugin", - "groupName": "springBootVersion", - "managerData": { - "fileReplacePosition": 53, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "1.2.3", - "depName": "com.github.jengelman.gradle.plugins:shadow", - "managerData": { - "fileReplacePosition": 417, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "0.1", - "depName": "com.fkorotkov:gradle-libraries-plugin", - "managerData": { - "fileReplacePosition": 481, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "0.2.3", - "depName": "gradle.plugin.se.patrikerdes:gradle-use-latest-versions-plugin", - "managerData": { - "fileReplacePosition": 568, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "3.1.1", - "depName": "org.apache.openjpa:openjpa", - "managerData": { - "fileReplacePosition": 621, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "0.13.0", - "depName": "com.gradle.publish:plugin-publish-plugin", - "managerData": { - "fileReplacePosition": 688, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "6.0.9.RELEASE", - "depName": "org.grails:gorm-hibernate5-spring-boot", - "managerData": { - "fileReplacePosition": 1882, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "6.0.5", - "depName": "mysql:mysql-connector-java", - "managerData": { - "fileReplacePosition": 1938, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "1.0-groovy-2.4", - "depName": "org.spockframework:spock-spring", - "managerData": { - "fileReplacePosition": 1996, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "1.3", - "depName": "org.hamcrest:hamcrest-core", - "managerData": { - "fileReplacePosition": 2101, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "3.1", - "depName": "cglib:cglib-nodep", - "managerData": { - "fileReplacePosition": 2189, - "packageFile": "build.gradle", - }, - }, - { - "currentValue": "3.1.1", - "depName": "org.apache.openjpa:openjpa", - "managerData": { - "fileReplacePosition": 2295, - "packageFile": "build.gradle", - }, - }, -] -`; diff --git a/lib/modules/manager/gradle/parser.spec.ts b/lib/modules/manager/gradle/parser.spec.ts index cfc2e4f3152896..6e835a56d6be00 100644 --- a/lib/modules/manager/gradle/parser.spec.ts +++ b/lib/modules/manager/gradle/parser.spec.ts @@ -803,7 +803,106 @@ describe('modules/manager/gradle/parser', () => { content.slice(managerData!.fileReplacePosition).indexOf(currentValue!), ); expect(replacementIndices.every((idx) => idx === 0)).toBeTrue(); - expect(deps).toMatchSnapshot(); + expect(deps).toMatchObject([ + { + currentValue: '1.5.2.RELEASE', + depName: 'org.springframework.boot:spring-boot-gradle-plugin', + groupName: 'springBootVersion', + managerData: { + fileReplacePosition: 53, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '1.2.3', + depName: 'com.github.jengelman.gradle.plugins:shadow', + managerData: { + fileReplacePosition: 417, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '0.1', + depName: 'com.fkorotkov:gradle-libraries-plugin', + managerData: { + fileReplacePosition: 481, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '0.2.3', + depName: + 'gradle.plugin.se.patrikerdes:gradle-use-latest-versions-plugin', + managerData: { + fileReplacePosition: 568, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '3.1.1', + depName: 'org.apache.openjpa:openjpa', + managerData: { + fileReplacePosition: 621, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '0.13.0', + depName: 'com.gradle.publish:plugin-publish-plugin', + managerData: { + fileReplacePosition: 688, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '6.0.9.RELEASE', + depName: 'org.grails:gorm-hibernate5-spring-boot', + managerData: { + fileReplacePosition: 1882, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '6.0.5', + depName: 'mysql:mysql-connector-java', + managerData: { + fileReplacePosition: 1938, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '1.0-groovy-2.4', + depName: 'org.spockframework:spock-spring', + managerData: { + fileReplacePosition: 1996, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '1.3', + depName: 'org.hamcrest:hamcrest-core', + managerData: { + fileReplacePosition: 2101, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '3.1', + depName: 'cglib:cglib-nodep', + managerData: { + fileReplacePosition: 2189, + packageFile: 'build.gradle', + }, + }, + { + currentValue: '3.1.1', + depName: 'org.apache.openjpa:openjpa', + managerData: { + fileReplacePosition: 2295, + packageFile: 'build.gradle', + }, + }, + ]); }); }); diff --git a/lib/modules/manager/gradle/parser/common.ts b/lib/modules/manager/gradle/parser/common.ts index fffc610c0cac41..a008c30249da4c 100644 --- a/lib/modules/manager/gradle/parser/common.ts +++ b/lib/modules/manager/gradle/parser/common.ts @@ -321,14 +321,24 @@ export const qDotOrBraceExpr = ( matcher: q.QueryBuilder, ): q.QueryBuilder => q.sym(symValue).alt( - q.alt( - q.op('.').join(matcher), - q.tree({ - type: 'wrapped-tree', - maxDepth: 1, - startsWith: '{', - endsWith: '}', - search: matcher, - }), - ), + q.op('.').join(matcher), + q.tree({ + type: 'wrapped-tree', + maxDepth: 1, + startsWith: '{', + endsWith: '}', + search: matcher, + }), ); + +export const qGroupId = qValueMatcher.handler((ctx) => + storeInTokenMap(ctx, 'groupId'), +); + +export const qArtifactId = qValueMatcher.handler((ctx) => + storeInTokenMap(ctx, 'artifactId'), +); + +export const qVersion = qValueMatcher.handler((ctx) => + storeInTokenMap(ctx, 'version'), +); diff --git a/lib/modules/manager/gradle/parser/dependencies.ts b/lib/modules/manager/gradle/parser/dependencies.ts index 93e029da4037bf..e9fb2b1265fe66 100644 --- a/lib/modules/manager/gradle/parser/dependencies.ts +++ b/lib/modules/manager/gradle/parser/dependencies.ts @@ -4,9 +4,12 @@ import type { Ctx } from '../types'; import { GRADLE_PLUGINS, cleanupTempVars, + qArtifactId, qDotOrBraceExpr, + qGroupId, qTemplateString, qValueMatcher, + qVersion, storeInTokenMap, storeVarToken, } from './common'; @@ -17,18 +20,6 @@ import { handleLongFormDep, } from './handlers'; -const qGroupId = qValueMatcher.handler((ctx) => - storeInTokenMap(ctx, 'groupId'), -); - -const qArtifactId = qValueMatcher.handler((ctx) => - storeInTokenMap(ctx, 'artifactId'), -); - -const qVersion = qValueMatcher.handler((ctx) => - storeInTokenMap(ctx, 'version'), -); - // "foo:bar:1.2.3" // "foo:bar:$baz" // "foo" + "${bar}" + baz diff --git a/lib/modules/manager/gradle/parser/plugins.ts b/lib/modules/manager/gradle/parser/plugins.ts index 5cf27b58c11891..aebb081067abe2 100644 --- a/lib/modules/manager/gradle/parser/plugins.ts +++ b/lib/modules/manager/gradle/parser/plugins.ts @@ -4,16 +4,12 @@ import type { Ctx } from '../types'; import { cleanupTempVars, qStringValue, - qValueMatcher, + qVersion, storeInTokenMap, storeVarToken, } from './common'; import { handlePlugin } from './handlers'; -const qVersion = qValueMatcher.handler((ctx) => - storeInTokenMap(ctx, 'version'), -); - export const qPlugins = q .sym(regEx(/^(?:id|kotlin)$/), storeVarToken) .handler((ctx) => storeInTokenMap(ctx, 'methodName')) diff --git a/lib/modules/manager/gradle/parser/registry-urls.ts b/lib/modules/manager/gradle/parser/registry-urls.ts index 341dc37d547ec2..e684135f808852 100644 --- a/lib/modules/manager/gradle/parser/registry-urls.ts +++ b/lib/modules/manager/gradle/parser/registry-urls.ts @@ -32,6 +32,7 @@ const qUri = q // mavenCentral { ... } const qPredefinedRegistries = q .sym(regEx(`^(?:${Object.keys(REGISTRY_URLS).join('|')})$`), storeVarToken) + .handler((ctx) => storeInTokenMap(ctx, 'registryUrl')) .alt( q.tree({ type: 'wrapped-tree', @@ -45,10 +46,31 @@ const qPredefinedRegistries = q endsWith: '}', }), ) - .handler((ctx) => storeInTokenMap(ctx, 'registryUrl')) .handler(handlePredefinedRegistryUrl) .handler(cleanupTempVars); +// { url = "https://some.repo" } +const qMavenArtifactRegistry = q.tree({ + type: 'wrapped-tree', + maxDepth: 1, + startsWith: '{', + endsWith: '}', + search: q.alt( + q + .sym('name') + .opt(q.op('=')) + .join(qValueMatcher) + .handler((ctx) => storeInTokenMap(ctx, 'name')), + q.sym('url').opt(q.op('=')).join(qUri), + q.sym('setUrl').tree({ + maxDepth: 1, + startsWith: '(', + endsWith: ')', + search: q.begin().join(qUri).end(), + }), + ), +}); + // maven(url = uri("https://foo.bar/baz")) // maven { name = some; url = "https://foo.bar/${name}" } const qCustomRegistryUrl = q @@ -61,26 +83,7 @@ const qCustomRegistryUrl = q endsWith: ')', search: q.begin().opt(q.sym('url').op('=')).join(qUri).end(), }), - q.tree({ - type: 'wrapped-tree', - maxDepth: 1, - startsWith: '{', - endsWith: '}', - search: q.alt( - q - .sym('name') - .opt(q.op('=')) - .join(qValueMatcher) - .handler((ctx) => storeInTokenMap(ctx, 'name')), - q.sym('url').opt(q.op('=')).join(qUri), - q.sym('setUrl').tree({ - maxDepth: 1, - startsWith: '(', - endsWith: ')', - search: q.begin().join(qUri).end(), - }), - ), - }), + qMavenArtifactRegistry, ) .handler(handleCustomRegistryUrl) .handler(cleanupTempVars); diff --git a/lib/modules/manager/gradle/parser/version-catalogs.ts b/lib/modules/manager/gradle/parser/version-catalogs.ts index 272688ee6084b1..c4c1259ccf424d 100644 --- a/lib/modules/manager/gradle/parser/version-catalogs.ts +++ b/lib/modules/manager/gradle/parser/version-catalogs.ts @@ -2,6 +2,8 @@ import { query as q } from 'good-enough-parser'; import type { Ctx } from '../types'; import { cleanupTempVars, + qArtifactId, + qGroupId, qStringValue, qStringValueAsSymbol, qValueMatcher, @@ -10,14 +12,6 @@ import { } from './common'; import { handleLibraryDep, handlePlugin } from './handlers'; -const qGroupId = qValueMatcher.handler((ctx) => - storeInTokenMap(ctx, 'groupId'), -); - -const qArtifactId = qValueMatcher.handler((ctx) => - storeInTokenMap(ctx, 'artifactId'), -); - const qVersionCatalogVersion = q .op('.') .alt(