From 26e1238a03d5a46c075b16be42f3eae0eac3390b Mon Sep 17 00:00:00 2001 From: John Patrick <142304+nhojpatrick@users.noreply.github.com> Date: Tue, 18 Aug 2020 09:06:40 +0100 Subject: [PATCH] Take 2 Global Settings and User Settings --- .../plugin/gitflow/AbstractGitFlowMojo.java | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) 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 8de164d5..5a0f9abc 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -117,6 +117,26 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { @Parameter(property = "argLine") private String argLine; + /** + * Global setting file to pass to the underlying Maven commands. + *
+ * If not defined will default to global settings file of executing Maven command. + * + * @since 1.14.1 + */ + @Parameter(property = "gitflow.maven.settings.global") + private String globalSettings; + + /** + * User setting file to pass to the underlying Maven commands. + *
+ * If not defined will default to user settings file of executing Maven command. + * + * @since 1.14.1 + */ + @Parameter(property = "gitflow.maven.settings.user") + private String userSettings; + /** * Whether to make a GPG-signed commit. * @@ -203,6 +223,22 @@ private void initExecutables() { } } + /** + * Initializes maven defaults. + */ + private void initMavenDefaults() { + if (StringUtils.isBlank(this.globalSettings)) { + this.globalSettings = this.mavenSession.getRequest() + .getGlobalSettingsFile() + .getAbsolutePath(); + } + if (StringUtils.isBlank(this.userSettings)) { + this.userSettings = this.mavenSession.getRequest() + .getUserSettingsFile() + .getAbsolutePath(); + } + } + /** * Validates plugin configuration. Throws exception if configuration is not * valid. @@ -1134,7 +1170,26 @@ private void executeGitCommand(final String... args) */ private void executeMvnCommand(final String... args) throws CommandLineException, MojoFailureException { - executeCommand(cmdMvn, true, argLine, args); + + initMavenDefaults(); + + final List argLines = new ArrayList(); + + if (StringUtils.isBlank(this.argLine) + || !this.argLine.contains("-gs")) { + argLines.add("-gs"); + argLines.add(this.globalSettings); + } + if (StringUtils.isBlank(this.argLine) + || !this.argLine.contains("-s")) { + argLines.add("-s"); + argLines.add(this.userSettings); + } + if (StringUtils.isNotBlank(this.argLine)) { + argLines.add(this.argLine); + } + + executeCommand(cmdMvn, true, StringUtils.join(argLines.toArray(), " "), args); } /**