Skip to content

Commit

Permalink
feat(gradle): support @<ext> file extentions (#11541)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
3 people committed Sep 6, 2021
1 parent b689d79 commit 773a111
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 17 deletions.
75 changes: 75 additions & 0 deletions lib/manager/gradle/shallow/extract.spec.ts
Expand Up @@ -68,6 +68,81 @@ describe('manager/gradle/shallow/extract', () => {
]);
});

it('works with file-ext', async () => {
mockFs({
'gradle.properties': '',
'build.gradle': 'url "https://example.com"; "foo:bar:1.2.3@zip"',
'settings.gradle': null,
});

const res = await extractAllPackageFiles({} as never, [
'build.gradle',
'gradle.properties',
'settings.gradle',
]);

expect(res).toMatchObject([
{
packageFile: 'gradle.properties',
deps: [],
},
{
packageFile: 'build.gradle',
deps: [
{
depName: 'foo:bar',
currentValue: '1.2.3',
registryUrls: [
'https://repo.maven.apache.org/maven2',
'https://example.com',
],
},
],
},
{
datasource: 'maven',
deps: [],
packageFile: 'settings.gradle',
},
]);
});

it('works with file-ext-var', async () => {
mockFs({
'gradle.properties': 'baz=1.2.3',
'build.gradle': 'url "https://example.com"; "foo:bar:$baz@zip"',
'settings.gradle': null,
});

const res = await extractAllPackageFiles({} as never, [
'build.gradle',
'gradle.properties',
'settings.gradle',
]);

expect(res).toMatchObject([
{
packageFile: 'gradle.properties',
deps: [
{
depName: 'foo:bar',
currentValue: '1.2.3',
registryUrls: [
'https://repo.maven.apache.org/maven2',
'https://example.com',
],
},
],
},
{ packageFile: 'build.gradle', deps: [] },
{
datasource: 'maven',
deps: [],
packageFile: 'settings.gradle',
},
]);
});

it('inherits gradle variables', async () => {
const fsMock = {
'gradle.properties': 'foo=1.0.0',
Expand Down
32 changes: 17 additions & 15 deletions lib/manager/gradle/shallow/parser.ts
Expand Up @@ -141,21 +141,21 @@ function processDepInterpolation({
if (interpolationResult && isDependencyString(interpolationResult)) {
const dep = parseDependencyString(interpolationResult);
if (dep) {
const lastChild = token.children[token.children.length - 1];
const lastChildValue = lastChild?.value;
const variable = variables[lastChildValue];
if (
lastChild?.type === TokenType.Variable &&
variable &&
variable?.value === dep.currentValue
) {
dep.managerData = {
fileReplacePosition: variable.fileReplacePosition,
packageFile: variable.packageFile,
};
dep.groupName = variable.key;
return { deps: [dep] };
}
token.children.forEach((child) => {
const variable = variables[child.value];
if (
child?.type === TokenType.Variable &&
variable &&
variable?.value === dep.currentValue
) {
dep.managerData = {
fileReplacePosition: variable.fileReplacePosition,
packageFile: variable.packageFile,
};
dep.groupName = variable.key;
}
});
return { deps: [dep] };
}
}
return null;
Expand Down Expand Up @@ -273,6 +273,7 @@ const matcherConfigs: SyntaxMatchConfig[] = [
},
{
// 'foo.bar:baz:1.2.3'
// 'foo.bar:baz:1.2.3@ext'
matchers: [
{
matchType: TokenType.String,
Expand All @@ -283,6 +284,7 @@ const matcherConfigs: SyntaxMatchConfig[] = [
},
{
// "foo.bar:baz:${bazVersion}"
// "foo.bar:baz:${bazVersion}@ext"
matchers: [
{
matchType: TokenType.StringInterpolation,
Expand Down
28 changes: 26 additions & 2 deletions lib/manager/gradle/shallow/utils.ts
Expand Up @@ -23,7 +23,23 @@ export function isDependencyString(input: string): boolean {
if (split?.length !== 3) {
return false;
}
const [groupId, artifactId, versionPart] = split;
// eslint-disable-next-line prefer-const
let [tempGroupId, tempArtifactId, tempVersionPart] = split;
if (
tempVersionPart !== versionLikeSubstring(tempVersionPart) &&
tempVersionPart.includes('@')
) {
const versionSplit = tempVersionPart?.split('@');
if (versionSplit?.length !== 2) {
return false;
}
[tempVersionPart] = versionSplit;
}
const [groupId, artifactId, versionPart] = [
tempGroupId,
tempArtifactId,
tempVersionPart,
];
return (
groupId &&
artifactId &&
Expand All @@ -40,10 +56,18 @@ export function parseDependencyString(
if (!isDependencyString(input)) {
return null;
}
const [groupId, artifactId, currentValue] = input?.split(':');
const [groupId, artifactId, FullValue] = input?.split(':');
if (FullValue === versionLikeSubstring(FullValue)) {
return {
depName: `${groupId}:${artifactId}`,
currentValue: FullValue,
};
}
const [currentValue, dataType] = FullValue?.split('@');
return {
depName: `${groupId}:${artifactId}`,
currentValue,
dataType,
};
}

Expand Down
1 change: 1 addition & 0 deletions lib/manager/types.ts
Expand Up @@ -100,6 +100,7 @@ export interface Package<T> extends ManagerData<T> {
repo?: string;
target?: string;
versioning?: string;
dataType?: string;

// npm manager
bumpVersion?: ReleaseType | string;
Expand Down

0 comments on commit 773a111

Please sign in to comment.