Skip to content

Commit

Permalink
Merge branch 'feature/fix-repeated-other-branch-renaming' of github.c…
Browse files Browse the repository at this point in the history
…om:rdefreitas/gitflow-helper-maven-plugin into feature/partial-multi-module-reversioning
  • Loading branch information
glimmerveen committed Oct 7, 2020
2 parents 264c0b4 + a79b41e commit 9d1c277
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Expand Up @@ -288,14 +288,18 @@ private boolean isProjectOfReplacedArtifactVersion(final MavenProject project, f

/**
* Given a String version (which may be a final or -SNAPSHOT version) return a
* version version string mangled to include a `+normalized-branch-name-SNAPSHOT format version.
* version string mangled to include a `+normalized-branch-name-SNAPSHOT format version.
*
* @param version The base version (ie, 1.0.2-SNAPSHOT)
* @param branchName to be normalized
* @return A mangled version string with the branchname and -SNAPSHOT.
*/
private String getAsBranchSnapshotVersion(final String version, final String branchName) {
return version.replace("-SNAPSHOT", "") + otherBranchVersionDelimiter + branchName.replaceAll("[^0-9A-Za-z-.]", "-") + "-SNAPSHOT";
public String getAsBranchSnapshotVersion(final String version, final String branchName) {
String branchNameSanitized = otherBranchVersionDelimiter + branchName.replaceAll("[^0-9A-Za-z-.]", "-") + "-SNAPSHOT";
if(version.endsWith(branchNameSanitized)) {
return version;
}
return version.replace("-SNAPSHOT", "") + branchNameSanitized;
}

}
@@ -0,0 +1,33 @@
package com.e_gineering.maven.gitflowhelper;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;

@RunWith(BlockJUnit4ClassRunner.class)
public class OtherBranchTest {

private final String baseVersion = "1.0.2";
private final String baseSnapshotVersion = "1.0.2-SNAPSHOT";
private final String branchName = "feature/other-branch-name";
private final String expectedSnapshotResult = "1.0.2+feature-other-branch-name-SNAPSHOT";

private OtherBranchVersionExtension getExtension() {
OtherBranchVersionExtension extension = new OtherBranchVersionExtension();
extension.otherBranchVersionDelimiter = "+";
return extension;
}

@Test
public void assertOtherBranchNameIsPrefixedBeforeSnapshot() {
OtherBranchVersionExtension extension = getExtension();
Assert.assertEquals(expectedSnapshotResult, extension.getAsBranchSnapshotVersion(baseSnapshotVersion,branchName));
}

@Test
public void assertOtherBranchNameIsOnlyPrefixedBeforeSnapshotOneTime() {
OtherBranchVersionExtension extension = getExtension();
Assert.assertEquals(expectedSnapshotResult, extension.getAsBranchSnapshotVersion(extension.getAsBranchSnapshotVersion(baseSnapshotVersion,branchName),branchName));
}
}

0 comments on commit 9d1c277

Please sign in to comment.