2019-11-15 16:01:13 -08:00
|
|
|
import * as path from 'path';
|
|
|
|
|
import * as core from '@actions/core';
|
|
|
|
|
import * as io from '@actions/io';
|
2021-04-05 13:02:27 +03:00
|
|
|
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as os from 'os';
|
2026-07-08 14:45:00 +05:30
|
|
|
import * as constants from './constants.js';
|
|
|
|
|
import * as gpg from './gpg.js';
|
|
|
|
|
import {getBooleanInput} from './util.js';
|
Optimize Maven configuration warm path (#1182)
* Optimize Maven configuration warm path
Avoid eager Maven XML initialization on warm JDK runs by using deterministic serializers for new Maven settings/toolchains files, lazy-loading xmlbuilder2 for existing toolchains merges, and deferring Maven configuration modules until after Java setup.
Add targeted tests for XML escaping, lazy xmlbuilder2 loading, concurrent Maven configuration, and a manual benchmark workflow for warm-path validation.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Address Maven optimization PR feedback
Make the toolchain XML generator consistently async, remove redundant Maven configuration await handling, and reuse the existing XML test helper.
Configure CodeQL to skip generated dist output so newly split vendored chunks do not report duplicate generated-code alerts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Apply rubber duck review suggestions
Document XML attribute escaping, simplify Maven configuration awaiting, and add a regression test that feeds fast-path toolchains output into the merge path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Delete .github/codeql/codeql-config.yml
* Update codeql-analysis.yml
* Replace xmlbuilder2 in Maven toolchain merge
Use fast-xml-parser for existing toolchains.xml parsing and serialize merged Maven toolchains deterministically. This removes the bundled xmlbuilder2 DOM/XML builder chunk from dist while preserving merge behavior for custom attributes, custom toolchains, partial entries, duplicate filtering, and escaping.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Move Maven benchmark out of setup-java
Remove the Maven warm-path benchmark workflow and helper script from setup-java. Benchmark coverage is being moved to actions/setup-java-benchmarks so this action repository only carries the runtime optimization, tests, and generated distribution artifacts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
---------
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
2026-07-30 15:09:35 -04:00
|
|
|
import {escapeXmlText} from './xml.js';
|
2019-11-15 16:01:13 -08:00
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
export interface MavenServerCredentials {
|
|
|
|
|
id: string;
|
|
|
|
|
usernameEnvVar: string;
|
|
|
|
|
passwordEnvVar: string;
|
2026-10-07 14:10:22 +02:00
|
|
|
repositoryOrigins?: string[];
|
2026-08-17 17:05:55 -04:00
|
|
|
}
|
|
|
|
|
|
2026-08-17 18:18:45 -04:00
|
|
|
export interface MavenRepository {
|
|
|
|
|
id: string;
|
|
|
|
|
url: string;
|
|
|
|
|
snapshotsEnabled: boolean;
|
|
|
|
|
releasesEnabled?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface MavenRepositorySettings {
|
|
|
|
|
repositories: MavenRepository[];
|
2026-10-14 16:11:40 -04:00
|
|
|
pluginRepositories?: MavenRepository[];
|
2026-08-17 18:18:45 -04:00
|
|
|
includeCentral: boolean;
|
|
|
|
|
prioritizeCentral: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-07 14:10:22 +02:00
|
|
|
const MAVEN_REPOSITORY_ORIGIN = /^[A-Za-z][A-Za-z0-9+.-]*:\/\/[^/?#@]+\/?$/;
|
|
|
|
|
|
2021-04-05 13:02:27 +03:00
|
|
|
export async function configureAuthentication() {
|
2026-08-17 17:05:55 -04:00
|
|
|
const servers = getMavenServerSettings();
|
2026-08-17 18:18:45 -04:00
|
|
|
const repositorySettings = getMavenRepositorySettings();
|
2021-04-05 13:02:27 +03:00
|
|
|
const settingsDirectory =
|
2023-03-09 14:49:35 +02:00
|
|
|
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
|
|
|
|
path.join(os.homedir(), constants.M2_DIR);
|
|
|
|
|
const overwriteSettings = getBooleanInput(
|
|
|
|
|
constants.INPUT_OVERWRITE_SETTINGS,
|
|
|
|
|
true
|
|
|
|
|
);
|
2021-04-05 13:02:27 +03:00
|
|
|
const gpgPrivateKey =
|
2023-03-09 14:49:35 +02:00
|
|
|
core.getInput(constants.INPUT_GPG_PRIVATE_KEY) ||
|
|
|
|
|
constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
|
2026-07-17 20:10:58 -04:00
|
|
|
const gpgPassphraseEnvVar = getInputWithDeprecatedAlias(
|
|
|
|
|
constants.INPUT_GPG_PASSPHRASE_ENV_VAR,
|
|
|
|
|
constants.INPUT_GPG_PASSPHRASE_DEPRECATED,
|
|
|
|
|
gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined
|
|
|
|
|
);
|
2021-04-05 13:02:27 +03:00
|
|
|
|
|
|
|
|
if (gpgPrivateKey) {
|
|
|
|
|
core.setSecret(gpgPrivateKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await createAuthenticationSettings(
|
2026-08-17 17:05:55 -04:00
|
|
|
servers,
|
2021-04-05 13:02:27 +03:00
|
|
|
settingsDirectory,
|
|
|
|
|
overwriteSettings,
|
2026-08-17 18:18:45 -04:00
|
|
|
gpgPassphraseEnvVar,
|
|
|
|
|
repositorySettings
|
2021-04-05 13:02:27 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (gpgPrivateKey) {
|
|
|
|
|
core.info('Importing private gpg key');
|
2026-08-05 18:05:36 +02:00
|
|
|
const gpgHome = await gpg.importKey(gpgPrivateKey);
|
|
|
|
|
try {
|
|
|
|
|
core.saveState(constants.STATE_GPG_HOME, gpgHome);
|
|
|
|
|
core.exportVariable('GNUPGHOME', gpg.toGpgPath(gpgHome));
|
|
|
|
|
} catch (error) {
|
|
|
|
|
await gpg.removeGpgHome(gpgHome);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2021-04-05 13:02:27 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 20:10:58 -04:00
|
|
|
export function getInputWithDeprecatedAlias(
|
|
|
|
|
inputName: string,
|
|
|
|
|
deprecatedInputName: string,
|
|
|
|
|
defaultValue?: string
|
|
|
|
|
): string {
|
|
|
|
|
const value = core.getInput(inputName);
|
|
|
|
|
const deprecatedValue = core.getInput(deprecatedInputName);
|
|
|
|
|
|
|
|
|
|
if (deprecatedValue) {
|
|
|
|
|
core.warning(
|
|
|
|
|
`The '${deprecatedInputName}' input is deprecated and may be removed in a future release. Please use '${inputName}' instead.`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value || deprecatedValue || defaultValue || '';
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
// only exported for testing purposes
|
|
|
|
|
export function getMavenServerSettings(): MavenServerCredentials[] {
|
|
|
|
|
const entries = core.getMultilineInput(
|
|
|
|
|
constants.INPUT_MVN_SERVER_CREDENTIALS
|
|
|
|
|
);
|
|
|
|
|
|
2026-10-07 14:10:22 +02:00
|
|
|
const servers = entries.some(entry => entry.trim())
|
|
|
|
|
? parseMavenServerCredentials(entries)
|
|
|
|
|
: [
|
|
|
|
|
{
|
|
|
|
|
id: core.getInput(constants.INPUT_SERVER_ID),
|
|
|
|
|
usernameEnvVar: getInputWithDeprecatedAlias(
|
|
|
|
|
constants.INPUT_SERVER_USERNAME_ENV_VAR,
|
|
|
|
|
constants.INPUT_SERVER_USERNAME_DEPRECATED,
|
|
|
|
|
constants.INPUT_DEFAULT_SERVER_USERNAME
|
|
|
|
|
),
|
|
|
|
|
passwordEnvVar: getInputWithDeprecatedAlias(
|
|
|
|
|
constants.INPUT_SERVER_PASSWORD_ENV_VAR,
|
|
|
|
|
constants.INPUT_SERVER_PASSWORD_DEPRECATED,
|
|
|
|
|
constants.INPUT_DEFAULT_SERVER_PASSWORD
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return addMavenServerRepositoryOrigins(
|
|
|
|
|
servers,
|
|
|
|
|
core.getMultilineInput(constants.INPUT_MVN_SERVER_REPOSITORY_ORIGINS)
|
|
|
|
|
);
|
2026-08-17 17:05:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only exported for testing purposes
|
|
|
|
|
export function parseMavenServerCredentials(
|
|
|
|
|
entries: string[]
|
|
|
|
|
): MavenServerCredentials[] {
|
|
|
|
|
const servers: MavenServerCredentials[] = [];
|
|
|
|
|
const serverIds = new Set<string>();
|
|
|
|
|
|
|
|
|
|
entries.forEach((entry, index) => {
|
|
|
|
|
if (!entry.trim()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fields = entry.split(':');
|
|
|
|
|
if (fields.length !== 3) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Invalid mvn-server-credentials entry at line ${index + 1}. Expected format: server-id:USERNAME_ENV:PASSWORD_ENV`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [id, usernameEnvVar, passwordEnvVar] = fields.map(field =>
|
|
|
|
|
field.trim()
|
|
|
|
|
);
|
|
|
|
|
if (!id || !usernameEnvVar || !passwordEnvVar) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Invalid mvn-server-credentials entry at line ${index + 1}. server-id, username environment variable, and password environment variable are required`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (serverIds.has(id)) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Duplicate server-id '${id}' in mvn-server-credentials input`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serverIds.add(id);
|
|
|
|
|
servers.push({id, usernameEnvVar, passwordEnvVar});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return servers;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-07 14:10:22 +02:00
|
|
|
// only exported for testing purposes
|
|
|
|
|
export function addMavenServerRepositoryOrigins(
|
|
|
|
|
servers: MavenServerCredentials[],
|
|
|
|
|
entries: string[]
|
|
|
|
|
): MavenServerCredentials[] {
|
|
|
|
|
const serverIds = new Set(servers.map(server => server.id));
|
|
|
|
|
const originsByServer = new Map<string, string[]>();
|
|
|
|
|
|
|
|
|
|
entries.forEach((entry, index) => {
|
|
|
|
|
if (!entry.trim()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const separator = entry.indexOf(':');
|
|
|
|
|
if (separator <= 0 || separator === entry.length - 1) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Invalid mvn-server-repository-origins entry at line ${index + 1}. Expected format: server-id:repository-origin`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const id = entry.slice(0, separator).trim();
|
|
|
|
|
const value = entry.slice(separator + 1).trim();
|
|
|
|
|
if (!id || !value) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Invalid mvn-server-repository-origins entry at line ${index + 1}. Server ID and repository origin are required`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (!serverIds.has(id)) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Unknown server-id '${id}' in mvn-server-repository-origins at line ${index + 1}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let url: URL;
|
|
|
|
|
try {
|
|
|
|
|
if (!MAVEN_REPOSITORY_ORIGIN.test(value)) {
|
|
|
|
|
throw new Error();
|
|
|
|
|
}
|
|
|
|
|
url = new URL(value);
|
|
|
|
|
} catch {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Invalid repository origin '${value}' in mvn-server-repository-origins at line ${index + 1}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
!url.host ||
|
|
|
|
|
url.username ||
|
|
|
|
|
url.password ||
|
|
|
|
|
(url.pathname !== '' && url.pathname !== '/') ||
|
|
|
|
|
url.search ||
|
|
|
|
|
url.hash
|
|
|
|
|
) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Invalid repository origin '${value}' in mvn-server-repository-origins at line ${index + 1}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const explicitPort = /:(\d+)\/?$/.exec(value)?.[1];
|
|
|
|
|
const port = explicitPort ? Number.parseInt(explicitPort, 10) : undefined;
|
|
|
|
|
const includePort =
|
|
|
|
|
port !== undefined &&
|
|
|
|
|
!(
|
|
|
|
|
(url.protocol === 'http:' && port === 80) ||
|
|
|
|
|
(url.protocol === 'https:' && port === 443)
|
|
|
|
|
);
|
|
|
|
|
const origin = `${url.protocol}//${url.hostname}${includePort ? `:${port}` : ''}`;
|
|
|
|
|
const origins = originsByServer.get(id) || [];
|
|
|
|
|
if (!origins.includes(origin)) {
|
|
|
|
|
origins.push(origin);
|
|
|
|
|
originsByServer.set(id, origins);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return servers.map(server => {
|
|
|
|
|
const repositoryOrigins = originsByServer.get(server.id);
|
|
|
|
|
return repositoryOrigins ? {...server, repositoryOrigins} : server;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-17 18:18:45 -04:00
|
|
|
// only exported for testing purposes
|
|
|
|
|
export function getMavenRepositorySettings():
|
|
|
|
|
MavenRepositorySettings | undefined {
|
|
|
|
|
const entries = core.getMultilineInput(constants.INPUT_MVN_REPOSITORIES);
|
2026-10-14 16:11:40 -04:00
|
|
|
const pluginEntries = core.getMultilineInput(
|
|
|
|
|
constants.INPUT_MVN_PLUGIN_REPOSITORIES
|
|
|
|
|
);
|
|
|
|
|
if (
|
|
|
|
|
!entries.some(entry => entry.trim()) &&
|
|
|
|
|
!pluginEntries.some(entry => entry.trim())
|
|
|
|
|
) {
|
2026-08-17 18:18:45 -04:00
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const includeCentral = getBooleanInput(
|
|
|
|
|
constants.INPUT_MVN_REPOSITORIES_INCLUDE_CENTRAL,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
return {
|
|
|
|
|
repositories: parseMavenRepositories(entries, includeCentral),
|
2026-10-14 16:11:40 -04:00
|
|
|
pluginRepositories: parseMavenRepositories(
|
|
|
|
|
pluginEntries,
|
|
|
|
|
includeCentral,
|
|
|
|
|
constants.INPUT_MVN_PLUGIN_REPOSITORIES
|
|
|
|
|
),
|
2026-08-17 18:18:45 -04:00
|
|
|
includeCentral,
|
|
|
|
|
prioritizeCentral: getBooleanInput(
|
|
|
|
|
constants.INPUT_MVN_REPOSITORIES_PRIORITIZE_CENTRAL,
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only exported for testing purposes
|
|
|
|
|
export function parseMavenRepositories(
|
|
|
|
|
entries: string[],
|
2026-10-14 16:11:40 -04:00
|
|
|
includeCentral: boolean,
|
|
|
|
|
inputName = constants.INPUT_MVN_REPOSITORIES
|
2026-08-17 18:18:45 -04:00
|
|
|
): MavenRepository[] {
|
|
|
|
|
const repositories: MavenRepository[] = [];
|
|
|
|
|
const repositoryIds = new Set<string>();
|
|
|
|
|
|
|
|
|
|
entries.forEach((entry, index) => {
|
|
|
|
|
if (!entry.trim()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const firstSeparator = entry.indexOf(':');
|
|
|
|
|
const lastSeparator = entry.lastIndexOf(':');
|
|
|
|
|
if (firstSeparator <= 0 || lastSeparator <= firstSeparator) {
|
|
|
|
|
throw new Error(
|
2026-10-14 16:11:40 -04:00
|
|
|
`Invalid ${inputName} entry at line ${index + 1}. Expected format: repository-id:repository-url:snapshots-enabled`
|
2026-08-17 18:18:45 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const id = entry.slice(0, firstSeparator).trim();
|
|
|
|
|
const url = entry.slice(firstSeparator + 1, lastSeparator).trim();
|
|
|
|
|
const snapshotsValue = entry
|
|
|
|
|
.slice(lastSeparator + 1)
|
|
|
|
|
.trim()
|
|
|
|
|
.toLowerCase();
|
|
|
|
|
if (!id || !url || !snapshotsValue) {
|
|
|
|
|
throw new Error(
|
2026-10-14 16:11:40 -04:00
|
|
|
`Invalid ${inputName} entry at line ${index + 1}. repository-id, repository URL, and snapshots-enabled are required`
|
2026-08-17 18:18:45 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (snapshotsValue !== 'true' && snapshotsValue !== 'false') {
|
|
|
|
|
throw new Error(
|
2026-10-14 16:11:40 -04:00
|
|
|
`Invalid snapshots-enabled value '${snapshotsValue}' in ${inputName} entry at line ${index + 1}. Expected true or false`
|
2026-08-17 18:18:45 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (repositoryIds.has(id)) {
|
2026-10-14 16:11:40 -04:00
|
|
|
throw new Error(`Duplicate repository-id '${id}' in ${inputName} input`);
|
2026-08-17 18:18:45 -04:00
|
|
|
}
|
|
|
|
|
if (includeCentral && id === constants.MAVEN_CENTRAL_REPOSITORY_ID) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Repository-id '${constants.MAVEN_CENTRAL_REPOSITORY_ID}' is reserved when ${constants.INPUT_MVN_REPOSITORIES_INCLUDE_CENTRAL} is enabled`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repositoryIds.add(id);
|
|
|
|
|
repositories.push({
|
|
|
|
|
id,
|
|
|
|
|
url,
|
|
|
|
|
snapshotsEnabled: snapshotsValue === 'true'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return repositories;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-14 16:11:40 -04:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 13:02:27 +03:00
|
|
|
export async function createAuthenticationSettings(
|
2026-08-17 17:05:55 -04:00
|
|
|
servers: MavenServerCredentials[],
|
2021-04-05 13:02:27 +03:00
|
|
|
settingsDirectory: string,
|
|
|
|
|
overwriteSettings: boolean,
|
2026-08-17 18:18:45 -04:00
|
|
|
gpgPassphraseEnvVar: string | undefined = undefined,
|
|
|
|
|
repositorySettings: MavenRepositorySettings | undefined = undefined
|
2019-11-28 12:40:45 -08:00
|
|
|
) {
|
2026-08-17 17:05:55 -04:00
|
|
|
core.info(
|
|
|
|
|
`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${servers.map(server => server.id).join(', ')}`
|
|
|
|
|
);
|
2019-12-19 11:28:11 -08:00
|
|
|
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
|
|
|
|
// otherwise use the home/.m2/ path
|
2020-05-02 04:33:15 -07:00
|
|
|
await io.mkdirP(settingsDirectory);
|
|
|
|
|
await write(
|
|
|
|
|
settingsDirectory,
|
2026-08-17 18:18:45 -04:00
|
|
|
generate(servers, gpgPassphraseEnvVar, repositorySettings),
|
2021-04-05 13:02:27 +03:00
|
|
|
overwriteSettings
|
2020-05-02 04:33:15 -07:00
|
|
|
);
|
2019-12-10 09:26:51 -08:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 16:01:13 -08:00
|
|
|
// only exported for testing purposes
|
2019-12-19 11:28:11 -08:00
|
|
|
export function generate(
|
2026-08-17 17:05:55 -04:00
|
|
|
servers: MavenServerCredentials[],
|
2026-08-17 18:18:45 -04:00
|
|
|
gpgPassphraseEnvVar?: string | undefined,
|
|
|
|
|
repositorySettings?: MavenRepositorySettings | undefined
|
2019-12-19 11:28:11 -08:00
|
|
|
) {
|
2026-07-15 10:33:09 -04:00
|
|
|
// The maven-gpg-plugin reads the passphrase from the environment variable
|
|
|
|
|
// named by the `gpg.passphraseEnvName` property (default MAVEN_GPG_PASSPHRASE).
|
|
|
|
|
// Only configure it when the requested env var name differs from that default;
|
|
|
|
|
// otherwise the plugin already reads the right variable and no extra settings
|
|
|
|
|
// are needed. Writing `gpg.passphrase` to settings.xml is deprecated and fails
|
|
|
|
|
// when the plugin's `bestPractices` mode is enabled.
|
Optimize Maven configuration warm path (#1182)
* Optimize Maven configuration warm path
Avoid eager Maven XML initialization on warm JDK runs by using deterministic serializers for new Maven settings/toolchains files, lazy-loading xmlbuilder2 for existing toolchains merges, and deferring Maven configuration modules until after Java setup.
Add targeted tests for XML escaping, lazy xmlbuilder2 loading, concurrent Maven configuration, and a manual benchmark workflow for warm-path validation.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Address Maven optimization PR feedback
Make the toolchain XML generator consistently async, remove redundant Maven configuration await handling, and reuse the existing XML test helper.
Configure CodeQL to skip generated dist output so newly split vendored chunks do not report duplicate generated-code alerts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Apply rubber duck review suggestions
Document XML attribute escaping, simplify Maven configuration awaiting, and add a regression test that feeds fast-path toolchains output into the merge path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Delete .github/codeql/codeql-config.yml
* Update codeql-analysis.yml
* Replace xmlbuilder2 in Maven toolchain merge
Use fast-xml-parser for existing toolchains.xml parsing and serialize merged Maven toolchains deterministically. This removes the bundled xmlbuilder2 DOM/XML builder chunk from dist while preserving merge behavior for custom attributes, custom toolchains, partial entries, duplicate filtering, and escaping.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Move Maven benchmark out of setup-java
Remove the Maven warm-path benchmark workflow and helper script from setup-java. Benchmark coverage is being moved to actions/setup-java-benchmarks so this action repository only carries the runtime optimization, tests, and generated distribution artifacts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
---------
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
2026-07-30 15:09:35 -04:00
|
|
|
const includeGpgPassphraseProfile =
|
2026-07-17 20:10:58 -04:00
|
|
|
gpgPassphraseEnvVar &&
|
Optimize Maven configuration warm path (#1182)
* Optimize Maven configuration warm path
Avoid eager Maven XML initialization on warm JDK runs by using deterministic serializers for new Maven settings/toolchains files, lazy-loading xmlbuilder2 for existing toolchains merges, and deferring Maven configuration modules until after Java setup.
Add targeted tests for XML escaping, lazy xmlbuilder2 loading, concurrent Maven configuration, and a manual benchmark workflow for warm-path validation.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Address Maven optimization PR feedback
Make the toolchain XML generator consistently async, remove redundant Maven configuration await handling, and reuse the existing XML test helper.
Configure CodeQL to skip generated dist output so newly split vendored chunks do not report duplicate generated-code alerts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Apply rubber duck review suggestions
Document XML attribute escaping, simplify Maven configuration awaiting, and add a regression test that feeds fast-path toolchains output into the merge path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Delete .github/codeql/codeql-config.yml
* Update codeql-analysis.yml
* Replace xmlbuilder2 in Maven toolchain merge
Use fast-xml-parser for existing toolchains.xml parsing and serialize merged Maven toolchains deterministically. This removes the bundled xmlbuilder2 DOM/XML builder chunk from dist while preserving merge behavior for custom attributes, custom toolchains, partial entries, duplicate filtering, and escaping.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Move Maven benchmark out of setup-java
Remove the Maven warm-path benchmark workflow and helper script from setup-java. Benchmark coverage is being moved to actions/setup-java-benchmarks so this action repository only carries the runtime optimization, tests, and generated distribution artifacts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
---------
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
2026-07-30 15:09:35 -04:00
|
|
|
gpgPassphraseEnvVar !== constants.MAVEN_GPG_PASSPHRASE_DEFAULT_ENV;
|
|
|
|
|
|
|
|
|
|
const lines = [
|
|
|
|
|
'<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"',
|
|
|
|
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"',
|
|
|
|
|
' xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">',
|
|
|
|
|
' <interactiveMode>false</interactiveMode>',
|
2026-08-17 17:05:55 -04:00
|
|
|
' <servers>'
|
Optimize Maven configuration warm path (#1182)
* Optimize Maven configuration warm path
Avoid eager Maven XML initialization on warm JDK runs by using deterministic serializers for new Maven settings/toolchains files, lazy-loading xmlbuilder2 for existing toolchains merges, and deferring Maven configuration modules until after Java setup.
Add targeted tests for XML escaping, lazy xmlbuilder2 loading, concurrent Maven configuration, and a manual benchmark workflow for warm-path validation.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Address Maven optimization PR feedback
Make the toolchain XML generator consistently async, remove redundant Maven configuration await handling, and reuse the existing XML test helper.
Configure CodeQL to skip generated dist output so newly split vendored chunks do not report duplicate generated-code alerts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Apply rubber duck review suggestions
Document XML attribute escaping, simplify Maven configuration awaiting, and add a regression test that feeds fast-path toolchains output into the merge path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Delete .github/codeql/codeql-config.yml
* Update codeql-analysis.yml
* Replace xmlbuilder2 in Maven toolchain merge
Use fast-xml-parser for existing toolchains.xml parsing and serialize merged Maven toolchains deterministically. This removes the bundled xmlbuilder2 DOM/XML builder chunk from dist while preserving merge behavior for custom attributes, custom toolchains, partial entries, duplicate filtering, and escaping.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Move Maven benchmark out of setup-java
Remove the Maven warm-path benchmark workflow and helper script from setup-java. Benchmark coverage is being moved to actions/setup-java-benchmarks so this action repository only carries the runtime optimization, tests, and generated distribution artifacts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
---------
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
2026-07-30 15:09:35 -04:00
|
|
|
];
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
for (const server of servers) {
|
|
|
|
|
lines.push(
|
|
|
|
|
' <server>',
|
|
|
|
|
` <id>${escapeXmlText(server.id)}</id>`,
|
|
|
|
|
` <username>${escapeXmlText(`\${env.${server.usernameEnvVar}}`)}</username>`,
|
2026-10-07 14:10:22 +02:00
|
|
|
` <password>${escapeXmlText(`\${env.${server.passwordEnvVar}}`)}</password>`
|
2026-08-17 17:05:55 -04:00
|
|
|
);
|
2026-10-07 14:10:22 +02:00
|
|
|
if (server.repositoryOrigins) {
|
|
|
|
|
lines.push(' <repositoryOrigins>');
|
|
|
|
|
for (const origin of server.repositoryOrigins) {
|
|
|
|
|
lines.push(
|
|
|
|
|
` <repositoryOrigin>${escapeXmlText(origin)}</repositoryOrigin>`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
lines.push(' </repositoryOrigins>');
|
|
|
|
|
}
|
|
|
|
|
lines.push(' </server>');
|
2026-08-17 17:05:55 -04:00
|
|
|
}
|
|
|
|
|
lines.push(' </servers>');
|
|
|
|
|
|
2026-08-17 18:18:45 -04:00
|
|
|
if (repositorySettings || includeGpgPassphraseProfile) {
|
|
|
|
|
lines.push(' <profiles>');
|
|
|
|
|
if (repositorySettings) {
|
|
|
|
|
lines.push(
|
|
|
|
|
' <profile>',
|
|
|
|
|
` <id>${constants.MAVEN_REPOSITORIES_PROFILE_ID}</id>`,
|
2026-10-14 16:11:40 -04:00
|
|
|
...generateRepositorySection(
|
|
|
|
|
repositorySettings.repositories,
|
|
|
|
|
repositorySettings,
|
|
|
|
|
'repository'
|
|
|
|
|
),
|
|
|
|
|
...generateRepositorySection(
|
|
|
|
|
repositorySettings.pluginRepositories ?? [],
|
|
|
|
|
repositorySettings,
|
|
|
|
|
'pluginRepository'
|
|
|
|
|
),
|
|
|
|
|
' </profile>'
|
2026-08-17 18:18:45 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (includeGpgPassphraseProfile) {
|
|
|
|
|
lines.push(
|
|
|
|
|
' <profile>',
|
|
|
|
|
` <id>${constants.GPG_PASSPHRASE_PROFILE_ID}</id>`,
|
|
|
|
|
' <properties>',
|
|
|
|
|
` <gpg.passphraseEnvName>${escapeXmlText(gpgPassphraseEnvVar)}</gpg.passphraseEnvName>`,
|
|
|
|
|
' </properties>',
|
|
|
|
|
' </profile>'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
lines.push(' </profiles>', ' <activeProfiles>');
|
|
|
|
|
if (repositorySettings) {
|
|
|
|
|
lines.push(
|
|
|
|
|
` <activeProfile>${constants.MAVEN_REPOSITORIES_PROFILE_ID}</activeProfile>`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (includeGpgPassphraseProfile) {
|
|
|
|
|
lines.push(
|
|
|
|
|
` <activeProfile>${constants.GPG_PASSPHRASE_PROFILE_ID}</activeProfile>`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
lines.push(' </activeProfiles>');
|
2020-05-02 04:33:15 -07:00
|
|
|
}
|
|
|
|
|
|
Optimize Maven configuration warm path (#1182)
* Optimize Maven configuration warm path
Avoid eager Maven XML initialization on warm JDK runs by using deterministic serializers for new Maven settings/toolchains files, lazy-loading xmlbuilder2 for existing toolchains merges, and deferring Maven configuration modules until after Java setup.
Add targeted tests for XML escaping, lazy xmlbuilder2 loading, concurrent Maven configuration, and a manual benchmark workflow for warm-path validation.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Address Maven optimization PR feedback
Make the toolchain XML generator consistently async, remove redundant Maven configuration await handling, and reuse the existing XML test helper.
Configure CodeQL to skip generated dist output so newly split vendored chunks do not report duplicate generated-code alerts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Apply rubber duck review suggestions
Document XML attribute escaping, simplify Maven configuration awaiting, and add a regression test that feeds fast-path toolchains output into the merge path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Delete .github/codeql/codeql-config.yml
* Update codeql-analysis.yml
* Replace xmlbuilder2 in Maven toolchain merge
Use fast-xml-parser for existing toolchains.xml parsing and serialize merged Maven toolchains deterministically. This removes the bundled xmlbuilder2 DOM/XML builder chunk from dist while preserving merge behavior for custom attributes, custom toolchains, partial entries, duplicate filtering, and escaping.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Move Maven benchmark out of setup-java
Remove the Maven warm-path benchmark workflow and helper script from setup-java. Benchmark coverage is being moved to actions/setup-java-benchmarks so this action repository only carries the runtime optimization, tests, and generated distribution artifacts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
---------
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
2026-07-30 15:09:35 -04:00
|
|
|
lines.push('</settings>');
|
|
|
|
|
return lines.join('\n');
|
2019-11-15 16:01:13 -08:00
|
|
|
}
|
|
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
async function write(
|
|
|
|
|
directory: string,
|
|
|
|
|
settings: string,
|
|
|
|
|
overwriteSettings: boolean
|
|
|
|
|
) {
|
2022-01-16 17:33:29 +01:00
|
|
|
const location = path.join(directory, constants.MVN_SETTINGS_FILE);
|
2021-04-05 13:02:27 +03:00
|
|
|
const settingsExists = fs.existsSync(location);
|
|
|
|
|
if (settingsExists && overwriteSettings) {
|
|
|
|
|
core.info(`Overwriting existing file ${location}`);
|
|
|
|
|
} else if (!settingsExists) {
|
|
|
|
|
core.info(`Writing to ${location}`);
|
2019-12-19 08:52:26 -08:00
|
|
|
} else {
|
2021-04-05 13:02:27 +03:00
|
|
|
core.info(
|
|
|
|
|
`Skipping generation ${location} because file already exists and overwriting is not required`
|
|
|
|
|
);
|
|
|
|
|
return;
|
2019-12-04 23:54:21 -05:00
|
|
|
}
|
2019-12-19 08:52:26 -08:00
|
|
|
|
|
|
|
|
return fs.writeFileSync(location, settings, {
|
|
|
|
|
encoding: 'utf-8',
|
|
|
|
|
flag: 'w'
|
|
|
|
|
});
|
2019-11-15 16:01:13 -08:00
|
|
|
}
|