mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-12 00:05:49 +08:00
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.js eol=lf
|
||||||
|
*.yml eol=lf
|
||||||
|
*.xml eol=lf
|
||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -37,6 +37,8 @@ jobs:
|
|||||||
properties: '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
properties: '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
||||||
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
mirrors: '[{"id": "mirrorId", "name": "mirrorName", "mirrorOf": "mirrorOf", "url": "mirrorUrl"}]'
|
||||||
sonatypeSnapshots: true
|
sonatypeSnapshots: true
|
||||||
|
oracleServers: '[{"id": "oServerId", "username": "oUsername", "password": "oPassword"}]'
|
||||||
|
oracleRepo: true
|
||||||
|
|
||||||
- run: cat ~/.m2/settings.xml
|
- run: cat ~/.m2/settings.xml
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
16
README.md
16
README.md
@ -79,6 +79,22 @@ steps:
|
|||||||
githubServer: false
|
githubServer: false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Create ```settings.xml``` with special server item configuration for oracle repository [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9015)
|
||||||
|
```yml
|
||||||
|
steps:
|
||||||
|
- uses: s4u/maven-settings-action@v2.1.1
|
||||||
|
with:
|
||||||
|
oracleServers: '[{"id": "serverId", "username": "username", "password": "password"}]'
|
||||||
|
```
|
||||||
|
|
||||||
|
Create ```settings.xml``` with [Oracle Maven Repository](https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9017)
|
||||||
|
```yml
|
||||||
|
steps:
|
||||||
|
- uses: s4u/maven-settings-action@v2.1.1
|
||||||
|
with:
|
||||||
|
oracleRepo: true
|
||||||
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||||
|
|||||||
@ -27,8 +27,13 @@ inputs:
|
|||||||
description: 'add to settings.xml servers server-id: github; username=$GITHUB_ACTOR and password=$GITHUB_TOKEN'
|
description: 'add to settings.xml servers server-id: github; username=$GITHUB_ACTOR and password=$GITHUB_TOKEN'
|
||||||
default: "true"
|
default: "true"
|
||||||
required: false
|
required: false
|
||||||
|
oracleServers:
|
||||||
|
description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}] for Oracle repository'
|
||||||
|
required: false
|
||||||
|
oracleRepo:
|
||||||
|
description: 'add Oracle Maven Repository'
|
||||||
|
default: "false"
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
|
|||||||
128
index.test.js
128
index.test.js
@ -63,18 +63,132 @@ afterAll(() => {
|
|||||||
|
|
||||||
test('run with all feature', () => {
|
test('run with all feature', () => {
|
||||||
|
|
||||||
process.env['INPUT_SERVERS'] = '[{"id": "serverId", "username": "username", "password": "password"}]';
|
process.env['INPUT_SERVERS'] = '[{"id": "serverId", "username": "sUsername", "password": "sPassword"}]';
|
||||||
process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
process.env['INPUT_ORACLESERVERS'] = '[{"id": "oServerId", "username": "oUsername", "password": "oPassword"}]';
|
||||||
process.env['INPUT_SONATYPESNAPSHOT'] = true;
|
process.env['INPUT_GITHUBSERVER'] = true;
|
||||||
|
|
||||||
cp.execSync(`node ${indexPath}`, { env: process.env }).toString();
|
process.env['INPUT_MIRRORS'] = '[{"id": "mirrorId", "name": "mirror Name", "mirrorOf": "mirror Off *", "url": "mirror url"}]';
|
||||||
|
process.env['INPUT_PROPERTIES'] = '[{"prop1": "value1"}, {"prop2": "value2"}]'
|
||||||
|
|
||||||
|
process.env['INPUT_SONATYPESNAPSHOTS'] = true;
|
||||||
|
process.env['INPUT_ORACLEREPO'] = true;
|
||||||
|
|
||||||
|
cp.execSync(`node ${indexPath}`, { env: process.env, stdio: 'inherit' });
|
||||||
|
|
||||||
const settingsStatus = fs.lstatSync(settingsPath);
|
const settingsStatus = fs.lstatSync(settingsPath);
|
||||||
expect(settingsStatus.isFile()).toBeTruthy();
|
expect(settingsStatus.isFile()).toBeTruthy();
|
||||||
expect(settingsStatus.size).toBeGreaterThan(0);
|
expect(settingsStatus.size).toBeGreaterThan(0);
|
||||||
|
|
||||||
const settingsBody = fs.readFileSync(settingsPath).toString();
|
const settingsBody = fs.readFileSync(settingsPath).toString();
|
||||||
expect(settingsBody).toMatch('<settings>');
|
expect(settingsBody).toBe(`<settings>
|
||||||
expect(settingsBody).toMatch('<servers><server><id>serverId</id><username>username</username><password>password</password></server></servers>');
|
<interactiveMode>false</interactiveMode>
|
||||||
expect(settingsBody).toMatch('prop1');
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>_properties_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties><prop1>value1</prop1><prop2>value2</prop2></properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>_sonatype-snapshots_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>sonatype-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>_maven.oracle.com_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>maven.oracle.com</id>
|
||||||
|
<url>https://maven.oracle.com</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>maven.oracle.com</id>
|
||||||
|
<url>https://maven.oracle.com</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</profile></profiles>
|
||||||
|
<servers>
|
||||||
|
<server>
|
||||||
|
<id>serverId</id>
|
||||||
|
<username>sUsername</username>
|
||||||
|
<password>sPassword</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>oServerId</id>
|
||||||
|
<username>oUsername</username>
|
||||||
|
<password>oPassword</password>
|
||||||
|
<configuration>
|
||||||
|
<basicAuthScope>
|
||||||
|
<host>ANY</host>
|
||||||
|
<port>ANY</port>
|
||||||
|
<realm>OAM 11g</realm>
|
||||||
|
</basicAuthScope>
|
||||||
|
<httpConfiguration>
|
||||||
|
<all>
|
||||||
|
<params>
|
||||||
|
<property>
|
||||||
|
<name>http.protocol.allow-circular-redirects</name>
|
||||||
|
<value>%b,true</value>
|
||||||
|
</property>
|
||||||
|
</params>
|
||||||
|
</all>
|
||||||
|
</httpConfiguration>
|
||||||
|
</configuration>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>github</id>
|
||||||
|
<username>\${env.GITHUB_ACTOR}</username>
|
||||||
|
<password>\${env.GITHUB_TOKEN}</password>
|
||||||
|
</server></servers>
|
||||||
|
<mirrors>
|
||||||
|
<mirror>
|
||||||
|
<id>mirrorId</id>
|
||||||
|
<name>mirror Name</name>
|
||||||
|
<mirrorOf>mirror Off *</mirrorOf>
|
||||||
|
<url>mirror url</url>
|
||||||
|
</mirror></mirrors>
|
||||||
|
</settings>`);
|
||||||
})
|
})
|
||||||
|
|||||||
7
package-lock.json
generated
7
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "maven-settings-action",
|
"name": "maven-settings-action",
|
||||||
"version": "1.0.0",
|
"version": "2.2.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -6341,11 +6341,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.3.0.tgz",
|
||||||
"integrity": "sha512-z9s6k3wxE+aZHgXYxSTpGDo7BYOUfJsIRyoZiX6HTjwpwfS2wpQBQKa2fD+ShLyPkqDYo5ud7KitmLZ2Cd6r0g=="
|
"integrity": "sha512-z9s6k3wxE+aZHgXYxSTpGDo7BYOUfJsIRyoZiX6HTjwpwfS2wpQBQKa2fD+ShLyPkqDYo5ud7KitmLZ2Cd6r0g=="
|
||||||
},
|
},
|
||||||
"xpath": {
|
|
||||||
"version": "0.0.30",
|
|
||||||
"resolved": "https://registry.npmjs.org/xpath/-/xpath-0.0.30.tgz",
|
|
||||||
"integrity": "sha512-R/uBDaAWrWdBjkn/lVd1E9CPty6/Els0Y14u21mdrnSfEswZaxTx4VQK4v3y9f0yYD5KcXZ53djRNcEi2RV6Wg=="
|
|
||||||
},
|
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "maven-settings-action",
|
"name": "maven-settings-action",
|
||||||
"version": "1.0.0",
|
"version": "2.2.0",
|
||||||
"description": "Prepare maven settings",
|
"description": "Prepare maven settings",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -25,8 +25,7 @@
|
|||||||
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
"homepage": "https://github.com/s4u/maven-settings-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"xmldom": "^0.3.0",
|
"xmldom": "^0.3.0"
|
||||||
"xpath": "0.0.30"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.11.0",
|
"eslint": "^7.11.0",
|
||||||
|
|||||||
111
settings.js
111
settings.js
@ -28,15 +28,13 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const DOMParser = require('xmldom').DOMParser;
|
const DOMParser = require('xmldom').DOMParser;
|
||||||
const XMLSerializer = require('xmldom').XMLSerializer;
|
const XMLSerializer = require('xmldom').XMLSerializer;
|
||||||
const xpath = require('xpath');
|
|
||||||
|
|
||||||
|
|
||||||
function getSettingsPath() {
|
function getSettingsPath() {
|
||||||
return path.join(os.homedir(), '.m2', 'settings.xml');
|
return path.join(os.homedir(), '.m2', 'settings.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSettingsTemplate() {
|
function getTemplate(templateName) {
|
||||||
const templatePath = path.join(__dirname, 'templates', 'settings.xml');
|
const templatePath = path.join(__dirname, 'templates', templateName);
|
||||||
const templateStr = fs.readFileSync(templatePath).toString();
|
const templateStr = fs.readFileSync(templatePath).toString();
|
||||||
return new DOMParser().parseFromString(templateStr, 'text/xml');
|
return new DOMParser().parseFromString(templateStr, 'text/xml');
|
||||||
}
|
}
|
||||||
@ -52,65 +50,45 @@ function writeSettings(settingsPath, templateXml) {
|
|||||||
fs.writeFileSync(settingsPath, settingStr);
|
fs.writeFileSync(settingsPath, settingStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createElementWithText(template, tag, text) {
|
function fillServer(templateXml, templateName, id, username, password) {
|
||||||
const tagXml = template.createElement(tag);
|
|
||||||
tagXml.textContent = text;
|
|
||||||
return tagXml;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fillServer(template, id, username, password) {
|
|
||||||
|
|
||||||
const serverXml = template.createElement('server');
|
|
||||||
|
|
||||||
if (!id || !username || !password) {
|
if (!id || !username || !password) {
|
||||||
core.setFailed('servers must contain id, username and password');
|
core.setFailed(templateName + ' must contain id, username and password');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const idXml = createElementWithText(template, 'id', id);
|
const serverXml = getTemplate(templateName + '.xml')
|
||||||
serverXml.appendChild(idXml);
|
serverXml.getElementsByTagName('id')[0].textContent = id;
|
||||||
|
serverXml.getElementsByTagName('username')[0].textContent = username;
|
||||||
|
serverXml.getElementsByTagName('password')[0].textContent = password;
|
||||||
|
|
||||||
const usernameXml = createElementWithText(template, 'username', username);
|
const serversXml = templateXml.getElementsByTagName('servers')[0];
|
||||||
serverXml.appendChild(usernameXml);
|
|
||||||
|
|
||||||
const passwordXml = createElementWithText(template, 'password', password);
|
|
||||||
serverXml.appendChild(passwordXml);
|
|
||||||
|
|
||||||
const serversXml = template.getElementsByTagName('servers')[0];
|
|
||||||
serversXml.appendChild(serverXml);
|
serversXml.appendChild(serverXml);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillServers(template) {
|
function fillServers(template, templateName) {
|
||||||
|
|
||||||
const servers = core.getInput('servers');
|
const servers = core.getInput(templateName);
|
||||||
|
|
||||||
if (!servers) {
|
if (!servers) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON.parse(servers).forEach((server) => fillServer(template, server.id, server.username, server.password));
|
JSON.parse(servers).forEach((server) => fillServer(template, templateName, server.id, server.username, server.password));
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillMirror(template, id, name, mirrorOf, url) {
|
function fillMirror(template, id, name, mirrorOf, url) {
|
||||||
|
|
||||||
const mirrorXml = template.createElement('mirror');
|
|
||||||
|
|
||||||
if (!id || !name || !mirrorOf || !url) {
|
if (!id || !name || !mirrorOf || !url) {
|
||||||
core.setFailed('mirrors must contain id, name, mirrorOf and url');
|
core.setFailed('mirrors must contain id, name, mirrorOf and url');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const idXml = createElementWithText(template, 'id', id);
|
const mirrorXml = getTemplate('mirrors.xml');
|
||||||
mirrorXml.appendChild(idXml);
|
mirrorXml.getElementsByTagName('id')[0].textContent = id;
|
||||||
|
mirrorXml.getElementsByTagName('name')[0].textContent = name;
|
||||||
const nameXml = createElementWithText(template, 'name', name);
|
mirrorXml.getElementsByTagName('mirrorOf')[0].textContent = mirrorOf;
|
||||||
mirrorXml.appendChild(nameXml);
|
mirrorXml.getElementsByTagName('url')[0].textContent = url;
|
||||||
|
|
||||||
const mirrorOfXml = createElementWithText(template, 'mirrorOf', mirrorOf);
|
|
||||||
mirrorXml.appendChild(mirrorOfXml);
|
|
||||||
|
|
||||||
const urlXml = createElementWithText(template, 'url', url);
|
|
||||||
mirrorXml.appendChild(urlXml);
|
|
||||||
|
|
||||||
const mirrorsXml = template.getElementsByTagName('mirrors')[0];
|
const mirrorsXml = template.getElementsByTagName('mirrors')[0];
|
||||||
mirrorsXml.appendChild(mirrorXml);
|
mirrorsXml.appendChild(mirrorXml);
|
||||||
@ -138,42 +116,48 @@ function fillServerForGithub(templateXml) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fillServer(templateXml, 'github', '${env.GITHUB_ACTOR}', '${env.GITHUB_TOKEN}');
|
fillServer(templateXml, 'servers', 'github', '${env.GITHUB_ACTOR}', '${env.GITHUB_TOKEN}');
|
||||||
}
|
|
||||||
|
|
||||||
function activateProfile(template, profileId) {
|
|
||||||
const activeByDefault = xpath
|
|
||||||
.select(`/settings/profiles/profile[id[contains(text(),"${profileId}")]]/activation/activeByDefault`, template);
|
|
||||||
|
|
||||||
if (activeByDefault) {
|
|
||||||
activeByDefault[0].textContent = 'true';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillProperties(template) {
|
function fillProperties(template) {
|
||||||
|
|
||||||
const properties = core.getInput('properties');
|
const properties = core.getInput('properties');
|
||||||
|
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
activateProfile(template, '_properties_')
|
const propertiesProfileXml = getTemplate('properties.xml');
|
||||||
const propertiesXml = xpath
|
const propertiesXml = propertiesProfileXml.getElementsByTagName('properties')[0];
|
||||||
.select(`/settings/profiles/profile[id[contains(text(),"_properties_")]]/properties`, template)[0];
|
|
||||||
|
|
||||||
JSON.parse(properties).forEach((property) => {
|
JSON.parse(properties).forEach((property) => {
|
||||||
|
|
||||||
for (const key in property) {
|
for (const key in property) {
|
||||||
const keyXml = template.createElement(key);
|
const keyXml = template.createElement(key);
|
||||||
keyXml.textContent = property[key];
|
keyXml.textContent = property[key];
|
||||||
propertiesXml.appendChild(keyXml);
|
propertiesXml.appendChild(keyXml);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const profilesXml = template.getElementsByTagName('profiles')[0];
|
||||||
|
profilesXml.appendChild(propertiesProfileXml);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function addProfile(template, profileName) {
|
||||||
|
const sonatypeXml = getTemplate(profileName);
|
||||||
|
const profilesXml = template.getElementsByTagName('profiles')[0];
|
||||||
|
profilesXml.appendChild(sonatypeXml);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSonatypeSnapshots(template) {
|
function addSonatypeSnapshots(template) {
|
||||||
if (isInputTrue('sonatypeSnapshots')) {
|
if (isInputTrue('sonatypeSnapshots')) {
|
||||||
activateProfile(template, '_sonatype-snapshots_')
|
addProfile(template, 'sonatype-snapshot.xml')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addOracleRepo(template) {
|
||||||
|
if (isInputTrue('oracleRepo')) {
|
||||||
|
addProfile(template, 'oracle-repo.xml')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,13 +176,15 @@ function generate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const templateXml = getSettingsTemplate();
|
const settingsXml = getTemplate('settings.xml');
|
||||||
fillMirrors(templateXml);
|
fillMirrors(settingsXml);
|
||||||
fillServers(templateXml);
|
fillServers(settingsXml, 'servers');
|
||||||
fillServerForGithub(templateXml);
|
fillServers(settingsXml, 'oracleServers');
|
||||||
fillProperties(templateXml);
|
fillServerForGithub(settingsXml);
|
||||||
addSonatypeSnapshots(templateXml);
|
fillProperties(settingsXml);
|
||||||
writeSettings(settingsPath, templateXml);
|
addSonatypeSnapshots(settingsXml);
|
||||||
|
addOracleRepo(settingsXml);
|
||||||
|
writeSettings(settingsPath, settingsXml);
|
||||||
core.saveState('maven-settings', 'ok');
|
core.saveState('maven-settings', 'ok');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,13 +205,14 @@ function cleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getSettingsTemplate,
|
getTemplate,
|
||||||
writeSettings,
|
writeSettings,
|
||||||
fillMirrors,
|
fillMirrors,
|
||||||
fillServers,
|
fillServers,
|
||||||
fillServerForGithub,
|
fillServerForGithub,
|
||||||
fillProperties,
|
fillProperties,
|
||||||
addSonatypeSnapshots,
|
addSonatypeSnapshots,
|
||||||
|
addOracleRepo,
|
||||||
generate,
|
generate,
|
||||||
cleanup
|
cleanup
|
||||||
}
|
}
|
||||||
|
|||||||
237
settings.test.js
237
settings.test.js
@ -99,7 +99,7 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('template should be read', () => {
|
test('template should be read', () => {
|
||||||
const template = settings.getSettingsTemplate();
|
const template = settings.getTemplate('settings.xml');
|
||||||
|
|
||||||
expect(template).toBeDefined();
|
expect(template).toBeDefined();
|
||||||
});
|
});
|
||||||
@ -121,7 +121,7 @@ test('fillServers do nothing if no params', () => {
|
|||||||
|
|
||||||
const xml = new DOMParser().parseFromString("<servers/>");
|
const xml = new DOMParser().parseFromString("<servers/>");
|
||||||
|
|
||||||
settings.fillServers(xml);
|
settings.fillServers(xml, 'servers');
|
||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
@ -134,13 +134,17 @@ test('fillServers one server', () => {
|
|||||||
|
|
||||||
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
|
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
|
||||||
|
|
||||||
settings.fillServers(xml);
|
settings.fillServers(xml, 'servers');
|
||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
expect(xmlStr).toBe("<servers>" +
|
expect(xmlStr).toBe(`<servers>
|
||||||
"<server><id>id1</id><username>username1</username><password>password1</password></server>" +
|
<server>
|
||||||
"</servers>");
|
<id>id1</id>
|
||||||
|
<username>username1</username>
|
||||||
|
<password>password1</password>
|
||||||
|
</server></servers>`);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillServers two servers', () => {
|
test('fillServers two servers', () => {
|
||||||
@ -150,23 +154,30 @@ test('fillServers two servers', () => {
|
|||||||
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"},\
|
process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"},\
|
||||||
{"id": "id2", "username": "username2", "password":"password2"}]';
|
{"id": "id2", "username": "username2", "password":"password2"}]';
|
||||||
|
|
||||||
settings.fillServers(xml);
|
settings.fillServers(xml, 'servers');
|
||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
expect(xmlStr).toBe("<servers>" +
|
expect(xmlStr).toBe(`<servers>
|
||||||
"<server><id>id1</id><username>username1</username><password>password1</password></server>" +
|
<server>
|
||||||
"<server><id>id2</id><username>username2</username><password>password2</password></server>" +
|
<id>id1</id>
|
||||||
"</servers>");
|
<username>username1</username>
|
||||||
|
<password>password1</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>id2</id>
|
||||||
|
<username>username2</username>
|
||||||
|
<password>password2</password>
|
||||||
|
</server></servers>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillServers incorrect fields', () => {
|
test('fill servers incorrect fields', () => {
|
||||||
|
|
||||||
const xml = new DOMParser().parseFromString("<servers/>");
|
const xml = new DOMParser().parseFromString("<servers/>");
|
||||||
|
|
||||||
process.env['INPUT_SERVERS'] = '[{"idx": "id1"}]';
|
process.env['INPUT_SERVERS'] = '[{"idx": "id1"}]';
|
||||||
|
|
||||||
settings.fillServers(xml);
|
settings.fillServers(xml, 'servers');
|
||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
@ -178,6 +189,41 @@ test('fillServers incorrect fields', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('fill oracleServers', () => {
|
||||||
|
|
||||||
|
const xml = new DOMParser().parseFromString("<servers/>");
|
||||||
|
|
||||||
|
process.env['INPUT_ORACLESERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]';
|
||||||
|
|
||||||
|
settings.fillServers(xml, 'oracleServers');
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
|
expect(xmlStr).toBe(`<servers>
|
||||||
|
<server>
|
||||||
|
<id>id1</id>
|
||||||
|
<username>username1</username>
|
||||||
|
<password>password1</password>
|
||||||
|
<configuration>
|
||||||
|
<basicAuthScope>
|
||||||
|
<host>ANY</host>
|
||||||
|
<port>ANY</port>
|
||||||
|
<realm>OAM 11g</realm>
|
||||||
|
</basicAuthScope>
|
||||||
|
<httpConfiguration>
|
||||||
|
<all>
|
||||||
|
<params>
|
||||||
|
<property>
|
||||||
|
<name>http.protocol.allow-circular-redirects</name>
|
||||||
|
<value>%b,true</value>
|
||||||
|
</property>
|
||||||
|
</params>
|
||||||
|
</all>
|
||||||
|
</httpConfiguration>
|
||||||
|
</configuration>
|
||||||
|
</server></servers>`);
|
||||||
|
});
|
||||||
|
|
||||||
test('fillServers github', () => {
|
test('fillServers github', () => {
|
||||||
|
|
||||||
const xml = new DOMParser().parseFromString("<servers/>");
|
const xml = new DOMParser().parseFromString("<servers/>");
|
||||||
@ -188,7 +234,12 @@ test('fillServers github', () => {
|
|||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
expect(xmlStr).toBe('<servers><server><id>github</id><username>${env.GITHUB_ACTOR}</username><password>${env.GITHUB_TOKEN}</password></server></servers>');
|
expect(xmlStr).toBe(`<servers>
|
||||||
|
<server>
|
||||||
|
<id>github</id>
|
||||||
|
<username>\${env.GITHUB_ACTOR}</username>
|
||||||
|
<password>\${env.GITHUB_TOKEN}</password>
|
||||||
|
</server></servers>`);
|
||||||
expect(consoleOutput).toEqual([]);
|
expect(consoleOutput).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -201,6 +252,7 @@ test('fillMirrors do nothing if no params', () => {
|
|||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
expect(xmlStr).toBe("<mirrors/>");
|
expect(xmlStr).toBe("<mirrors/>");
|
||||||
|
expect(consoleOutput).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillMirrors one mirror', () => {
|
test('fillMirrors one mirror', () => {
|
||||||
@ -213,9 +265,14 @@ test('fillMirrors one mirror', () => {
|
|||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
expect(xmlStr).toBe("<mirrors>" +
|
expect(xmlStr).toBe(`<mirrors>
|
||||||
"<mirror><id>id1</id><name>name</name><mirrorOf>mirrorOf</mirrorOf><url>url</url></mirror>" +
|
<mirror>
|
||||||
"</mirrors>");
|
<id>id1</id>
|
||||||
|
<name>name</name>
|
||||||
|
<mirrorOf>mirrorOf</mirrorOf>
|
||||||
|
<url>url</url>
|
||||||
|
</mirror></mirrors>`);
|
||||||
|
expect(consoleOutput).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillMirrors two mirrors', () => {
|
test('fillMirrors two mirrors', () => {
|
||||||
@ -228,9 +285,20 @@ test('fillMirrors two mirrors', () => {
|
|||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xml);
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
|
||||||
expect(xmlStr).toBe("<mirrors>" +
|
expect(xmlStr).toBe(`<mirrors>
|
||||||
"<mirror><id>id1</id><name>name1</name><mirrorOf>mirrorOf1</mirrorOf><url>url1</url></mirror><mirror><id>id2</id><name>name2</name><mirrorOf>mirrorOf2</mirrorOf><url>url2</url></mirror>" +
|
<mirror>
|
||||||
"</mirrors>");
|
<id>id1</id>
|
||||||
|
<name>name1</name>
|
||||||
|
<mirrorOf>mirrorOf1</mirrorOf>
|
||||||
|
<url>url1</url>
|
||||||
|
</mirror>
|
||||||
|
<mirror>
|
||||||
|
<id>id2</id>
|
||||||
|
<name>name2</name>
|
||||||
|
<mirrorOf>mirrorOf2</mirrorOf>
|
||||||
|
<url>url2</url>
|
||||||
|
</mirror></mirrors>`);
|
||||||
|
expect(consoleOutput).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillMirrors incorrect fields', () => {
|
test('fillMirrors incorrect fields', () => {
|
||||||
@ -251,56 +319,107 @@ test('fillMirrors incorrect fields', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('addSonatypeSnapshots activate', () => {
|
test('addSonatypeSnapshots', () => {
|
||||||
|
|
||||||
process.env['INPUT_SONATYPESNAPSHOTS'] = "true";
|
process.env['INPUT_SONATYPESNAPSHOTS'] = "true";
|
||||||
|
|
||||||
settings.addSonatypeSnapshots(xmlTestProfile);
|
const xml = new DOMParser().parseFromString('<profiles/>');
|
||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xmlTestProfile);
|
settings.addSonatypeSnapshots(xml);
|
||||||
expect(xmlStr).toBe(`<settings>
|
|
||||||
<profiles>
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
<profile>
|
expect(xmlStr).toBe(`<profiles>
|
||||||
<id>_properties_</id>
|
<profile>
|
||||||
<activation>
|
<id>_sonatype-snapshots_</id>
|
||||||
<activeByDefault>false</activeByDefault>
|
<activation>
|
||||||
</activation>
|
<activeByDefault>true</activeByDefault>
|
||||||
<properties/>
|
</activation>
|
||||||
</profile>
|
<repositories>
|
||||||
<profile>
|
<repository>
|
||||||
<id>_sonatype-snapshots_</id>
|
<id>sonatype-snapshots</id>
|
||||||
<activation>
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
<activeByDefault>true</activeByDefault>
|
<releases>
|
||||||
</activation>
|
<enabled>false</enabled>
|
||||||
</profile>
|
</releases>
|
||||||
</profiles>
|
<snapshots>
|
||||||
</settings>`);
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>sonatype-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</profile></profiles>`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('addOracleRepo', () => {
|
||||||
|
|
||||||
|
process.env['INPUT_ORACLEREPO'] = "true";
|
||||||
|
|
||||||
|
const xml = new DOMParser().parseFromString('<profiles/>');
|
||||||
|
|
||||||
|
settings.addOracleRepo(xml);
|
||||||
|
|
||||||
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
|
expect(xmlStr).toBe(`<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>_maven.oracle.com_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>maven.oracle.com</id>
|
||||||
|
<url>https://maven.oracle.com</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>maven.oracle.com</id>
|
||||||
|
<url>https://maven.oracle.com</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</profile></profiles>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fillProperties', () => {
|
test('fillProperties', () => {
|
||||||
|
|
||||||
process.env['INPUT_PROPERTIES'] = '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]';
|
process.env['INPUT_PROPERTIES'] = '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]';
|
||||||
|
|
||||||
settings.fillProperties(xmlTestProfile);
|
const xml = new DOMParser().parseFromString('<profiles/>');
|
||||||
|
|
||||||
const xmlStr = new XMLSerializer().serializeToString(xmlTestProfile);
|
settings.fillProperties(xml);
|
||||||
expect(xmlStr).toBe(`<settings>
|
|
||||||
<profiles>
|
const xmlStr = new XMLSerializer().serializeToString(xml);
|
||||||
<profile>
|
expect(xmlStr).toBe(`<profiles>
|
||||||
<id>_properties_</id>
|
<profile>
|
||||||
<activation>
|
<id>_properties_</id>
|
||||||
<activeByDefault>true</activeByDefault>
|
<activation>
|
||||||
</activation>
|
<activeByDefault>true</activeByDefault>
|
||||||
<properties><propertyName1>propertyValue1</propertyName1><propertyName2>propertyValue2</propertyName2></properties>
|
</activation>
|
||||||
</profile>
|
<properties><propertyName1>propertyValue1</propertyName1><propertyName2>propertyValue2</propertyName2></properties>
|
||||||
<profile>
|
</profile></profiles>`);
|
||||||
<id>_sonatype-snapshots_</id>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>false</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
</settings>`);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('fillProperties do nothing if no params', () => {
|
test('fillProperties do nothing if no params', () => {
|
||||||
|
|||||||
7
templates/mirrors.xml
Normal file
7
templates/mirrors.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
<mirror>
|
||||||
|
<id/>
|
||||||
|
<name/>
|
||||||
|
<mirrorOf/>
|
||||||
|
<url/>
|
||||||
|
</mirror>
|
||||||
31
templates/oracle-repo.xml
Normal file
31
templates/oracle-repo.xml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>_maven.oracle.com_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>maven.oracle.com</id>
|
||||||
|
<url>https://maven.oracle.com</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>maven.oracle.com</id>
|
||||||
|
<url>https://maven.oracle.com</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</profile>
|
||||||
23
templates/oracleServers.xml
Normal file
23
templates/oracleServers.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
<server>
|
||||||
|
<id />
|
||||||
|
<username />
|
||||||
|
<password />
|
||||||
|
<configuration>
|
||||||
|
<basicAuthScope>
|
||||||
|
<host>ANY</host>
|
||||||
|
<port>ANY</port>
|
||||||
|
<realm>OAM 11g</realm>
|
||||||
|
</basicAuthScope>
|
||||||
|
<httpConfiguration>
|
||||||
|
<all>
|
||||||
|
<params>
|
||||||
|
<property>
|
||||||
|
<name>http.protocol.allow-circular-redirects</name>
|
||||||
|
<value>%b,true</value>
|
||||||
|
</property>
|
||||||
|
</params>
|
||||||
|
</all>
|
||||||
|
</httpConfiguration>
|
||||||
|
</configuration>
|
||||||
|
</server>
|
||||||
8
templates/properties.xml
Normal file
8
templates/properties.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>_properties_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties />
|
||||||
|
</profile>
|
||||||
6
templates/servers.xml
Normal file
6
templates/servers.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
<server>
|
||||||
|
<id />
|
||||||
|
<username />
|
||||||
|
<password />
|
||||||
|
</server>
|
||||||
@ -1,46 +1,6 @@
|
|||||||
<settings>
|
<settings>
|
||||||
<interactiveMode>false</interactiveMode>
|
<interactiveMode>false</interactiveMode>
|
||||||
<profiles>
|
<profiles/>
|
||||||
<!-- generic ############################################################# -->
|
<servers />
|
||||||
<profile>
|
<mirrors />
|
||||||
<id>_properties_</id>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>false</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
<properties />
|
|
||||||
</profile>
|
|
||||||
<!-- sonatype ############################################################# -->
|
|
||||||
<profile>
|
|
||||||
<id>_sonatype-snapshots_</id>
|
|
||||||
<activation>
|
|
||||||
<activeByDefault>false</activeByDefault>
|
|
||||||
</activation>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>sonatype-snapshots</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>false</enabled>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<pluginRepositories>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>sonatype-snapshots</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>false</enabled>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</pluginRepository>
|
|
||||||
</pluginRepositories>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
<servers />
|
|
||||||
<mirrors />
|
|
||||||
</settings>
|
</settings>
|
||||||
|
|||||||
31
templates/sonatype-snapshot.xml
Normal file
31
templates/sonatype-snapshot.xml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>_sonatype-snapshots_</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>sonatype-snapshots</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</profile>
|
||||||
Reference in New Issue
Block a user