diff --git a/README.md b/README.md index f387667b..02d27ae8 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,12 @@ Has effect only when there are separate development and production branches. The `gitflow:release-start` goal have `fromCommit` parameter which allows to start the release from the specific commit (SHA). +The `gitflow:release-start` and `gitflow:release-finish` goals have `useSnapshotInRelease` parameter which allows to start the release with SNAPSHOT version and finish it without this value in project version. By default the value is `false`. +For example, if the release version is `1.0.2` and `useSnapshotInRelease` is set to `true` and using `gitflow:release-start` goal then the release version will be `1.0.2-SNAPSHOT` and when finishing the release with `gitflow:release-finish` goal, the release version will be `1.0.2` + +The `gitflow:hotfix-start` and `gitflow:hotfix-finish` goals have `useSnapshotInHotfix` parameter which allows to start the hotfix with SNAPSHOT version and finish it without this value in the version. By default the value is `false`. +For example, if the hotfix version is `1.0.2.1` and `useSnapshotInHotfix` is set to `true` and using `gitflow:hotfix-start` goal then the hotfix version will be `1.0.2.1-SNAPSHOT` and when finishing the release with `gitflow:hotfix-finish` goal, the release version will be `1.0.2.1` + ### Remote interaction At the start of the each goal remote branch(es) will be fetched and compared with the local branch(es). If the local branch doesn't exist it will be checked out from the remote. 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 de42b204..e2dd086a 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -83,7 +83,7 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { */ @Parameter(defaultValue = "false") protected boolean tychoBuild; - + /** * Whether to call Maven install goal during the mojo execution. * 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 0c9e96a9..9ccdac9a 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -94,6 +94,14 @@ public class GitFlowHotfixFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "gpgSignTag", defaultValue = "false") private boolean gpgSignTag = false; + /** + * Whether this is use snapshot in hotfix. + * + * @since 1.9.1 + */ + @Parameter(property = "useSnapshotInHotfix", defaultValue = "false") + protected boolean useSnapshotInHotfix; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -177,9 +185,23 @@ public void execute() throws MojoExecutionException, MojoFailureException { gitMergeNoff(hotfixBranchName); final String currentVersion = getCurrentProjectVersion(); + if (useSnapshotInHotfix && ArtifactUtils.isSnapshot(currentVersion)) { + String commitVersion = currentVersion.replace("-" + + Artifact.SNAPSHOT_VERSION, ""); + + // mvn versions:set -DnewVersion=... -DgenerateBackupPoms=false + mvnSetVersions(commitVersion); + + Map properties = new HashMap(); + properties.put("version", commitVersion); + + // git commit -a -m updating version for release + gitCommit(commitMessages.getHotfixStartMessage(), properties); + } + if (!skipTag) { String tagVersion = currentVersion; - if (tychoBuild && ArtifactUtils.isSnapshot(tagVersion)) { + if ((tychoBuild || useSnapshotInHotfix) && ArtifactUtils.isSnapshot(tagVersion)) { tagVersion = tagVersion .replace("-" + Artifact.SNAPSHOT_VERSION, ""); } diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java index aeeb7705..45e9ec04 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixStartMojo.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; +import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -61,6 +62,14 @@ public class GitFlowHotfixStartMojo extends AbstractGitFlowMojo { @Parameter(property = "hotfixVersion") private String hotfixVersion; + /** + * Whether this is use snapshot in hotfix. + * + * @since 1.9.1 + */ + @Parameter(property = "useSnapshotInHotfix", defaultValue = "false") + protected boolean useSnapshotInHotfix; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -210,11 +219,16 @@ public void execute() throws MojoExecutionException, MojoFailureException { // execute if version changed if (!version.equals(currentVersion)) { + String projectVersion = version; + if (useSnapshotInHotfix && !ArtifactUtils.isSnapshot(version)) { + projectVersion = version + "-SNAPSHOT"; + } + // mvn versions:set -DnewVersion=... -DgenerateBackupPoms=false - mvnSetVersions(version); + mvnSetVersions(projectVersion); Map properties = new HashMap(); - properties.put("version", version); + properties.put("version", projectVersion); // git commit -a -m updating versions for hotfix gitCommit(commitMessages.getHotfixStartMessage(), properties); 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 1638380a..54d4eb90 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java @@ -151,6 +151,14 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "gpgSignTag", defaultValue = "false") private boolean gpgSignTag = false; + /** + * Whether this is use snapshot in release. + * + * @since 1.9.1 + */ + @Parameter(property = "useSnapshotInRelease", defaultValue = "false") + protected boolean useSnapshotInRelease; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -223,9 +231,23 @@ public void execute() throws MojoExecutionException, MojoFailureException { // get current project version from pom final String currentVersion = getCurrentProjectVersion(); + if (useSnapshotInRelease && ArtifactUtils.isSnapshot(currentVersion)) { + String commitVersion = currentVersion.replace("-" + + Artifact.SNAPSHOT_VERSION, ""); + + // mvn versions:set -DnewVersion=... -DgenerateBackupPoms=false + mvnSetVersions(commitVersion); + + Map properties = new HashMap(); + properties.put("version", commitVersion); + + // git commit -a -m updating version for release + gitCommit(commitMessages.getReleaseFinishMessage(), properties); + } + if (!skipTag) { String tagVersion = currentVersion; - if (tychoBuild && ArtifactUtils.isSnapshot(currentVersion)) { + if ((tychoBuild || useSnapshotInRelease) && ArtifactUtils.isSnapshot(currentVersion)) { tagVersion = currentVersion.replace("-" + Artifact.SNAPSHOT_VERSION, ""); } 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 93bdcdc7..786800b7 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseStartMojo.java @@ -18,6 +18,8 @@ import java.util.HashMap; import java.util.Map; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -118,6 +120,14 @@ public class GitFlowReleaseStartMojo extends AbstractGitFlowMojo { @Parameter(property = "fromCommit") private String fromCommit; + /** + * Whether this is use snapshot in release. + * + * @since 1.9.1 + */ + @Parameter(property = "useSnapshotInRelease", defaultValue = "false") + protected boolean useSnapshotInRelease; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -178,11 +188,15 @@ public void execute() throws MojoExecutionException, MojoFailureException { branchName += releaseVersion; } + String projectVersion = releaseVersion; + if (useSnapshotInRelease && !ArtifactUtils.isSnapshot(projectVersion)) { + projectVersion = projectVersion + "-" + Artifact.SNAPSHOT_VERSION; + } if (commitDevelopmentVersionAtStart) { // mvn versions:set ... // git commit -a -m ... - commitProjectVersion(releaseVersion, - commitMessages.getReleaseStartMessage()); + commitProjectVersion(projectVersion, + commitMessages.getReleaseStartMessage()); // git branch release/... develop gitCreateBranch(branchName, startPoint); @@ -203,7 +217,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // mvn versions:set ... // git commit -a -m ... - commitProjectVersion(releaseVersion, + commitProjectVersion(projectVersion, commitMessages.getReleaseStartMessage()); }