/*
 *  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.
 */

apply plugin: 'org.nosphere.apache.rat'

tasks.named('rat') {
    def allExcludes = [
            '.asf.yaml', // ASF metadata for github integration excluded from src zip
            'CODE_OF_CONDUCT.md',
            'BUILD_DATE', // build artifact for storing the build date / verifying
            'CHECKSUMS', // build artifact for storing checksums for easy verification
            'PUBLISHED_ARTIFACTS', // build artifact for storing published artifacts coordinates & paths
            'licenses/**', // licenses directory excluded
            '.git-blame-ignore-revs', // git configuration isn't code
            'grails-web-common/src/main/groovy/org/grails/web/json/JSONObject.java',
            'grails-web-common/src/main/groovy/org/grails/web/json/JSONArray.java',
            'grails-web-common/src/main/groovy/org/grails/web/json/JSONTokener.java',
            'grails-web-common/src/main/groovy/org/grails/web/json/JSONElement.java',
            'grails-web-common/src/main/groovy/org/grails/web/json/JSONException.java',
            'grails-web-common/src/main/groovy/org/grails/web/json/JSONWriter.java',
            '**/.gitattributes', // git configuration isn't code
            '**/.gradle/**', '**/wrapper/**', 'gradlew*',  // gradle wrapper files excluded from src zip
            '**/*.html', // html files are only in test
            '**/resources/*', // exclude test artifacts
            'out/**', '*.ipr', '**/*.iml', '*.iws', '.idea/**', // Intellij generated files
            'src/*', // exclude build artifacts
            '**/.sdkmanrc', // tool selection files aren't code
            '.github/**', // github configuration isn't shipped in the source distro
            '**/.gitignore', // git configuration isn't code
            '**/.gitkeep', // git configuration isn't code
            'etc/bin/results/**', // exclude build directories
            '**/*.png', '**/*.svg', '**/*.ico', '**/*.eps', '**/*.icns', '**/*.jpg', '**/*.jpeg', '**/*.gif', // Image files
            '**/*.db', // H2 database test files
            '**/*.gitkeep', // Empty Gitkeep file
            'grails-fields/grails-app/views/layouts/_fields/*.gsp', // template files that people are expected to use in the end application
            'grails-fields/grails-app/views/templates/_fields/*.gsp', // template files that people are expected to use in the end application
            'grails-geb/src/main/templates/*.groovy', // template files that people are expected to use in the end application
            'grails-doc/src/en/ref/Versions/Grails BOM.adoc', // exclude generated data
            'grails-profiles/**/templates/**', // template files that people are expected to use in the end application
            'grails-profiles/**/commands/**', // template files that people are expected to use in the end application
            'grails-profiles/**/features/**', // template files that people are expected to use in the end application
            'grails-profiles/**/skeleton/**', // template files that people are expected to use in the end application
            'grails-scaffolding/src/main/templates/scaffolding/**/*', // template files that people are expected to use in the end application
            'grails-gradle/docs-core/src/main/template/**', // template files that people are expected to use in the end application
            'bin/**', // scripts generated during build for grails-shell-cli
            'grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/Attribute.java', // See license file, BSD licensed
            'grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/ByteVector.java', // See license file, BSD licensed
            'grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/ClassReader.java', // See license file, BSD licensed
            'grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/Context.java', // See license file, BSD licensed
            'grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/TypePath.java', // See license file, BSD licensed
            'grails-forge/**/src/main/resources/**', // src/main/resources are included in generated application and should not include a license
            'grails-forge/**/src/test/resources/**', // src/test/resources are used in tests against files included in generated application and should not include a license
            'grails-gradle/**/build/**', // grails-gradle does not have a build package name so exclude any build directories
            'grails-forge/*/build/**', // grails-forge build directories
            'grails-forge/build/**', // grails-forge build directories
            'build-logic/build/**', // grails-forge build directories
            'grails-forge/.idea/**', // grails-forge idea directories
            'grails-gradle/.idea/**', // grails-gradle idea directories
            'build-logic/.idea/**', // grails-gradle idea directories
            'build/**', // build directories
            'buildSrc/build/**', // build directories
    ] + rootProject.subprojects.collect{"${rootProject.projectDir.relativePath(it.layout.buildDirectory.get().asFile).toString()}/**/*" }
    // logger.lifecycle("Excludes for RAT task: ${allExcludes.join(', \n')}")
    excludes = allExcludes
    // never cache license audits
    it.outputs.upToDateWhen { false }
}