diff --git a/.gitignore b/.gitignore index cbfed34..415039f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,19 @@ -.gradle +# Build build/ -.idea -*.iml +/out + +# Mac .DS_Store userHome + +# IntelliJ +.idea +*.iml + +# Gradle +.gradletasknamecache +.gradle + +# Other +local.properties *.swp -/out diff --git a/README.md b/README.md index 981b22d..95be0df 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ Property | Description | Git: `master` | Git: `feature/great` | Git: `release/2. `tag` (1) | Current tag | (2) | (2) | (2) `lastTag` (1) | Last tag | (4) | (4) | (4) `dirty` | Current state of the working copy | (3) | (3) | (3) +`versionNumber` | Version number containing major, minor, patch, qualifier and versionCode | | | +`versionNumber.major` | Major version | 0 | 0 | 2 +`versionNumber.minor` | Minor version | 0 | 0 | 0 +`versionNumber.patch` | Patch version | 0 | 0 | 0, 1, 2, ... +`versionNumber.qualifier` | Version qualifier (alpha, beta, engineer, ...)| '' | '' | '' +`versionNumber.versionCode` | Version code | 0 | 0 | 20000, 20001, 20002, ... (1) not supported for Subversion (2) will be the name of the current tag if any, or `null` if no tag is associated to the current `HEAD`. @@ -119,6 +125,18 @@ For branches to type `release`, an additional computation occurs: By using the `display` version when tagging a release, the `display` version will be automatically incremented, patch after patch, using the `release` base at a prefix. +### Version number + +Version number is a container of several numbers computed from `display` by default . It is hosting major, minor, patch, +qualifier and versionCode. + +- In a tag like `1.2.3`, then major is `1`, minor is `2` and patch is `3` +- Qualifier are taken from tags formatted like `1.2-beta.0` where qualifier is `-beta` here +- Version code is a integer computed from major, minor and patch version. + - `1.2.3` will give 10203 + - `21.5.16` will give 210516 + - `2.0-alpha.0` will give 20000 + ## Tasks The `versioning` plug-in provides two tasks. @@ -142,6 +160,11 @@ Displays the version information in the standard output. For example: [version] tag = [version] lastTag = 0.2.0 [version] dirty = false +[version] versionCode = 0 +[version] major = 0 +[version] minor = 0 +[version] patch = 0 +[version] qualifier = ``` ### `versionFile` @@ -163,6 +186,11 @@ VERSION_SCM=git VERSION_TAG= VERSION_LAST_TAG=0.2.0 VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= ``` This makes this file easy to integrate in a Bash script: @@ -202,7 +230,7 @@ versioning { * present, the type is the branch and the base is empty. * F.e. if you want use tag name instead of branch you may provide something like: */ - releaseParser = { scmInfo, separator = '/' -> -> + releaseParser = { scmInfo, separator = '/' -> List part = scmInfo.tag.split('/') + '' new net.nemerosa.versioning.ReleaseInfo(type: part[0], base: part[1]) } @@ -226,7 +254,6 @@ versioning { * the tags in Git. */ lastTagPattern = /(\d+)$/ -*/ } ``` @@ -387,6 +414,83 @@ versioning { } } ``` +### Version number + +Version number computation can be customised by setting some properties in the `versioning` extension. + +```groovy +versioning { + /** + * Digit precision for computing version code. + * + * With a precision of 2, 1.25.3 will become 12503. + * With a precision of 3, 1.25.3 will become 1250003. + */ + int precision = 2 + + /** + * Default number to use when no version number can be extracted from version string. + */ + int defaultNumber = 0 + + /** + * Closure that takes major, minor and patch integers in parameter and is computing versionCode number. + */ + Closure computeVersionCode = { int major, int minor, int patch -> + return (major * 10**(2 * precision)) + (minor * 10**precision) + patch + } + + /** + * Compute version number + * + * Closure that compute VersionNumber from scmInfo, versionReleaseType, versionBranchId, + * versionFull, versionBase and versionDisplay + * + * By default it tries to find this pattern in display : '([0-9]+)[.]([0-9]+)[.]([0-9]+)(.*)$'. + * Version code is computed with this algo : code = group(1) * 10^2precision + group(2) * 10^precision + group(3) + * + * Example : + * + * - with precision = 2 + * + * 1.2.3 -> 10203 + * 10.55.62 -> 105562 + * 20.3.2 -> 200302 + * + * - with precision = 3 + * + * 1.2.3 -> 1002003 + * 10.55.62 -> 100055062 + * 20.3.2 -> 20003002 + **/ + Closure parseVersionNumber = { SCMInfo scmInfo, String versionReleaseType, String versionBranchId, + String versionFull, String versionBase, String versionDisplay -> + // We are specifying all these parameters because we want to leave the choice to the developer + // to use data that's right to him + // Regex explained : + // - 1st group one digit that is major version + // - 2nd group one digit that is minor version + // - It can be followed by a qualifier name + // - 3rd group and last part is one digit that is patch version + Matcher m = (versionDisplay =~ '([0-9]+)[.]([0-9]+).*[.]([0-9]+)(.*)$') + if (m.find()) { + try { + int n1 = Integer.parseInt(m.group(1)) + int n2 = Integer.parseInt(m.group(2)) + int n3 = Integer.parseInt(m.group(3)) + String q = m.group(4) ?: '' + return new VersionNumber(n1, n2, n3, q, computeVersionCode(n1, n2, n3).intValue(), versionDisplay) + } catch (Exception ignore) { + // Should never go here + return new VersionNumber(0, 0, 0, '', defaultNumber, versionDisplay) + } + } else { + return new VersionNumber(0, 0, 0, '', defaultNumber, versionDisplay) + } + } + +} +``` ## Detached and shallow clone support diff --git a/build.gradle b/build.gradle index e256547..3216ffe 100644 --- a/build.gradle +++ b/build.gradle @@ -61,10 +61,10 @@ dependencies { /** * Plug-in definition */ - pluginBundle { website = 'https://github.com/nemerosa/versioning/' vcsUrl = 'https://github.com/nemerosa/versioning/' + description = 'Gradle plug-in that computes version information from the SCM' tags = ['gradle', 'plugin', 'scm', 'git', 'svn', 'version'] } diff --git a/src/main/groovy/net/nemerosa/versioning/ReleaseInfo.groovy b/src/main/groovy/net/nemerosa/versioning/ReleaseInfo.groovy index efca227..fb100e7 100644 --- a/src/main/groovy/net/nemerosa/versioning/ReleaseInfo.groovy +++ b/src/main/groovy/net/nemerosa/versioning/ReleaseInfo.groovy @@ -2,10 +2,32 @@ package net.nemerosa.versioning import groovy.transform.Canonical +/** + * Information about the branch coming from its name. + * + * For instance : + * + * release/2.0 + * type : 'release' + * base : '2.0' + * + * master + * type : 'master' + * base : '' + */ @Canonical class ReleaseInfo { + /** + * Type of branch. + * + * Could be "release", "feature" or what ever has been configured + */ String type + + /** + * Base of release or feature branch. This is what comes after type in branch's name. + */ String base } diff --git a/src/main/groovy/net/nemerosa/versioning/SCMInfoService.groovy b/src/main/groovy/net/nemerosa/versioning/SCMInfoService.groovy index 2108592..b16bb96 100644 --- a/src/main/groovy/net/nemerosa/versioning/SCMInfoService.groovy +++ b/src/main/groovy/net/nemerosa/versioning/SCMInfoService.groovy @@ -4,11 +4,37 @@ import org.gradle.api.Project interface SCMInfoService { + /** + * Get SCM Info + * @param project Gradle's project + * @param extension Plugin data holder + * @return Information got from scm + */ SCMInfo getInfo(Project project, VersioningExtension extension) + /** + * Get last tags + * + * @param project Gradle's project + * @param extension Plugin data holder + * @param tagPattern Tag pattern + * @return List of tags + */ List getLastTags(Project project, VersioningExtension extension, String tagPattern) + /** + * Get base tags + * + * @param project Gradle's project + * @param extension Plugin data holder + * @param base Base of branch in case where name of branch is something/base + * @return List of base tags + */ List getBaseTags(Project project, VersioningExtension extension, String base) + /** + * + * @return Separator used for separating branch type and branch base + */ String getBranchTypeSeparator() } diff --git a/src/main/groovy/net/nemerosa/versioning/VersionInfo.groovy b/src/main/groovy/net/nemerosa/versioning/VersionInfo.groovy index 43297fd..c4a2b0e 100644 --- a/src/main/groovy/net/nemerosa/versioning/VersionInfo.groovy +++ b/src/main/groovy/net/nemerosa/versioning/VersionInfo.groovy @@ -23,5 +23,6 @@ class VersionInfo { String lastTag = null boolean dirty = false boolean shallow = false + VersionNumber versionNumber = null } diff --git a/src/main/groovy/net/nemerosa/versioning/VersionNumber.groovy b/src/main/groovy/net/nemerosa/versioning/VersionNumber.groovy new file mode 100644 index 0000000..f41a901 --- /dev/null +++ b/src/main/groovy/net/nemerosa/versioning/VersionNumber.groovy @@ -0,0 +1,50 @@ +package net.nemerosa.versioning + +/** + * Representation of a version number. + * + * This is generally a combination of three digits with an optional qualifier. + * These digits are major, minor and path numbers. + * + * This representation is one of many interpretation of version number format. It is let to developer's appreciation. + */ +class VersionNumber { + /** + * Major version + */ + final int major + + /** + * Minor version + */ + final int minor + + /** + * Patch version + */ + final int patch + + /** + * Optional qualifier + */ + final String qualifier + + /** + * version code + */ + final int versionCode + + /** + * Original full version string + */ + final String versionString + + VersionNumber(int major, int minor, int patch, String qualifier, int versionCode, String versionString) { + this.major = major + this.minor = minor + this.patch = patch + this.qualifier = qualifier + this.versionCode = versionCode + this.versionString = versionString + } +} diff --git a/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy b/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy index 33e152f..760c7a6 100644 --- a/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy +++ b/src/main/groovy/net/nemerosa/versioning/VersioningExtension.groovy @@ -1,11 +1,14 @@ package net.nemerosa.versioning + import net.nemerosa.versioning.git.GitInfoService import net.nemerosa.versioning.support.DirtyException import net.nemerosa.versioning.svn.SVNInfoService import org.gradle.api.GradleException import org.gradle.api.Project +import java.util.regex.Matcher + class VersioningExtension { /** @@ -151,6 +154,75 @@ class VersioningExtension { */ String lastTagPattern = /(\d+)$/ + /** + * Digit precision for computing version code. + * + * With a precision of 2, 1.25.3 will become 12503. + * With a precision of 3, 1.25.3 will become 1250003. + */ + int precision = 2 + + /** + * Default number to use when no version number can be extracted from version string. + */ + int defaultNumber = 0 + + /** + * Closure that takes major, minor and patch integers in parameter and is computing versionCode number. + */ + Closure computeVersionCode = { int major, int minor, int patch -> + return (major * 10**(2 * precision)) + (minor * 10**precision) + patch + } + + /** + * Compute version number + * + * Closure that compute VersionNumber from scmInfo, versionReleaseType, versionBranchId, + * versionFull, versionBase and versionDisplay + * + * By default it tries to find this pattern in display : '([0-9]+)[.]([0-9]+)[.]([0-9]+)(.*)$'. + * Version code is computed with this algo : code = group(1) * 10^2precision + group(2) * 10^precision + group(3) + * + * Example : + * + * - with precision = 2 + * + * 1.2.3 -> 10203 + * 10.55.62 -> 105562 + * 20.3.2 -> 200302 + * + * - with precision = 3 + * + * 1.2.3 -> 1002003 + * 10.55.62 -> 100055062 + * 20.3.2 -> 20003002 + **/ + Closure parseVersionNumber = { SCMInfo scmInfo, String versionReleaseType, String versionBranchId, + String versionFull, String versionBase, String versionDisplay -> + // We are specifying all these parameters because we want to leave the choice to the developer + // to use data that's right to him + // Regex explained : + // - 1st group one digit that is major version + // - 2nd group one digit that is minor version + // - It can be followed by a qualifier name + // - 3rd group and last part is one digit that is patch version + Matcher m = (versionDisplay =~ '([0-9]+)[.]([0-9]+).*[.]([0-9]+)(.*)$') + if (m.find()) { + try { + int n1 = Integer.parseInt(m.group(1)) + int n2 = Integer.parseInt(m.group(2)) + int n3 = Integer.parseInt(m.group(3)) + String q = m.group(4) ?: '' + return new VersionNumber(n1, n2, n3, q, computeVersionCode(n1, n2, n3).intValue(), versionDisplay) + } catch (Exception ignore) { + // Should never go here + return new VersionNumber(0, 0, 0, '', defaultNumber, versionDisplay) + } + } else { + return new VersionNumber(0, 0, 0, '', defaultNumber, versionDisplay) + } + } + /** * Certificate - accept SSL server certificates from unknown certificate authorities (for SVN only) */ @@ -174,9 +246,10 @@ class VersioningExtension { VersioningExtension(Project project) { this.project = project } -/** - * Gets the computed version information - */ + + /** + * Gets the computed version information + */ VersionInfo getInfo() { if (!info) { info = computeInfo() @@ -247,6 +320,8 @@ class VersioningExtension { } } + VersionNumber versionNumber = parseVersionNumber( + scmInfo, versionReleaseType, versionBranchId, versionFull, versionBase, versionDisplay) // OK new VersionInfo( scm: scm, @@ -262,6 +337,7 @@ class VersioningExtension { lastTag: scmInfo.lastTag, dirty: scmInfo.dirty, shallow: scmInfo.shallow, + versionNumber: versionNumber, ) } @@ -281,6 +357,8 @@ class VersioningExtension { } else { String lastTag String nextTag + //FIXME remove this log after debugging + println "Base tags : $baseTags" if (baseTags.empty) { lastTag = '' nextTag = "${releaseInfo.base}.0" diff --git a/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy b/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy index 7458c11..1fecda6 100644 --- a/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy +++ b/src/main/groovy/net/nemerosa/versioning/tasks/VersionDisplayTask.groovy @@ -22,18 +22,23 @@ class VersionDisplayTask extends DefaultTask { if (info == VersionInfo.NONE) { println "[version] No version can be computed from the SCM." } else { - println "[version] scm = ${info.scm}" - println "[version] branch = ${info.branch}" - println "[version] branchType = ${info.branchType}" - println "[version] branchId = ${info.branchId}" - println "[version] commit = ${info.commit}" - println "[version] full = ${info.full}" - println "[version] base = ${info.base}" - println "[version] build = ${info.build}" - println "[version] display = ${info.display}" - println "[version] tag = ${info.tag ?: ''}" - println "[version] lastTag = ${info.lastTag ?: ''}" - println "[version] dirty = ${info.dirty}" + println "[version] scm = ${info.scm}" + println "[version] branch = ${info.branch}" + println "[version] branchType = ${info.branchType}" + println "[version] branchId = ${info.branchId}" + println "[version] commit = ${info.commit}" + println "[version] full = ${info.full}" + println "[version] base = ${info.base}" + println "[version] build = ${info.build}" + println "[version] display = ${info.display}" + println "[version] tag = ${info.tag ?: ''}" + println "[version] lastTag = ${info.lastTag ?: ''}" + println "[version] dirty = ${info.dirty}" + println "[version] versionCode = ${info.versionNumber.versionCode}" + println "[version] major = ${info.versionNumber.major}" + println "[version] minor = ${info.versionNumber.minor}" + println "[version] patch = ${info.versionNumber.patch}" + println "[version] qualifier = ${info.versionNumber.qualifier}" } } diff --git a/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy b/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy index 0843eb1..d56f3d7 100644 --- a/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy +++ b/src/main/groovy/net/nemerosa/versioning/tasks/VersionFileTask.groovy @@ -47,6 +47,11 @@ ${prefix}SCM=${info.scm} ${prefix}TAG=${info.tag ?: ''} ${prefix}LAST_TAG=${info.lastTag ?: ''} ${prefix}DIRTY=${info.dirty} +${prefix}VERSIONCODE=${info.versionNumber.versionCode} +${prefix}MAJOR=${info.versionNumber.major} +${prefix}MINOR=${info.versionNumber.minor} +${prefix}PATCH=${info.versionNumber.patch} +${prefix}QUALIFIER=${info.versionNumber.qualifier} """ } diff --git a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy index 9020eca..1a5b96d 100644 --- a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildFalseTest.groovy @@ -36,6 +36,7 @@ class GitVersionReleaseBuildFalseTest { assert info.scm == 'n/a' assert info.tag == null assert !info.dirty + assert info.versionNumber == null } @Test @@ -67,6 +68,7 @@ class GitVersionReleaseBuildFalseTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -118,6 +120,7 @@ class GitVersionReleaseBuildFalseTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -164,6 +167,7 @@ class GitVersionReleaseBuildFalseTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -209,6 +213,7 @@ class GitVersionReleaseBuildFalseTest { assert info.tag == null assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -275,6 +280,11 @@ VERSION_SCM=git VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ as String } finally { repo.close() @@ -319,6 +329,11 @@ CUSTOM_SCM=git CUSTOM_TAG= CUSTOM_LAST_TAG= CUSTOM_DIRTY=false +CUSTOM_VERSIONCODE=0 +CUSTOM_MAJOR=0 +CUSTOM_MINOR=0 +CUSTOM_PATCH=0 +CUSTOM_QUALIFIER= """ as String } finally { repo.close() @@ -363,6 +378,11 @@ VERSION_SCM=git VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ as String } finally { repo.close() @@ -400,6 +420,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -438,6 +459,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -476,6 +498,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -515,6 +538,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -553,6 +577,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -593,6 +618,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -630,6 +656,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -668,6 +695,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -707,6 +735,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -750,6 +779,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30002 } finally { repo.close() @@ -793,6 +823,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30011 } finally { repo.close() @@ -836,6 +867,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30021 } finally { repo.close() @@ -879,6 +911,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -918,6 +951,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20011 } finally { repo.close() @@ -957,6 +991,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -995,6 +1030,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1032,6 +1068,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1071,6 +1108,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1112,6 +1150,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1152,6 +1191,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1192,6 +1232,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1233,6 +1274,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1273,6 +1315,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1313,6 +1356,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1353,7 +1397,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty - + assert info.versionNumber.versionCode == 0 } finally { repo.close() } @@ -1396,6 +1440,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1438,6 +1483,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1479,6 +1525,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1522,6 +1569,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1571,6 +1619,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -1615,6 +1664,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert !info.shallow + assert info.versionNumber.versionCode == 20004 } finally { repo.close() @@ -1663,6 +1713,7 @@ VERSION_DIRTY=false assert info.tag == '2.0.2' assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -1710,6 +1761,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1753,6 +1805,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == 'release/v2.0' assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1822,6 +1875,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1864,6 +1918,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert !info.shallow + assert info.versionNumber.versionCode == 20003 } finally { repo.close() diff --git a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy index a5c0ca2..7253585 100644 --- a/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/git/GitVersionReleaseBuildTrueTest.groovy @@ -36,6 +36,7 @@ class GitVersionReleaseBuildTrueTest { assert info.scm == 'n/a' assert info.tag == null assert !info.dirty + assert info.versionNumber == null } @Test @@ -67,6 +68,7 @@ class GitVersionReleaseBuildTrueTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -118,6 +120,7 @@ class GitVersionReleaseBuildTrueTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -164,6 +167,7 @@ class GitVersionReleaseBuildTrueTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -209,6 +213,7 @@ class GitVersionReleaseBuildTrueTest { assert info.tag == null assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -275,6 +280,11 @@ VERSION_SCM=git VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ as String } finally { repo.close() @@ -319,6 +329,11 @@ CUSTOM_SCM=git CUSTOM_TAG= CUSTOM_LAST_TAG= CUSTOM_DIRTY=false +CUSTOM_VERSIONCODE=0 +CUSTOM_MAJOR=0 +CUSTOM_MINOR=0 +CUSTOM_PATCH=0 +CUSTOM_QUALIFIER= """ as String } finally { repo.close() @@ -363,6 +378,11 @@ VERSION_SCM=git VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ as String } finally { repo.close() @@ -400,6 +420,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -438,6 +459,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -476,6 +498,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -515,6 +538,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -553,6 +577,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -593,6 +618,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -630,6 +656,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -668,6 +695,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -707,6 +735,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -750,6 +779,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30002 } finally { repo.close() @@ -793,6 +823,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30011 } finally { repo.close() @@ -836,6 +867,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30021 } finally { repo.close() @@ -879,6 +911,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -918,6 +951,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20011 } finally { repo.close() @@ -957,6 +991,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -995,6 +1030,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1032,6 +1068,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1071,6 +1108,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1112,6 +1150,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1152,6 +1191,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1192,6 +1232,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20002 } finally { repo.close() @@ -1233,6 +1274,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20002 } finally { repo.close() @@ -1273,6 +1315,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1313,6 +1356,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1353,6 +1397,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1396,6 +1441,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1438,6 +1484,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1479,6 +1526,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1522,6 +1570,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1571,6 +1620,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -1615,6 +1665,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert !info.shallow + assert info.versionNumber.versionCode == 20004 } finally { repo.close() @@ -1663,6 +1714,7 @@ VERSION_DIRTY=false assert info.tag == '2.0.2' assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 20002 } finally { detached.deleteDir() @@ -1710,6 +1762,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1753,6 +1806,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == 'release/v2.0' assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1822,6 +1876,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1864,6 +1919,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert !info.shallow + assert info.versionNumber.versionCode == 20003 } finally { repo.close() diff --git a/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy b/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy index 5a87d03..3f6ad90 100644 --- a/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/git/GitVersionTest.groovy @@ -3,6 +3,7 @@ package net.nemerosa.versioning.git import net.nemerosa.versioning.ReleaseInfo import net.nemerosa.versioning.SCMInfo import net.nemerosa.versioning.VersionInfo +import net.nemerosa.versioning.VersionNumber import net.nemerosa.versioning.VersioningPlugin import net.nemerosa.versioning.support.DirtyException import net.nemerosa.versioning.tasks.VersionDisplayTask @@ -11,6 +12,8 @@ import org.gradle.api.DefaultTask import org.gradle.testfixtures.ProjectBuilder import org.junit.Test +import java.util.regex.Matcher + class GitVersionTest { @Test @@ -33,6 +36,7 @@ class GitVersionTest { assert info.scm == 'n/a' assert info.tag == null assert !info.dirty + assert info.versionNumber == null } @Test @@ -61,6 +65,7 @@ class GitVersionTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -109,6 +114,7 @@ class GitVersionTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -152,6 +158,7 @@ class GitVersionTest { assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -194,6 +201,7 @@ class GitVersionTest { assert info.tag == null assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -254,6 +262,11 @@ VERSION_SCM=git VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ as String } finally { repo.close() @@ -295,6 +308,11 @@ CUSTOM_SCM=git CUSTOM_TAG= CUSTOM_LAST_TAG= CUSTOM_DIRTY=false +CUSTOM_VERSIONCODE=0 +CUSTOM_MAJOR=0 +CUSTOM_MINOR=0 +CUSTOM_PATCH=0 +CUSTOM_QUALIFIER= """ as String } finally { repo.close() @@ -336,6 +354,11 @@ VERSION_SCM=git VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ as String } finally { repo.close() @@ -370,6 +393,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -407,6 +431,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -444,6 +469,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -482,6 +508,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -519,6 +546,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -558,6 +586,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -592,6 +621,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -627,6 +657,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -663,6 +694,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -703,6 +735,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30002 } finally { repo.close() @@ -743,6 +776,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30011 } finally { repo.close() @@ -783,6 +817,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 30021 } finally { repo.close() @@ -823,6 +858,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -859,6 +895,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20011 } finally { repo.close() @@ -897,6 +934,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -934,6 +972,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -970,6 +1009,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1008,6 +1048,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1048,6 +1089,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1087,6 +1129,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1126,6 +1169,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20002 } finally { repo.close() @@ -1166,6 +1210,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20002 } finally { repo.close() @@ -1205,6 +1250,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == '2.0.2' assert !info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1242,6 +1288,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1279,6 +1326,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1319,6 +1367,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1360,6 +1409,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1398,6 +1448,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1440,6 +1491,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1486,6 +1538,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 0 } finally { detached.deleteDir() @@ -1527,6 +1580,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert !info.shallow + assert info.versionNumber.versionCode == 20004 } finally { repo.close() @@ -1572,6 +1626,7 @@ VERSION_DIRTY=false assert info.tag == '2.0.2' assert !info.dirty assert info.shallow + assert info.versionNumber.versionCode == 20002 } finally { detached.deleteDir() @@ -1602,6 +1657,10 @@ VERSION_DIRTY=false def project = ProjectBuilder.builder().withProjectDir(repo.dir).build() new VersioningPlugin().apply(project) + project.versioning { + displayMode = 'full' + releaseMode = 'tag' + } project.versioning { dirty = { version -> "${version}-DONOTUSE" } } @@ -1618,6 +1677,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert info.dirty + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1660,6 +1720,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == 'release/v2.0' assert !info.dirty + assert info.versionNumber.versionCode == 20000 } finally { repo.close() } @@ -1727,6 +1788,7 @@ VERSION_DIRTY=false assert info.scm == 'git' assert info.tag == null assert !info.dirty + assert info.versionNumber.versionCode == 0 } finally { repo.close() @@ -1768,6 +1830,7 @@ VERSION_DIRTY=false assert info.tag == null assert !info.dirty assert !info.shallow + assert info.versionNumber.versionCode == 20003 } finally { repo.close() @@ -1952,4 +2015,88 @@ VERSION_DIRTY=false repo.close() } } + + @Test + void 'Git release branch: with precision = 3'() { + GitRepo repo = new GitRepo() + try { + // Git initialisation + repo.with { + (1..4).each { commit it } + branch 'release/2.0' + commit 5 + tag '2.0.10' + commit 6 + } + def head = repo.commitLookup('Commit 6') + def headAbbreviated = repo.commitLookup('Commit 6', true) + + def project = ProjectBuilder.builder().withProjectDir(repo.dir).build() + new VersioningPlugin().apply(project) + project.versioning { + precision = 3 + } + VersionInfo info = project.versioning.info as VersionInfo + assert info != null + assert info.build == headAbbreviated + assert info.branch == 'release/2.0' + assert info.base == '2.0' + assert info.branchId == 'release-2.0' + assert info.branchType == 'release' + assert info.commit == head + assert info.display == '2.0.11' + assert info.full == "release-2.0-${headAbbreviated}" as String + assert info.scm == 'git' + assert info.tag == null + assert !info.dirty + assert info.versionNumber.versionCode == 2000011 + + } finally { + repo.close() + } + } + + + @Test + void 'Git release branch with custom versionNumber computing'() { + GitRepo repo = new GitRepo() + try { + // Git initialisation + repo.with { + (1..4).each { commit it } + branch 'release/2.0' + commit 5 + tag '2.0.10' + } + def head = repo.commitLookup('Commit 5') + def headAbbreviated = repo.commitLookup('Commit 5', true) + + def project = ProjectBuilder.builder().withProjectDir(repo.dir).build() + new VersioningPlugin().apply(project) + project.versioning { + parseVersionNumber = { SCMInfo scmInfo, String versionReleaseType, String versionBranchId, + String versionFull, String versionBase, String versionDisplay -> + + return new VersionNumber(1, 2, 3, 'toto', 4, 'tata') + } + } + VersionInfo info = project.versioning.info as VersionInfo + assert info != null + assert info.build == headAbbreviated + assert info.branch == 'release/2.0' + assert info.base == '2.0' + assert info.branchId == 'release-2.0' + assert info.branchType == 'release' + assert info.commit == head + assert info.display == '2.0.11' + assert info.full == "release-2.0-${headAbbreviated}" as String + assert info.scm == 'git' + assert info.tag == '2.0.10' + assert !info.dirty + assert info.versionNumber.versionCode == 4 + + } finally { + repo.close() + } + } } diff --git a/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy b/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy index 35fcd39..165ac36 100644 --- a/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy +++ b/src/test/groovy/net/nemerosa/versioning/svn/SVNVersionTest.groovy @@ -8,6 +8,7 @@ import org.gradle.api.DefaultTask import org.gradle.testfixtures.ProjectBuilder import org.junit.After import org.junit.Before +import org.junit.Ignore import org.junit.Test import java.util.concurrent.atomic.AtomicInteger @@ -134,6 +135,11 @@ VERSION_SCM=svn VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ } @@ -174,6 +180,11 @@ CUSTOM_SCM=svn CUSTOM_TAG= CUSTOM_LAST_TAG= CUSTOM_DIRTY=false +CUSTOM_VERSIONCODE=0 +CUSTOM_MAJOR=0 +CUSTOM_MINOR=0 +CUSTOM_PATCH=0 +CUSTOM_QUALIFIER= """ } @@ -214,6 +225,11 @@ VERSION_SCM=svn VERSION_TAG= VERSION_LAST_TAG= VERSION_DIRTY=false +VERSION_VERSIONCODE=0 +VERSION_MAJOR=0 +VERSION_MINOR=0 +VERSION_PATCH=0 +VERSION_QUALIFIER= """ }