/*
 * Copyright 2020 Google LLC
 *
 * 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.
 */
buildscript {
    ext {
        dataflowBeamVersion = '2.23.0'
       
        
    }
    repositories {
        mavenCentral()
        jcenter()
        maven {
     		 url "https://plugins.gradle.org/m2/"
    	}
    	dependencies {
        	classpath "net.ltgt.gradle:gradle-apt-plugin:0.19"
        	classpath "gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:2.5.0"
         	classpath "com.diffplug.spotless:spotless-plugin-gradle:3.24.2"
        
        
    }
    	
    }
    
}

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "net.ltgt.apt"
apply plugin: 'com.google.cloud.tools.jib'
apply plugin: "com.diffplug.gradle.spotless"

// Licence header enforced by spotless
def javaLicenseHeader = """/*
 * Copyright 2020 Google LLC
 *
 * 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.
 */
"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
applicationDefaultJvmArgs = ['-Xms4g', '-Xmx16g']
mainClassName = System.getProperty('mainClass', 'com.google.solutions.df.log.aggregations.SecureLogAggregationPipeline')

group 'com.google.solutions'
version '0.1.0'


tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
   mavenCentral()
   flatDir {
       		dirs 'libs'
   		}
    

}

dependencies {
    compile group: 'org.apache.beam', name: 'beam-sdks-java-core', version: dataflowBeamVersion
    compile group: 'org.apache.beam', name: 'beam-runners-google-cloud-dataflow-java', version: dataflowBeamVersion
    compile group: 'org.apache.beam', name: 'beam-runners-direct-java', version: dataflowBeamVersion	
	compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
	compile group: 'org.apache.beam', name: 'beam-sdks-java-extensions-zetasketch', version: dataflowBeamVersion
	compile "com.google.auto.value:auto-value-annotations:1.6.2"
    annotationProcessor "com.google.auto.value:auto-value:1.6.2"
	compile 'com.google.cloud:google-cloud-storage:1.98.0'
	compile group: 'org.apache.commons', name: 'commons-math3', version: '3.0'
	compile group: 'commons-validator', name: 'commons-validator', version: '1.4.0'
	compile 'commons-net:commons-net:3.6'
    compile group: 'com.google.cloud', name: 'google-cloud-dlp', version: '1.1.4'
    compile name: 'json-data-generator-1.10-SNAPSHOT-standalone'
    compile 'com.maxmind.geoip2:geoip2:2.14.0'
    compile group: 'com.google.api-client', name: 'google-api-client', version: '1.30.9'
    compile group: 'com.google.apis', name: 'google-api-services-discovery', version: 'v1-rev134-1.25.0'
	testCompile group: 'org.apache.beam', name: 'beam-runners-direct-java', version: dataflowBeamVersion
	testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
    testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
    testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
	testCompile 'junit:junit:4.12'
	



}
jar {
    manifest {
        attributes ('Main-Class': mainClassName)
    }
}

compileJava {
    options.compilerArgs.addAll(['-Xlint:all', '-Xlint:-serial'])
    options.encoding = 'UTF-8'
}

// default tasks when you run ./gradlew
defaultTasks 'clean', 'assemble'

// Google Cloud Dataflow requires the resource/main directory to exist
task resources {
    def resourcesDir = new File('build/resources/main')
    resourcesDir.mkdirs()
}

run {
    if (project.hasProperty('args')) {
        args project.args.split('\\s')
    }
    mustRunAfter 'resources'
}

// Spotless configuration

def enableSpotlessCheck = project.hasProperty('enableSpotlessCheck') && project.enableSpotlessCheck == 'true'
spotless {
  enforceCheck enableSpotlessCheck
  java {
    licenseHeader javaLicenseHeader
    googleJavaFormat()
  }
}


jib {
  from {
    image = 'gcr.io/dataflow-templates-base/java8-template-launcher-base:latest'
  }
  container {
    appRoot = '/template/df-log-streaming-template'
    entrypoint = 'INHERIT'
	environment = [DATAFLOW_JAVA_COMMAND_SPEC:'/template/df-log-streaming-template/resources/java_command_spec.json']
	
  }
}