apply plugin: 'com.github.ben-manes.versions'

buildscript {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

static Properties loadProperties(File propsFile) {
    new Properties().with { props ->
        propsFile.withInputStream { stream ->
            props.load(stream)
        }
        props
    }
}

/**
 * @return an Array containing the [versionNameString, versionCodeInt]
 */
static Object[] screengrabVersion(File propsFile) {
    Properties versionProps = loadProperties(propsFile)

    int versionMajor = (versionProps['major'] ?: 0) as int
    int versionMinor = (versionProps['minor'] ?: 0) as int
    int versionPatch = (versionProps['patch'] ?: 0) as int

    String versionNameString = [versionMajor, versionMinor, versionPatch].join('.')
    int versionCodeInt = (1000000 * versionMajor) + (10000 * versionMinor) + (100 * versionPatch)

    [versionNameString, versionCodeInt]
}