mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
fix(gradle-lite): Inherit variables from parent build.gradle (#8451)
This commit is contained in:
parent
9e09363305
commit
1b2a3f8006
3 changed files with 54 additions and 6 deletions
|
@ -66,4 +66,34 @@ describe('manager/gradle-lite/extract', () => {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('inherits gradle variables', async () => {
|
||||||
|
const fsMock = {
|
||||||
|
'gradle.properties': 'foo=1.0.0',
|
||||||
|
'build.gradle': 'foo = "1.0.1"',
|
||||||
|
'aaa/gradle.properties': 'bar = "2.0.0"',
|
||||||
|
'aaa/build.gradle': 'bar = "2.0.1"',
|
||||||
|
'aaa/bbb/build.gradle': ['foo:foo:$foo', 'bar:bar:$bar']
|
||||||
|
.map((x) => `"${x}"`)
|
||||||
|
.join('\n'),
|
||||||
|
};
|
||||||
|
|
||||||
|
mockFs(fsMock);
|
||||||
|
|
||||||
|
const res = await extractAllPackageFiles({} as never, Object.keys(fsMock));
|
||||||
|
|
||||||
|
expect(res).toMatchObject([
|
||||||
|
{ packageFile: 'gradle.properties', deps: [] },
|
||||||
|
{
|
||||||
|
packageFile: 'build.gradle',
|
||||||
|
deps: [{ depName: 'foo:foo', currentValue: '1.0.1' }],
|
||||||
|
},
|
||||||
|
{ packageFile: 'aaa/gradle.properties', deps: [] },
|
||||||
|
{
|
||||||
|
packageFile: 'aaa/build.gradle',
|
||||||
|
deps: [{ depName: 'bar:bar', currentValue: '2.0.1' }],
|
||||||
|
},
|
||||||
|
{ packageFile: 'aaa/bbb/build.gradle', deps: [] },
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as datasourceMaven from '../../datasource/maven';
|
||||||
import { logger } from '../../logger';
|
import { logger } from '../../logger';
|
||||||
import { readLocalFile } from '../../util/fs';
|
import { readLocalFile } from '../../util/fs';
|
||||||
import { ExtractConfig, PackageDependency, PackageFile } from '../common';
|
import { ExtractConfig, PackageDependency, PackageFile } from '../common';
|
||||||
import { ManagerData, VariableRegistry } from './common';
|
import { ManagerData, PackageVariables, VariableRegistry } from './common';
|
||||||
import { parseGradle, parseProps } from './parser';
|
import { parseGradle, parseProps } from './parser';
|
||||||
import {
|
import {
|
||||||
getVars,
|
getVars,
|
||||||
|
@ -46,18 +46,30 @@ export async function extractAllPackageFiles(
|
||||||
try {
|
try {
|
||||||
const content = await readLocalFile(packageFile, 'utf8');
|
const content = await readLocalFile(packageFile, 'utf8');
|
||||||
const dir = upath.dirname(toAbsolutePath(packageFile));
|
const dir = upath.dirname(toAbsolutePath(packageFile));
|
||||||
|
|
||||||
|
const updateVars = (newVars: PackageVariables): void => {
|
||||||
|
const oldVars = registry[dir] || {};
|
||||||
|
registry[dir] = { ...oldVars, ...newVars };
|
||||||
|
};
|
||||||
|
|
||||||
if (isPropsFile(packageFile)) {
|
if (isPropsFile(packageFile)) {
|
||||||
const { vars, deps } = parseProps(content, packageFile);
|
const { vars, deps } = parseProps(content, packageFile);
|
||||||
registry[dir] = vars;
|
updateVars(vars);
|
||||||
extractedDeps.push(...deps);
|
extractedDeps.push(...deps);
|
||||||
} else if (isGradleFile(packageFile)) {
|
} else if (isGradleFile(packageFile)) {
|
||||||
const vars = getVars(registry, dir);
|
const vars = getVars(registry, dir);
|
||||||
const { deps, urls } = parseGradle(content, vars, packageFile);
|
const { deps, urls, vars: gradleVars } = parseGradle(
|
||||||
|
content,
|
||||||
|
vars,
|
||||||
|
packageFile
|
||||||
|
);
|
||||||
urls.forEach((url) => {
|
urls.forEach((url) => {
|
||||||
if (!registryUrls.includes(url)) {
|
if (!registryUrls.includes(url)) {
|
||||||
registryUrls.push(url);
|
registryUrls.push(url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
registry[dir] = { ...registry[dir], ...gradleVars };
|
||||||
|
updateVars(gradleVars);
|
||||||
extractedDeps.push(...deps);
|
extractedDeps.push(...deps);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -458,12 +458,18 @@ function tryMatch({
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ParseGradleResult {
|
||||||
|
deps: PackageDependency<ManagerData>[];
|
||||||
|
urls: string[];
|
||||||
|
vars: PackageVariables;
|
||||||
|
}
|
||||||
|
|
||||||
export function parseGradle(
|
export function parseGradle(
|
||||||
input: string,
|
input: string,
|
||||||
initVars: PackageVariables = {},
|
initVars: PackageVariables = {},
|
||||||
packageFile?: string
|
packageFile?: string
|
||||||
): { deps: PackageDependency<ManagerData>[]; urls: string[] } {
|
): ParseGradleResult {
|
||||||
const vars = { ...initVars };
|
const vars: PackageVariables = { ...initVars };
|
||||||
const deps: PackageDependency<ManagerData>[] = [];
|
const deps: PackageDependency<ManagerData>[] = [];
|
||||||
const urls = [];
|
const urls = [];
|
||||||
|
|
||||||
|
@ -493,7 +499,7 @@ export function parseGradle(
|
||||||
prevTokensLength = tokens.length;
|
prevTokensLength = tokens.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { deps, urls };
|
return { deps, urls, vars };
|
||||||
}
|
}
|
||||||
|
|
||||||
const propWord = '[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*';
|
const propWord = '[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*';
|
||||||
|
|
Loading…
Reference in a new issue