/*
 * fdb-record-layer-lucene.gradle
 *
 * This source file is part of the FoundationDB open source project
 *
 * Copyright 2015-2021 Apple Inc. and the FoundationDB project authors
 *
 * Licensed 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.
 */

apply from: rootProject.file('gradle/proto.gradle')
apply from: rootProject.file('gradle/publishing.gradle')

def coreProject = ":${ext.coreProjectName}"
dependencies {
    api project(coreProject)
    api(libs.lucene.core)
    api(libs.lucene.analyzers)
    implementation(libs.lucene.queryParser)
    implementation(libs.lucene.suggest)
    implementation(libs.lucene.highlighter)
    implementation(libs.slf4j.api)
    compileOnly(libs.autoService)
    annotationProcessor(libs.autoService)

    testImplementation testFixtures(project(':fdb-extensions'))
    testImplementation project(path: coreProject, configuration: 'tests')
    testImplementation(libs.bundles.test.impl)
    testImplementation(libs.lucene.testFramework)
    testRuntimeOnly(libs.junit.vintange)
    testRuntimeOnly(libs.bundles.test.runtime)
    testCompileOnly(libs.bundles.test.compileOnly)
    testAnnotationProcessor(libs.autoService)
}

// Disable blocking detection, because we do this *a lot* in lucene
test.systemProperties['com.apple.foundationdb.record.blockingInAsyncDetection'] = System.getenv('BLOCKING_DETECTION') ?: "DISABLED"
// Used by lucene tests to create Directory objects for testing our codecs
test.systemProperties['tests.directory'] = 'com.apple.foundationdb.record.lucene.codec.TestFDBDirectory'
// uncomment this line, and comment out the one above to easily test against Lucene's RAMDirectory to see how
// it might differ
// test.systemProperties['tests.directory'] = 'org.apache.lucene.store.RAMDirectory'

tasks.withType(Test) { theTask ->
    // We use special lucene properties here, because lucene still fails sometimes
    // see: https://github.com/FoundationDB/fdb-record-layer/issues/2480
    // When that issue is resolved these can be changed align with the global properties
    if (!project.hasProperty('tests.luceneIncludeRandom')) {
        println("Fixing seed for lucene tests")
        theTask.systemProperties['tests.seed'] = "C185081D42F0F43C" // a fixed seed, should pass reliably in prb/release
    }
    if (project.hasProperty('tests.luceneIterations')) {
        theTask.systemProperties['tests.iters'] = project.getProperty('tests.luceneIterations') // TODO this is broken on main...
    }
}

publishing {
    publications {
        library(MavenPublication) {
            pom {
                description = 'Lucene index support for fdb-record-layer'
            }
        }
    }
}
