mirror of
https://github.com/s4u/maven-settings-action.git
synced 2026-02-12 00:05:49 +08:00
cleanup and overide
This commit is contained in:
53
settings.js
53
settings.js
@ -1,3 +1,27 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Slawomir Jaranowski and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
const core = require('@actions/core');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
@ -7,7 +31,9 @@ const XMLSerializer = require('xmldom').XMLSerializer;
|
||||
const xpath = require('xpath');
|
||||
|
||||
|
||||
const settingsPath = path.join(os.homedir(), '.m2', 'settings.xml');
|
||||
function getSettingsPath() {
|
||||
return path.join(os.homedir(), '.m2', 'settings.xml');
|
||||
}
|
||||
|
||||
function getSettingsTemplate() {
|
||||
const templatePath = path.join(__dirname, 'templates', 'settings.xml');
|
||||
@ -87,11 +113,19 @@ function addSonatypeSnapshots(template) {
|
||||
}
|
||||
|
||||
function generate() {
|
||||
|
||||
const settingsPath = getSettingsPath();
|
||||
|
||||
core.info('Prepare maven setings: ' + settingsPath);
|
||||
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
core.warning('maven settings.xml already exists - skip');
|
||||
return;
|
||||
const val = core.getInput("override");
|
||||
if (val && val.toLocaleLowerCase() == 'true') {
|
||||
core.info('maven settings.xml already exists - override');
|
||||
} else {
|
||||
core.warning('maven settings.xml already exists - skip');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const templateXml = getSettingsTemplate();
|
||||
@ -103,8 +137,19 @@ function generate() {
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
|
||||
const mavenSettingsState = core.getState('maven-settings');
|
||||
core.info('Cleanup maven setings: ' + settingsPath + " state: " + mavenSettingsState);
|
||||
const settingsPath = getSettingsPath();
|
||||
if (mavenSettingsState == 'ok') {
|
||||
if (fs.existsSync(settingsPath)) {
|
||||
fs.unlinkSync(settingsPath);
|
||||
core.info('Cleanup maven setings: ' + settingsPath + ' - file was removed');
|
||||
} else {
|
||||
core.warning('Cleanup maven setings: ' + settingsPath + ' - file not exist');
|
||||
}
|
||||
} else {
|
||||
core.info('Cleanup maven setings: ' + settingsPath + ' - file wasn\'t generated by action');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user