Skip to content

Commit

Permalink
Merge pull request #25 from terrestris/add-debug-option
Browse files Browse the repository at this point in the history
feat: add mvn debug option
  • Loading branch information
simonseyock committed Sep 6, 2023
2 parents fede208 + f0155f2 commit add38ca
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
55 changes: 47 additions & 8 deletions src/maven.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,57 @@ const { exec } = require('./exec');
/**
* @param {Logger} logger
* @param {string} versionStr
* @param {boolean} processAllModules
* @param {string} settingsPath
* @param {boolean} processAllModules
* @param {boolean} debug
* @returns {Promise<void>}
*/
async function updateVersion(logger, versionStr, processAllModules, settingsPath) {
async function updateVersion(logger, versionStr, settingsPath, processAllModules, debug) {
logger.log(`Updating pom.xml to version ${versionStr}`);

const processAllModulesOption = processAllModules ? ['-DprocessAllModules'] : [];
const debugOption = debug ? ['-X'] : []

await exec(
'mvn',
['versions:set', '--batch-mode', '-DgenerateBackupPoms=false', '--settings', settingsPath, `-DnewVersion=${versionStr}`, ...processAllModulesOption]
[
'versions:set',
...debugOption,
'--batch-mode',
'-DgenerateBackupPoms=false',
'--settings',
settingsPath,
`-DnewVersion=${versionStr}`,
...processAllModulesOption
]
);
}

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

const processAllModulesOption = processAllModules ? ['-DprocessAllModules'] : [];
const debugOption = debug ? ['-X'] : []

await exec(
'mvn',
['versions:set', '--batch-mode', '-DnextSnapshot=true', '--settings', settingsPath, '-DgenerateBackupPoms=false', ...processAllModulesOption]
[
'versions:set',
...debugOption,
'--batch-mode',
'-DnextSnapshot=true',
'--settings',
settingsPath,
'-DgenerateBackupPoms=false',
...processAllModulesOption
]
);
}

Expand All @@ -41,17 +69,28 @@ async function updateSnapshotVersion(logger, processAllModules, settingsPath) {
* @param {string} mavenTarget
* @param {string} settingsPath
* @param {boolean} clean
* @param {boolean} debug
* @returns {Promise<void>}
*/
async function deploy(logger, nextVersion, mavenTarget, settingsPath, clean) {
async function deploy(logger, nextVersion, mavenTarget, settingsPath, clean, debug) {
logger.log('Deploying version %s with maven', nextVersion);

const cleanTarget = clean ? ['clean'] : [];
const cleanOption = clean ? ['clean'] : [];
const debugOption = debug ? ['-X'] : []

try {
await exec(
'mvn',
[...cleanTarget, ...mavenTarget.split(' '), '--batch-mode', '--no-transfer-progress', '-DskipTests', '--settings', settingsPath]
[
...cleanOption,
...mavenTarget.split(' '),
...debugOption,
'--batch-mode',
'--no-transfer-progress',
'-DskipTests',
'--settings',
settingsPath
]
);
} catch (e) {
logger.error('failed to deploy to maven');
Expand Down
1 change: 1 addition & 0 deletions src/plugin-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
* @property {boolean} [clean=true] Whether the `clean` target will be applied before publishing.
* @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.
*/
3 changes: 2 additions & 1 deletion src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = async function prepare(pluginConfig, {
}

const processAllModules = pluginConfig.processAllModules || false;
const debug = pluginConfig.debug || false;

await updateVersion(logger, nextRelease.version, processAllModules, settingsPath);
await updateVersion(logger, nextRelease.version, settingsPath, processAllModules, debug);
};
3 changes: 2 additions & 1 deletion src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = async function publish(pluginConfig, {
const settingsPath = pluginConfig.settingsPath || '.m2/settings.xml';
const mavenTarget = pluginConfig.mavenTarget || 'deploy';
const clean = pluginConfig.clean || true;
const debug = pluginConfig.debug || false;

if (!/^[\w~./-]*$/.test(settingsPath)) {
throw new Error('config settingsPath contains disallowed characters');
Expand All @@ -32,5 +33,5 @@ module.exports = async function publish(pluginConfig, {
throw new Error(`unrecognized maven target ${mavenTarget}`);
}

await deploy(logger, nextRelease.version, mavenTarget, settingsPath, clean);
await deploy(logger, nextRelease.version, mavenTarget, settingsPath, clean, debug);
};
3 changes: 2 additions & 1 deletion src/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = async function success(pluginConfig, {
const updateSnapshotVersionOpt = pluginConfig.updateSnapshotVersion || false;
const snapshotCommitMessage = pluginConfig.snapshotCommitMessage || 'chore: setting next snapshot version [skip ci]';
const processAllModules = pluginConfig.processAllModules || false;
const debug = pluginConfig.debug || false;

const filesToCommit = await glob('**/pom.xml', {
cwd,
Expand All @@ -41,7 +42,7 @@ module.exports = async function success(pluginConfig, {
if (!/^[\w~./-]*$/.test(settingsPath)) {
throw new Error('config settingsPath contains disallowed characters');
}
await updateSnapshotVersion(logger, processAllModules, settingsPath);
await updateSnapshotVersion(logger, settingsPath, processAllModules, debug);
const execaOptions = { env, cwd };
logger.log('Staging all changed files: ' + filesToCommit.join(", "));
await add(filesToCommit, execaOptions);
Expand Down

0 comments on commit add38ca

Please sign in to comment.