Skip to content

Commit c0b13b5

Browse files
authored
Merge pull request #236 from stefanseifert/feature/issue235-version-policy
Fixes #235 add projectVersionPolicyId parameter to support VersionPolicy implementations
2 parents f3492cf + 4d26f89 commit c0b13b5

20 files changed

+231
-28
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@
254254
<version>2.5.3</version>
255255
<scope>compile</scope>
256256
</dependency>
257+
<dependency>
258+
<groupId>org.apache.maven.release</groupId>
259+
<artifactId>maven-release-oddeven-policy</artifactId>
260+
<version>2.5.3</version>
261+
<scope>test</scope>
262+
</dependency>
257263
<dependency>
258264
<groupId>junit</groupId>
259265
<artifactId>junit</artifactId>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.4</version>
7+
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>com.amashchenko.maven.plugin</groupId>
12+
<artifactId>gitflow-maven-plugin</artifactId>
13+
<configuration>
14+
<projectVersionPolicyId>OddEvenVersionPolicy</projectVersionPolicyId>
15+
</configuration>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.apache.maven.release</groupId>
19+
<artifactId>maven-release-oddeven-policy</artifactId>
20+
<version>2.5.3</version>
21+
</dependency>
22+
</dependencies>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
27+
</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
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
try {
2+
new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore"));
3+
4+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " init");
5+
p.waitFor();
6+
7+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.email '[email protected]'");
8+
p.waitFor();
9+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.name 'a'");
10+
p.waitFor();
11+
12+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
13+
p.waitFor();
14+
15+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init");
16+
p.waitFor();
17+
18+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b develop");
19+
p.waitFor();
20+
21+
} catch (Exception e) {
22+
e.printStackTrace();
23+
return false;
24+
}
25+
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}:release-start -B
2+
3+
invoker.description=Non-interactive simple release-start.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>com.amashchenko.maven.plugin</groupId>
12+
<artifactId>gitflow-maven-plugin</artifactId>
13+
<configuration>
14+
<projectVersionPolicyId>OddEvenVersionPolicy</projectVersionPolicyId>
15+
</configuration>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.apache.maven.release</groupId>
19+
<artifactId>maven-release-oddeven-policy</artifactId>
20+
<version>2.5.3</version>
21+
</dependency>
22+
</dependencies>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
27+
</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/release/0.0.4");
5+
if (!gitRef.exists()) {
6+
System.out.println("release-start .git/refs/heads/release/0.0.4 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("release-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/AbstractGitFlowMojo.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.maven.project.ProjectBuilder;
3838
import org.apache.maven.project.ProjectBuildingResult;
3939
import org.apache.maven.settings.Settings;
40+
import org.apache.maven.shared.release.policy.version.VersionPolicy;
4041
import org.codehaus.plexus.components.interactivity.Prompter;
4142
import org.codehaus.plexus.util.StringUtils;
4243
import org.codehaus.plexus.util.cli.CommandLineException;
@@ -195,6 +196,17 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
195196
@Parameter(property = "gitExecutable")
196197
private String gitExecutable;
197198

199+
/**
200+
* The role-hint for the {@link org.apache.maven.shared.release.policy.version.VersionPolicy}
201+
* implementation used to calculate the project versions.
202+
* If a policy is set other parameters controlling the generation of version are ignored
203+
* (digitsOnlyDevVersion, versionDigitToIncrement).
204+
*
205+
* @since 1.18.0
206+
*/
207+
@Parameter(property="projectVersionPolicyId")
208+
private String projectVersionPolicyId;
209+
198210
/** Maven session. */
199211
@Parameter(defaultValue = "${session}", readonly = true)
200212
protected MavenSession mavenSession;
@@ -208,6 +220,8 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
208220
/** Maven settings. */
209221
@Parameter(defaultValue = "${settings}", readonly = true)
210222
protected Settings settings;
223+
@Component
224+
protected Map<String,VersionPolicy> versionPolicies;
211225

212226
/**
213227
* Initializes command line executables.
@@ -1380,4 +1394,16 @@ public String getError() {
13801394
public void setArgLine(String argLine) {
13811395
this.argLine = argLine;
13821396
}
1397+
1398+
protected VersionPolicy getVersionPolicy() {
1399+
if (StringUtils.isNotBlank(projectVersionPolicyId)) {
1400+
VersionPolicy versionPolicy = versionPolicies.get(projectVersionPolicyId);
1401+
if (versionPolicy == null) {
1402+
throw new IllegalArgumentException("No implementation found for projectVersionPolicyId: " + projectVersionPolicyId);
1403+
}
1404+
return versionPolicy;
1405+
}
1406+
return null;
1407+
}
1408+
13831409
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
167167
if (incrementVersionAtFinish) {
168168
// prevent incrementing feature name which can hold numbers
169169
String ver = featureVersion.replaceFirst("-" + featName, "");
170-
GitFlowVersionInfo nextVersionInfo = new GitFlowVersionInfo(ver);
170+
GitFlowVersionInfo nextVersionInfo = new GitFlowVersionInfo(ver, getVersionPolicy());
171171
ver = nextVersionInfo.nextSnapshotVersion();
172-
GitFlowVersionInfo featureVersionInfo = new GitFlowVersionInfo(ver);
172+
GitFlowVersionInfo featureVersionInfo = new GitFlowVersionInfo(ver, getVersionPolicy());
173173
featureVersion = featureVersionInfo.featureVersion(featName);
174174

175175
mvnSetVersions(featureVersion);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
132132
// get current project version from pom
133133
final String currentVersion = getCurrentProjectVersion();
134134

135-
final String version = new GitFlowVersionInfo(currentVersion)
135+
final String version = new GitFlowVersionInfo(currentVersion, getVersionPolicy())
136136
.featureVersion(featureBranchName);
137137

138138
if (StringUtils.isNotBlank(version)) {

0 commit comments

Comments
 (0)