/*
 * Copyright 2015-2017 Hayai Software
 * Copyright 2018 The KeikaiLauncher Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
 * either express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */
plugins {
    id 'com.android.application'
    id 'pl.allegro.tech.build.axion-release' version '1.8.1'
}

scmVersion {
    tag {
        prefix = ''
    }
}

/**
 * Takes version {@code major.minor.patch[-suffix]} and returns numeric versionCode based on it
 * Example: {@code 1.2.3-SNAPSHOT} will return {@code 1002003}
 */
static int versionCode(String versionName) {
    def matcher = (versionName =~ /(\d+)\.(\d+)\.(\d+).*/)
    return matcher.matches() ?
            matcher.collect { version, major, minor, patch ->
                major.toInteger() * 10000 + minor.toInteger() * 100 + patch.toInteger()
            }.head() :
            -1
}

def androidVersion = [
    name: scmVersion.version,
    code: versionCode(scmVersion.version),
]

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId 'com.anpmech.launcher'
        minSdkVersion 15
        targetSdkVersion 28
        versionName androidVersion.name
        versionCode androidVersion.code
    }
    lintOptions {
        abortOnError false
    }
    buildTypes {
        all {
            buildConfigField("String", "GITHUB_USER", "\"KeikaiLauncher\"")
            buildConfigField("String", "GITHUB_PROJECT", "\"KeikaiLauncher\"")
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.txt'
        }
        debug {
            versionNameSuffix "-debug"
        }
    }
    dependencies {
        implementation 'com.android.support:support-annotations:28.0.0'
    }
}

dependencies {
}
