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(datasource/maven): Use relocation information #32636

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions lib/modules/datasource/maven/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,72 @@ describe('modules/datasource/maven/index', () => {
expect(res?.sourceUrl).toBe('https://github.com/example/test');
});

describe('supports relocation', () => {
it('with only groupId present', async () => {
const pom = `
jonasrutishauser marked this conversation as resolved.
Show resolved Hide resolved
<project>
<distributionManagement>
<relocation>
<groupId>io.example</groupId>
</relocation>
</distributionManagement>
</project>
`;
mockGenericPackage({ pom, html: null });

const res = await get();

expect(res).toMatchObject({
replacementName: 'io.example:package',
replacementVersion: '2.0.0',
});
});

it('with only artifactId present', async () => {
const pom = `
<project>
<distributionManagement>
<relocation>
<artifactId>foo</artifactId>
</relocation>
</distributionManagement>
</project>
`;
mockGenericPackage({ pom, html: null });

const res = await get();

expect(res).toMatchObject({
replacementName: 'org.example:foo',
replacementVersion: '2.0.0',
});
});

it('with all elments present', async () => {
const pom = `
<project>
<distributionManagement>
<relocation>
<groupId>io.example</groupId>
<artifactId>foo</artifactId>
<version>1.2.3</version>
<message>test relocation</message>
</relocation>
</distributionManagement>
</project>
`;
mockGenericPackage({ pom, html: null });

const res = await get();

expect(res).toMatchObject({
replacementName: 'io.example:foo',
replacementVersion: '1.2.3',
deprecationMessage: 'test relocation',
});
});
});

it('removes authentication header after redirect', async () => {
const frontendHost = 'frontend_for_private_s3_repository';
const frontendUrl = `https://${frontendHost}/maven2`;
Expand Down
17 changes: 17 additions & 0 deletions lib/modules/datasource/maven/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,23 @@ export async function getDependencyInfo(
}
}

const relocation = pomContent.descendantWithPath(
'distributionManagement.relocation',
);
jonasrutishauser marked this conversation as resolved.
Show resolved Hide resolved
if (relocation) {
const relocationGroup =
relocation.valueWithPath('groupId') ?? dependency.group;
const relocationName =
relocation.valueWithPath('artifactId') ?? dependency.name;
result.replacementName = `${relocationGroup}:${relocationName}`;
const relocationVersion = relocation.valueWithPath('version');
result.replacementVersion = relocationVersion ?? version;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip version, do not set if not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be wrong, if the version will not be set.
The documentation says the following:

If any of the values are omitted, it is assumed to be the same as it was before.

const relocationMessage = relocation.valueWithPath('message');
if (relocationMessage) {
result.deprecationMessage = relocationMessage;
}
}

const groupId = pomContent.valueWithPath('groupId');
if (groupId) {
result.packageScope = groupId;
Expand Down