From f31d62810c90965582ec741c441c0573a1731c87 Mon Sep 17 00:00:00 2001 From: Johannes Feichtner <343448+Churro@users.noreply.github.com> Date: Tue, 7 Mar 2023 05:59:12 +0100 Subject: [PATCH] feat(manager/gradle): add support for jmh plugin (#20784) --- lib/modules/manager/gradle/parser.spec.ts | 31 ++++++------ lib/modules/manager/gradle/parser/common.ts | 22 +++++---- .../manager/gradle/parser/dependencies.ts | 47 +++++++++++-------- lib/modules/manager/gradle/parser/handlers.ts | 2 +- 4 files changed, 58 insertions(+), 44 deletions(-) diff --git a/lib/modules/manager/gradle/parser.spec.ts b/lib/modules/manager/gradle/parser.spec.ts index 5b1a99bcf7..be59d51b67 100644 --- a/lib/modules/manager/gradle/parser.spec.ts +++ b/lib/modules/manager/gradle/parser.spec.ts @@ -890,27 +890,28 @@ describe('modules/manager/gradle/parser', () => { describe('implicit gradle plugins', () => { test.each` def | input | output - ${'baz = "1.2.3"'} | ${'checkstyle { toolVersion = "${baz}" }'} | ${{ depName: 'checkstyle', packageName: GRADLE_PLUGINS['checkstyle'], currentValue: '1.2.3' }} - ${''} | ${'codenarc { toolVersion = "1.2.3" }'} | ${{ depName: 'codenarc', packageName: GRADLE_PLUGINS['codenarc'], currentValue: '1.2.3' }} - ${''} | ${'detekt { toolVersion = "1.2.3" }'} | ${{ depName: 'detekt', packageName: GRADLE_PLUGINS['detekt'], currentValue: '1.2.3' }} - ${''} | ${'findbugs { toolVersion = "1.2.3" }'} | ${{ depName: 'findbugs', packageName: GRADLE_PLUGINS['findbugs'], currentValue: '1.2.3' }} - ${''} | ${'googleJavaFormat { toolVersion = "1.2.3" }'} | ${{ depName: 'googleJavaFormat', packageName: GRADLE_PLUGINS['googleJavaFormat'], currentValue: '1.2.3' }} - ${'baz = "1.2.3"'} | ${'jacoco { toolVersion = baz }'} | ${{ depName: 'jacoco', packageName: GRADLE_PLUGINS['jacoco'], currentValue: '1.2.3', groupName: 'baz' }} - ${'baz = "1.2.3"'} | ${'jacoco { toolVersion = property("baz") }'} | ${{ depName: 'jacoco', packageName: GRADLE_PLUGINS['jacoco'], currentValue: '1.2.3' }} - ${''} | ${'lombok { version = "1.2.3" }'} | ${{ depName: 'lombok', packageName: GRADLE_PLUGINS['lombok'], currentValue: '1.2.3' }} - ${''} | ${'lombok { version.set("1.2.3") }'} | ${{ depName: 'lombok', packageName: GRADLE_PLUGINS['lombok'], currentValue: '1.2.3' }} - ${''} | ${'lombok { version.value("1.2.3") }'} | ${{ depName: 'lombok', packageName: GRADLE_PLUGINS['lombok'], currentValue: '1.2.3' }} - ${''} | ${'pmd { toolVersion = "1.2.3" }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'], currentValue: '1.2.3' }} - ${''} | ${'pmd { toolVersion.set("1.2.3") }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'], currentValue: '1.2.3' }} - ${''} | ${'pmd { toolVersion.value("1.2.3") }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'], currentValue: '1.2.3' }} - ${''} | ${'pmd { foo = "bar"; toolVersion = "1.2.3" }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'], currentValue: '1.2.3' }} - ${''} | ${'spotbugs { toolVersion = "1.2.3" }'} | ${{ depName: 'spotbugs', packageName: GRADLE_PLUGINS['spotbugs'], currentValue: '1.2.3' }} + ${'baz = "1.2.3"'} | ${'checkstyle { toolVersion = "${baz}" }'} | ${{ depName: 'checkstyle', packageName: GRADLE_PLUGINS['checkstyle'][1], currentValue: '1.2.3' }} + ${''} | ${'codenarc { toolVersion = "1.2.3" }'} | ${{ depName: 'codenarc', packageName: GRADLE_PLUGINS['codenarc'][1], currentValue: '1.2.3' }} + ${''} | ${'detekt { toolVersion = "1.2.3" }'} | ${{ depName: 'detekt', packageName: GRADLE_PLUGINS['detekt'][1], currentValue: '1.2.3' }} + ${''} | ${'findbugs { toolVersion = "1.2.3" }'} | ${{ depName: 'findbugs', packageName: GRADLE_PLUGINS['findbugs'][1], currentValue: '1.2.3' }} + ${''} | ${'googleJavaFormat { toolVersion = "1.2.3" }'} | ${{ depName: 'googleJavaFormat', packageName: GRADLE_PLUGINS['googleJavaFormat'][1], currentValue: '1.2.3' }} + ${'baz = "1.2.3"'} | ${'jacoco { toolVersion = baz }'} | ${{ depName: 'jacoco', packageName: GRADLE_PLUGINS['jacoco'][1], currentValue: '1.2.3', groupName: 'baz' }} + ${'baz = "1.2.3"'} | ${'jacoco { toolVersion = property("baz") }'} | ${{ depName: 'jacoco', packageName: GRADLE_PLUGINS['jacoco'][1], currentValue: '1.2.3' }} + ${''} | ${'lombok { version = "1.2.3" }'} | ${{ depName: 'lombok', packageName: GRADLE_PLUGINS['lombok'][1], currentValue: '1.2.3' }} + ${''} | ${'lombok { version.set("1.2.3") }'} | ${{ depName: 'lombok', packageName: GRADLE_PLUGINS['lombok'][1], currentValue: '1.2.3' }} + ${''} | ${'lombok { version.value("1.2.3") }'} | ${{ depName: 'lombok', packageName: GRADLE_PLUGINS['lombok'][1], currentValue: '1.2.3' }} + ${''} | ${'pmd { toolVersion = "1.2.3" }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'][1], currentValue: '1.2.3' }} + ${''} | ${'pmd { toolVersion.set("1.2.3") }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'][1], currentValue: '1.2.3' }} + ${''} | ${'pmd { toolVersion.value("1.2.3") }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'][1], currentValue: '1.2.3' }} + ${''} | ${'pmd { foo = "bar"; toolVersion = "1.2.3" }'} | ${{ depName: 'pmd', packageName: GRADLE_PLUGINS['pmd'][1], currentValue: '1.2.3' }} + ${''} | ${'spotbugs { toolVersion = "1.2.3" }'} | ${{ depName: 'spotbugs', packageName: GRADLE_PLUGINS['spotbugs'][1], currentValue: '1.2.3' }} ${''} | ${'pmd { toolVersion = "@@@" }'} | ${null} ${''} | ${'pmd { toolVersion = "${baz}" }'} | ${null} ${'baz = "1.2.3"'} | ${'pmd { toolVersion = "${baz}.456" }'} | ${{ depName: 'pmd', currentValue: '1.2.3.456', skipReason: 'unknown-version' }} ${'baz = "1.2.3"'} | ${'pmd { toolVersion = baz + ".456" }'} | ${{ depName: 'pmd', currentValue: '1.2.3.456', skipReason: 'unknown-version' }} ${''} | ${'pmd { [toolVersion = "6.36.0"] }'} | ${null} ${''} | ${'unknown { toolVersion = "1.2.3" }'} | ${null} + ${''} | ${'jmh { jmhVersion = "1.2.3" }'} | ${{ depName: 'jmh', packageName: GRADLE_PLUGINS['jmh'][1], currentValue: '1.2.3' }} `('$def | $input', ({ def, input, output }) => { const { deps } = parseGradle([def, input].join('\n')); expect(deps).toMatchObject([output].filter(is.truthy)); diff --git a/lib/modules/manager/gradle/parser/common.ts b/lib/modules/manager/gradle/parser/common.ts index 69fddc9147..b6f653bf17 100644 --- a/lib/modules/manager/gradle/parser/common.ts +++ b/lib/modules/manager/gradle/parser/common.ts @@ -11,15 +11,19 @@ export const REGISTRY_URLS = { }; export const GRADLE_PLUGINS = { - checkstyle: 'com.puppycrawl.tools:checkstyle', - codenarc: 'org.codenarc:CodeNarc', - detekt: 'io.gitlab.arturbosch.detekt:detekt-core', - findbugs: 'com.google.code.findbugs:findbugs', - googleJavaFormat: 'com.google.googlejavaformat:google-java-format', - jacoco: 'org.jacoco:jacoco', - lombok: 'org.projectlombok:lombok', - pmd: 'net.sourceforge.pmd:pmd-java', - spotbugs: 'com.github.spotbugs:spotbugs', + checkstyle: ['toolVersion', 'com.puppycrawl.tools:checkstyle'], + codenarc: ['toolVersion', 'org.codenarc:CodeNarc'], + detekt: ['toolVersion', 'io.gitlab.arturbosch.detekt:detekt-core'], + findbugs: ['toolVersion', 'com.google.code.findbugs:findbugs'], + googleJavaFormat: [ + 'toolVersion', + 'com.google.googlejavaformat:google-java-format', + ], + jacoco: ['toolVersion', 'org.jacoco:jacoco'], + jmh: ['jmhVersion', 'org.openjdk.jmh:jmh-core'], + lombok: ['version', 'org.projectlombok:lombok'], + pmd: ['toolVersion', 'net.sourceforge.pmd:pmd-java'], + spotbugs: ['toolVersion', 'com.github.spotbugs:spotbugs'], }; export const ANNOYING_METHODS: ReadonlySet<string> = new Set([ diff --git a/lib/modules/manager/gradle/parser/dependencies.ts b/lib/modules/manager/gradle/parser/dependencies.ts index 098a2367e0..6336337902 100644 --- a/lib/modules/manager/gradle/parser/dependencies.ts +++ b/lib/modules/manager/gradle/parser/dependencies.ts @@ -162,29 +162,38 @@ export const qLongFormDep = q // pmd { toolVersion = "1.2.3" } const qImplicitGradlePlugin = q - .sym(regEx(`^(?:${Object.keys(GRADLE_PLUGINS).join('|')})$`), storeVarToken) - .handler((ctx) => storeInTokenMap(ctx, 'pluginName')) - .tree({ - type: 'wrapped-tree', - maxDepth: 1, - maxMatches: 1, - startsWith: '{', - endsWith: '}', - search: q.sym<Ctx>(regEx(/^(?:toolVersion|version)$/)).alt( - // toolVersion = "1.2.3" - q.op<Ctx>('=').join(qVersion), - // toolVersion.set("1.2.3"), toolVersion.value("1.2.3") + .alt( + ...Object.keys(GRADLE_PLUGINS).map((pluginName) => q - .op<Ctx>('.') - .sym(regEx(/^(?:set|value)$/)) + .sym<Ctx>(pluginName, storeVarToken) + .handler((ctx) => storeInTokenMap(ctx, 'pluginName')) .tree({ + type: 'wrapped-tree', maxDepth: 1, - startsWith: '(', - endsWith: ')', - search: q.begin<Ctx>().join(qVersion).end(), + maxMatches: 1, + startsWith: '{', + endsWith: '}', + search: q + .sym<Ctx>( + GRADLE_PLUGINS[pluginName as keyof typeof GRADLE_PLUGINS][0] + ) + .alt( + // toolVersion = "1.2.3" + q.op<Ctx>('=').join(qVersion), + // toolVersion.set("1.2.3"), toolVersion.value("1.2.3") + q + .op<Ctx>('.') + .sym(regEx(/^(?:set|value)$/)) + .tree({ + maxDepth: 1, + startsWith: '(', + endsWith: ')', + search: q.begin<Ctx>().join(qVersion).end(), + }) + ), }) - ), - }) + ) + ) .handler(handleImplicitGradlePlugin) .handler(cleanupTempVars); diff --git a/lib/modules/manager/gradle/parser/handlers.ts b/lib/modules/manager/gradle/parser/handlers.ts index 1b633d2d78..44f3f97006 100644 --- a/lib/modules/manager/gradle/parser/handlers.ts +++ b/lib/modules/manager/gradle/parser/handlers.ts @@ -397,7 +397,7 @@ export function handleImplicitGradlePlugin(ctx: Ctx): Ctx { } const groupIdArtifactId = - GRADLE_PLUGINS[pluginName as keyof typeof GRADLE_PLUGINS]; + GRADLE_PLUGINS[pluginName as keyof typeof GRADLE_PLUGINS][1]; const dep = parseDependencyString(`${groupIdArtifactId}:${versionValue}`); if (!dep) { return ctx; -- GitLab