Skip to content

Commit

Permalink
Merge pull request #39 from terrestris/mvnw
Browse files Browse the repository at this point in the history
feat: add option to use mvnw
  • Loading branch information
simonseyock authored Jul 10, 2024
2 parents d0f1d14 + 52b4aa3 commit 2a2e087
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
26 changes: 18 additions & 8 deletions src/maven.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ function settingsOption(settingsPath) {

/**
* @param {Logger} logger
* @param {boolean} mvnw
* @param {string} versionStr
* @param {string|undefined} settingsPath
* @param {boolean} processAllModules
* @param {boolean} debug
* @returns {Promise<void>}
*/
async function updateVersion(logger, versionStr, settingsPath, processAllModules, debug) {
async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllModules, debug) {
logger.log(`Updating pom.xml to version ${versionStr}`);

const command = mvnw ? './mvnw' : 'mvn';
const processAllModulesOption = processAllModules ? ['-DprocessAllModules'] : [];
const debugOption = debug ? ['-X'] : []

await exec(
'mvn',
command,
[
'versions:set',
...debugOption,
Expand All @@ -52,19 +54,21 @@ async function updateVersion(logger, versionStr, settingsPath, processAllModules

/**
* @param {Logger} logger
* @param {boolean} mvnw
* @param {string|undefined} settingsPath
* @param {boolean} processAllModules
* @param {boolean} debug
* @returns {Promise<void>}
*/
async function updateSnapshotVersion(logger, settingsPath, processAllModules, debug) {
async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug) {
logger.log(`Update pom.xml to next snapshot version`);

const command = mvnw ? './mvnw' : 'mvn';
const processAllModulesOption = processAllModules ? ['-DprocessAllModules'] : [];
const debugOption = debug ? ['-X'] : []

await exec(
'mvn',
command,
[
'versions:set',
...debugOption,
Expand All @@ -80,22 +84,24 @@ async function updateSnapshotVersion(logger, settingsPath, processAllModules, de

/**
* @param {Logger} logger
* @param {boolean} mvnw
* @param {string} nextVersion
* @param {string} mavenTarget
* @param {string|undefined} settingsPath
* @param {boolean} clean
* @param {boolean} debug
* @returns {Promise<void>}
*/
async function deploy(logger, nextVersion, mavenTarget, settingsPath, clean, debug) {
async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clean, debug) {
logger.log('Deploying version %s with maven', nextVersion);

const command = mvnw ? './mvnw' : 'mvn';
const cleanOption = clean ? ['clean'] : [];
const debugOption = debug ? ['-X'] : []

try {
await exec(
'mvn',
command,
[
...cleanOption,
...mavenTarget.split(' '),
Expand All @@ -115,13 +121,17 @@ async function deploy(logger, nextVersion, mavenTarget, settingsPath, clean, deb

/**
* @param {Logger} logger
* @param {boolean} mvnw
* @returns {Promise<void>}
*/
async function testMvn(logger) {
async function testMvn(logger, mvnw) {
logger.log('Testing if mvn exists');

const command = mvnw ? './mvnw' : 'mvn';

try {
await exec(
'mvn',
command,
['-v']
)
} catch (e) {
Expand Down
4 changes: 3 additions & 1 deletion src/plugin-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @property {boolean} [updateSnapshotVersion=false] Whether a new snapshot version should be set after releasing.
* @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
*/

/**
Expand All @@ -20,7 +21,8 @@ function evaluateConfig(config) {
clean: true,
updateSnapshotVersion: false,
snapshotCommitMessage: 'chore: setting next snapshot version [skip ci]',
debug: false
debug: false,
mvnw: false
}, config);

if (!/^[\w~./-]*$/.test(withDefaults.settingsPath)) {
Expand Down
5 changes: 3 additions & 2 deletions src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ module.exports = async function prepare(pluginConfig, {
const {
settingsPath,
processAllModules,
debug
debug,
mvnw
} = evaluateConfig(pluginConfig);

await updateVersion(logger, nextRelease.version, settingsPath, processAllModules, debug);
await updateVersion(logger, mvnw, nextRelease.version, settingsPath, processAllModules, debug);
};
5 changes: 3 additions & 2 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ module.exports = async function publish(pluginConfig, {
settingsPath,
mavenTarget,
clean,
debug
debug,
mvnw
} = evaluateConfig(pluginConfig);

await deploy(logger, nextRelease.version, mavenTarget, settingsPath, clean, debug);
await deploy(logger, mvnw, nextRelease.version, mavenTarget, settingsPath, clean, debug);
};
5 changes: 3 additions & 2 deletions src/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module.exports = async function success(pluginConfig, {
snapshotCommitMessage,
processAllModules,
debug,
settingsPath
settingsPath,
mvnw
} = evaluateConfig(pluginConfig)

const filesToCommit = await glob('**/pom.xml', {
Expand All @@ -44,7 +45,7 @@ module.exports = async function success(pluginConfig, {
});

if (updateSnapshotVersionOpt) {
await updateSnapshotVersion(logger, settingsPath, processAllModules, debug);
await updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug);
const execaOptions = { env, cwd };
logger.log('Staging all changed files: ' + filesToCommit.join(", "));
await add(filesToCommit, execaOptions);
Expand Down
9 changes: 8 additions & 1 deletion src/verify-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const {
testMvn
} = require("./maven");

const {
evaluateConfig
} = require("./plugin-config");

/**
* @param {PluginConfig} pluginConfig
* @param {Logger} logger
Expand All @@ -10,5 +14,8 @@ const {
module.exports = async function verifyConditions(pluginConfig, {
logger
}) {
await testMvn(logger);
const {
mvnw
} = evaluateConfig(pluginConfig);
await testMvn(logger, mvnw);
};

0 comments on commit 2a2e087

Please sign in to comment.