diff --git a/.factorypath b/.factorypath new file mode 100644 index 00000000..3ca9c6e3 --- /dev/null +++ b/.factorypath @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 8153554e..aebf34cd 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java @@ -179,6 +179,12 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "noBackMerge", defaultValue = "false") private boolean noBackMerge = false; + /** Release branch to use in non-interactive mode. Must start with releasae branch + * prefix. The releaseBranchName parameter will be used if there are multiple release Branches in the Repository + * */ + @Parameter(property = "releaseBranchName") + private String releaseBranchName; + /** * Whether to skip merging release into the development branch. * @@ -191,36 +197,47 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { validateConfiguration(preReleaseGoals, postReleaseGoals); - + String releaseBranch = null; try { // check uncommitted changes checkUncommittedChanges(); - String releaseBranch = gitFindBranches(gitFlowConfig.getReleaseBranchPrefix(), false); + if (StringUtils.isNotBlank(releaseBranchName)) { + if (!releaseBranchName.startsWith(gitFlowConfig.getReleaseBranchPrefix())) { + throw new MojoFailureException("The releaseBranchName parameter doesn't start with release branch prefix."); + } + if (!gitCheckBranchExists(releaseBranchName)) { + throw new MojoFailureException("Release branch with name '" + releaseBranchName + "' doesn't exist. Cannot finish release."); + } + releaseBranch = releaseBranchName; + } else { + + releaseBranch = gitFindBranches(gitFlowConfig.getReleaseBranchPrefix(), false); - if (StringUtils.isBlank(releaseBranch)) { - if (fetchRemote) { - releaseBranch = gitFetchAndFindRemoteBranches(gitFlowConfig.getReleaseBranchPrefix(), false); - if (StringUtils.isBlank(releaseBranch)) { - throw new MojoFailureException("There is no remote or local release branch."); - } + if (StringUtils.isBlank(releaseBranch)) { + if (fetchRemote) { + releaseBranch = gitFetchAndFindRemoteBranches(gitFlowConfig.getReleaseBranchPrefix(), false); + if (StringUtils.isBlank(releaseBranch)) { + throw new MojoFailureException("There is no remote or local release branch."); + } - // remove remote name with slash from branch name - releaseBranch = releaseBranch.substring(gitFlowConfig.getOrigin().length() + 1); + // remove remote name with slash from branch name + releaseBranch = releaseBranch.substring(gitFlowConfig.getOrigin().length() + 1); - if (StringUtils.countMatches(releaseBranch, gitFlowConfig.getReleaseBranchPrefix()) > 1) { - throw new MojoFailureException("More than one remote release branch exists. Cannot finish release."); + if (StringUtils.countMatches(releaseBranch, gitFlowConfig.getReleaseBranchPrefix()) > 1) { + throw new MojoFailureException("More than one remote release branch exists. And the parameter releaseBranchName is not set. Cannot finish release."); + } + + gitCreateAndCheckout(releaseBranch, gitFlowConfig.getOrigin() + "/" + releaseBranch); + } else { + throw new MojoFailureException("There is no release branch."); } + } + if (StringUtils.countMatches(releaseBranch, gitFlowConfig.getReleaseBranchPrefix()) > 1) { - gitCreateAndCheckout(releaseBranch, gitFlowConfig.getOrigin() + "/" + releaseBranch); - } else { - throw new MojoFailureException("There is no release branch."); + throw new MojoFailureException("More than one release branch exists. Cannot finish release."); } } - if (StringUtils.countMatches(releaseBranch, gitFlowConfig.getReleaseBranchPrefix()) > 1) { - throw new MojoFailureException("More than one release branch exists. Cannot finish release."); - } - // check snapshots dependencies if (!allowSnapshots) { gitCheckout(releaseBranch); diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java index a4684eca..e1a03d83 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java @@ -138,6 +138,13 @@ public class GitFlowReleaseStartMojo extends AbstractGitFlowMojo { @Parameter(property = "branchName") private String branchName; + /** + * Whether to allow multiple release branches. + * + */ + @Parameter(property = "allowMultipleReleaseBranches", defaultValue = "true") + private boolean allowMultipleReleaseBranches; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -152,7 +159,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { final String releaseBranch = gitFindBranches(gitFlowConfig.getReleaseBranchPrefix(), true); - if (StringUtils.isNotBlank(releaseBranch)) { + if (StringUtils.isNotBlank(releaseBranch) && !allowMultipleReleaseBranches ) { throw new MojoFailureException("Release branch already exists. Cannot start release."); } @@ -193,6 +200,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { fullBranchName += releaseVersion; } + if (gitCheckBranchExists(fullBranchName)) { + throw new MojoFailureException("Release branch" + fullBranchName + "already exists. Cannot start release."); + } + String projectVersion = releaseVersion; if (useSnapshotInRelease && !ArtifactUtils.isSnapshot(projectVersion)) { projectVersion = projectVersion + "-" + Artifact.SNAPSHOT_VERSION;