plugins {
    id 'java-library'
}

java {
    sourceCompatibility = 21
    targetCompatibility = 21
}

repositories {
    mavenCentral()
    flatDir {
        // Raspberry Pi 32-bit library
        dirs project(':').projectDir.absolutePath + "/swt-lib"
    }
}

dependencies {
    implementation project(':lib:ac-api')

    implementation "net.sf.applecommander:applesingle-api:$asVersion"
    implementation "net.sf.applecommander:bastools-api:$btVersion"

    testImplementation platform("org.junit:junit-bom:$junitVersion")
    testImplementation 'org.junit.jupiter:junit-jupiter'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    testImplementation "org.apache.commons:commons-lang3:$commonsLang3Version"
}

test {
    useJUnitPlatform()
    String osName = System.getProperty('os.name').toLowerCase().split()[0]
    String osArch = System.getProperty('os.arch').toLowerCase().split()[0]
    switch (osArch) {
        case 'amd64':
            osArch = "x86_64"
            break
        case 'arm':
            swtVersion = "$piSwtVersion"
            break
    }
    String swtDependency
    switch (osName) {
        case 'windows':
            swtDependency = "org.eclipse.platform:org.eclipse.swt.win32.win32.${osArch}:$swtVersion"
            break
        case 'linux':
            swtDependency = "org.eclipse.platform:org.eclipse.swt.gtk.linux.${osArch}:$swtVersion"
            break
        case 'mac':
            swtDependency = "org.eclipse.platform:org.eclipse.swt.cocoa.macosx.${osArch}:$swtVersion"
            break
        default:
            throw new Exception('Unknown OS')
    }
    dependencies {
        compileOnly("$swtDependency") {
            exclude group: "org.eclipse.platform", module: "org.eclipse.swt"
        }
        testImplementation("$swtDependency") {
            exclude group: "org.eclipse.platform", module: "org.eclipse.swt"
        }
    }
}

jar {
    archiveBaseName = 'AppleCommander'
    archiveAppendix = 'swt-common'
}
