plugins {
    id 'com.github.johnrengelman.shadow' version '8.1.1'
    id 'java'
    id 'application'
}

group = 'com.annimon'
version = versions.project

ext.mainClassName = 'com.annimon.ownlang.Main'
application {
    mainClass = project.mainClassName
}

jar {
    manifest {
        attributes 'Main-Class': project.mainClassName
    }
}

dependencies {
    implementation project(":ownlang-core")
    implementation project(":ownlang-parser")
    implementation project(":ownlang-utils")
    implementation project(":modules:main")

    testImplementation platform("org.junit:junit-bom:${versions.junit}")
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
    useJUnitPlatform()
}

def ownlangExec = tasks.register('ownlangExec', JavaExec) {
    dependsOn classes
    mainClass = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
}

tasks.register('runProgram') {
    group = "application"
    description = "Run sample program"
    doFirst {
        ownlangExec.configure {
            args '-f ../program.own'.split(' ')
        }
    }
    finalizedBy ownlangExec
}

tasks.register('runOptimizing') {
    group = "application"
    description = "Run sample program with optimizations and measurements"
    doFirst {
        ownlangExec.configure {
            args '-o 9 -m -a -f ../program.own'.split(' ')
        }
    }
    finalizedBy ownlangExec
}

tasks.register('runOptimizationDumper', JavaExec) {
    group = "application"
    description = "Run optmizer and dump results"
    dependsOn classes
    mainClass = 'com.annimon.ownlang.utils.OptimizationDumper'
    classpath = sourceSets.main.runtimeClasspath
    args '../program.own'
}
