-
Couldn't load subscription status.
- Fork 163
Description
I really like behavior of versionCreator 'versionWithBranch', except for one thing.
I want it to work for snapshots only.
E.g. on branch hotfix I want currentVersion return:
1.0.1 when on release tag, current behavior is 1.0.1-hotfix
1.0.2-hotfix-SNAPSHOT otherwise
This was mentioned (and closed) before in Issue #269 because the Creator interface didn't facilitate this behaviour.
I've made a fix for this, by introducing a new interface specifically for a version Creator in VersionProperties.java
public interface VersionCreator { String apply(String versionFromTag, ScmPosition position, VersionContext versionContext); }
This allowed me to create a new predefined version creator specifically for this need:
VERSION_WITH_BRANCH_WHEN_SNAPSHOT('versionWithBranchWhenSnapshot', { String versionFromTag, ScmPosition position, VersionContext versionContext -> if ((versionContext.position.branch != 'master' && versionContext.position.branch != 'main') && versionContext.position.branch != 'HEAD' && versionContext.isSnapshot()) { return "$versionFromTag-$versionContext.position.branch".toString() } return versionFromTag }),
Of course, I refactored all predefined version creators (and their tests) to be adhere to this new interface. It is, however, of course not backwards compatible with custom made version creators, as it needs an extra parameter. The change needed is however, very minor, like this:
{version, position -> ...}
to
{version, position, context -> ...}
where the context param can be ignored for existing creators.
I've attached my fix to this post. It does not contain new tests, but the existing ones are respected. Of course I will, should you approve my fix, provide test cases as well.
Please consider this extra functionality.