Skip to content

Commit

Permalink
GitFlow Profiles parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nhojpatrick committed Oct 13, 2022
1 parent 20c2530 commit cb513d1
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 18 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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<String> args = asList(CommandLineUtils.translateCommandline(goals));

executeMvnCommand(CommandLineUtils.translateCommandline(goals));
if (StringUtils.isNotBlank(profiles)) {
args.add("-P" + profiles);
}

executeMvnCommand(args.toArray(new String[args.size()]));
}

/**
Expand Down Expand Up @@ -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<String> localArgs = asList(args);
if (StringUtils.isNotBlank(profiles)) {
localArgs.add("-P" + profiles);
}
executeCommand(cmdMvn, true, argLine, localArgs.toArray(new String[localArgs.size()]));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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
Expand Down Expand Up @@ -243,7 +260,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// maven goals before release
if (StringUtils.isNotBlank(preReleaseGoals)) {
mvnRun(preReleaseGoals);
mvnRun(preReleaseGoals, preReleaseProfiles);
}

Map<String, String> messageProperties = new HashMap<>();
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit cb513d1

Please sign in to comment.