Skip to content

Commit 9c20758

Browse files
committed
Allow to use snapshot version in support branch - closes #250
1 parent 284607b commit 9c20758

File tree

8 files changed

+135
-0
lines changed

8 files changed

+135
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.amashchenko.maven.plugin</groupId>
4+
<artifactId>gitflow-maven-test</artifactId>
5+
<packaging>pom</packaging>
6+
<version>0.0.3-SNAPSHOT</version>
7+
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build.log
2+
expected-pom.xml
3+
invoker.properties
4+
init.bsh
5+
verify.bsh

src/it/support-start-3-it/init.bsh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import org.codehaus.plexus.util.FileUtils;
2+
3+
try {
4+
new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore"));
5+
6+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " init");
7+
p.waitFor();
8+
9+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.email 'a@a.aa'");
10+
p.waitFor();
11+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.name 'a'");
12+
p.waitFor();
13+
14+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
15+
p.waitFor();
16+
17+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init");
18+
p.waitFor();
19+
20+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " tag -a 0.0.1 -m 0.0.1");
21+
p.waitFor();
22+
23+
File file = new File(basedir, "test.txt");
24+
FileUtils.fileAppend(file.getPath(), "next commit");
25+
26+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
27+
p.waitFor();
28+
29+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m next");
30+
p.waitFor();
31+
32+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " tag -a 0.0.3 -m 0.0.3");
33+
p.waitFor();
34+
35+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b develop");
36+
p.waitFor();
37+
38+
} catch (Exception e) {
39+
e.printStackTrace();
40+
return false;
41+
}
42+
return true;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:support-start -DpushRemote=false -B -DuseSnapshotInSupport
2+
3+
invoker.description=Non-interactive support-start using useSnapshotInSupport parameter.

src/it/support-start-3-it/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.amashchenko.maven.plugin</groupId>
4+
<artifactId>gitflow-maven-test</artifactId>
5+
<packaging>pom</packaging>
6+
<version>0.0.3</version>
7+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import org.codehaus.plexus.util.FileUtils;
2+
3+
try {
4+
File gitRef = new File(basedir, ".git/refs/heads/support/0.0.3");
5+
if (!gitRef.exists()) {
6+
System.out.println("support-start .git/refs/heads/support/0.0.3 doesn't exist");
7+
return false;
8+
}
9+
10+
File file = new File(basedir, "pom.xml");
11+
File expectedFile = new File(basedir, "expected-pom.xml");
12+
13+
String actual = FileUtils.fileRead(file, "UTF-8");
14+
String expected = FileUtils.fileRead(expectedFile, "UTF-8");
15+
16+
actual = actual.replaceAll("\\r?\\n", "");
17+
expected = expected.replaceAll("\\r?\\n", "");
18+
19+
if (!expected.equals(actual)) {
20+
System.out.println("support-start expected: " + expected + " actual was:" + actual);
21+
return false;
22+
}
23+
} catch (Exception e) {
24+
e.printStackTrace();
25+
return false;
26+
}
27+
return true;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class CommitMessages {
5555
private String updateFeatureBackMessage;
5656
private String featureFinishIncrementVersionMessage;
5757

58+
private String supportStartMessage;
59+
5860
public CommitMessages() {
5961
featureStartMessage = "Update versions for feature branch";
6062
featureFinishMessage = "Update versions for development branch";
@@ -83,6 +85,8 @@ public CommitMessages() {
8385

8486
updateFeatureBackMessage = "Update feature branch back to feature version";
8587
featureFinishIncrementVersionMessage = "Increment feature version";
88+
89+
supportStartMessage = "Update versions for support branch";
8690
}
8791

8892
/**
@@ -423,4 +427,19 @@ public String getFeatureFinishIncrementVersionMessage() {
423427
public void setFeatureFinishIncrementVersionMessage(String featureFinishIncrementVersionMessage) {
424428
this.featureFinishIncrementVersionMessage = featureFinishIncrementVersionMessage;
425429
}
430+
431+
/**
432+
* @return the supportStartMessage
433+
*/
434+
public String getSupportStartMessage() {
435+
return supportStartMessage;
436+
}
437+
438+
/**
439+
* @param supportStartMessage
440+
* the supportStartMessage to set
441+
*/
442+
public void setSupportStartMessage(String supportStartMessage) {
443+
this.supportStartMessage = supportStartMessage;
444+
}
426445
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
package com.amashchenko.maven.plugin.gitflow;
1717

1818
import java.util.Arrays;
19+
import java.util.HashMap;
20+
import java.util.Map;
1921

22+
import org.apache.maven.artifact.Artifact;
23+
import org.apache.maven.artifact.ArtifactUtils;
2024
import org.apache.maven.plugin.MojoExecutionException;
2125
import org.apache.maven.plugin.MojoFailureException;
2226
import org.apache.maven.plugins.annotations.Mojo;
@@ -56,6 +60,13 @@ public class GitFlowSupportStartMojo extends AbstractGitFlowMojo {
5660
@Parameter(property = "supportBranchName")
5761
private String supportBranchName;
5862

63+
/**
64+
* Whether to use snapshot in support.
65+
*
66+
*/
67+
@Parameter(property = "useSnapshotInSupport", defaultValue = "false")
68+
private boolean useSnapshotInSupport;
69+
5970
/** {@inheritDoc} */
6071
@Override
6172
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -113,6 +124,20 @@ public void execute() throws MojoExecutionException, MojoFailureException {
113124
// git checkout -b ... tag
114125
gitCreateAndCheckout(gitFlowConfig.getSupportBranchPrefix() + branchName, tag);
115126

127+
if (useSnapshotInSupport) {
128+
String version = getCurrentProjectVersion();
129+
if (!ArtifactUtils.isSnapshot(version)) {
130+
version = version + "-" + Artifact.SNAPSHOT_VERSION;
131+
132+
mvnSetVersions(version);
133+
134+
Map<String, String> properties = new HashMap<String, String>();
135+
properties.put("version", version);
136+
137+
gitCommit(commitMessages.getSupportStartMessage(), properties);
138+
}
139+
}
140+
116141
if (installProject) {
117142
// mvn clean install
118143
mvnCleanInstall();

0 commit comments

Comments
 (0)