mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-12 00:05:49 +08:00
Add support for custom repositories
This commit is contained in:
committed by
Slawomir Jaranowski
parent
25432ff633
commit
879f94d6bf
63
settings.js
63
settings.js
@ -124,6 +124,59 @@ function fillServers(template, templateName) {
|
||||
server.configuration));
|
||||
}
|
||||
|
||||
function fillRepository(templateXml, templateName, id, name, url, snapshots) {
|
||||
|
||||
if (!id || !url) {
|
||||
core.setFailed(templateName + ' must contain id and url');
|
||||
return;
|
||||
}
|
||||
|
||||
const repositoryXml = getTemplate(templateName + '.xml')
|
||||
repositoryXml.getElementsByTagName('id')[0].textContent = id;
|
||||
|
||||
const repositoryTags = {
|
||||
'name': name,
|
||||
'url': url
|
||||
};
|
||||
for (const tag in repositoryTags) {
|
||||
const repositoryTag = repositoryXml.getElementsByTagName(tag)[0];
|
||||
const tagValue = repositoryTags[tag];
|
||||
if (tagValue) {
|
||||
repositoryTag.textContent = tagValue;
|
||||
} else {
|
||||
repositoryXml.documentElement.removeChild(repositoryTag);
|
||||
}
|
||||
}
|
||||
|
||||
const snapshotsTag = repositoryXml.getElementsByTagName('snapshots')[0];
|
||||
if (snapshots) {
|
||||
jsonToXml(templateXml, snapshotsTag, snapshots);
|
||||
} else {
|
||||
repositoryXml.documentElement.removeChild(snapshotsTag);
|
||||
}
|
||||
|
||||
const repositoriesXml = templateXml.getElementsByTagName('repositories')[0];
|
||||
repositoriesXml.appendChild(repositoryXml);
|
||||
}
|
||||
|
||||
function fillRepositories(template, templateName) {
|
||||
|
||||
const repositories = core.getInput(templateName);
|
||||
|
||||
if (!repositories) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const customRepositoriesTemplate = getTemplate('custom-repositories.xml');
|
||||
const profilesXml = template.getElementsByTagName('profiles')[0];
|
||||
profilesXml.appendChild(customRepositoriesTemplate);
|
||||
|
||||
JSON.parse(repositories).forEach((repository) =>
|
||||
fillRepository(customRepositoriesTemplate, templateName, repository.id, repository.name, repository.url,
|
||||
repository.snapshots));
|
||||
}
|
||||
|
||||
function fillMirror(template, id, name, mirrorOf, url) {
|
||||
|
||||
if (!id || !name || !mirrorOf || !url) {
|
||||
@ -247,7 +300,7 @@ function generate() {
|
||||
|
||||
const settingsPath = getSettingsPath();
|
||||
|
||||
core.info('Prepare maven setings: ' + settingsPath);
|
||||
core.info('Prepare maven settings: ' + settingsPath);
|
||||
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
if (isInputTrue('override')) {
|
||||
@ -268,6 +321,7 @@ function generate() {
|
||||
addApacheSnapshots(settingsXml);
|
||||
addSonatypeSnapshots(settingsXml);
|
||||
addOracleRepo(settingsXml);
|
||||
fillRepositories(settingsXml,'repositories')
|
||||
writeSettings(settingsPath, settingsXml);
|
||||
core.saveState('maven-settings', 'ok');
|
||||
}
|
||||
@ -279,12 +333,12 @@ function cleanup() {
|
||||
if (mavenSettingsState == 'ok') {
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
fs.unlinkSync(settingsPath);
|
||||
core.info('Cleanup maven setings: ' + settingsPath + ' - file was removed');
|
||||
core.info('Cleanup maven settings: ' + settingsPath + ' - file was removed');
|
||||
} else {
|
||||
core.warning('Cleanup maven setings: ' + settingsPath + ' - file not exist');
|
||||
core.warning('Cleanup maven settings: ' + settingsPath + ' - file not exist');
|
||||
}
|
||||
} else {
|
||||
core.info('Cleanup maven setings: ' + settingsPath + ' - file wasn\'t generated by action');
|
||||
core.info('Cleanup maven settings: ' + settingsPath + ' - file wasn\'t generated by action');
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,6 +350,7 @@ module.exports = {
|
||||
fillProxies,
|
||||
fillServerForGithub,
|
||||
fillProperties,
|
||||
fillRepositories,
|
||||
addApacheSnapshots,
|
||||
addSonatypeSnapshots,
|
||||
addOracleRepo,
|
||||
|
||||
Reference in New Issue
Block a user