/*
 * 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.apache.beam.module' }

def antlr_version = "4.7"

applyJavaNature(
  automaticModuleName: 'org.apache.beam.sdk',
  classesTriggerCheckerBugs: [
    'DoFnTester': 'https://github.com/typetools/checker-framework/issues/3776',
    'FileIO': 'https://github.com/typetools/checker-framework/issues/6388',
    'MergingActiveWindowSetTest': 'https://github.com/typetools/checker-framework/issues/3776',
    'WindowFnTestUtils': 'https://github.com/typetools/checker-framework/issues/3776',
  ],
  shadowClosure: {
    dependencies {
      include(dependency(library.java.commons_compress))
      include(dependency(library.java.commons_lang3))
      // Shade and repackage antlr runtime into Java core jar
      include(dependency("org.antlr:antlr4-runtime:$antlr_version"))
    }
    relocate "com.google.thirdparty", getJavaRelocatedPath("com.google.thirdparty")
    relocate "org.apache.commons.compress", getJavaRelocatedPath("org.apache.commons.compress")
    relocate "org.apache.commons.lang3", getJavaRelocatedPath("org.apache.commons.lang3")
    relocate "org.antlr.v4", getJavaRelocatedPath("org.antlr.v4")
  },
)
applyAntlrNature()

generateGrammarSource {
  arguments += ["-visitor"]
}

description = "Apache Beam :: SDKs :: Java :: Core"
ext.summary = """Beam SDK Java All provides a simple, Java-based
interface for processing virtually any size data. This
artifact includes entire Apache Beam Java SDK."""

processResources {
  inputs.property('version', version)
  inputs.property('sdk_version', sdk_version)
  inputs.property('docker_image_default_repo_root', docker_image_default_repo_root)
  inputs.property('docker_image_default_repo_prefix', docker_image_default_repo_prefix)
  filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
    'pom.version': version,
    'pom.sdk_version': sdk_version,
    'pom.docker_image_default_repo_root': docker_image_default_repo_root,
    'pom.docker_image_default_repo_prefix': docker_image_default_repo_prefix,
  ]
}

// Exclude tests that need a runner
test {
  systemProperty "beamUseDummyRunner", "true"
  useJUnit {
    excludeCategories "org.apache.beam.sdk.testing.NeedsRunner"
  }
}

dependencies {
  // antlr is used to generate code from sdks/java/core/src/main/antlr/
  antlr "org.antlr:antlr4:$antlr_version"
  permitUnusedDeclared "org.antlr:antlr4:$antlr_version"
  // alrady shaded and repackaged
  permitUsedUndeclared "org.antlr:antlr4-runtime:$antlr_version"
  // Required to load constants from the model, e.g. max timestamp for global window
  shadow project(path: ":model:pipeline", configuration: "shadow")
  shadow project(path: ":model:fn-execution", configuration: "shadow")
  shadow project(path: ":model:job-management", configuration: "shadow")
  shadow project(path: ":sdks:java:transform-service:launcher")
  shadow library.java.vendored_grpc_1_69_0
  shadow library.java.vendored_guava_32_1_2_jre
  shadow library.java.byte_buddy
  shadow library.java.commons_compress
  shadow library.java.commons_lang3
  testImplementation library.java.mockito_inline
  shadow library.java.classgraph
  shadow library.java.jsr305
  shadow library.java.error_prone_annotations
  shadow library.java.jackson_core
  shadow library.java.jackson_annotations
  shadow library.java.jackson_databind
  shadow library.java.slf4j_api
  shadow library.java.snappy_java
  shadow library.java.joda_time
  implementation enforcedPlatform(library.java.google_cloud_platform_libraries_bom)
  implementation library.java.google_cloud_secret_manager
  implementation library.java.proto_google_cloud_secret_manager_v1
  implementation library.java.protobuf_java
  permitUnusedDeclared enforcedPlatform(library.java.google_cloud_platform_libraries_bom)
  provided library.java.json_org
  implementation library.java.everit_json_schema
  implementation library.java.guava
  implementation library.java.snake_yaml
  shadowTest library.java.everit_json_schema
  provided library.java.junit
  provided library.java.hamcrest
  provided 'io.airlift:aircompressor:0.18'
  provided 'com.facebook.presto.hadoop:hadoop-apache2:3.2.0-1'
  provided library.java.zstd_jni
  permitUnusedDeclared 'com.facebook.presto.hadoop:hadoop-apache2:3.2.0-1'
  shadowTest library.java.jackson_dataformat_yaml
  shadowTest library.java.guava_testlib
  shadowTest library.java.mockito_core
  shadowTest library.java.hamcrest
  shadowTest "com.esotericsoftware.kryo:kryo:2.21"
  shadowTest library.java.quickcheck_core
  shadowTest library.java.quickcheck_generators
  shadowTest library.java.zstd_jni
  shadowTest library.java.commons_logging
  shadowTest library.java.log4j
  shadowTest library.java.log4j2_api
  shadowTest library.java.jamm
  shadowTest 'com.google.cloud:google-cloud-secretmanager:2.75.0'
  testRuntimeOnly library.java.slf4j_jdk14
}

project.tasks.compileTestJava {
  // TODO: fix other places with warnings in tests and delete this option
  options.compilerArgs += ['-Xlint:-rawtypes']
}

// Configure test task to use JUnit 4. JUnit 5 support is provided in module
// sdks/java/testing/junit, which configures useJUnitPlatform(). Submodules that
// need to run both JUnit 4 and 5 via the JUnit Platform must also add the
// Vintage engine explicitly.
test {
  useJUnit()
}
