repositories {
    mavenCentral()
}

def target = System.getProperty("substrate.target")

configurations {
    substrate
}

dependencies {
    substrate "com.gluonhq:substrate:$substrateVersion"
}

mainClassName = "com.gluonhq.substrate.test.Main"

task runScript(type: Exec) {
    def javaHome = validateJavaHome()
    def graalvmHome = validateGraalvmHome()

    def skipsigning = System.getProperty("skipsigning")
    def expected = System.getProperty("expected")
    def consoleProcessLog = System.getProperty("consoleProcessLog")

    def argsList = ["${javaHome}/bin/java", '-cp', "${project.configurations.substrate.asPath}",
                   "-Dimagecp=${project.sourceSets.main.runtimeClasspath.asPath}",
                   "-Dgraalvm=${graalvmHome}"]
    if (target != null) {
        argsList += ["-DtargetProfile=$target"]
    }
    if (skipsigning != null) {
        argsList += ["-Dskipsigning=$skipsigning"]
    }
    if (expected != null) {
        argsList += ["-Dexpected=$expected"]
    }
    if (consoleProcessLog != null) {
        argsList += ["-DconsoleProcessLog=$consoleProcessLog", "-Dverbose=true"]
    }
    argsList += ["-Dmainclass=$mainClassName", 'com.gluonhq.substrate.SubstrateDispatcher']
    commandLine argsList
}
