/*
 *  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
 *
 *    http://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 'groovy'
    id 'java-library'
    id 'codenarc'
    id 'geb.base'
    id 'org.nosphere.apache.rat'
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(11)
    }
}

configurations {
    groovy

    api.extendsFrom groovy
    codenarc.extendsFrom groovy
}

codenarc.configFile = rootProject.file('gradle/codenarc/rulesets.groovy')

def codenarcTasks = tasks.withType(CodeNarc)

tasks.register('codenarc') {
    dependsOn codenarcTasks
}

codenarcTasks.configureEach {
    exclude 'GebConfig*.groovy'
}

tasks.withType(GroovyCompile).configureEach {
    groovyOptions.forkOptions.memoryMaximumSize = '256m'
    groovyOptions.parameters = true
}

tasks.withType(Test).configureEach {
    shouldRunAfter codenarcTasks
}

tasks.named('rat') {
    excludes = [
        '**/build/**',
        '**/.gradle/**',
        'out/**', '*.ipr', '**/*.iml', '*.iws', '.idea/**', // Intellij files
        '**/src/main/resources/public', // Site Only
        '**/public/robots.txt', // Doesn't support comments
        '**/public/css/*.css', // site only
        '**/public/fonts/*.svg', // site only
        '**/public/fonts/*.ttf', // site only
        '**/public/fonts/*.woff', // site only
        '**/public/fonts/*.woff2', // site only
        '**/public/js/*.js', // JavaScript files MIT license, site/test only
        '**/*.min.js', // JavaScript files MIT license, site/test only
        '**/*.min.css', // CSS files MIT license, site only
        '**/TransformedClass.template', // TODO: can we remove this?
        '**/logo.svg',
        '**/icons.svg', // TODO: licensing info required
        '.classpath', '.project', '.settings/**', 'bin/**', // Eclipse files
        '**/MANIFEST.MF', // TODO: can we remove this?
        '**/META-INF/services/**', // TODO: can we remove this?
        '**/META-INF/groovy/**', // TODO: can we remove this?
    ]
}