diff --git a/README.md b/README.md index 8b2a4af8..b4a246a3 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,17 @@ You can configure the version and properties adjustments for specific branches a - `` An arbitrary regex to match tag names for git describe command - has to be a **full match pattern** e.g. `v.+`) - will override global `` value + - can contain placeholders with `{{}}` delimiters that can be from env, properties, project version, or ref, but + not from `describe`. For example: + ```xml + + \d+)\.(?\d+)(?:\.x)?]]> + \Qrelease-marker-{{ref.major}}.{{ref.minor}}\E + ${ref.major}.${ref.minor}.0-rc.${describe.distance}-SNAPSHOT + + ``` + will first read the major and minor part of the version from the branch name, then will try to find a tag that + matches this specific version pieces to set the final version using describe. - `` Enable(`true`) or disable(`false`) following only the first parent in a merge commit - default is `true`

diff --git a/src/main/java/me/qoomon/gitversioning/commons/GitSituation.java b/src/main/java/me/qoomon/gitversioning/commons/GitSituation.java index a22ab8e9..feb4a457 100644 --- a/src/main/java/me/qoomon/gitversioning/commons/GitSituation.java +++ b/src/main/java/me/qoomon/gitversioning/commons/GitSituation.java @@ -32,7 +32,9 @@ public class GitSituation { private final Supplier clean = Lazy.by(this::clean); - private Pattern describeTagPattern = Pattern.compile(".*"); + private Supplier describeTagPattern = Lazy.by(() -> Pattern.compile(".*")); + + private String rawDescribeTagPattern = ".*"; private boolean firstParent = true; @@ -121,13 +123,28 @@ public boolean isClean() { return clean.get(); } - public void setDescribeTagPattern(Pattern describeTagPattern) { + /** + * Returns the describeTagPattern as set in config. It may contain placeholders delimited by {{}}, + * e.g. {{ref.myCaptureGroupFromRef}}. In order to get placeholder resolved, + * {@link GitSituation#getDescribeTagPattern()} should be used. + * + * @return the raw expressing for describe tag pattern + */ + public String getRawDescribeTagPattern() { + return rawDescribeTagPattern; + } + + public void setRawDescribeTagPattern(String rawDescribeTagPattern) { + this.rawDescribeTagPattern = requireNonNull(rawDescribeTagPattern); + } + + public void setDescribeTagPattern(Supplier describeTagPattern) { this.describeTagPattern = requireNonNull(describeTagPattern); this.description = Lazy.by(this::describe); } public Pattern getDescribeTagPattern() { - return describeTagPattern; + return describeTagPattern.get(); } public boolean isFirstParent() { @@ -163,6 +180,6 @@ private boolean clean() throws GitAPIException { } private GitDescription describe() throws IOException { - return GitUtil.describe(head, describeTagPattern, repository, firstParent); + return GitUtil.describe(head, describeTagPattern.get(), repository, firstParent); } } \ No newline at end of file diff --git a/src/main/java/me/qoomon/maven/gitversioning/Configuration.java b/src/main/java/me/qoomon/maven/gitversioning/Configuration.java index a9b8a929..8e9e7faf 100644 --- a/src/main/java/me/qoomon/maven/gitversioning/Configuration.java +++ b/src/main/java/me/qoomon/maven/gitversioning/Configuration.java @@ -48,13 +48,6 @@ public Pattern projectVersionPattern() { public Boolean describeTagFirstParent = true; - public Pattern describeTagPattern() { - if(describeTagPattern == null) { - return null; - } - return Pattern.compile(describeTagPattern); - } - public Boolean updatePom = false; public RefPatchDescriptionList refs = new RefPatchDescriptionList(); @@ -72,13 +65,6 @@ public static class PatchDescription { @JsonDeserialize(using = IgnoreWhitespaceDeserializer.class) public String describeTagPattern; - public Pattern describeTagPattern() { - if(describeTagPattern == null) { - return null; - } - return Pattern.compile(describeTagPattern); - } - @JsonDeserialize(using = IgnoreWhitespaceDeserializer.class) public String version; diff --git a/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java b/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java index 28c90f98..1e4bc6ba 100644 --- a/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java +++ b/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java @@ -8,6 +8,7 @@ import me.qoomon.gitversioning.commons.GitDescription; import me.qoomon.gitversioning.commons.GitSituation; import me.qoomon.gitversioning.commons.Lazy; +import me.qoomon.gitversioning.commons.StringUtil; import me.qoomon.maven.gitversioning.Configuration.PatchDescription; import me.qoomon.maven.gitversioning.Configuration.RefPatchDescription; import org.apache.maven.building.Source; @@ -49,7 +50,8 @@ import static java.util.Objects.requireNonNullElse; import static java.util.stream.Collectors.*; import static me.qoomon.gitversioning.commons.GitRefType.*; -import static me.qoomon.gitversioning.commons.StringUtil.*; +import static me.qoomon.gitversioning.commons.StringUtil.patternGroupValues; +import static me.qoomon.gitversioning.commons.StringUtil.substituteText; import static me.qoomon.maven.gitversioning.BuildProperties.projectArtifactId; import static me.qoomon.maven.gitversioning.GitVersioningMojo.asPlugin; import static me.qoomon.maven.gitversioning.MavenUtil.*; @@ -67,6 +69,7 @@ public class GitVersioningModelProcessor implements ModelProcessor { private static final Pattern VERSION_PATTERN = Pattern.compile(".*?(?(?(?\\d+)(?:\\.(?\\d+)(?:\\.(?\\d+))?)?)(?:-(?