def validateJavaHome() {
    def javaHome = hasProperty('org.gradle.java.home') ? getProperty('org.gradle.java.home') : System.getenv('JAVA_HOME')
    if (javaHome == null || !file(javaHome).exists()) {
        throw new GradleException("JAVA_HOME is not defined or is pointing to a non-existing directory: ${javaHome}")
    }
    return javaHome
}

def validateGraalvmHome() {
    def graalvmHome = System.getenv('GRAALVM_HOME')
    if (graalvmHome == null || !file(graalvmHome).exists()) {
        throw new GradleException("GRAALVM_HOME is not defined or is pointing to a non-existing directory: ${graalvmHome}")
    }
    return graalvmHome
}

def validateJavafxStaticSdk() {
    def javafxStaticSdk = hasProperty('javafx.static.sdk') ? getProperty('javafx.static.sdk') : System.getenv('JAVAFX_STATIC_SDK')
    if (javafxStaticSdk != null && !file(javafxStaticSdk).exists()) {
        throw new GradleException("JAVAFX_STATIC_SDK is pointing to a non-existing directory: ${javafxStaticSdk}")
    }
    return javafxStaticSdk
}

subprojects {
    apply plugin: 'application'

    ext.substrateVersion = "0.0.3"
    def propFile = file("$project.rootDir/../gradle.properties")
    if (propFile.canRead()) {
        def props = new Properties()
        props.load(new FileInputStream(propFile))
        if (props.containsKey('version')) {
            ext.substrateVersion = props['version']
        }
    }

    sourceCompatibility = 11
    targetCompatibility = 11
}
