/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    https://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

plugins {
    id 'java-library'
    id 'org.apache.grails.gradle.grails-gsp'
    id 'org.apache.grails.gradle.grails-plugin'
    id 'cloud.wondrify.asset-pipeline'
}

group = 'org.apache.grails'

ext {
    publishArtifactId = 'grails-spring-security-ui'
    pomTitle = 'Grails Spring Security UI'
    pomDescription = 'The Spring Security UI plugin provides CRUD screens and other user management workflows.'
    pomDevelopers = [burtbeckwith: 'Burt Beckwith']
}

dependencies {

    implementation platform("org.apache.grails:grails-bom:$grailsVersion")

    // Must be on the compileClasspath of consuming applications to
    // enable compilation of AbstractS2UiDomainController subclasses.
    compileOnlyApi 'org.apache.grails:grails-converters'

    implementation project(':core-plugin')
    implementation 'org.apache.grails:grails-controllers'
    implementation 'org.apache.grails:grails-converters'
    implementation 'org.apache.grails:grails-gsp'
    implementation 'org.apache.grails:grails-layout'
    implementation 'org.springframework.security:spring-security-core'
    implementation 'org.springframework.security:spring-security-web'

    // 3rd party client-side assets bundled in webjars
    implementation 'org.webjars:datatables:1.10.25'
    implementation 'org.webjars:jquery:2.1.4'
    implementation 'org.webjars:jquery-form:3.51'
    implementation 'org.webjars:jquery-ui:1.10.3'
    implementation 'org.webjars:jquery-ui-themes:1.10.3'
    implementation 'org.webjars.bower:bgiframe:3.0.1'
    implementation 'org.webjars.bower:jgrowl:1.4.6'

    compileOnly 'org.apache.grails:grails-core' // Provided, as this is a Grails plugin
    compileOnly 'org.apache.grails:grails-services'
    compileOnly 'org.apache.grails:grails-domain-class'

    runtimeOnly 'cloud.wondrify:asset-pipeline-grails'

    testImplementation 'org.apache.grails:grails-testing-support-web'
    testImplementation 'org.spockframework:spock-core'
}

tasks.register('copyGspIntoTemplates', Copy) {
    from(layout.projectDirectory.dir('grails-app/views'))
    into(layout.projectDirectory.dir('src/main/templates/views'))
    dependsOn('copyTemplates', 'processResources')
}

tasks.register('removeGspFromTemplates', Delete) {
    delete(layout.projectDirectory.dir('src/main/templates/views'))
}

tasks.named('compileAstJava') {
    dependsOn('copyGspIntoTemplates')
}

assets {
    packagePlugin = true
    excludes = ['webjars/**']
}

apply {
    from rootProject.layout.projectDirectory.file('gradle/plugin-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/groovydoc-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/reproducible-config.gradle')
}