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): rewrite and extend parser #18484

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d4c73f8
feat(manager/gradle): rewrite and extend parser
Churro Oct 23, 2022
6f73306
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Oct 27, 2022
9f66b4d
switch to flexible template strings, re2 and add more tests, in-line …
Churro Oct 28, 2022
cb332af
replace qStringValue with qTemplateString, where feasible
Churro Oct 28, 2022
79ec2a2
ignore mapScalar() method from Apollo Kotlin plugin (#18625)
Churro Oct 28, 2022
bd2b85c
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Oct 28, 2022
627a53f
reduce nesting by always returning early if parseDependencyString() f…
Churro Oct 28, 2022
002ec22
rename IMPLICIT_GRADLE_PLUGINS to GRADLE_PLUGINS and add depType: 'de…
Churro Oct 28, 2022
0512132
align logger.debug() style with PR #18466
Churro Oct 29, 2022
df77fb8
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Oct 29, 2022
c5331aa
add support Kotlin dependencySet notation
Churro Oct 29, 2022
f024b66
versionCatalog: interpolation support for groupId and artifactId
Churro Oct 29, 2022
8e9378f
versionCatalog: interpolation support for version too
Churro Oct 29, 2022
5037fe8
versionCatalog: simplify version matching
Churro Oct 30, 2022
8bf48da
plugin: don't set already set currentValue redundantly
Churro Oct 30, 2022
6aedd0b
add support for Groovy and Kotlin maps with interpolated dep strings
Churro Oct 31, 2022
ac117ab
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Nov 4, 2022
6dab5fc
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Nov 5, 2022
8200558
prefix version catalog aliases with "libs."
Churro Nov 8, 2022
6e5b7c1
change RegExp to regEx
Churro Nov 8, 2022
62729b8
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Nov 10, 2022
0e7b4d3
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Nov 14, 2022
0d4aa65
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Nov 17, 2022
01332d2
use common.spec.ts from current master
Churro Nov 17, 2022
c84581c
Merge branch 'main' of github.com:Churro/renovate into gradle-parser-…
Churro Nov 18, 2022
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
40 changes: 24 additions & 16 deletions lib/modules/manager/gradle/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ jest.mock('../../../util/fs');

function mockFs(files: Record<string, string>): void {
// TODO: fix types, jest is using wrong overload (#7154)
fs.readLocalFile.mockImplementation((fileName: string): Promise<any> => {
const content = files?.[fileName];
return Promise.resolve(content ?? '');
});
fs.getFileContentMap.mockImplementation(
(fileNames: string[]): Promise<any> => {
const fileContentMap: Record<string, string | null> = {};
for (const fileName of fileNames) {
fileContentMap[fileName] = files?.[fileName];
}

return Promise.resolve(fileContentMap);
}
);

fs.getSiblingFileName.mockImplementation(
(existingFileNameWithPath: string, otherFileName: string) => {
Expand Down Expand Up @@ -45,7 +51,9 @@ describe('modules/manager/gradle/extract', () => {
const filename = 'build.gradle';
const err = new Error('unknown');

jest.spyOn(parser, 'parseGradle').mockRejectedValueOnce(err);
jest.spyOn(parser, 'parseGradle').mockImplementationOnce(() => {
throw err;
});
await extractAllPackageFiles({} as ExtractConfig, [filename]);

expect(logger.logger.warn).toHaveBeenCalledWith(
Expand Down Expand Up @@ -641,7 +649,7 @@ describe('modules/manager/gradle/extract', () => {
const res = await extractAllPackageFiles({} as ExtractConfig, [
'gradleX/libs1.gradle',
'gradle/libs2.gradle',
// 'gradle/libs3.gradle', is intentionally not listed here
'gradle/libs3.gradle',
'gradleX/gradleX/libs4.gradle',
'build.gradle',
'gradle.properties',
Expand All @@ -663,6 +671,16 @@ describe('modules/manager/gradle/extract', () => {
},
],
},
{
packageFile: 'gradle/libs3.gradle',
deps: [
{
depName: 'com.google.guava:guava',
currentValue: '30.1-jre',
managerData: { packageFile: 'gradle/libs3.gradle' },
},
],
},
{
packageFile: 'gradleX/libs1.gradle',
deps: [
Expand All @@ -688,16 +706,6 @@ describe('modules/manager/gradle/extract', () => {
},
],
},
{
packageFile: 'gradle/libs3.gradle',
deps: [
{
depName: 'com.google.guava:guava',
currentValue: '30.1-jre',
managerData: { packageFile: 'gradle/libs3.gradle' },
},
],
},
]);
});

Expand Down
9 changes: 6 additions & 3 deletions lib/modules/manager/gradle/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import upath from 'upath';
import { logger } from '../../../logger';
import { readLocalFile } from '../../../util/fs';
import { getFileContentMap } from '../../../util/fs';
import { MavenDatasource } from '../../datasource/maven';
import type { ExtractConfig, PackageDependency, PackageFile } from '../types';
import { parseCatalog } from './extract/catalog';
Expand Down Expand Up @@ -44,6 +44,8 @@ export async function extractAllPackageFiles(
const packageFilesByName: Record<string, PackageFile> = {};
const registryUrls: string[] = [];
const reorderedFiles = reorderFiles(packageFiles);
const fileContents = await getFileContentMap(packageFiles, true);

for (const packageFile of reorderedFiles) {
packageFilesByName[packageFile] = {
packageFile,
Expand All @@ -53,7 +55,7 @@ export async function extractAllPackageFiles(

try {
// TODO #7154
const content = (await readLocalFile(packageFile, 'utf8'))!;
const content = fileContents[packageFile]!;
const dir = upath.dirname(toAbsolutePath(packageFile));

const updateVars = (newVars: PackageVariables): void => {
Expand All @@ -74,7 +76,7 @@ export async function extractAllPackageFiles(
deps,
urls,
vars: gradleVars,
} = await parseGradle(content, vars, packageFile);
} = parseGradle(content, vars, packageFile, fileContents);
urls.forEach((url) => {
if (!registryUrls.includes(url)) {
registryUrls.push(url);
Expand All @@ -101,6 +103,7 @@ export async function extractAllPackageFiles(
// istanbul ignore else
if (key) {
let pkgFile = packageFilesByName[key];
// istanbul ignore if: won't happen if "apply from" processes only initially known files
viceice marked this conversation as resolved.
Show resolved Hide resolved
if (!pkgFile) {
pkgFile = {
packageFile: key,
Expand Down