This commit is contained in:
Nikolas Grottendieck 2025-04-10 16:24:42 +06:30 committed by GitHub
commit b567cfb844
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 563 additions and 76 deletions

79
dist/setup/index.js vendored
View file

@ -131404,46 +131404,53 @@ function createToolchainsSettings({ jdkInfo, settingsDirectory, overwriteSetting
exports.createToolchainsSettings = createToolchainsSettings;
// only exported for testing purposes
function generateToolchainDefinition(original, version, vendor, id, jdkHome) {
let xmlObj;
let jsToolchains = [
{
type: 'jdk',
provides: {
version: `${version}`,
vendor: `${vendor}`,
id: `${id}`
},
configuration: {
jdkHome: `${jdkHome}`
}
}
];
if (original === null || original === void 0 ? void 0 : original.length) {
xmlObj = (0, xmlbuilder2_1.create)(original)
// convert existing toolchains into TS native objects for better handling
// xmlbuilder2 will convert the document into a `{toolchains: { toolchain: [] | {} }}` structure
// instead of the desired `toolchains: [{}]` one or simply `[{}]`
const jsObj = (0, xmlbuilder2_1.create)(original)
.root()
.ele({
toolchain: {
type: 'jdk',
provides: {
version: `${version}`,
vendor: `${vendor}`,
id: `${id}`
},
configuration: {
jdkHome: `${jdkHome}`
}
.toObject();
if (jsObj.toolchains && jsObj.toolchains.toolchain) {
// in case only a single child exists xmlbuilder2 will not create an array and using verbose = true equally doesn't work here
// See https://oozcitak.github.io/xmlbuilder2/serialization.html#js-object-and-map-serializers for details
if (Array.isArray(jsObj.toolchains.toolchain)) {
jsToolchains.push(...jsObj.toolchains.toolchain);
}
});
else {
jsToolchains.push(jsObj.toolchains.toolchain);
}
}
// remove potential duplicates based on type & id (which should be a unique combination);
// self.findIndex will only return the first occurrence, ensuring duplicates are skipped
jsToolchains = jsToolchains.filter((value, index, self) =>
// ensure non-jdk toolchains are kept in the results, we must not touch them because they belong to the user
value.type !== 'jdk' ||
index ===
self.findIndex(t => t.type === value.type && t.provides.id === value.provides.id));
}
else
xmlObj = (0, xmlbuilder2_1.create)({
toolchains: {
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'@xsi:schemaLocation': 'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
toolchain: [
{
type: 'jdk',
provides: {
version: `${version}`,
vendor: `${vendor}`,
id: `${id}`
},
configuration: {
jdkHome: `${jdkHome}`
}
}
]
}
});
return xmlObj.end({
// TODO: technically bad because we shouldn't re-create the toolchains root node (with possibly different schema values) if it already exists, however, just overriding the toolchain array with xmlbuilder2 is … uh non-trivial
return (0, xmlbuilder2_1.create)({
toolchains: {
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'@xsi:schemaLocation': 'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
toolchain: jsToolchains
}
}).end({
format: 'xml',
wellFormed: false,
headless: false,