Use try/catch with logging for version number

This commit is contained in:
Tim Mutton 2017-04-06 19:53:25 +10:00
parent c8d66fa246
commit 1fe1e11e0e
1 changed files with 9 additions and 8 deletions

View File

@ -1,5 +1,3 @@
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
@ -96,12 +94,15 @@ dependencies {
} }
def getVersion() { def getVersion() {
String result def versionNumber = '0.0'
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
result = 'cmd /c git describe --always --long'.execute([], project.rootDir).text try {
} else { versionNumber = 'git describe --always --long'.execute([], project.rootDir).text
result = 'git describe --always --long'.execute([], project.rootDir).text .trim()
.replaceAll(/(-0)?-[^-]+$/, "")
} catch (Exception e) {
logger.error('Cannot find git, defaulting to dummy version number')
} }
return result.trim().replaceAll(/(-0)?-[^-]+$/, "") return versionNumber
} }