Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager/gradle): Support properties map in gradle kts #21792

Merged
merged 5 commits into from May 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/modules/manager/gradle/parser.spec.ts
Expand Up @@ -363,6 +363,7 @@ describe('modules/manager/gradle/parser', () => {
${'baz = "1.2.3"'} | ${'"foo:bar:${ext.baz}"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }}
${'baz = "1.2.3"'} | ${'"foo:bar:${project.ext[\'baz\']}"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' }}
${'a = "foo"; b = "bar"; c="1.2.3"'} | ${'"${a}:${b}:${property("c")}"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'c' }}
${'a = "foo"; b = "bar"; c="1.2.3"'} | ${'"${a}:${b}:${properties["c"]}"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'c' }}
`('$def | $str', ({ def, str, output }) => {
const { deps } = parseGradle([def, str].join('\n'));
expect(deps).toMatchObject([output].filter(is.truthy));
Expand Down Expand Up @@ -418,6 +419,24 @@ describe('modules/manager/gradle/parser', () => {
});
});

describe('properties map accessors', () => {
viceice marked this conversation as resolved.
Show resolved Hide resolved
test.each`
accessor
${'properties'}
${'project.properties'}
${'rootProject.properties'}
`('$accessor', ({ accessor }) => {
const input = `
baz = "1.2.3"
api("foo:bar:$\{${String(accessor)}["baz"]}")
`;
const { deps } = parseGradle(input);
expect(deps).toMatchObject([
{ depName: 'foo:bar', currentValue: '1.2.3', groupName: 'baz' },
]);
});
});

describe('kotlin() short notation dependencies', () => {
const output = {
depName: 'foo',
Expand Down
9 changes: 8 additions & 1 deletion lib/modules/manager/gradle/parser/common.spec.ts
Expand Up @@ -94,7 +94,14 @@ describe('modules/manager/gradle/parser/common', () => {
});

it('stripReservedPrefixFromKeyTokens', () => {
const tokenValues = ['rootProject', 'project', 'ext', 'extra', 'foo'];
const tokenValues = [
'rootProject',
'project',
'ext',
'extra',
'properties',
'foo',
];

ctx.varTokens.push(
...tokenValues.map((value) => partial<lexer.Token>({ value }))
Expand Down
8 changes: 7 additions & 1 deletion lib/modules/manager/gradle/parser/common.ts
Expand Up @@ -83,7 +83,13 @@ export function cleanupTempVars(ctx: Ctx): Ctx {
}

export function stripReservedPrefixFromKeyTokens(ctx: Ctx): Ctx {
const unwantedPrefixes = ['ext', 'extra', 'project', 'rootProject'];
const unwantedPrefixes = [
'ext',
'extra',
'project',
'rootProject',
'properties',
];
while (
ctx.varTokens.length > 1 && // ensures there will be always at least one token
ctx.varTokens[0] &&
Expand Down