Skip to content

Commit cb513d1

Browse files
committed
GitFlow Profiles parameter
1 parent 20c2530 commit cb513d1

File tree

6 files changed

+121
-18
lines changed

6 files changed

+121
-18
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ E.g. `mvn gitflow:release-finish -DpostReleaseGoals=deploy` will run `mvn deploy
356356

357357
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.
358358

359+
### Activating custom Maven profiles
360+
361+
The `profiles` parameter is avaliable for all maven commands executed.
362+
363+
The `mvn gitflow:feature-finish` goal has `preFeatureFinishProfiles` and `postFeatureFinishProfiles` parameters, which will be activated for the corresponding goals.
364+
365+
The `mvn gitflow:hotfix-finish` goal has `preHotfixProfiles` and `postHotfixProfiles` parameters, which will be activated for the corresponding goals.
366+
367+
The `mvn gitflow:release-finish` and `mvn gitflow:release` goal both have `preReleaseProfiles` and `postReleaseProfiles` parameters, which will be activated for the corresponding goals.
368+
359369
# Non-interactive Mode
360370

361371
Maven can be run in non-interactive (batch) mode. By using non-interactive mode goals can be run in continuous integration environment.

src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.codehaus.plexus.util.cli.CommandLineUtils;
5050
import org.codehaus.plexus.util.cli.Commandline;
5151

52+
import static java.util.Arrays.asList;
53+
5254
/**
5355
* Abstract git flow mojo.
5456
*
@@ -271,6 +273,14 @@ public AbstractGitFlowMojo() {
271273
gitModulesExists = FileUtils.fileExists(".gitmodules");
272274
}
273275

276+
/**
277+
* Maven profiles to activate for every maven goal.
278+
*
279+
* @since 1.19.0
280+
*/
281+
@Parameter(property = "profiles")
282+
private String profiles;
283+
274284
/**
275285
* Initializes command line executables.
276286
*
@@ -1248,17 +1258,25 @@ protected void mvnCleanInstall() throws MojoFailureException,
12481258
}
12491259

12501260
/**
1251-
* Executes Maven goals.
1252-
*
1261+
* Executes Maven goals, with activated profiles.
1262+
*
12531263
* @param goals
12541264
* The goals to execute.
1265+
* @param profiles
1266+
* The profiles to activate.
12551267
* @throws Exception
12561268
* If command line parsing or execution fails.
12571269
*/
1258-
protected void mvnRun(final String goals) throws Exception {
1259-
getLog().info("Running Maven goals: " + goals);
1270+
protected void mvnRun(final String goals, final String profiles) throws Exception {
1271+
getLog().info("Running Maven goals: " + goals + ", profiles: " + profiles);
1272+
1273+
final List<String> args = asList(CommandLineUtils.translateCommandline(goals));
12601274

1261-
executeMvnCommand(CommandLineUtils.translateCommandline(goals));
1275+
if (StringUtils.isNotBlank(profiles)) {
1276+
args.add("-P" + profiles);
1277+
}
1278+
1279+
executeMvnCommand(args.toArray(new String[args.size()]));
12621280
}
12631281

12641282
/**
@@ -1320,7 +1338,11 @@ private void executeGitCommand(final String... args)
13201338
*/
13211339
private void executeMvnCommand(final String... args)
13221340
throws CommandLineException, MojoFailureException {
1323-
executeCommand(cmdMvn, true, argLine, args);
1341+
final List<String> localArgs = asList(args);
1342+
if (StringUtils.isNotBlank(profiles)) {
1343+
localArgs.add("-P" + profiles);
1344+
}
1345+
executeCommand(cmdMvn, true, argLine, localArgs.toArray(new String[localArgs.size()]));
13241346
}
13251347

13261348
/**

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowFeatureFinishMojo.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo {
9191
@Parameter(property = "preFeatureFinishGoals")
9292
private String preFeatureFinishGoals;
9393

94+
/**
95+
* Maven profiles to activate in the feature branch before merging into the
96+
* development branch.
97+
*
98+
* @since 1.19.0
99+
*/
100+
@Parameter(property = "preFeatureFinishProfiles")
101+
private String preFeatureFinishProfiles;
102+
94103
/**
95104
* Maven goals to execute in the development branch after merging a feature.
96105
*
@@ -99,6 +108,14 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo {
99108
@Parameter(property = "postFeatureFinishGoals")
100109
private String postFeatureFinishGoals;
101110

111+
/**
112+
* Maven profiles to activate in the development branch after merging a feature.
113+
*
114+
* @since 1.19.0
115+
*/
116+
@Parameter(property = "postFeatureFinishProfiles")
117+
private String postFeatureFinishProfiles;
118+
102119
/**
103120
* Whether to increment the version during feature-finish goal.
104121
*
@@ -110,7 +127,8 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo {
110127
/** {@inheritDoc} */
111128
@Override
112129
public void execute() throws MojoExecutionException, MojoFailureException {
113-
validateConfiguration(preFeatureFinishGoals, postFeatureFinishGoals);
130+
validateConfiguration(preFeatureFinishGoals, preFeatureFinishProfiles,
131+
postFeatureFinishGoals, postFeatureFinishProfiles);
114132

115133
try {
116134
// check uncommitted changes
@@ -157,7 +175,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
157175

158176
// maven goals before merge
159177
if (StringUtils.isNotBlank(preFeatureFinishGoals)) {
160-
mvnRun(preFeatureFinishGoals);
178+
mvnRun(preFeatureFinishGoals, preFeatureFinishProfiles);
161179
}
162180

163181
String featureVersion = getCurrentProjectVersion();
@@ -213,7 +231,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
213231

214232
// maven goals after merge
215233
if (StringUtils.isNotBlank(postFeatureFinishGoals)) {
216-
mvnRun(postFeatureFinishGoals);
234+
mvnRun(postFeatureFinishGoals, postFeatureFinishProfiles);
217235
}
218236

219237
if (installProject) {

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo {
7070
@Parameter(property = "preHotfixGoals")
7171
private String preHotfixGoals;
7272

73+
/**
74+
* Maven profiles to activate in the hotfix branch before merging into the
75+
* production or support branch.
76+
*
77+
* @since 1.19.0
78+
*/
79+
@Parameter(property = "preHotfixProfiles")
80+
private String preHotfixProfiles;
81+
7382
/**
7483
* Maven goals to execute in the release or support branch after the hotfix.
7584
*
@@ -78,6 +87,14 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo {
7887
@Parameter(property = "postHotfixGoals")
7988
private String postHotfixGoals;
8089

90+
/**
91+
* Maven profiles to activate in the release or support branch after the hotfix.
92+
*
93+
* @since 1.19.0
94+
*/
95+
@Parameter(property = "postHotfixProfiles")
96+
private String postHotfixProfiles;
97+
8198
/**
8299
* Hotfix version to use in non-interactive mode.
83100
*
@@ -143,7 +160,8 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo {
143160
/** {@inheritDoc} */
144161
@Override
145162
public void execute() throws MojoExecutionException, MojoFailureException {
146-
validateConfiguration(preHotfixGoals, postHotfixGoals);
163+
validateConfiguration(preHotfixGoals, preHotfixProfiles,
164+
postHotfixGoals, postHotfixProfiles);
147165

148166
try {
149167
// check uncommitted changes
@@ -220,7 +238,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
220238

221239
// maven goals before merge
222240
if (StringUtils.isNotBlank(preHotfixGoals)) {
223-
mvnRun(preHotfixGoals);
241+
mvnRun(preHotfixGoals, preHotfixProfiles);
224242
}
225243

226244
String currentHotfixVersion = getCurrentProjectVersion();
@@ -270,7 +288,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
270288

271289
// maven goals after merge
272290
if (StringUtils.isNotBlank(postHotfixGoals)) {
273-
mvnRun(postHotfixGoals);
291+
mvnRun(postHotfixGoals, postHotfixProfiles);
274292
}
275293

276294
// check whether release branch exists

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo {
135135
@Parameter(property = "preReleaseGoals")
136136
private String preReleaseGoals;
137137

138+
/**
139+
* Maven profiles to activate in the release branch before merging into the
140+
* production branch.
141+
*
142+
* @since 1.19.0
143+
*/
144+
@Parameter(property = "preReleaseProfiles")
145+
private String preReleaseProfiles;
146+
138147
/**
139148
* Maven goals to execute in the production branch after the release.
140149
*
@@ -143,6 +152,14 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo {
143152
@Parameter(property = "postReleaseGoals")
144153
private String postReleaseGoals;
145154

155+
/**
156+
* Maven profiles to activate in the production branch after the release.
157+
*
158+
* @since 1.19.0
159+
*/
160+
@Parameter(property = "postReleaseProfiles")
161+
private String postReleaseProfiles;
162+
146163
/**
147164
* Whether to make a GPG-signed tag.
148165
*
@@ -182,7 +199,8 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo {
182199
/** {@inheritDoc} */
183200
@Override
184201
public void execute() throws MojoExecutionException, MojoFailureException {
185-
validateConfiguration(preReleaseGoals, postReleaseGoals);
202+
validateConfiguration(preReleaseGoals, preReleaseProfiles,
203+
postReleaseGoals, postReleaseProfiles);
186204

187205
try {
188206
// check uncommitted changes
@@ -243,7 +261,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
243261

244262
// maven goals before merge
245263
if (StringUtils.isNotBlank(preReleaseGoals)) {
246-
mvnRun(preReleaseGoals);
264+
mvnRun(preReleaseGoals, preReleaseProfiles);
247265
}
248266

249267
String currentReleaseVersion = getCurrentProjectVersion();
@@ -285,7 +303,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
285303

286304
// maven goals after merge
287305
if (StringUtils.isNotBlank(postReleaseGoals)) {
288-
mvnRun(postReleaseGoals);
306+
mvnRun(postReleaseGoals, postReleaseProfiles);
289307
}
290308

291309
if (notSameProdDevName()) {

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseMojo.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ public class GitFlowReleaseMojo extends AbstractGitFlowMojo {
131131
@Parameter(property = "preReleaseGoals")
132132
private String preReleaseGoals;
133133

134+
/**
135+
* Maven profiles to activate before the release.
136+
*
137+
* @since 1.19.0
138+
*/
139+
@Parameter(property = "preReleaseProfiles")
140+
private String preReleaseProfiles;
141+
134142
/**
135143
* Maven goals to execute after the release.
136144
*
@@ -139,6 +147,14 @@ public class GitFlowReleaseMojo extends AbstractGitFlowMojo {
139147
@Parameter(property = "postReleaseGoals")
140148
private String postReleaseGoals;
141149

150+
/**
151+
* Maven profiles to activate after the release.
152+
*
153+
* @since 1.19.0
154+
*/
155+
@Parameter(property = "postReleaseProfiles")
156+
private String postReleaseProfiles;
157+
142158
/**
143159
* Whether to make a GPG-signed tag.
144160
*
@@ -158,7 +174,8 @@ public class GitFlowReleaseMojo extends AbstractGitFlowMojo {
158174
/** {@inheritDoc} */
159175
@Override
160176
public void execute() throws MojoExecutionException, MojoFailureException {
161-
validateConfiguration(preReleaseGoals, postReleaseGoals);
177+
validateConfiguration(preReleaseGoals, preReleaseProfiles,
178+
postReleaseGoals, postReleaseProfiles);
162179

163180
try {
164181
// set git flow configuration
@@ -243,7 +260,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
243260

244261
// maven goals before release
245262
if (StringUtils.isNotBlank(preReleaseGoals)) {
246-
mvnRun(preReleaseGoals);
263+
mvnRun(preReleaseGoals, preReleaseProfiles);
247264
}
248265

249266
Map<String, String> messageProperties = new HashMap<>();
@@ -281,7 +298,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
281298

282299
// maven goals after release
283300
if (StringUtils.isNotBlank(postReleaseGoals)) {
284-
mvnRun(postReleaseGoals);
301+
mvnRun(postReleaseGoals, postReleaseProfiles);
285302
}
286303

287304
if (notSameProdDevName()) {

0 commit comments

Comments
 (0)