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

apply plugin: 'java-library'
// this is actually more of an 'application' but we don't want all of what Gradle adds

description = 'Prometheus exporter for exposing metrics from Solr using Metrics API and Search API'

dependencies {
  implementation platform(project(':platform'))
  implementation platform(libs.fasterxml.jackson.bom)
  implementation project(':solr:solrj')
  runtimeOnly project(':solr:solrj-zookeeper')
  // ideally remove ZK dep
  implementation(libs.apache.zookeeper.zookeeper, {
    exclude group: "org.apache.yetus", module: "audience-annotations"
  })

  implementation(libs.prometheus.simpleclient, {
    exclude group: "io.prometheus", module: "simpleclient_tracer_common"
    exclude group: "io.prometheus", module: "simpleclient_tracer_otel"
    exclude group: "io.prometheus", module: "simpleclient_tracer_otel_agent"
  })
  implementation(libs.prometheus.simpleclient.httpserver, {
    exclude group: "io.prometheus", module: "simpleclient_tracer_common"
    exclude group: "io.prometheus", module: "simpleclient_tracer_otel"
    exclude group: "io.prometheus", module: "simpleclient_tracer_otel_agent"
  })
  implementation(libs.thisptr.jacksonjq, {
    exclude group: "org.jruby.joni", module: "joni"
    exclude group: "com.fasterxml.jackson.core", module: "jackson-databind"
  })
  implementation libs.fasterxml.jackson.core.databind
  implementation libs.commonscli.commonscli
  implementation(libs.benmanes.caffeine) { transitive = false }
  implementation libs.slf4j.api
  implementation libs.commonscodec.commonscodec

  runtimeOnly libs.apache.log4j.api
  runtimeOnly libs.apache.log4j.core
  runtimeOnly libs.apache.log4j.slf4j2impl
  runtimeOnly libs.lmax.disruptor

  testImplementation project(':solr:test-framework')
  testImplementation project(':solr:solrj-zookeeper')
  testImplementation libs.carrotsearch.randomizedtesting.runner
  testImplementation libs.junit.junit
  testImplementation libs.apache.lucene.testframework

  testImplementation libs.apache.httpcomponents.httpclient
  testImplementation libs.apache.httpcomponents.httpcore
}

ext {
  mainClass = 'org.apache.solr.prometheus.exporter.SolrExporter'
}

task run(type: JavaExec) {
  group = 'application'
  description = 'Run the main class with JavaExecTask'
  mainClass = project.ext.mainClass
  classpath = sourceSets.main.runtimeClasspath
  systemProperties = ["log4j.configurationFile":"file:conf/log4j2.xml"]
  args = ["-f", "conf/solr-exporter-config.xml"]
}

jar {
  manifest {
    attributes('Main-Class': project.ext.mainClass)
  }
}

assemblePackaging {
  // Add two folders to default packaging.
  from(projectDir, {
    include "bin/**"
    include "conf/**"
  })
}
