Skip to content

Commit 7973a0a

Browse files
feat(additional options): added support for additional parameters
1 parent 45b8903 commit 7973a0a

File tree

8 files changed

+50
-23
lines changed

8 files changed

+50
-23
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ Was inspired by https://github.com/conveyal/maven-semantic-release. It differs i
5151
| snapshotCommitMessage | <code>string</code> | <code>&quot;&#x27;chore:&quot;</code> | setting next snapshot version [skip ci]' The commit message used if a new snapshot version should be created. |
5252
| debug | <code>boolean</code> | <code>false</code> | Sets the `-X` option for all maven calls. |
5353
| mvnw | <code>boolean</code> | <code>false</code> | Use the mvnw script instead of mvn |
54+
| [options] | <code>string</code> | | Sets the additional options e.g. `-Pdev` |
5455
<!-- AUTO_GENERATED_OPTIONS -->

src/maven.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,31 @@ function settingsOption(settingsPath) {
2222
}
2323
}
2424

25+
/**
26+
* @param {string|undefined} additionalOpts
27+
* @returns {string[]}
28+
* @private
29+
*/
30+
function setOpts(additionalOpts) {
31+
if (additionalOpts) {
32+
return additionalOpts.split(' ');
33+
} else {
34+
return [];
35+
}
36+
}
37+
2538
/**
2639
* @param {Logger} logger
2740
* @param {boolean} mvnw
2841
* @param {string} versionStr
2942
* @param {string|undefined} settingsPath
3043
* @param {boolean} processAllModules
3144
* @param {boolean} debug
45+
* @param {string} options
3246
* @returns {Promise<void>}
3347
* @private
3448
*/
35-
async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllModules, debug) {
49+
async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllModules, debug, options) {
3650
logger.log(`Updating pom.xml to version ${versionStr}`);
3751

3852
const command = mvnw ? './mvnw' : 'mvn';
@@ -50,7 +64,8 @@ async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllM
5064
'--no-transfer-progress',
5165
'-DgenerateBackupPoms=false',
5266
`-DnewVersion=${versionStr}`,
53-
...processAllModulesOption
67+
...processAllModulesOption,
68+
...setOpts(options)
5469
]
5570
);
5671
} catch (e) {
@@ -66,10 +81,11 @@ async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllM
6681
* @param {string|undefined} settingsPath
6782
* @param {boolean} processAllModules
6883
* @param {boolean} debug
84+
* @param {string} options
6985
* @returns {Promise<void>}
7086
* @private
7187
*/
72-
async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug) {
88+
async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug, options) {
7389
logger.log('Update pom.xml to next snapshot version');
7490

7591
const command = mvnw ? './mvnw' : 'mvn';
@@ -87,7 +103,8 @@ async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModul
87103
'--no-transfer-progress',
88104
'-DnextSnapshot=true',
89105
'-DgenerateBackupPoms=false',
90-
...processAllModulesOption
106+
...processAllModulesOption,
107+
...setOpts(options)
91108
]
92109
);
93110
} catch (e) {
@@ -105,10 +122,11 @@ async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModul
105122
* @param {string|undefined} settingsPath
106123
* @param {boolean} clean
107124
* @param {boolean} debug
125+
* @param {string} options
108126
* @returns {Promise<void>}
109127
* @private
110128
*/
111-
async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clean, debug) {
129+
async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clean, debug, options) {
112130
logger.log(`Deploying version ${nextVersion} with maven`);
113131

114132
const command = mvnw ? './mvnw' : 'mvn';
@@ -125,7 +143,8 @@ async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clea
125143
...debugOption,
126144
'--batch-mode',
127145
'--no-transfer-progress',
128-
'-DskipTests'
146+
'-DskipTests',
147+
...setOpts(options)
129148
]
130149
);
131150
} catch (e) {

src/plugin-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @property {string} snapshotCommitMessage='chore: setting next snapshot version [skip ci]' The commit message used if a new snapshot version should be created.
1313
* @property {boolean} debug=false Sets the `-X` option for all maven calls.
1414
* @property {boolean} mvnw=false Use the mvnw script instead of mvn
15+
* @property {string} opts=assign additional set of options
1516
*/
1617

1718
const SemanticReleaseError = require("@semantic-release/error");
@@ -29,7 +30,8 @@ function evaluateConfig(config) {
2930
updateSnapshotVersion: false,
3031
snapshotCommitMessage: 'chore: setting next snapshot version [skip ci]',
3132
debug: false,
32-
mvnw: false
33+
mvnw: false,
34+
opts: ''
3335
}, config);
3436

