plugins {
    id "io.codearte.nexus-staging" version "0.30.0"
}

def getArchName() {
    var arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT)
    if (arch == 'amd64' || arch == 'x86_64') {
        return 'x86_64'
    }

    if (arch == 'arm' || arch == 'aarch64') {
        return 'arm64'
    }

    if (arch == 'x86') {
        return 'x86'
    }

    return arch
}

project.ext {
    ci = System.getenv('CI') != null
    os = org.gradle.internal.os.OperatingSystem.current()
    allExtensions = Arrays.stream(file("$rootDir/ext").list())
            .filter(s -> !s.equals('csv') && !s.equals('office') && !s.equals('pdx') && !s.equals('jackson') && !s.equals('collections'))
            .map(l -> project(":$l")).toList()
    fullVersion = file("$rootDir/private_files.txt").exists()
    arch = getArchName()
    privateExtensions = file("$rootDir/private_extensions.txt").exists() ? file("$rootDir/private_extensions.txt").readLines() : []
    isFullRelease = System.getenv('RELEASE') != null && Boolean.parseBoolean(System.getenv('RELEASE'))
    isStage = System.getenv('STAGE') != null && Boolean.parseBoolean(System.getenv('STAGE'))
    versionString = file('version').text + (isFullRelease || isStage ? '' : '-SNAPSHOT')
    canonicalVersionString = file('version').text
    buildId = UUID.nameUUIDFromBytes(versionString.getBytes())
    obfuscate = true
}
