import groovy.json.JsonOutput

/*
 *
 *  * 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' }
applyJavaNature(
    automaticModuleName: 'org.apache.beam.sdk.extensions.ml'
)

description = 'Apache Beam :: SDKs :: Java :: Extensions :: ML'

dependencies {
    implementation project(path: ":sdks:java:core", configuration: "shadow")
    implementation project(":sdks:java:expansion-service")
    permitUnusedDeclared project(":sdks:java:expansion-service") // BEAM-11761
    implementation library.java.google_http_client
    implementation 'com.google.cloud:google-cloud-recommendations-ai:0.3.7'
    implementation 'com.google.cloud:google-cloud-video-intelligence:1.2.0'
    implementation 'com.google.cloud:google-cloud-dlp:1.1.4'
    implementation 'com.google.cloud:google-cloud-language:1.99.4'
    implementation library.java.protobuf_java_util
    implementation library.java.json_org
    implementation 'com.google.api.grpc:proto-google-cloud-dlp-v2:1.1.4'
    implementation 'com.google.api.grpc:proto-google-cloud-language-v1:1.81.4'
    implementation 'com.google.api.grpc:proto-google-cloud-video-intelligence-v1:1.2.0'
    implementation 'com.google.api.grpc:proto-google-cloud-vision-v1:1.81.3'
    implementation 'com.google.api.grpc:proto-google-cloud-recommendations-ai-v1beta1:0.3.7'
    implementation library.java.joda_time
    implementation library.java.auto_value_annotations
    implementation library.java.gax
    implementation library.java.protobuf_java
    implementation library.java.slf4j_api
    testImplementation project(path: ':sdks:java:core', configuration: 'shadowTest')
    implementation 'com.google.cloud:google-cloud-vision:1.99.3'
    testImplementation library.java.mockito_core
    testImplementation library.java.google_http_client
    testImplementation library.java.protobuf_java_util
    testImplementation library.java.json_org
    // TODO(https://github.com/apache/beam/issues/30405) duplicate testImplemention used to force
    //  older version of recommendations-ai than that in gcp-bom due to compatiblility issue
    testImplementation 'com.google.cloud:google-cloud-recommendations-ai:0.3.7'
    testImplementation 'com.google.cloud:google-cloud-video-intelligence:1.2.0'
    testImplementation 'com.google.cloud:google-cloud-dlp:1.1.4'
    testImplementation project(path: ":sdks:java:extensions:google-cloud-platform-core", configuration: "testRuntimeMigration")
    testRuntimeOnly project(path: ":runners:direct-java", configuration: "shadow")
    testRuntimeOnly project(":runners:google-cloud-dataflow-java")
}

/**
 * These are integration tests with the GCP ML services and the DirectRunner.
 */
task integrationTest(type: Test) {
  group = "Verification"
  def gcpProject = project.findProperty('gcpProject') ?: 'apache-beam-testing'
  def gcpTempRoot = project.findProperty('gcpTempRoot') ?: 'gs://temp-storage-for-end-to-end-tests'
  systemProperty "beamTestPipelineOptions", JsonOutput.toJson([
          "--runner=DirectRunner",
          "--project=${gcpProject}",
          "--tempRoot=${gcpTempRoot}",
  ])

  // Disable Gradle cache: these ITs interact with live service that should always be considered "out of date"
  outputs.upToDateWhen { false }

  include '**/*IT.class'
  maxParallelForks 4
  classpath = sourceSets.test.runtimeClasspath
  testClassesDirs = sourceSets.test.output.classesDirs
}

task postCommit {
  group = "Verification"
  description = "Integration tests of ML service connectors using the DirectRunner."
  dependsOn integrationTest
}
