description = "Apereo CAS Management Web Application"

apply plugin: "war"

project.ext["mainClassName"] = "org.apereo.cas.mgmt.web.CasManagementWebApplication"

sourceSets {
    main {
        resources {
            srcDirs "${project.buildDir}/generated-src/main/resources"
        }
    }
    /**
     * Make resources become reloadable.
     * Application’s static resources are loaded from their source location.
     */
    bootRun {
        resources {
            srcDirs new File(project(":webapp").getProjectDir(), "resources")
        }
    }
}
apply from: rootProject.file("gradle/springboot.gradle")

if (!Boolean.getBoolean("skipClientBuild")) {
    if (Boolean.getBoolean("buildDev")) {
        processResources.dependsOn(':webapp:cas-mgmt-webapp-workspace:buildClientDev')
    } else {
        processResources.dependsOn(':webapp:cas-mgmt-webapp-workspace:buildClient')
    }
}

dependencies {

    implementation "org.apereo.cas:cas-server-core-configuration:$casVersion"
    
    implementation project(":config:cas-mgmt-config-audit")
    implementation project(":config:cas-mgmt-config-authentication")
    implementation project(":config:cas-mgmt-config-authz")
    implementation project(":config:cas-mgmt-config-core")
    implementation project(":config:cas-mgmt-config-search")
    implementation project(":config:cas-mgmt-config-register")
    implementation project(":config:cas-mgmt-config-version-control")
    implementation project(":config:cas-mgmt-config-saml")
    implementation project(":config:cas-mgmt-config-oauth")
    implementation project(":webapp:cas-mgmt-webapp-config")
    implementation project(":webapp:cas-mgmt-webapp-init")
    implementation project(":config:cas-mgmt-config-delegated")
    implementation project(":config:cas-mgmt-config-dashboard")
    implementation project(":config:cas-mgmt-config-submissions")
}

/**
 * Share the resources directory outside the content root of the project
 * for all webapp projects in a dynamic fashion, and do it only when the taskGraph is ready.
 * 
 * This allows the IDE, specially Intellij IDEA, to ignore the resources
 * directory for webapp projects, allowing it to be shared across modules.
 * While the directory isn't recognizes as a "resources" directory by the IDE,
 * it is still a valid legitimate resources directory recognized by Gradle.
 * Note that bootRun also includes the same directory for resources, allowing
 * for automatic updates to static resources, etc.
 */
gradle.taskGraph.whenReady {taskGraph ->
    def resourcesDir = "${project.projectDir}/../resources"
    logger.info("Adding resources directory ${resourcesDir} to project ${project.name}")
    
    sourceSets {
        main {
            resources {
                srcDir resourcesDir
            }
        }
    }
    
}