3537
if (withDefaults.settingsPath && !/^[\w~./-]*$/.test(withDefaults.settingsPath)) {

src/prepare.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ module.exports = async function prepare(pluginConfig, {
2727
settingsPath,
2828
processAllModules,
2929
debug,
30-
mvnw
30+
mvnw,
31+
opts
3132
} = evaluateConfig(pluginConfig);
3233

33-
await updateVersion(logger, mvnw, nextRelease.version, settingsPath, processAllModules, debug);
34+
await updateVersion(logger, mvnw, nextRelease.version, settingsPath, processAllModules, debug, opts);
3435
};

src/publish.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ module.exports = async function publish(pluginConfig, {
2828
mavenTarget,
2929
clean,
3030
debug,
31-
mvnw
31+
mvnw,
32+
opts
3233
} = evaluateConfig(pluginConfig);
3334

34-
await deploy(logger, mvnw, nextRelease.version, mavenTarget, settingsPath, clean, debug);
35+
await deploy(logger, mvnw, nextRelease.version, mavenTarget, settingsPath, clean, debug, opts);
3536
};

src/success.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ module.exports = async function success(pluginConfig, {
3232
processAllModules,
3333
debug,
3434
settingsPath,
35-
mvnw
35+
mvnw,
36+
opts
3637
} = evaluateConfig(pluginConfig)
3738

3839
if (!updateSnapshotVersionOpt) {
3940
return;
4041
}
4142

42-
await updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug);
43+
await updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug, opts);
4344
if (!options?.repositoryUrl) {
4445
logger.error('No git repository url configured. No files are commited.');
4546
return;

test/maven.spec.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('maven', () => {
1414
});
1515

1616
test('updateVersion with all options off', () => {
17-
updateVersion(logger, false, '1.1.1', undefined, false, false);
17+
updateVersion(logger, false, '1.1.1', undefined, false, false, "");
1818
expect(exec).toBeCalledWith(
1919
'mvn',
2020
[
@@ -32,7 +32,7 @@ describe('maven', () => {
3232
});
3333

3434
test('updateVersion with all options on', () => {
35-
updateVersion(logger, true, '1.1.2', 'some/path', true, true);
35+
updateVersion(logger, true, '1.1.2', 'some/path', true, true, "");
3636
expect(exec).toBeCalledWith(
3737
'./mvnw',
3838
[
@@ -54,7 +54,7 @@ describe('maven', () => {
5454
});
5555

5656
test('updateSnapshotVersion with all options off', () => {
57-
updateSnapshotVersion(logger, false, undefined, false, false);
57+
updateSnapshotVersion(logger, false, undefined, false, false, "");
5858

5959
expect(exec).toBeCalledWith(
6060
'mvn',
@@ -73,7 +73,7 @@ describe('maven', () => {
7373
});
7474

7575
test('updateSnapshotVersion with all options on', () => {
76-
updateSnapshotVersion(logger, true, 'some/path', true, true);
76+
updateSnapshotVersion(logger, true, 'some/path', true, true, "-Pdev");
7777

7878
expect(exec).toBeCalledWith(
7979
'./mvnw',
@@ -86,7 +86,8 @@ describe('maven', () => {
8686
'--no-transfer-progress',
8787
'-DnextSnapshot=true',
8888
'-DgenerateBackupPoms=false',
89-
'-DprocessAllModules'
89+
'-DprocessAllModules',
90+
'-Pdev'
9091
]
9192
);
9293

@@ -96,15 +97,15 @@ describe('maven', () => {
9697
});
9798

9899
test('deploy with all options off', () => {
99-
deploy(logger, false, '1.1.3', 'deploy', undefined, false, false);
100+
deploy(logger, false, '1.1.3', 'deploy', undefined, false, false, "");
100101

101102
expect(exec).toBeCalledWith(
102103
'mvn',
103104
[
104105
'deploy',
105106
'--batch-mode',
106107
'--no-transfer-progress',
107-
'-DskipTests',
108+
'-DskipTests'
108109
]
109110
);
110111

@@ -114,7 +115,7 @@ describe('maven', () => {
114115
});
115116

116117
test('deploy with all options on', () => {
117-
deploy(logger, true, '1.1.4', 'deploy jib:build', 'some/path', true, true);
118+
deploy(logger, true, '1.1.4', 'deploy jib:build', 'some/path', true, true, "-Pdev");
118119

119120
expect(exec).toBeCalledWith(
120121
'./mvnw',
@@ -127,7 +128,8 @@ describe('maven', () => {
127128
'-X',
128129
'--batch-mode',
129130
'--no-transfer-progress',
130-
'-DskipTests'
131+
'-DskipTests',
132+
'-Pdev'
131133
]
132134
);
133135

test/plugin-config.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {evaluateConfig} = require("../src/plugin-config");
33
describe('evaluateConfig', () => {
44
test('will reject settings path with illegal characters', () => {
55
expect(() => {
6-
evaluateConfig({ settingsPath: '; echo "test"' });
6+
evaluateConfig({ settingsPath: '; echo "test"', opts: '-Pdev' });
77
}).toThrow('Config settingsPath contains disallowed characters')
88
});
99

0 commit comments

Comments
 (0)