Support Maven plugin repositories in generated settings.xml (#1286)

* Add Maven plugin repository support

Generate plugin repositories alongside dependency repositories and share Central inclusion and ordering controls. Cover repository parsing, credentials, explicit Central overrides, plugin ordering, and effective Maven models; document the compatibility change and rebuild runtime bundles.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 52a8a8e2-7965-42d3-88d9-d66f64d0d60d

* Fix CI audit by updating Handlebars to 4.7.10

Update the transitive test dependency to the patched release without changing runtime dependencies or suppressing audit checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 282b173f-7b1d-4fcd-bca4-9c8e2fa72a37

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 52a8a8e2-7965-42d3-88d9-d66f64d0d60d
Copilot-Session: 282b173f-7b1d-4fcd-bca4-9c8e2fa72a37
This commit is contained in:
Bruno Borges
2026-10-14 16:11:40 -04:00
committed by GitHub
parent 2a69be27b0
commit b843ebf9b9
11 changed files with 845 additions and 163 deletions

View File

@@ -25,6 +25,7 @@ export interface MavenRepository {
export interface MavenRepositorySettings {
repositories: MavenRepository[];
pluginRepositories?: MavenRepository[];
includeCentral: boolean;
prioritizeCentral: boolean;
}
@@ -245,7 +246,13 @@ export function addMavenServerRepositoryOrigins(
export function getMavenRepositorySettings():
MavenRepositorySettings | undefined {
const entries = core.getMultilineInput(constants.INPUT_MVN_REPOSITORIES);
if (!entries.some(entry => entry.trim())) {
const pluginEntries = core.getMultilineInput(
constants.INPUT_MVN_PLUGIN_REPOSITORIES
);
if (
!entries.some(entry => entry.trim()) &&
!pluginEntries.some(entry => entry.trim())
) {
return undefined;
}
@@ -255,6 +262,11 @@ export function getMavenRepositorySettings():
);
return {
repositories: parseMavenRepositories(entries, includeCentral),
pluginRepositories: parseMavenRepositories(
pluginEntries,
includeCentral,
constants.INPUT_MVN_PLUGIN_REPOSITORIES
),
includeCentral,
prioritizeCentral: getBooleanInput(
constants.INPUT_MVN_REPOSITORIES_PRIORITIZE_CENTRAL,
@@ -266,7 +278,8 @@ export function getMavenRepositorySettings():
// only exported for testing purposes
export function parseMavenRepositories(
entries: string[],
includeCentral: boolean
includeCentral: boolean,
inputName = constants.INPUT_MVN_REPOSITORIES
): MavenRepository[] {
const repositories: MavenRepository[] = [];
const repositoryIds = new Set<string>();
@@ -280,7 +293,7 @@ export function parseMavenRepositories(
const lastSeparator = entry.lastIndexOf(':');
if (firstSeparator <= 0 || lastSeparator <= firstSeparator) {
throw new Error(
`Invalid mvn-repositories entry at line ${index + 1}. Expected format: repository-id:repository-url:snapshots-enabled`
`Invalid ${inputName} entry at line ${index + 1}. Expected format: repository-id:repository-url:snapshots-enabled`
);
}
@@ -292,18 +305,16 @@ export function parseMavenRepositories(
.toLowerCase();
if (!id || !url || !snapshotsValue) {
throw new Error(
`Invalid mvn-repositories entry at line ${index + 1}. repository-id, repository URL, and snapshots-enabled are required`
`Invalid ${inputName} entry at line ${index + 1}. repository-id, repository URL, and snapshots-enabled are required`
);
}
if (snapshotsValue !== 'true' && snapshotsValue !== 'false') {
throw new Error(
`Invalid snapshots-enabled value '${snapshotsValue}' in mvn-repositories entry at line ${index + 1}. Expected true or false`
`Invalid snapshots-enabled value '${snapshotsValue}' in ${inputName} entry at line ${index + 1}. Expected true or false`
);
}
if (repositoryIds.has(id)) {
throw new Error(
`Duplicate repository-id '${id}' in mvn-repositories input`
);
throw new Error(`Duplicate repository-id '${id}' in ${inputName} input`);
}
if (includeCentral && id === constants.MAVEN_CENTRAL_REPOSITORY_ID) {
throw new Error(
@@ -322,6 +333,56 @@ export function parseMavenRepositories(
return repositories;
}
function generateRepositorySection(
customRepositories: MavenRepository[],
settings: MavenRepositorySettings,
element: 'repository' | 'pluginRepository'
): string[] {
if (!customRepositories.length && settings.includeCentral) {
return [];
}
const centralRepository: MavenRepository = {
id: constants.MAVEN_CENTRAL_REPOSITORY_ID,
url: constants.MAVEN_CENTRAL_REPOSITORY_URL,
snapshotsEnabled: false
};
const customCentralConfigured = customRepositories.some(
repository => repository.id === constants.MAVEN_CENTRAL_REPOSITORY_ID
);
const repositories = settings.includeCentral
? settings.prioritizeCentral
? [centralRepository, ...customRepositories]
: [...customRepositories, centralRepository]
: customCentralConfigured
? customRepositories
: [...customRepositories, {...centralRepository, releasesEnabled: false}];
const container =
element === 'repository' ? 'repositories' : 'pluginRepositories';
const lines = [` <${container}>`];
for (const repository of repositories) {
lines.push(
` <${element}>`,
` <id>${escapeXmlText(repository.id)}</id>`,
` <url>${escapeXmlText(repository.url)}</url>`,
...(repository.releasesEnabled === undefined
? []
: [
' <releases>',
` <enabled>${repository.releasesEnabled}</enabled>`,
' </releases>'
]),
' <snapshots>',
` <enabled>${repository.snapshotsEnabled}</enabled>`,
' </snapshots>',
` </${element}>`
);
}
lines.push(` </${container}>`);
return lines;
}
export async function createAuthenticationSettings(
servers: MavenServerCredentials[],
settingsDirectory: string,
@@ -389,49 +450,21 @@ export function generate(
if (repositorySettings || includeGpgPassphraseProfile) {
lines.push(' <profiles>');
if (repositorySettings) {
const centralRepository: MavenRepository = {
id: constants.MAVEN_CENTRAL_REPOSITORY_ID,
url: constants.MAVEN_CENTRAL_REPOSITORY_URL,
snapshotsEnabled: false
};
const customCentralConfigured = repositorySettings.repositories.some(
repository => repository.id === constants.MAVEN_CENTRAL_REPOSITORY_ID
);
const repositories = repositorySettings.includeCentral
? repositorySettings.prioritizeCentral
? [centralRepository, ...repositorySettings.repositories]
: [...repositorySettings.repositories, centralRepository]
: customCentralConfigured
? repositorySettings.repositories
: [
...repositorySettings.repositories,
{...centralRepository, releasesEnabled: false}
];
lines.push(
' <profile>',
` <id>${constants.MAVEN_REPOSITORIES_PROFILE_ID}</id>`,
' <repositories>'
...generateRepositorySection(
repositorySettings.repositories,
repositorySettings,
'repository'
),
...generateRepositorySection(
repositorySettings.pluginRepositories ?? [],
repositorySettings,
'pluginRepository'
),
' </profile>'
);
for (const repository of repositories) {
lines.push(
' <repository>',
` <id>${escapeXmlText(repository.id)}</id>`,
` <url>${escapeXmlText(repository.url)}</url>`,
...(repository.releasesEnabled === undefined
? []
: [
' <releases>',
` <enabled>${repository.releasesEnabled}</enabled>`,
' </releases>'
]),
' <snapshots>',
` <enabled>${repository.snapshotsEnabled}</enabled>`,
' </snapshots>',
' </repository>'
);
}
lines.push(' </repositories>', ' </profile>');
}
if (includeGpgPassphraseProfile) {
lines.push(