2026-07-08 14:45:00 +05:30
|
|
|
import {
|
|
|
|
|
jest,
|
|
|
|
|
describe,
|
|
|
|
|
it,
|
|
|
|
|
expect,
|
|
|
|
|
beforeEach,
|
|
|
|
|
afterEach,
|
|
|
|
|
beforeAll,
|
|
|
|
|
afterAll
|
|
|
|
|
} from '@jest/globals';
|
|
|
|
|
import {fileURLToPath} from 'url';
|
2023-03-09 14:49:35 +02:00
|
|
|
import * as io from '@actions/io';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as path from 'path';
|
2021-04-05 13:02:27 +03:00
|
|
|
import os from 'os';
|
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 {XMLParser} from 'fast-xml-parser';
|
2019-11-15 16:01:13 -08:00
|
|
|
|
2026-07-08 14:45:00 +05:30
|
|
|
// Mock @actions/core before importing source modules that depend on it
|
|
|
|
|
jest.unstable_mockModule('@actions/core', () => ({
|
|
|
|
|
info: jest.fn(),
|
|
|
|
|
warning: jest.fn(),
|
|
|
|
|
debug: jest.fn(),
|
|
|
|
|
error: jest.fn(),
|
|
|
|
|
notice: jest.fn(),
|
|
|
|
|
setFailed: jest.fn(),
|
|
|
|
|
setOutput: jest.fn(),
|
|
|
|
|
getInput: jest.fn(),
|
|
|
|
|
getBooleanInput: jest.fn(),
|
2026-08-17 17:05:55 -04:00
|
|
|
getMultilineInput: jest.fn(() => []),
|
2026-07-08 14:45:00 +05:30
|
|
|
addPath: jest.fn(),
|
|
|
|
|
exportVariable: jest.fn(),
|
|
|
|
|
saveState: jest.fn(),
|
|
|
|
|
getState: jest.fn(),
|
|
|
|
|
setSecret: jest.fn(),
|
|
|
|
|
isDebug: jest.fn(() => false),
|
|
|
|
|
startGroup: jest.fn(),
|
|
|
|
|
endGroup: jest.fn(),
|
|
|
|
|
group: jest.fn((_name: string, fn: () => Promise<unknown>) => fn()),
|
|
|
|
|
toPlatformPath: jest.fn((p: string) => p),
|
|
|
|
|
toWin32Path: jest.fn((p: string) => p),
|
|
|
|
|
toPosixPath: jest.fn((p: string) => p)
|
|
|
|
|
}));
|
2019-11-15 16:01:13 -08:00
|
|
|
|
2026-08-05 18:05:36 +02:00
|
|
|
jest.unstable_mockModule('../src/gpg.js', () => ({
|
|
|
|
|
importKey: jest.fn(),
|
|
|
|
|
removeGpgHome: jest.fn(),
|
|
|
|
|
toGpgPath: jest.fn()
|
|
|
|
|
}));
|
|
|
|
|
|
2026-07-08 14:45:00 +05:30
|
|
|
// Dynamic imports after mocking
|
|
|
|
|
const core = await import('@actions/core');
|
2026-08-05 18:05:36 +02:00
|
|
|
const gpg = await import('../src/gpg.js');
|
2026-07-08 14:45:00 +05:30
|
|
|
const auth = await import('../src/auth.js');
|
2026-08-05 18:05:36 +02:00
|
|
|
const {M2_DIR, MVN_SETTINGS_FILE, STATE_GPG_HOME} =
|
|
|
|
|
await import('../src/constants.js');
|
2026-07-08 14:45:00 +05:30
|
|
|
|
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
2022-01-16 17:33:29 +01:00
|
|
|
const m2Dir = path.join(__dirname, M2_DIR);
|
|
|
|
|
const settingsFile = path.join(m2Dir, MVN_SETTINGS_FILE);
|
2026-08-17 17:05:55 -04:00
|
|
|
const credentials = (id: string, username: string, password: string) => [
|
|
|
|
|
{id, usernameEnvVar: username, passwordEnvVar: password}
|
|
|
|
|
];
|
2026-08-17 18:18:45 -04:00
|
|
|
const repositorySettings = (
|
|
|
|
|
repositories: auth.MavenRepository[],
|
|
|
|
|
includeCentral = true,
|
|
|
|
|
prioritizeCentral = true
|
|
|
|
|
): auth.MavenRepositorySettings => ({
|
|
|
|
|
repositories,
|
|
|
|
|
includeCentral,
|
|
|
|
|
prioritizeCentral
|
|
|
|
|
});
|
2019-11-20 10:25:21 -08:00
|
|
|
|
2019-11-15 16:01:13 -08:00
|
|
|
describe('auth tests', () => {
|
2026-07-08 14:45:00 +05:30
|
|
|
let spyOSHomedir: any;
|
|
|
|
|
let spyInfo: any;
|
2021-04-05 13:02:27 +03:00
|
|
|
|
2019-11-20 10:25:21 -08:00
|
|
|
beforeEach(async () => {
|
2019-11-15 16:01:13 -08:00
|
|
|
await io.rmRF(m2Dir);
|
2021-04-05 13:02:27 +03:00
|
|
|
spyOSHomedir = jest.spyOn(os, 'homedir');
|
|
|
|
|
spyOSHomedir.mockReturnValue(__dirname);
|
2026-07-08 14:45:00 +05:30
|
|
|
spyInfo = core.info as jest.Mock;
|
2021-08-23 11:31:06 +03:00
|
|
|
spyInfo.mockImplementation(() => null);
|
2026-08-05 18:05:36 +02:00
|
|
|
(gpg.toGpgPath as jest.Mock<any>).mockImplementation((p: string) => p);
|
2019-11-15 16:01:13 -08:00
|
|
|
}, 300000);
|
|
|
|
|
|
2026-08-05 18:05:36 +02:00
|
|
|
afterEach(() => {
|
|
|
|
|
(core.getInput as jest.Mock).mockReset();
|
2026-08-17 17:05:55 -04:00
|
|
|
(core.getMultilineInput as jest.Mock).mockReset();
|
|
|
|
|
(core.getMultilineInput as jest.Mock).mockReturnValue([]);
|
|
|
|
|
(core.warning as jest.Mock).mockReset();
|
2026-08-05 18:05:36 +02:00
|
|
|
(core.exportVariable as jest.Mock).mockReset();
|
|
|
|
|
(gpg.importKey as jest.Mock).mockReset();
|
|
|
|
|
(gpg.removeGpgHome as jest.Mock).mockReset();
|
|
|
|
|
(gpg.toGpgPath as jest.Mock).mockReset();
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-15 16:01:13 -08:00
|
|
|
afterAll(async () => {
|
|
|
|
|
try {
|
|
|
|
|
await io.rmRF(m2Dir);
|
|
|
|
|
} catch {
|
|
|
|
|
console.log('Failed to remove test directories');
|
|
|
|
|
}
|
2021-04-05 13:02:27 +03:00
|
|
|
jest.resetAllMocks();
|
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
jest.restoreAllMocks();
|
2019-11-15 16:01:13 -08:00
|
|
|
}, 100000);
|
|
|
|
|
|
2019-12-10 10:03:33 -08:00
|
|
|
it('creates settings.xml in alternate locations', async () => {
|
|
|
|
|
const id = 'packages';
|
2019-12-19 11:28:11 -08:00
|
|
|
const username = 'UNAMI';
|
|
|
|
|
const password = 'TOLKIEN';
|
2019-12-10 10:03:33 -08:00
|
|
|
|
|
|
|
|
const altHome = path.join(__dirname, 'runner', 'settings');
|
2022-01-16 17:33:29 +01:00
|
|
|
const altSettingsFile = path.join(altHome, MVN_SETTINGS_FILE);
|
2019-12-10 10:03:33 -08:00
|
|
|
await io.rmRF(altHome); // ensure it doesn't already exist
|
|
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
await auth.createAuthenticationSettings(
|
2026-08-17 17:05:55 -04:00
|
|
|
credentials(id, username, password),
|
2023-03-09 14:49:35 +02:00
|
|
|
altHome,
|
|
|
|
|
true
|
|
|
|
|
);
|
2019-12-10 10:03:33 -08:00
|
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(false);
|
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(false);
|
|
|
|
|
|
|
|
|
|
expect(fs.existsSync(altHome)).toBe(true);
|
|
|
|
|
expect(fs.existsSync(altSettingsFile)).toBe(true);
|
|
|
|
|
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
|
2026-08-17 17:05:55 -04:00
|
|
|
auth.generate(credentials(id, username, password))
|
2019-12-10 10:03:33 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await io.rmRF(altHome);
|
|
|
|
|
}, 100000);
|
|
|
|
|
|
2020-05-02 04:33:15 -07:00
|
|
|
it('creates settings.xml with minimal configuration', async () => {
|
2019-11-28 12:40:08 -08:00
|
|
|
const id = 'packages';
|
2019-12-19 11:28:11 -08:00
|
|
|
const username = 'UNAME';
|
|
|
|
|
const password = 'TOKEN';
|
2019-11-15 16:01:13 -08:00
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
await auth.createAuthenticationSettings(
|
2026-08-17 17:05:55 -04:00
|
|
|
credentials(id, username, password),
|
2023-03-09 14:49:35 +02:00
|
|
|
m2Dir,
|
|
|
|
|
true
|
|
|
|
|
);
|
2019-11-15 16:01:13 -08:00
|
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
2023-03-09 14:49:35 +02:00
|
|
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
2026-08-17 17:05:55 -04:00
|
|
|
auth.generate(credentials(id, username, password))
|
2023-03-09 14:49:35 +02:00
|
|
|
);
|
2019-11-15 16:01:13 -08:00
|
|
|
}, 100000);
|
2019-11-20 10:25:21 -08:00
|
|
|
|
2020-05-02 04:33:15 -07:00
|
|
|
it('creates settings.xml with additional configuration', async () => {
|
2019-12-06 14:46:35 -05:00
|
|
|
const id = 'packages';
|
2020-05-02 04:33:15 -07:00
|
|
|
const username = 'UNAME';
|
|
|
|
|
const password = 'TOKEN';
|
|
|
|
|
const gpgPassphrase = 'GPG';
|
2019-12-06 14:46:35 -05:00
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
await auth.createAuthenticationSettings(
|
2026-08-17 17:05:55 -04:00
|
|
|
credentials(id, username, password),
|
2023-03-09 14:49:35 +02:00
|
|
|
m2Dir,
|
|
|
|
|
true,
|
|
|
|
|
gpgPassphrase
|
|
|
|
|
);
|
2019-12-06 14:46:35 -05:00
|
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
|
|
|
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
2026-08-17 17:05:55 -04:00
|
|
|
auth.generate(credentials(id, username, password), gpgPassphrase)
|
2019-12-06 14:46:35 -05:00
|
|
|
);
|
|
|
|
|
}, 100000);
|
|
|
|
|
|
2026-08-05 18:05:36 +02:00
|
|
|
it('exports a GPG-compatible path and persists the native GPG home', async () => {
|
|
|
|
|
const gpgHome = 'D:\\a\\_temp\\setup-java-gpg-1';
|
|
|
|
|
const exportedGpgHome = '/d/a/_temp/setup-java-gpg-1';
|
|
|
|
|
(gpg.importKey as jest.Mock<any>).mockResolvedValue(gpgHome);
|
|
|
|
|
(gpg.toGpgPath as jest.Mock<any>).mockReturnValue(exportedGpgHome);
|
|
|
|
|
(core.getInput as jest.Mock<any>).mockImplementation((name: string) => {
|
|
|
|
|
const inputs: Record<string, string> = {
|
|
|
|
|
'server-id': 'packages',
|
|
|
|
|
'server-username-env-var': 'USERNAME',
|
|
|
|
|
'server-password-env-var': 'PASSWORD',
|
|
|
|
|
'settings-path': m2Dir,
|
|
|
|
|
'gpg-private-key': 'KEY ONE\nKEY TWO'
|
|
|
|
|
};
|
|
|
|
|
return inputs[name] ?? '';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await auth.configureAuthentication();
|
|
|
|
|
|
|
|
|
|
expect(gpg.importKey).toHaveBeenCalledWith('KEY ONE\nKEY TWO');
|
|
|
|
|
expect(core.saveState).toHaveBeenCalledWith(STATE_GPG_HOME, gpgHome);
|
|
|
|
|
expect(gpg.toGpgPath).toHaveBeenCalledWith(gpgHome);
|
|
|
|
|
expect(core.exportVariable).toHaveBeenCalledWith(
|
|
|
|
|
'GNUPGHOME',
|
|
|
|
|
exportedGpgHome
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('removes the isolated GPG home when environment export fails', async () => {
|
|
|
|
|
const gpgHome = path.join(__dirname, 'runner', 'temp', 'setup-java-gpg-2');
|
|
|
|
|
(gpg.importKey as jest.Mock<any>).mockResolvedValue(gpgHome);
|
|
|
|
|
(core.exportVariable as jest.Mock<any>).mockImplementation(() => {
|
|
|
|
|
throw new Error('environment file unavailable');
|
|
|
|
|
});
|
|
|
|
|
(core.getInput as jest.Mock<any>).mockImplementation((name: string) => {
|
|
|
|
|
if (name === 'gpg-private-key') return 'KEY CONTENTS';
|
|
|
|
|
if (name === 'settings-path') return m2Dir;
|
|
|
|
|
return '';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await expect(auth.configureAuthentication()).rejects.toThrow(
|
|
|
|
|
'environment file unavailable'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(gpg.removeGpgHome).toHaveBeenCalledWith(gpgHome);
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-02 04:33:15 -07:00
|
|
|
it('overwrites existing settings.xml files', async () => {
|
|
|
|
|
const id = 'packages';
|
|
|
|
|
const username = 'USERNAME';
|
|
|
|
|
const password = 'PASSWORD';
|
2019-11-28 12:40:08 -08:00
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
fs.mkdirSync(m2Dir, {recursive: true});
|
2020-05-02 04:33:15 -07:00
|
|
|
fs.writeFileSync(settingsFile, 'FAKE FILE');
|
2019-12-19 11:28:11 -08:00
|
|
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
2019-11-28 12:40:08 -08:00
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
await auth.createAuthenticationSettings(
|
2026-08-17 17:05:55 -04:00
|
|
|
credentials(id, username, password),
|
2023-03-09 14:49:35 +02:00
|
|
|
m2Dir,
|
|
|
|
|
true
|
|
|
|
|
);
|
2019-11-20 10:25:21 -08:00
|
|
|
|
2019-12-19 11:28:11 -08:00
|
|
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
2023-03-09 14:49:35 +02:00
|
|
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
2026-08-17 17:05:55 -04:00
|
|
|
auth.generate(credentials(id, username, password))
|
2023-03-09 14:49:35 +02:00
|
|
|
);
|
2021-04-05 13:02:27 +03:00
|
|
|
}, 100000);
|
|
|
|
|
|
|
|
|
|
it('does not overwrite existing settings.xml files', async () => {
|
|
|
|
|
const id = 'packages';
|
|
|
|
|
const username = 'USERNAME';
|
|
|
|
|
const password = 'PASSWORD';
|
|
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
fs.mkdirSync(m2Dir, {recursive: true});
|
2021-04-05 13:02:27 +03:00
|
|
|
fs.writeFileSync(settingsFile, 'FAKE FILE');
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
|
|
|
|
|
2023-03-09 14:49:35 +02:00
|
|
|
await auth.createAuthenticationSettings(
|
2026-08-17 17:05:55 -04:00
|
|
|
credentials(id, username, password),
|
2023-03-09 14:49:35 +02:00
|
|
|
m2Dir,
|
|
|
|
|
false
|
|
|
|
|
);
|
2021-04-05 13:02:27 +03:00
|
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
|
|
|
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual('FAKE FILE');
|
2019-11-20 10:25:21 -08:00
|
|
|
}, 100000);
|
2019-12-10 09:26:51 -08:00
|
|
|
|
2020-05-02 04:33:15 -07:00
|
|
|
it('generates valid settings.xml with minimal configuration', () => {
|
2019-12-10 09:26:51 -08:00
|
|
|
const id = 'packages';
|
2019-12-19 11:28:11 -08:00
|
|
|
const username = 'USER';
|
2019-12-10 09:26:51 -08:00
|
|
|
const password = '&<>"\'\'"><&';
|
|
|
|
|
|
2020-05-02 04:33:15 -07:00
|
|
|
const expectedSettings = `<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">
|
2026-07-02 17:22:38 -04:00
|
|
|
<interactiveMode>false</interactiveMode>
|
2020-05-02 04:33:15 -07:00
|
|
|
<servers>
|
|
|
|
|
<server>
|
|
|
|
|
<id>${id}</id>
|
|
|
|
|
<username>\${env.${username}}</username>
|
|
|
|
|
<password>\${env.&<>"''"><&}</password>
|
|
|
|
|
</server>
|
|
|
|
|
</servers>
|
|
|
|
|
</settings>`;
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
expect(auth.generate(credentials(id, username, password))).toEqual(
|
|
|
|
|
expectedSettings
|
|
|
|
|
);
|
2020-05-02 04:33:15 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('generates valid settings.xml with additional configuration', () => {
|
|
|
|
|
const id = 'packages';
|
|
|
|
|
const username = 'USER';
|
|
|
|
|
const password = '&<>"\'\'"><&';
|
|
|
|
|
const gpgPassphrase = 'PASSPHRASE';
|
|
|
|
|
|
|
|
|
|
const expectedSettings = `<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">
|
2026-07-02 17:22:38 -04:00
|
|
|
<interactiveMode>false</interactiveMode>
|
2020-05-02 04:33:15 -07:00
|
|
|
<servers>
|
|
|
|
|
<server>
|
|
|
|
|
<id>${id}</id>
|
|
|
|
|
<username>\${env.${username}}</username>
|
|
|
|
|
<password>\${env.&<>"''"><&}</password>
|
|
|
|
|
</server>
|
2026-07-15 10:33:09 -04:00
|
|
|
</servers>
|
|
|
|
|
<profiles>
|
|
|
|
|
<profile>
|
|
|
|
|
<id>setup-java-gpg</id>
|
|
|
|
|
<properties>
|
|
|
|
|
<gpg.passphraseEnvName>${gpgPassphrase}</gpg.passphraseEnvName>
|
|
|
|
|
</properties>
|
|
|
|
|
</profile>
|
|
|
|
|
</profiles>
|
|
|
|
|
<activeProfiles>
|
|
|
|
|
<activeProfile>setup-java-gpg</activeProfile>
|
|
|
|
|
</activeProfiles>
|
|
|
|
|
</settings>`;
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
expect(
|
|
|
|
|
auth.generate(credentials(id, username, password), gpgPassphrase)
|
|
|
|
|
).toEqual(expectedSettings);
|
2026-07-15 10:33:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not add a gpg profile when the passphrase env var is the maven-gpg-plugin default', () => {
|
|
|
|
|
const id = 'packages';
|
|
|
|
|
const username = 'USER';
|
|
|
|
|
const password = '&<>"\'\'"><&';
|
|
|
|
|
const gpgPassphrase = 'MAVEN_GPG_PASSPHRASE';
|
|
|
|
|
|
|
|
|
|
const expectedSettings = `<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>
|
|
|
|
|
<servers>
|
2020-05-02 04:33:15 -07:00
|
|
|
<server>
|
2026-07-15 10:33:09 -04:00
|
|
|
<id>${id}</id>
|
|
|
|
|
<username>\${env.${username}}</username>
|
|
|
|
|
<password>\${env.&<>"''"><&}</password>
|
2020-05-02 04:33:15 -07:00
|
|
|
</server>
|
|
|
|
|
</servers>
|
|
|
|
|
</settings>`;
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
expect(
|
|
|
|
|
auth.generate(credentials(id, username, password), gpgPassphrase)
|
|
|
|
|
).toEqual(expectedSettings);
|
2019-12-10 09:26:51 -08:00
|
|
|
});
|
2026-07-17 20:10:58 -04: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
|
|
|
it('escapes settings.xml values while preserving parsed semantics', () => {
|
|
|
|
|
const id = `packages&<>"'é`;
|
|
|
|
|
const username = `USER&<>"'é`;
|
|
|
|
|
const password = `TOKEN&<>"'é`;
|
|
|
|
|
const gpgPassphrase = `GPG&<>"'é`;
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
const xml = auth.generate(
|
|
|
|
|
credentials(id, username, password),
|
|
|
|
|
gpgPassphrase
|
|
|
|
|
);
|
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 parsed = parseXmlObject(xml) as any;
|
|
|
|
|
|
|
|
|
|
expect(parsed.settings.interactiveMode).toBe('false');
|
|
|
|
|
expect(xmlElementText(xml, 'id')).toBe(id);
|
|
|
|
|
expect(xmlElementText(xml, 'username')).toBe(`\${env.${username}}`);
|
|
|
|
|
expect(xmlElementText(xml, 'password')).toBe(`\${env.${password}}`);
|
|
|
|
|
expect(xmlElementText(xml, 'gpg.passphraseEnvName')).toBe(gpgPassphrase);
|
|
|
|
|
expect(parsed.settings.activeProfiles.activeProfile).toBe('setup-java-gpg');
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
it('generates ordered settings.xml entries for multiple servers', () => {
|
|
|
|
|
const servers = [
|
|
|
|
|
{
|
|
|
|
|
id: 'releases',
|
|
|
|
|
usernameEnvVar: 'RELEASES_USERNAME',
|
|
|
|
|
passwordEnvVar: 'RELEASES_PASSWORD'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'snapshots',
|
|
|
|
|
usernameEnvVar: 'SNAPSHOTS_USERNAME',
|
|
|
|
|
passwordEnvVar: 'SNAPSHOTS_PASSWORD'
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const parsed = parseXmlObject(auth.generate(servers)) as any;
|
|
|
|
|
|
|
|
|
|
expect(parsed.settings.servers.server).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'releases',
|
|
|
|
|
username: '${env.RELEASES_USERNAME}',
|
|
|
|
|
password: '${env.RELEASES_PASSWORD}'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'snapshots',
|
|
|
|
|
username: '${env.SNAPSHOTS_USERNAME}',
|
|
|
|
|
password: '${env.SNAPSHOTS_PASSWORD}'
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-17 18:18:45 -04:00
|
|
|
it('generates an active profile with Central before custom repositories by default', () => {
|
|
|
|
|
const parsed = parseXmlObject(
|
|
|
|
|
auth.generate(
|
|
|
|
|
credentials('packages', 'USERNAME', 'PASSWORD'),
|
|
|
|
|
undefined,
|
|
|
|
|
repositorySettings([
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com/maven',
|
|
|
|
|
snapshotsEnabled: true
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
)
|
|
|
|
|
) as any;
|
|
|
|
|
|
|
|
|
|
expect(parsed.settings.profiles.profile).toEqual({
|
|
|
|
|
id: 'setup-java-repositories',
|
|
|
|
|
repositories: {
|
|
|
|
|
repository: [
|
|
|
|
|
{
|
|
|
|
|
id: 'central',
|
|
|
|
|
url: 'https://repo.maven.apache.org/maven2',
|
|
|
|
|
snapshots: {enabled: 'false'}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com/maven',
|
|
|
|
|
snapshots: {enabled: 'true'}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
expect(parsed.settings.activeProfiles.activeProfile).toBe(
|
|
|
|
|
'setup-java-repositories'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('places custom repositories before Central when configured', () => {
|
|
|
|
|
const parsed = parseXmlObject(
|
|
|
|
|
auth.generate(
|
|
|
|
|
credentials('packages', 'USERNAME', 'PASSWORD'),
|
|
|
|
|
undefined,
|
|
|
|
|
repositorySettings(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
id: 'first',
|
|
|
|
|
url: 'https://first.example.com',
|
|
|
|
|
snapshotsEnabled: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'second',
|
|
|
|
|
url: 'https://second.example.com',
|
|
|
|
|
snapshotsEnabled: true
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
true,
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) as any;
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
parsed.settings.profiles.profile.repositories.repository.map(
|
|
|
|
|
(repository: {id: string}) => repository.id
|
|
|
|
|
)
|
|
|
|
|
).toEqual(['first', 'second', 'central']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('excludes Central from the generated repository profile when configured', () => {
|
|
|
|
|
const parsed = parseXmlObject(
|
|
|
|
|
auth.generate(
|
|
|
|
|
credentials('packages', 'USERNAME', 'PASSWORD'),
|
|
|
|
|
undefined,
|
|
|
|
|
repositorySettings(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com',
|
|
|
|
|
snapshotsEnabled: false
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) as any;
|
|
|
|
|
|
|
|
|
|
expect(parsed.settings.profiles.profile.repositories.repository).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com',
|
|
|
|
|
snapshots: {enabled: 'false'}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'central',
|
|
|
|
|
url: 'https://repo.maven.apache.org/maven2',
|
|
|
|
|
releases: {enabled: 'false'},
|
|
|
|
|
snapshots: {enabled: 'false'}
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('combines repository and GPG configuration in shared profile blocks', () => {
|
|
|
|
|
const parsed = parseXmlObject(
|
|
|
|
|
auth.generate(
|
|
|
|
|
credentials('packages', 'USERNAME', 'PASSWORD'),
|
|
|
|
|
'GPG_PASSPHRASE',
|
|
|
|
|
repositorySettings(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com',
|
|
|
|
|
snapshotsEnabled: false
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) as any;
|
|
|
|
|
|
|
|
|
|
expect(parsed.settings.profiles.profile).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'setup-java-repositories',
|
|
|
|
|
repositories: {
|
|
|
|
|
repository: [
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com',
|
|
|
|
|
snapshots: {enabled: 'false'}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'central',
|
|
|
|
|
url: 'https://repo.maven.apache.org/maven2',
|
|
|
|
|
releases: {enabled: 'false'},
|
|
|
|
|
snapshots: {enabled: 'false'}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'setup-java-gpg',
|
|
|
|
|
properties: {['gpg.passphraseEnvName']: 'GPG_PASSPHRASE'}
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
expect(parsed.settings.activeProfiles.activeProfile).toEqual([
|
|
|
|
|
'setup-java-repositories',
|
|
|
|
|
'setup-java-gpg'
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('escapes repository values while preserving parsed semantics', () => {
|
|
|
|
|
const repository = {
|
|
|
|
|
id: `private&<>"'é`,
|
|
|
|
|
url: `https://repo.example.com/a?x=1&y=<value>"'é`,
|
|
|
|
|
snapshotsEnabled: true
|
|
|
|
|
};
|
|
|
|
|
const xml = auth.generate(
|
|
|
|
|
credentials('packages', 'USERNAME', 'PASSWORD'),
|
|
|
|
|
undefined,
|
|
|
|
|
repositorySettings([repository], false)
|
|
|
|
|
);
|
|
|
|
|
const parsed = parseXmlObject(xml) as any;
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
parsed.settings.profiles.profile.repositories.repository.find(
|
|
|
|
|
(entry: {id: string}) => entry.id === repository.id
|
|
|
|
|
)
|
|
|
|
|
).toEqual({
|
|
|
|
|
id: repository.id,
|
|
|
|
|
url: repository.url,
|
|
|
|
|
snapshots: {enabled: 'true'}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
it('parses and trims multiline Maven server credentials', () => {
|
|
|
|
|
expect(
|
|
|
|
|
auth.parseMavenServerCredentials([
|
|
|
|
|
'',
|
|
|
|
|
' releases : RELEASES_USERNAME : RELEASES_PASSWORD ',
|
|
|
|
|
'snapshots:SNAPSHOTS_USERNAME:SNAPSHOTS_PASSWORD'
|
|
|
|
|
])
|
|
|
|
|
).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'releases',
|
|
|
|
|
usernameEnvVar: 'RELEASES_USERNAME',
|
|
|
|
|
passwordEnvVar: 'RELEASES_PASSWORD'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'snapshots',
|
|
|
|
|
usernameEnvVar: 'SNAPSHOTS_USERNAME',
|
|
|
|
|
passwordEnvVar: 'SNAPSHOTS_PASSWORD'
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-17 18:18:45 -04:00
|
|
|
it('parses Maven repositories while preserving colons in URLs', () => {
|
|
|
|
|
expect(
|
|
|
|
|
auth.parseMavenRepositories(
|
|
|
|
|
[
|
|
|
|
|
'',
|
|
|
|
|
' private : https://repo.example.com:8443/maven : true ',
|
|
|
|
|
'releases:https://repo.example.com/releases:false'
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com:8443/maven',
|
|
|
|
|
snapshotsEnabled: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'releases',
|
|
|
|
|
url: 'https://repo.example.com/releases',
|
|
|
|
|
snapshotsEnabled: false
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
|
{
|
|
|
|
|
entries: ['private'],
|
|
|
|
|
error:
|
|
|
|
|
'Invalid mvn-repositories entry at line 1. Expected format: repository-id:repository-url:snapshots-enabled'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
entries: ['private:https://repo.example.com'],
|
|
|
|
|
error:
|
|
|
|
|
"Invalid snapshots-enabled value '//repo.example.com' in mvn-repositories entry at line 1. Expected true or false"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
entries: ['private::true'],
|
|
|
|
|
error:
|
|
|
|
|
'Invalid mvn-repositories entry at line 1. repository-id, repository URL, and snapshots-enabled are required'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
entries: ['private:https://repo.example.com:sometimes'],
|
|
|
|
|
error:
|
|
|
|
|
"Invalid snapshots-enabled value 'sometimes' in mvn-repositories entry at line 1. Expected true or false"
|
|
|
|
|
}
|
|
|
|
|
])('rejects malformed Maven repositories: $entries', ({entries, error}) => {
|
|
|
|
|
expect(() => auth.parseMavenRepositories(entries, true)).toThrow(error);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects duplicate Maven repository ids', () => {
|
|
|
|
|
expect(() =>
|
|
|
|
|
auth.parseMavenRepositories(
|
|
|
|
|
[
|
|
|
|
|
'private:https://first.example.com:false',
|
|
|
|
|
'private:https://second.example.com:true'
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
).toThrow("Duplicate repository-id 'private' in mvn-repositories input");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('reserves the Central repository id only when automatic Central inclusion is enabled', () => {
|
|
|
|
|
const central = 'central:https://custom.example.com/maven:false';
|
|
|
|
|
|
|
|
|
|
expect(() => auth.parseMavenRepositories([central], true)).toThrow(
|
|
|
|
|
"Repository-id 'central' is reserved when mvn-repositories-include-central is enabled"
|
|
|
|
|
);
|
|
|
|
|
expect(auth.parseMavenRepositories([central], false)).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'central',
|
|
|
|
|
url: 'https://custom.example.com/maven',
|
|
|
|
|
snapshotsEnabled: false
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uses an explicit Central repository instead of adding a disabled override', () => {
|
|
|
|
|
const parsed = parseXmlObject(
|
|
|
|
|
auth.generate(
|
|
|
|
|
credentials('packages', 'USERNAME', 'PASSWORD'),
|
|
|
|
|
undefined,
|
|
|
|
|
repositorySettings(
|
|
|
|
|
auth.parseMavenRepositories(
|
|
|
|
|
['central:https://mirror.example.com/maven:true'],
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) as any;
|
|
|
|
|
|
|
|
|
|
expect(parsed.settings.profiles.profile.repositories.repository).toEqual({
|
|
|
|
|
id: 'central',
|
|
|
|
|
url: 'https://mirror.example.com/maven',
|
|
|
|
|
snapshots: {enabled: 'true'}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('reads Maven repository settings and Central controls', () => {
|
|
|
|
|
(core.getMultilineInput as jest.Mock).mockImplementation((name: string) =>
|
|
|
|
|
name === 'mvn-repositories'
|
|
|
|
|
? ['private:https://repo.example.com:true']
|
|
|
|
|
: []
|
|
|
|
|
);
|
|
|
|
|
(core.getInput as jest.Mock).mockImplementation((name: string) => {
|
|
|
|
|
const inputs: Record<string, string> = {
|
|
|
|
|
'mvn-repositories-include-central': 'false',
|
|
|
|
|
'mvn-repositories-prioritize-central': 'false'
|
|
|
|
|
};
|
|
|
|
|
return inputs[name] ?? '';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(auth.getMavenRepositorySettings()).toEqual({
|
|
|
|
|
repositories: [
|
|
|
|
|
{
|
|
|
|
|
id: 'private',
|
|
|
|
|
url: 'https://repo.example.com',
|
|
|
|
|
snapshotsEnabled: true
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
includeCentral: false,
|
|
|
|
|
prioritizeCentral: false
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not read repository controls when no repositories are configured', () => {
|
|
|
|
|
expect(auth.getMavenRepositorySettings()).toBeUndefined();
|
|
|
|
|
expect(core.getInput).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-17 17:05:55 -04:00
|
|
|
it.each([
|
|
|
|
|
{
|
|
|
|
|
entries: ['releases:RELEASES_USERNAME'],
|
|
|
|
|
error:
|
|
|
|
|
'Invalid mvn-server-credentials entry at line 1. Expected format: server-id:USERNAME_ENV:PASSWORD_ENV'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
entries: ['', 'releases:RELEASES_USERNAME:RELEASES_PASSWORD:EXTRA'],
|
|
|
|
|
error:
|
|
|
|
|
'Invalid mvn-server-credentials entry at line 2. Expected format: server-id:USERNAME_ENV:PASSWORD_ENV'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
entries: ['releases::RELEASES_PASSWORD'],
|
|
|
|
|
error:
|
|
|
|
|
'Invalid mvn-server-credentials entry at line 1. server-id, username environment variable, and password environment variable are required'
|
|
|
|
|
}
|
|
|
|
|
])(
|
|
|
|
|
'rejects malformed Maven server credentials: $entries',
|
|
|
|
|
({entries, error}) => {
|
|
|
|
|
expect(() => auth.parseMavenServerCredentials(entries)).toThrow(error);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
it('rejects duplicate Maven server ids', () => {
|
|
|
|
|
expect(() =>
|
|
|
|
|
auth.parseMavenServerCredentials([
|
|
|
|
|
'releases:RELEASES_USERNAME:RELEASES_PASSWORD',
|
|
|
|
|
'releases:OTHER_USERNAME:OTHER_PASSWORD'
|
|
|
|
|
])
|
|
|
|
|
).toThrow("Duplicate server-id 'releases' in mvn-server-credentials input");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uses multiline Maven server credentials instead of single-server inputs', () => {
|
|
|
|
|
(core.getMultilineInput as jest.Mock).mockReturnValue([
|
|
|
|
|
'releases:RELEASES_USERNAME:RELEASES_PASSWORD',
|
|
|
|
|
'snapshots:SNAPSHOTS_USERNAME:SNAPSHOTS_PASSWORD'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(auth.getMavenServerSettings()).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'releases',
|
|
|
|
|
usernameEnvVar: 'RELEASES_USERNAME',
|
|
|
|
|
passwordEnvVar: 'RELEASES_PASSWORD'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'snapshots',
|
|
|
|
|
usernameEnvVar: 'SNAPSHOTS_USERNAME',
|
|
|
|
|
passwordEnvVar: 'SNAPSHOTS_PASSWORD'
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
expect(core.getInput).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uses the existing single-server inputs when multiline credentials are absent', () => {
|
|
|
|
|
(core.getInput as jest.Mock).mockImplementation((name: string) =>
|
|
|
|
|
name === 'server-id' ? 'github' : ''
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(auth.getMavenServerSettings()).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'github',
|
|
|
|
|
usernameEnvVar: 'GITHUB_ACTOR',
|
|
|
|
|
passwordEnvVar: 'GITHUB_TOKEN'
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('preserves deprecated single-server aliases as fallback inputs', () => {
|
|
|
|
|
(core.getInput as jest.Mock).mockImplementation((name: string) => {
|
|
|
|
|
const inputs: Record<string, string> = {
|
|
|
|
|
'server-id': 'legacy',
|
|
|
|
|
'server-username': 'LEGACY_USERNAME',
|
|
|
|
|
'server-password': 'LEGACY_PASSWORD'
|
|
|
|
|
};
|
|
|
|
|
return inputs[name] ?? '';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(auth.getMavenServerSettings()).toEqual([
|
|
|
|
|
{
|
|
|
|
|
id: 'legacy',
|
|
|
|
|
usernameEnvVar: 'LEGACY_USERNAME',
|
|
|
|
|
passwordEnvVar: 'LEGACY_PASSWORD'
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
expect(core.warning).toHaveBeenCalledTimes(2);
|
|
|
|
|
});
|
|
|
|
|
|
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
|
|
|
function xmlElementText(xml: string, tagName: string): string {
|
|
|
|
|
const match = new RegExp(`<${tagName}>([\\s\\S]*?)</${tagName}>`).exec(xml);
|
|
|
|
|
expect(match).not.toBeNull();
|
|
|
|
|
return (parseXmlObject(`<value>${match?.[1]}</value>`) as {value: string})
|
|
|
|
|
.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseXmlObject(xml: string): unknown {
|
|
|
|
|
const parser = new XMLParser({
|
|
|
|
|
ignoreAttributes: false,
|
|
|
|
|
attributeNamePrefix: '@',
|
|
|
|
|
parseAttributeValue: false,
|
|
|
|
|
parseTagValue: false,
|
|
|
|
|
trimValues: true
|
|
|
|
|
});
|
|
|
|
|
return parser.parse(xml);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 20:10:58 -04:00
|
|
|
it('uses deprecated input aliases and warns', () => {
|
|
|
|
|
const mockGetInput = core.getInput as jest.MockedFunction<
|
|
|
|
|
typeof core.getInput
|
|
|
|
|
>;
|
|
|
|
|
const mockWarning = core.warning as jest.MockedFunction<
|
|
|
|
|
typeof core.warning
|
|
|
|
|
>;
|
|
|
|
|
mockGetInput.mockImplementation(name =>
|
|
|
|
|
name === 'server-username' ? 'LEGACY_USERNAME' : ''
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
auth.getInputWithDeprecatedAlias(
|
|
|
|
|
'server-username-env-var',
|
|
|
|
|
'server-username',
|
|
|
|
|
'GITHUB_ACTOR'
|
|
|
|
|
)
|
|
|
|
|
).toBe('LEGACY_USERNAME');
|
|
|
|
|
expect(mockWarning).toHaveBeenCalledWith(
|
|
|
|
|
"The 'server-username' input is deprecated and may be removed in a future release. Please use 'server-username-env-var' instead."
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
mockGetInput.mockReset();
|
|
|
|
|
mockWarning.mockReset();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('prefers the replacement input over its deprecated alias', () => {
|
|
|
|
|
const mockGetInput = core.getInput as jest.MockedFunction<
|
|
|
|
|
typeof core.getInput
|
|
|
|
|
>;
|
|
|
|
|
mockGetInput.mockImplementation(name => {
|
|
|
|
|
const inputs: Record<string, string> = {
|
|
|
|
|
'server-password-env-var': 'NEW_PASSWORD',
|
|
|
|
|
'server-password': 'LEGACY_PASSWORD'
|
|
|
|
|
};
|
|
|
|
|
return inputs[name] || '';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
auth.getInputWithDeprecatedAlias(
|
|
|
|
|
'server-password-env-var',
|
|
|
|
|
'server-password',
|
|
|
|
|
'GITHUB_TOKEN'
|
|
|
|
|
)
|
|
|
|
|
).toBe('NEW_PASSWORD');
|
|
|
|
|
expect(core.warning).toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
mockGetInput.mockReset();
|
|
|
|
|
(core.warning as jest.Mock).mockReset();
|
|
|
|
|
});
|
2019-11-15 16:01:13 -08:00
|
|
|
});
|