Skip to content

Commit

Permalink
Allow to use snapshot versions in release and hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
alsanrum authored and aleksandr-m committed Jun 17, 2018
1 parent fe11509 commit 9715c26
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String, String> properties = new HashMap<String, String>();
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, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String, String> properties = new HashMap<String, String>();
properties.put("version", version);
properties.put("version", projectVersion);

// git commit -a -m updating versions for hotfix
gitCommit(commitMessages.getHotfixStartMessage(), properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String, String> properties = new HashMap<String, String>();
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, "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -203,7 +217,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// mvn versions:set ...
// git commit -a -m ...
commitProjectVersion(releaseVersion,
commitProjectVersion(projectVersion,
commitMessages.getReleaseStartMessage());
}

Expand Down

0 comments on commit 9715c26

Please sign in to comment.