buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.wisepersist:gwt-gradle-plugin:1.0.13'
        classpath 'org.akhikhl.gretty:gretty:2.0.0'
    }
}

apply plugin: 'gwt'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'

sourceSets {
    main.java.srcDirs = ['src']
}

dependencies {
    providedCompile project(':vtm-web')
    providedCompile 'org.timepedia.exporter:gwtexporter:2.5.1'
    providedCompile 'ru.finam:slf4j-gwt:1.7.7.1'
}

// explicit dependencies for org.gradle.configureondemand=true
evaluationDependsOn(':vtm')
evaluationDependsOn(':vtm-themes')
evaluationDependsOn(':vtm-gdx')
evaluationDependsOn(':vtm-web')

gwt {
    gwtVersion = project.ext.gwtVersion
    modules 'org.oscim.web.VtmWebJs'

    minHeapSize = "512M"
    maxHeapSize = "2048M"

    superDev {
        noPrecompile = true
    }
    compiler {
        //enableClosureCompiler = false // activates -XenableClosureCompiler
        disableClassMetadata = true // activates -XdisableClassMetadata
        disableCastChecking = true // activates -XdisableCastChecking
    }

    src += files(sourceSets.main.java.srcDirs)
    src += files(project(':vtm').sourceSets.main.allJava.srcDirs)
    src += files(project(':vtm-themes').sourceSets.main.allJava.srcDirs)
    src += files(project(':vtm-themes').sourceSets.main.resources.srcDirs)
    src += files(project(':vtm-gdx').sourceSets.main.allJava.srcDirs)
    src += files(project(':vtm-web').sourceSets.main.allJava.srcDirs)
}

farm {
    webapp draftWar.archivePath, contextPath: "/$name"
}

project.afterEvaluate {
    farmRun.dependsOn draftWar
}

task copyThemeAssets(type: Copy) {
    from "$rootDir/vtm-themes/resources/assets"
    into "assets"
    include '**/*'
}

task copyVtmAssets(type: Copy) {
    from "$rootDir/vtm/resources/assets"
    into "assets"
    include '**/*'
}

task copyWarSources(type: Copy) {
    from 'war/index.html'
    from 'war/default.css'
    from 'war/map.js'
    into "src/main/webapp"
    //include '**/*'
}

tasks.withType(JavaCompile) { compileTask ->
    compileTask.dependsOn copyThemeAssets
    compileTask.dependsOn copyVtmAssets
    compileTask.dependsOn copyWarSources
}

clean {
    delete "assets"
    delete "war/WEB-INF"
}
