Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions lib/modules/manager/ant/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,138 @@ describe('modules/manager/ant/extract', () => {
]);
});

it('follows import file references', async () => {
fs.readLocalFile.mockImplementation((fileName: string) => {
const files: Record<string, string> = {
'build.xml': codeBlock`
<project>
<import file="deps.xml" />
</project>
`,
'deps.xml': codeBlock`
<project>
<artifact:dependencies>
<dependency groupId="junit" artifactId="junit" version="4.13.2" />
</artifact:dependencies>
</project>
`,
};
return Promise.resolve(files[fileName] ?? null);
});

const result = await extractAllPackageFiles({}, ['build.xml']);

expect(result).toEqual([
{
packageFile: 'deps.xml',
deps: [
expect.objectContaining({
depName: 'junit:junit',
currentValue: '4.13.2',
}),
],
},
]);
});

it('skips missing import files', async () => {
fs.readLocalFile.mockImplementation((fileName: string) => {
const files: Record<string, string> = {
'build.xml': codeBlock`
<project>
<import file="missing.xml" />
<artifact:dependencies>
<dependency groupId="junit" artifactId="junit" version="4.13.2" />
</artifact:dependencies>
</project>
`,
};
return Promise.resolve(files[fileName] ?? null);
});

const result = await extractAllPackageFiles({}, ['build.xml']);

expect(result).toEqual([
{
packageFile: 'build.xml',
deps: [
expect.objectContaining({
depName: 'junit:junit',
currentValue: '4.13.2',
}),
],
},
]);
});

it('does not loop on self-importing files', async () => {
fs.readLocalFile.mockImplementation((fileName: string) => {
const files: Record<string, string> = {
'build.xml': codeBlock`
<project>
<import file="build.xml" />
<artifact:dependencies>
<dependency groupId="junit" artifactId="junit" version="4.13.2" />
</artifact:dependencies>
</project>
`,
};
return Promise.resolve(files[fileName] ?? null);
});

const result = await extractAllPackageFiles({}, ['build.xml']);

expect(result).toEqual([
{
packageFile: 'build.xml',
deps: [
expect.objectContaining({
depName: 'junit:junit',
currentValue: '4.13.2',
}),
],
},
]);
});

it('shares properties across imported files', async () => {
fs.readLocalFile.mockImplementation((fileName: string) => {
const files: Record<string, string> = {
'build.xml': codeBlock`
<project>
<property name="junit.version" value="4.13.2" />
<import file="deps.xml" />
</project>
`,
'deps.xml': codeBlock`
<project>
<artifact:dependencies>
<dependency groupId="junit" artifactId="junit" version="\${junit.version}" />
</artifact:dependencies>
</project>
`,
};
return Promise.resolve(files[fileName] ?? null);
});

const result = await extractAllPackageFiles({}, ['build.xml']);

expect(fs.readLocalFile).toHaveBeenCalledWith('deps.xml', 'utf8');
expect(result).toEqual([
{
packageFile: 'build.xml',
Comment thread
jamietanna marked this conversation as resolved.
deps: [
expect.objectContaining({
depName: 'junit:junit',
currentValue: '4.13.2',
sharedVariableName: 'junit.version',
editFile: 'build.xml',
}),
],
},
]);
});

it('handles chain referencing undefined property', async () => {
fs.readLocalFile.mockResolvedValue(codeBlock`
<project>
Expand Down
8 changes: 8 additions & 0 deletions lib/modules/manager/ant/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ async function walkNodeInOrder(
}
}
}
} else if (child.name === 'import' && child.attr.file) {
const importedFile = upath.normalize(
upath.join(baseDir, child.attr.file),
);
await walkXmlFile(importedFile, visitedFiles, allProps, allRawDeps);
} else if (child.name === 'dependency') {
const rawDep = collectDependency(child, packageFile, content);
if (rawDep) {
Expand All @@ -182,6 +187,9 @@ async function walkXmlFile(
allProps: Record<string, AntProp>,
allRawDeps: RawDep[],
): Promise<void> {
if (visitedFiles.has(packageFile)) {
return;
}
visitedFiles.add(packageFile);

const content = await readLocalFile(packageFile, 'utf8');
Expand Down
Loading