/*
 *  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 "org.kordamp.gradle.oci-build-cache" version "0.6.0"
    id "org.gradle.toolchains.foojay-resolver" version "0.8.0"
    // Check https://gradle.com/enterprise/releases with new versions. GE plugin version should not lag behind Gradle version, but before
    // updating this, check the compatibility from https://docs.gradle.com/enterprise/compatibility/#develocity_compatibility and https://develocity.apache.org/scans.
    id "com.gradle.develocity" version "3.18.2"
    id 'com.gradle.common-custom-user-data-gradle-plugin' version '2.0.2'
    // The Ratpack server providing the gem repository uses classes from
    // jakarta.activation-api.jar brought in here by org.kordamp.gradle.oci-build-cache
    // but the classes in there cannot work properly as classes from
    // the activation implementation are missing, so bring the plugin
    // to the classpath here to fix compatibility problems
    id 'org.asciidoctor.jvm.gems' version '4.0.4' apply false
}

apply from: 'gradle/build-scans.gradle'

include "module",
    "module:geb-core",
    "module:geb-spock",
    "module:geb-junit",
    "module:geb-junit4",
    "module:geb-junit5",
    "module:geb-testng",
    "module:geb-implicit-assertions",
    "module:geb-ast",
    "module:geb-waiting",
    "module:geb-exceptions",
    "internal",
    "internal:test-support",
    "internal:test-support-spock",
    "integration",
    "integration:geb-gradle",
    "doc:asciidoctor-extension",
    "doc:manual",
    "doc:manual-snippets",
    "doc:manual-snippets:fixtures",
    "doc:manual-snippets:real-browser",
    "doc:site"

rootProject.name = 'geb'

def setBuildFile(project) {
    project.buildFileName = "${project.name}.gradle"

    project.children.each {
        setBuildFile(it)
    }
}

setBuildFile(rootProject)

ext.isCiServer = System.getenv("OCI_WRITER_KEY_PASSPHRASE")?.size() > 0

buildCache {
    local {
        enabled = !isCiServer
    }
    remote(org.kordamp.gradle.plugin.buildcache.OCIBuildCache) {
        push = isCiServer
        compartmentId = 'ocid1.compartment.oc1..aaaaaaaap3fg3t2n5lm4vopfcn4ypw6frqgr5qblb3kdkjrwstskho2o5y6q'
        config {
            region = 'us-ashburn-1'
            tenantId = 'ocid1.tenancy.oc1..aaaaaaaakdvpvkhjg75hmgkzgwt5f6bxycvfinbi5fh4hk5jwwvrflitradq'
            if (isCiServer) {
                userId = 'ocid1.user.oc1..aaaaaaaavxg4ceribtzyjqcjgjq44dnwo4d4wdunxkh7l5owk2zifrr7dfea'
                keyfile = new File('.oci/writer.pem')
                passphrase = System.getenv("OCI_WRITER_KEY_PASSPHRASE")
                fingerprint = 'ff:d9:c6:96:cb:20:64:77:1d:4e:a0:3e:bf:85:c7:e3'
            } else {
                userId = 'ocid1.user.oc1..aaaaaaaa463rzwweyef2fcby47wz73i6eyp7hwd6skx7bdgf2ie6ido35tla'
                keyfile = new File('.oci/reader.pem')
                fingerprint = '20:b5:2b:b1:c7:ab:da:2d:82:e9:81:1b:63:f8:59:16'
            }
        }
    }
}

toolchainManagement {
    jvm {
        javaRepositories {
            repository("foojay") {
                resolverClass = org.gradle.toolchains.foojay.FoojayToolchainResolver
            }
        }
    }
}
