From 7973a0a10fa24b3c1ee3da84e54df752a40e5c57 Mon Sep 17 00:00:00 2001 From: AsifNawaz-cnic Date: Wed, 13 Nov 2024 14:45:24 +0000 Subject: [PATCH] feat(additional options): added support for additional parameters --- README.md | 1 + src/maven.js | 31 +++++++++++++++++++++++++------ src/plugin-config.js | 4 +++- src/prepare.js | 5 +++-- src/publish.js | 5 +++-- src/success.js | 5 +++-- test/maven.spec.js | 20 +++++++++++--------- test/plugin-config.spec.js | 2 +- 8 files changed, 50 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5ccc330..2a55f78 100644 --- a/README.md +++ b/README.md @@ -51,4 +51,5 @@ Was inspired by https://github.com/conveyal/maven-semantic-release. It differs i | snapshotCommitMessage | string | "'chore:" | setting next snapshot version [skip ci]' The commit message used if a new snapshot version should be created. | | debug | boolean | false | Sets the `-X` option for all maven calls. | | mvnw | boolean | false | Use the mvnw script instead of mvn | +| [options] | string | | Sets the additional options e.g. `-Pdev` | diff --git a/src/maven.js b/src/maven.js index 147d3a9..bc99b63 100644 --- a/src/maven.js +++ b/src/maven.js @@ -22,6 +22,19 @@ function settingsOption(settingsPath) { } } +/** + * @param {string|undefined} additionalOpts + * @returns {string[]} + * @private + */ +function setOpts(additionalOpts) { + if (additionalOpts) { + return additionalOpts.split(' '); + } else { + return []; + } +} + /** * @param {Logger} logger * @param {boolean} mvnw @@ -29,10 +42,11 @@ function settingsOption(settingsPath) { * @param {string|undefined} settingsPath * @param {boolean} processAllModules * @param {boolean} debug + * @param {string} options * @returns {Promise} * @private */ -async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllModules, debug) { +async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllModules, debug, options) { logger.log(`Updating pom.xml to version ${versionStr}`); const command = mvnw ? './mvnw' : 'mvn'; @@ -50,7 +64,8 @@ async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllM '--no-transfer-progress', '-DgenerateBackupPoms=false', `-DnewVersion=${versionStr}`, - ...processAllModulesOption + ...processAllModulesOption, + ...setOpts(options) ] ); } catch (e) { @@ -66,10 +81,11 @@ async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllM * @param {string|undefined} settingsPath * @param {boolean} processAllModules * @param {boolean} debug + * @param {string} options * @returns {Promise} * @private */ -async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug) { +async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug, options) { logger.log('Update pom.xml to next snapshot version'); const command = mvnw ? './mvnw' : 'mvn'; @@ -87,7 +103,8 @@ async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModul '--no-transfer-progress', '-DnextSnapshot=true', '-DgenerateBackupPoms=false', - ...processAllModulesOption + ...processAllModulesOption, + ...setOpts(options) ] ); } catch (e) { @@ -105,10 +122,11 @@ async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModul * @param {string|undefined} settingsPath * @param {boolean} clean * @param {boolean} debug + * @param {string} options * @returns {Promise} * @private */ -async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clean, debug) { +async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clean, debug, options) { logger.log(`Deploying version ${nextVersion} with maven`); const command = mvnw ? './mvnw' : 'mvn'; @@ -125,7 +143,8 @@ async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clea ...debugOption, '--batch-mode', '--no-transfer-progress', - '-DskipTests' + '-DskipTests', + ...setOpts(options) ] ); } catch (e) { diff --git a/src/plugin-config.js b/src/plugin-config.js index 4193a88..1696861 100644 --- a/src/plugin-config.js +++ b/src/plugin-config.js @@ -12,6 +12,7 @@ * @property {string} snapshotCommitMessage='chore: setting next snapshot version [skip ci]' The commit message used if a new snapshot version should be created. * @property {boolean} debug=false Sets the `-X` option for all maven calls. * @property {boolean} mvnw=false Use the mvnw script instead of mvn + * @property {string} opts=assign additional set of options */ const SemanticReleaseError = require("@semantic-release/error"); @@ -29,7 +30,8 @@ function evaluateConfig(config) { updateSnapshotVersion: false, snapshotCommitMessage: 'chore: setting next snapshot version [skip ci]', debug: false, - mvnw: false + mvnw: false, + opts: '' }, config); if (withDefaults.settingsPath && !/^[\w~./-]*$/.test(withDefaults.settingsPath)) { diff --git a/src/prepare.js b/src/prepare.js index 7c32ea5..c6cb441 100644 --- a/src/prepare.js +++ b/src/prepare.js @@ -27,8 +27,9 @@ module.exports = async function prepare(pluginConfig, { settingsPath, processAllModules, debug, - mvnw + mvnw, + opts } = evaluateConfig(pluginConfig); - await updateVersion(logger, mvnw, nextRelease.version, settingsPath, processAllModules, debug); + await updateVersion(logger, mvnw, nextRelease.version, settingsPath, processAllModules, debug, opts); }; diff --git a/src/publish.js b/src/publish.js index 148d0a8..c5310b9 100644 --- a/src/publish.js +++ b/src/publish.js @@ -28,8 +28,9 @@ module.exports = async function publish(pluginConfig, { mavenTarget, clean, debug, - mvnw + mvnw, + opts } = evaluateConfig(pluginConfig); - await deploy(logger, mvnw, nextRelease.version, mavenTarget, settingsPath, clean, debug); + await deploy(logger, mvnw, nextRelease.version, mavenTarget, settingsPath, clean, debug, opts); }; diff --git a/src/success.js b/src/success.js index fb9dad3..7b553fb 100644 --- a/src/success.js +++ b/src/success.js @@ -32,14 +32,15 @@ module.exports = async function success(pluginConfig, { processAllModules, debug, settingsPath, - mvnw + mvnw, + opts } = evaluateConfig(pluginConfig) if (!updateSnapshotVersionOpt) { return; } - await updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug); + await updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug, opts); if (!options?.repositoryUrl) { logger.error('No git repository url configured. No files are commited.'); return; diff --git a/test/maven.spec.js b/test/maven.spec.js index b1a1e1f..72230db 100644 --- a/test/maven.spec.js +++ b/test/maven.spec.js @@ -14,7 +14,7 @@ describe('maven', () => { }); test('updateVersion with all options off', () => { - updateVersion(logger, false, '1.1.1', undefined, false, false); + updateVersion(logger, false, '1.1.1', undefined, false, false, ""); expect(exec).toBeCalledWith( 'mvn', [ @@ -32,7 +32,7 @@ describe('maven', () => { }); test('updateVersion with all options on', () => { - updateVersion(logger, true, '1.1.2', 'some/path', true, true); + updateVersion(logger, true, '1.1.2', 'some/path', true, true, ""); expect(exec).toBeCalledWith( './mvnw', [ @@ -54,7 +54,7 @@ describe('maven', () => { }); test('updateSnapshotVersion with all options off', () => { - updateSnapshotVersion(logger, false, undefined, false, false); + updateSnapshotVersion(logger, false, undefined, false, false, ""); expect(exec).toBeCalledWith( 'mvn', @@ -73,7 +73,7 @@ describe('maven', () => { }); test('updateSnapshotVersion with all options on', () => { - updateSnapshotVersion(logger, true, 'some/path', true, true); + updateSnapshotVersion(logger, true, 'some/path', true, true, "-Pdev"); expect(exec).toBeCalledWith( './mvnw', @@ -86,7 +86,8 @@ describe('maven', () => { '--no-transfer-progress', '-DnextSnapshot=true', '-DgenerateBackupPoms=false', - '-DprocessAllModules' + '-DprocessAllModules', + '-Pdev' ] ); @@ -96,7 +97,7 @@ describe('maven', () => { }); test('deploy with all options off', () => { - deploy(logger, false, '1.1.3', 'deploy', undefined, false, false); + deploy(logger, false, '1.1.3', 'deploy', undefined, false, false, ""); expect(exec).toBeCalledWith( 'mvn', @@ -104,7 +105,7 @@ describe('maven', () => { 'deploy', '--batch-mode', '--no-transfer-progress', - '-DskipTests', + '-DskipTests' ] ); @@ -114,7 +115,7 @@ describe('maven', () => { }); test('deploy with all options on', () => { - deploy(logger, true, '1.1.4', 'deploy jib:build', 'some/path', true, true); + deploy(logger, true, '1.1.4', 'deploy jib:build', 'some/path', true, true, "-Pdev"); expect(exec).toBeCalledWith( './mvnw', @@ -127,7 +128,8 @@ describe('maven', () => { '-X', '--batch-mode', '--no-transfer-progress', - '-DskipTests' + '-DskipTests', + '-Pdev' ] ); diff --git a/test/plugin-config.spec.js b/test/plugin-config.spec.js index 4a32594..a08a870 100644 --- a/test/plugin-config.spec.js +++ b/test/plugin-config.spec.js @@ -3,7 +3,7 @@ const {evaluateConfig} = require("../src/plugin-config"); describe('evaluateConfig', () => { test('will reject settings path with illegal characters', () => { expect(() => { - evaluateConfig({ settingsPath: '; echo "test"' }); + evaluateConfig({ settingsPath: '; echo "test"', opts: '-Pdev' }); }).toThrow('Config settingsPath contains disallowed characters') });