Bumps version to snapshot only for numeric values

This commit is contained in:
Marcin Grzejszczak
2018-06-30 07:45:22 +02:00
parent 932205be61
commit bbd45dcd3b
2 changed files with 15 additions and 1 deletions

View File

@@ -43,13 +43,20 @@ public class ProjectVersion {
public String bumpedVersion() {
// 1.0.0.BUILD-SNAPSHOT
String[] splitVersion = this.version.split("\\.");
if (splitVersion.length < 4) {
if (splitVersion.length < 4 && isNumeric(splitVersion[0])) {
throw new IllegalStateException("Version is invalid. Should be of format [1.2.3.A]");
}
if (splitVersion.length == 2 && !isNumeric(splitVersion[0])) {
return this.version;
}
Integer incrementedPatch = Integer.valueOf(splitVersion[2]) + 1;
return String.format("%s.%s.%s.%s", splitVersion[0], splitVersion[1], incrementedPatch, splitVersion[3]);
}
private boolean isNumeric(String string) {
return string.matches("[0-9]+");
}
public String groupId() {
if (this.model == null) {
return "";

View File

@@ -82,6 +82,13 @@ public class ProjectVersionTests {
then(projectVersion(version).bumpedVersion()).isEqualTo("1.0.2.BUILD-SNAPSHOT");
}
@Test
public void should_return_the_previous_version_for_release_train_version() {
String version = "Edgware.BUILD-SNAPSHOT";
then(projectVersion(version).bumpedVersion()).isEqualTo("Edgware.BUILD-SNAPSHOT");
}
@Test
public void should_return_true_for_snapshot_version() {
String version = "1.0.1.BUILD-SNAPSHOT";