blob: 8eaf09cc05b3b6db38bd5b81294f9a3ff5507508 [file] [log] [blame]
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.
*/
apply plugin: org.apache.beam.gradle.BeamModulePlugin
applyJavaNature(
// javacc generated code produces lint warnings
disableLintWarnings: ['dep-ann'],
testShadowJar: true,
shadowClosure: DEFAULT_SHADOW_CLOSURE << {
dependencies {
include(dependency(library.java.protobuf_java))
include(dependency(library.java.protobuf_java_util))
include(dependency("org.apache.calcite:.*"))
include(dependency("org.apache.calcite.avatica:.*"))
include(dependency("org.codehaus.janino:.*"))
}
relocate "com.google.protobuf", getJavaRelocatedPath("com.google.protobuf")
relocate "org.apache.calcite", getJavaRelocatedPath("org.apache.calcite")
// Looking up the compiler factory in Calcite depends on having a properties
// file in the right location. We package one that is shading compatible
// in src/main/resources. Note that if this shaded path changes, that
// files name and contents need to be updated as well. TODO, swap to use
// getJavaRelocatedPath once the Maven build is no longer also shading this
// module.
relocate "org.codehaus", "org.apache.beam.sdks.java.extensions.sql.repackaged.org.codehaus"
})
apply plugin: 'ca.coglinc.javacc'
description = "Apache Beam :: SDKs :: Java :: Extensions :: SQL"
ext.summary = "Beam SQL provides a new interface to generate a Beam pipeline from SQL statement"
configurations {
// Create an fmppTask configuration representing the dependencies
// required to define and execute the Ant FMPP task.
// TODO: Migrate to a FMPP plugin once one exists
fmppTask
fmppTemplates
}
def calcite_version = "1.17.0"
def avatica_version = "1.12.0"
dependencies {
javacc "net.java.dev.javacc:javacc:4.0"
fmppTask "com.googlecode.fmpp-maven-plugin:fmpp-maven-plugin:1.0"
fmppTask "org.freemarker:freemarker:2.3.28"
fmppTemplates "org.apache.calcite:calcite-core:$calcite_version"
compile library.java.guava
compile "org.apache.calcite:calcite-core:$calcite_version"
compile "org.apache.calcite:calcite-linq4j:$calcite_version"
compile "org.apache.calcite.avatica:avatica-core:$avatica_version"
shadow project(path: ":beam-sdks-java-core", configuration: "shadow")
shadow project(path: ":beam-sdks-java-extensions-join-library", configuration: "shadow")
shadow library.java.slf4j_api
shadow library.java.commons_csv
shadow library.java.commons_lang3
shadow library.java.jackson_databind
shadow library.java.joda_time
shadow "com.alibaba:fastjson:1.2.49"
shadow project(path: ":beam-runners-direct-java", configuration: "shadow")
provided project(path: ":beam-sdks-java-io-kafka", configuration: "shadow")
provided project(path: ":beam-sdks-java-io-google-cloud-platform", configuration: "shadow")
provided library.java.kafka_clients
shadowTest library.java.slf4j_jdk14
shadowTest library.java.junit
shadowTest library.java.hamcrest_core
shadowTest library.java.hamcrest_library
shadowTest library.java.mockito_core
shadowTest library.java.quickcheck_core
}
// Copy Caclcite templates and our own template into the build directory
// so we have one location for the FMPP task to parse.
task copyFmppTemplatesFromSrc(type: Copy) {
from "src/main/codegen"
into "${project.buildDir}/templates-fmpp/codegen"
}
task copyFmppTemplatesFromCalciteCore(type: Copy) {
dependsOn configurations.fmppTemplates
File calciteCoreJar = files(configurations.fmppTemplates.files).filter {
it.name.startsWith("calcite-core")
}.singleFile
from zipTree(calciteCoreJar)
include "**/Parser.jj"
into "${project.buildDir}/templates-fmpp"
}
// Generate the FMPP sources from the FMPP templates.
def generateFmppOutputDir = "${project.buildDir}/generated/fmpp"
task generateFmppSources {
dependsOn configurations.fmppTask
dependsOn copyFmppTemplatesFromSrc
dependsOn copyFmppTemplatesFromCalciteCore
doLast {
ant.taskdef(name: "fmpp", classname: "fmpp.tools.AntTask", classpath: configurations.fmppTask.asPath)
ant.fmpp(configuration: "src/main/codegen/config.fmpp", sourceRoot: "${project.buildDir}/templates-fmpp/codegen/templates", outputRoot: generateFmppOutputDir)
}
}
// Match the output directory for generated code with the package, to be more tool-friendly
def generateFmppJavaccRoot = "${generateFmppOutputDir}/javacc"
def generatedJavaccSourceDir = "${project.buildDir}/generated/javacc"
def generatedJavaccPackageDir = "${generatedJavaccSourceDir}/org/apache/beam/sdk/extensions/sql/impl/parser/impl"
compileJavacc {
dependsOn generateFmppSources
inputDirectory = file(generateFmppJavaccRoot)
outputDirectory = file(generatedJavaccPackageDir)
arguments = [grammar_encoding: "UTF-8", static: "false", lookahead: "2"]
}
// Help IntelliJ find the fmpp bits
idea {
module {
sourceDirs += file(generateFmppOutputDir)
generatedSourceDirs += file(generateFmppOutputDir)
sourceDirs += file(generatedJavaccSourceDir)
generatedSourceDirs += file(generatedJavaccSourceDir)
}
}
// Run basic SQL example
task runBasicExample(type: JavaExec) {
description = "Run basic SQL example"
main = "org.apache.beam.sdk.extensions.sql.example.BeamSqlExample"
classpath = sourceSets.main.runtimeClasspath
args = ["--runner=DirectRunner"]
}
// Run SQL example on POJO inputs
task runPojoExample(type: JavaExec) {
description = "Run SQL example for PCollections of POJOs"
main = "org.apache.beam.sdk.extensions.sql.example.BeamSqlPojoExample"
classpath = sourceSets.main.runtimeClasspath
args = ["--runner=DirectRunner"]
}
task integrationTest(type: Test) {
group = "Verification"
def gcpProject = project.findProperty('gcpProject') ?: 'apache-beam-testing'
def gcsTempRoot = project.findProperty('gcsTempRoot') ?: 'gs://temp-storage-for-end-to-end-tests/'
// Disable Gradle cache (it should not be used because the IT's won't run).
outputs.upToDateWhen { false }
def pipelineOptions = [
"--project=${gcpProject}",
"--tempLocation=${gcsTempRoot}",
"--blockOnRun=false"]
systemProperty "beamTestPipelineOptions", JsonOutput.toJson(pipelineOptions)
include '**/*IT.class'
maxParallelForks 4
classpath = project(":beam-sdks-java-extensions-sql").sourceSets.test.runtimeClasspath
testClassesDirs = files(project(":beam-sdks-java-extensions-sql").sourceSets.test.output.classesDirs)
useJUnit { }
}
task postCommit {
group = "Verification"
description = "Various integration tests"
dependsOn integrationTest
}