This commit is contained in:
Johannes Feichtner 2025-01-08 20:44:45 +01:00 committed by GitHub
commit 731ed6951b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 150 additions and 160 deletions

View file

@ -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",
},
},
]
`;

View file

@ -792,7 +792,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',
},
},
]);
});
});

View file

@ -321,14 +321,24 @@ export const qDotOrBraceExpr = (
matcher: q.QueryBuilder<Ctx, parser.Node>,
): q.QueryBuilder<Ctx, parser.Node> =>
q.sym<Ctx>(symValue).alt(
q.alt<Ctx>(
q.op<Ctx>('.').join(matcher),
q.tree({
type: 'wrapped-tree',
maxDepth: 1,
startsWith: '{',
endsWith: '}',
search: matcher,
}),
),
q.op<Ctx>('.').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'),
);

View file

@ -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

View file

@ -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'))

View file

@ -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<Ctx>('name')
.opt(q.op('='))
.join(qValueMatcher)
.handler((ctx) => storeInTokenMap(ctx, 'name')),
q.sym<Ctx>('url').opt(q.op('=')).join(qUri),
q.sym<Ctx>('setUrl').tree({
maxDepth: 1,
startsWith: '(',
endsWith: ')',
search: q.begin<Ctx>().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<Ctx>().opt(q.sym<Ctx>('url').op('=')).join(qUri).end(),
}),
q.tree({
type: 'wrapped-tree',
maxDepth: 1,
startsWith: '{',
endsWith: '}',
search: q.alt(
q
.sym<Ctx>('name')
.opt(q.op('='))
.join(qValueMatcher)
.handler((ctx) => storeInTokenMap(ctx, 'name')),
q.sym<Ctx>('url').opt(q.op('=')).join(qUri),
q.sym<Ctx>('setUrl').tree({
maxDepth: 1,
startsWith: '(',
endsWith: ')',
search: q.begin<Ctx>().join(qUri).end(),
}),
),
}),
qMavenArtifactRegistry,
)
.handler(handleCustomRegistryUrl)
.handler(cleanupTempVars);

View file

@ -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<Ctx>('.')
.alt(