plugins {
    id "com.vanniktech.maven.publish" version "0.34.0"
}
apply plugin: 'com.android.library'
apply plugin: "de.mannodermaus.android-junit5"
apply plugin: 'jacoco'

def junit_version = '6.0.0'

System.setProperty("line.separator", "\n")
Properties versionProps = new Properties()
def versionPropsFile = file('../app/version.properties')
if (versionPropsFile.exists()) {
    versionProps.load(new FileInputStream(versionPropsFile))
}
int vcode = Integer.parseInt((versionProps['VERSION_CODE'] == null || versionProps['VERSION_CODE'].startsWith('$')) ? String.valueOf((int) ((System.currentTimeMillis() / 1000 / 60) - 26_797_800)) : versionProps['VERSION_CODE'])
String vname = (versionProps['VERSION_NAME'] == null || versionProps['VERSION_NAME'].startsWith('$')) ? '3.0.0-dev' : versionProps['VERSION_NAME']

jacoco {
    toolVersion = "0.8.12"
}

tasks.register("unitTestCoverageReport", JacocoReport) {
    group = "Coverage"
    dependsOn tasks.testDebugUnitTest
    reports {
        html.required = true
        xml.required = true
    }
    executionData.from = layout.buildDirectory.dir("outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec")
    classDirectories.from = layout.buildDirectory.dir("intermediates/javac/debug/compileDebugJavaWithJavac/classes")
    sourceDirectories.from = layout.projectDirectory.dir("src/main/java")
}

android {
    compileSdkVersion(36)

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 36

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
        buildConfigField 'int', 'VERSION_CODE', "${vcode}"
        buildConfigField 'String', 'VERSION_NAME', "\"${vname}\""
    }

    buildTypes {
        debug {
            enableUnitTestCoverage true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
    namespace 'com.github.frimtec.android.securesmsproxyapi'
}

tasks.register('sourceJar', Jar) {
    from android.sourceSets.main.java.srcDirs
}

mavenPublishing {
    publishToMavenCentral(true)
    signAllPublications()
    coordinates("com.github.frimtec", "secure-sms-proxy-api", vname)
    pom {
        name = 'Secure SMS Proxy API'
        description = 'API to integrate S2MSP (Secure SMS Proxy) into an android application.'
        url = 'https://github.com/frimtec/secure-sms-proxy'
        licenses {
            license {
                name = 'The Apache License, Version 2.0'
                url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
            }
        }
        developers {
            developer {
                id = 'frimtec'
                name = 'Markus Friedli'
                email = 'frimtec@gmx.ch'
                url = 'https://github.com/frimtec'
            }
        }
        scm {
            connection = 'scm:git:git@github.com:frimtec/secure-sms-proxy'
            developerConnection = 'scm:git:git@github.com:frimtec/secure-sms-proxy'
            url = 'https://github.com/frimtec/secure-sms-proxy'
        }
        issueManagement {
            system = 'github'
            url = 'https://github.com/frimtec/secure-sms-proxy/issues'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.7.1'
    implementation 'com.vdurmont:semver4j:3.1.0'
    testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
    testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
    testImplementation "org.assertj:assertj-core:3.27.6"
    testImplementation 'org.json:json:20250517'
    testImplementation "org.mockito:mockito-core:5.20.0"
    androidTestImplementation 'androidx.test:runner:1.7.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
}

