Skip to content

Commit 629e566

Browse files
authored
Merge pull request #304 from olivergondza/issue-299
Fix #299: Introduce `describe.distance.snapshot` for compatibility with maven deploy plugin
2 parents 3869c38 + e70282e commit 629e566

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ e.g `${dirty:-SNAPSHOT}` resolves to `-SNAPSHOT` instead of `-DIRTY`
236236

237237
- `${describe}` Will resolve to `git describe` output
238238
- `${describe.distance}` The distance count to last matching tag
239+
- `${describe.distance.snapshot}` Empty string on matching tag, `-SNAPSHOT` if `describe.distance > 0`
239240
- `${describe.tag}` The matching tag of `git describe`
240241
- `${describe.tag.version}` the tag version determined by regex `(?<version>(?<core>(?<major>\d+)(?:\.(?<minor>\d+)(?:\.(?<patch>\d+))?)?)(?:-(?<label>.*))?)`
241242
- `${describe.tag.version.core}` the core version component of `${describe.tag.version}` e.g. '1.2.3'

src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class GitVersioningModelProcessor implements ModelProcessor {
8080

8181
// gets injected by setter, see below
8282
private ModelProcessor delegatedModelProcessor;
83-
83+
8484
@Inject
8585
void setDelegatedModelProcessor(List<ModelProcessor> modelProcessors) {
8686
this.delegatedModelProcessor = modelProcessors.stream()
@@ -967,6 +967,7 @@ private Map<String, Supplier<String>> generateGlobalFormatPlaceholderMap(GitSitu
967967

968968
final Lazy<Integer> descriptionDistance = Lazy.by(() -> description.get().getDistance());
969969
placeholderMap.put("describe.distance", Lazy.by(() -> String.valueOf(descriptionDistance.get())));
970+
placeholderMap.put("describe.distance.snapshot", Lazy.by(() -> (descriptionDistance.get() == 0 ? "" : "-SNAPSHOT")));
970971

971972
placeholderMap.put("describe.tag.version.patch.plus.describe.distance", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.patch").get(), descriptionDistance.get())));
972973
placeholderMap.put("describe.tag.version.patch.next.plus.describe.distance", Lazy.by(() -> increase(placeholderMap.get("describe.tag.version.patch.next").get(), descriptionDistance.get())));

src/test/java/me/qoomon/maven/gitversioning/GitVersioningExtensionIT.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,61 @@ void apply_TwoCommitsSinceLastTagGivesExpectedPlusDistanceResult() throws Except
807807
Model gitVersionedPomModel = readModel(projectDir.resolve(GIT_VERSIONING_POM_NAME).toFile());
808808
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
809809
}
810+
}
811+
812+
@Test
813+
void apply_DescribeDistanceSnapshotRelease() throws Exception {
814+
// given
815+
try (Git git = Git.init().setInitialBranch(MASTER).setDirectory(projectDir.toFile()).call()) {
816+
git.commit().setMessage("initial commit").setAllowEmpty(true).call();
817+
git.tag().setName("2.0.4").call();
810818

819+
writeModel(projectDir.resolve("pom.xml").toFile(), pomModel);
820+
writeExtensionsFile(projectDir);
821+
writeExtensionConfigFile(projectDir, new Configuration() {{
822+
refs.list.add(createVersionDescription(BRANCH, "${describe.tag}${describe.distance.snapshot}"));
823+
}});
824+
825+
// When
826+
Verifier verifier = getVerifier(projectDir);
827+
verifier.executeGoal("verify");
828+
829+
// Then
830+
String expectedVersion = "2.0.4";
831+
Model gitVersionedPomModel = readModel(projectDir.resolve(GIT_VERSIONING_POM_NAME).toFile());
832+
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
833+
834+
verifier.verifyErrorFreeLog();
835+
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
836+
}
837+
}
838+
839+
@Test
840+
void apply_DescribeDistanceSnapshot() throws Exception {
841+
// given
842+
try (Git git = Git.init().setInitialBranch(MASTER).setDirectory(projectDir.toFile()).call()) {
843+
git.commit().setMessage("initial commit").setAllowEmpty(true).call();
844+
git.tag().setName("2.0.4").call();
845+
git.commit().setMessage("commit one").setAllowEmpty(true).call();
846+
847+
writeModel(projectDir.resolve("pom.xml").toFile(), pomModel);
848+
writeExtensionsFile(projectDir);
849+
writeExtensionConfigFile(projectDir, new Configuration() {{
850+
refs.list.add(createVersionDescription(BRANCH, "${describe.tag}${describe.distance.snapshot}"));
851+
}});
852+
853+
// When
854+
Verifier verifier = getVerifier(projectDir);
855+
verifier.executeGoal("verify");
856+
857+
// Then
858+
String expectedVersion = "2.0.4-SNAPSHOT";
859+
Model gitVersionedPomModel = readModel(projectDir.resolve(GIT_VERSIONING_POM_NAME).toFile());
860+
assertThat(gitVersionedPomModel.getVersion()).isEqualTo(expectedVersion);
861+
862+
verifier.verifyErrorFreeLog();
863+
verifier.verifyTextInLog("Building " + pomModel.getArtifactId() + " " + expectedVersion);
864+
}
811865
}
812866

813867
@Test

0 commit comments

Comments
 (0)