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

configurations {
  // This is a configuration that references an 'folder-expanded' binary distribution
  // tests will run against. The distribution is slightly trimmed (no docs, licenses)
  // because we don't test these parts of the distribution anyway.
  binaryDistribution
}

dependencies {
  binaryDistribution project(path: ":lucene:distribution", configuration: "binaryDirForTests")

  moduleTestImplementation deps.procfork
  moduleTestImplementation(deps.randomizedtesting.runner, {
    exclude group: "junit"
  })

  moduleTestImplementation(deps.junit, {
    exclude group: "org.hamcrest"
  })
  moduleTestImplementation deps.hamcrest
  moduleTestImplementation deps.assertj
}

test {
  dependsOn configurations.binaryDistribution

  // We need to pass the system property using a lazy provider, not supported at the moment:
  // https://github.com/gradle/gradle/issues/12247
  // so we'll use a workaround and pass command-line arguments directly.
  jvmArgumentProviders.add(new CommandLineArgumentProvider() {
        @Override
        Iterable<String> asArguments() {
          return [
            "-Dlucene.distribution.dir=${configurations.binaryDistribution.singleFile.absolutePath }",
            "-Dlucene.distribution.version=${project.version}"
          ]
        }
      })

  doFirst {
    logger.lifecycle("Testing binary distribution at: ${configurations.binaryDistribution.singleFile}")
  }
}
