diff --git a/README.md b/README.md index 14591e43..12e6779d 100644 --- a/README.md +++ b/README.md @@ -356,6 +356,16 @@ E.g. `mvn gitflow:release-finish -DpostReleaseGoals=deploy` will run `mvn deploy The `gitflow:hotfix-finish` goal has `preHotfixGoals` and `postHotfixGoals` parameters which can be used to run defined Maven goals before and after the hotfix respectively. +### Activating custom Maven profiles + +The `profiles` parameter is avaliable for all maven commands executed. + +The `mvn gitflow:feature-finish` goal has `preFeatureFinishProfiles` and `postFeatureFinishProfiles` parameters, which will be activated for the corresponding goals. + +The `mvn gitflow:hotfix-finish` goal has `preHotfixProfiles` and `postHotfixProfiles` parameters, which will be activated for the corresponding goals. + +The `mvn gitflow:release-finish` and `mvn gitflow:release` goal both have `preReleaseProfiles` and `postReleaseProfiles` parameters, which will be activated for the corresponding goals. + # Non-interactive Mode Maven can be run in non-interactive (batch) mode. By using non-interactive mode goals can be run in continuous integration environment. diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java index 835aa49e..312d918c 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -49,6 +49,8 @@ import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; +import static java.util.Arrays.asList; + /** * Abstract git flow mojo. * @@ -271,6 +273,14 @@ public AbstractGitFlowMojo() { gitModulesExists = FileUtils.fileExists(".gitmodules"); } + /** + * Maven profiles to activate for every maven goal. + * + * @since 1.19.0 + */ + @Parameter(property = "profiles") + private String profiles; + /** * Initializes command line executables. * @@ -1248,17 +1258,25 @@ protected void mvnCleanInstall() throws MojoFailureException, } /** - * Executes Maven goals. - * + * Executes Maven goals, with activated profiles. + * * @param goals * The goals to execute. + * @param profiles + * The profiles to activate. * @throws Exception * If command line parsing or execution fails. */ - protected void mvnRun(final String goals) throws Exception { - getLog().info("Running Maven goals: " + goals); + protected void mvnRun(final String goals, final String profiles) throws Exception { + getLog().info("Running Maven goals: " + goals + ", profiles: " + profiles); + + final List args = asList(CommandLineUtils.translateCommandline(goals)); - executeMvnCommand(CommandLineUtils.translateCommandline(goals)); + if (StringUtils.isNotBlank(profiles)) { + args.add("-P" + profiles); + } + + executeMvnCommand(args.toArray(new String[args.size()])); } /** @@ -1320,7 +1338,11 @@ private void executeGitCommand(final String... args) */ private void executeMvnCommand(final String... args) throws CommandLineException, MojoFailureException { - executeCommand(cmdMvn, true, argLine, args); + final List localArgs = asList(args); + if (StringUtils.isNotBlank(profiles)) { + localArgs.add("-P" + profiles); + } + executeCommand(cmdMvn, true, argLine, localArgs.toArray(new String[localArgs.size()])); } /** diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java index 1376431c..b972b37f 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java @@ -91,6 +91,15 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "preFeatureFinishGoals") private String preFeatureFinishGoals; + /** + * Maven profiles to activate in the feature branch before merging into the + * development branch. + * + * @since 1.19.0 + */ + @Parameter(property = "preFeatureFinishProfiles") + private String preFeatureFinishProfiles; + /** * Maven goals to execute in the development branch after merging a feature. * @@ -99,6 +108,14 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "postFeatureFinishGoals") private String postFeatureFinishGoals; + /** + * Maven profiles to activate in the development branch after merging a feature. + * + * @since 1.19.0 + */ + @Parameter(property = "postFeatureFinishProfiles") + private String postFeatureFinishProfiles; + /** * Whether to increment the version during feature-finish goal. * @@ -110,7 +127,8 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo { /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { - validateConfiguration(preFeatureFinishGoals, postFeatureFinishGoals); + validateConfiguration(preFeatureFinishGoals, preFeatureFinishProfiles, + postFeatureFinishGoals, postFeatureFinishProfiles); try { // check uncommitted changes @@ -157,7 +175,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals before merge if (StringUtils.isNotBlank(preFeatureFinishGoals)) { - mvnRun(preFeatureFinishGoals); + mvnRun(preFeatureFinishGoals, preFeatureFinishProfiles); } String featureVersion = getCurrentProjectVersion(); @@ -213,7 +231,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals after merge if (StringUtils.isNotBlank(postFeatureFinishGoals)) { - mvnRun(postFeatureFinishGoals); + mvnRun(postFeatureFinishGoals, postFeatureFinishProfiles); } if (installProject) { diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java index 013be434..a3aef82c 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -70,6 +70,15 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "preHotfixGoals") private String preHotfixGoals; + /** + * Maven profiles to activate in the hotfix branch before merging into the + * production or support branch. + * + * @since 1.19.0 + */ + @Parameter(property = "preHotfixProfiles") + private String preHotfixProfiles; + /** * Maven goals to execute in the release or support branch after the hotfix. * @@ -78,6 +87,14 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "postHotfixGoals") private String postHotfixGoals; + /** + * Maven profiles to activate in the release or support branch after the hotfix. + * + * @since 1.19.0 + */ + @Parameter(property = "postHotfixProfiles") + private String postHotfixProfiles; + /** * Hotfix version to use in non-interactive mode. * @@ -143,7 +160,8 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo { /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { - validateConfiguration(preHotfixGoals, postHotfixGoals); + validateConfiguration(preHotfixGoals, preHotfixProfiles, + postHotfixGoals, postHotfixProfiles); try { // check uncommitted changes @@ -220,7 +238,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals before merge if (StringUtils.isNotBlank(preHotfixGoals)) { - mvnRun(preHotfixGoals); + mvnRun(preHotfixGoals, preHotfixProfiles); } String currentHotfixVersion = getCurrentProjectVersion(); @@ -270,7 +288,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals after merge if (StringUtils.isNotBlank(postHotfixGoals)) { - mvnRun(postHotfixGoals); + mvnRun(postHotfixGoals, postHotfixProfiles); } // check whether release branch exists diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java index 9acfd240..51310de4 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java @@ -135,6 +135,15 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "preReleaseGoals") private String preReleaseGoals; + /** + * Maven profiles to activate in the release branch before merging into the + * production branch. + * + * @since 1.19.0 + */ + @Parameter(property = "preReleaseProfiles") + private String preReleaseProfiles; + /** * Maven goals to execute in the production branch after the release. * @@ -143,6 +152,14 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "postReleaseGoals") private String postReleaseGoals; + /** + * Maven profiles to activate in the production branch after the release. + * + * @since 1.19.0 + */ + @Parameter(property = "postReleaseProfiles") + private String postReleaseProfiles; + /** * Whether to make a GPG-signed tag. * @@ -182,7 +199,8 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { - validateConfiguration(preReleaseGoals, postReleaseGoals); + validateConfiguration(preReleaseGoals, preReleaseProfiles, + postReleaseGoals, postReleaseProfiles); try { // check uncommitted changes @@ -243,7 +261,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals before merge if (StringUtils.isNotBlank(preReleaseGoals)) { - mvnRun(preReleaseGoals); + mvnRun(preReleaseGoals, preReleaseProfiles); } String currentReleaseVersion = getCurrentProjectVersion(); @@ -285,7 +303,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals after merge if (StringUtils.isNotBlank(postReleaseGoals)) { - mvnRun(postReleaseGoals); + mvnRun(postReleaseGoals, postReleaseProfiles); } if (notSameProdDevName()) { diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java index ad64a3c9..6d1c04a6 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java @@ -131,6 +131,14 @@ public class GitFlowReleaseMojo extends AbstractGitFlowMojo { @Parameter(property = "preReleaseGoals") private String preReleaseGoals; + /** + * Maven profiles to activate before the release. + * + * @since 1.19.0 + */ + @Parameter(property = "preReleaseProfiles") + private String preReleaseProfiles; + /** * Maven goals to execute after the release. * @@ -139,6 +147,14 @@ public class GitFlowReleaseMojo extends AbstractGitFlowMojo { @Parameter(property = "postReleaseGoals") private String postReleaseGoals; + /** + * Maven profiles to activate after the release. + * + * @since 1.19.0 + */ + @Parameter(property = "postReleaseProfiles") + private String postReleaseProfiles; + /** * Whether to make a GPG-signed tag. * @@ -158,7 +174,8 @@ public class GitFlowReleaseMojo extends AbstractGitFlowMojo { /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { - validateConfiguration(preReleaseGoals, postReleaseGoals); + validateConfiguration(preReleaseGoals, preReleaseProfiles, + postReleaseGoals, postReleaseProfiles); try { // set git flow configuration @@ -243,7 +260,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals before release if (StringUtils.isNotBlank(preReleaseGoals)) { - mvnRun(preReleaseGoals); + mvnRun(preReleaseGoals, preReleaseProfiles); } Map messageProperties = new HashMap<>(); @@ -281,7 +298,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // maven goals after release if (StringUtils.isNotBlank(postReleaseGoals)) { - mvnRun(postReleaseGoals); + mvnRun(postReleaseGoals, postReleaseProfiles); } if (notSameProdDevName()) {