blob: b8a3ef27f9a8a0dcbafaa67bf18e11bab29d2e96 [file] [log] [blame]
/*
* 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.
*/
/*
* A convenient task to run individual example directly on Beam repo.
*
* Usage:
* ./gradlew :examples:java:execute -PmainClass=org.apache.beam.examples.<ClassName>`\
* -Pexec.args="runner=[DataflowRunner|DirectRunner|FlinkRunner|SparkRunner|PrismRunner] \
* <pipeline options>"
*/
tasks.create(name:"execute", type:JavaExec) {
mainClass = project.hasProperty("mainClass") ? project.getProperty("mainClass") : "NONE"
def execArgs = project.findProperty("exec.args")
String runner
if (execArgs) {
// configure runner dependency from args
def runnerPattern = /runner[ =]([A-Za-z]+)/
def matcher = execArgs =~ runnerPattern
if (matcher) {
runner = matcher[0][1]
runner = runner.substring(0, 1).toLowerCase() + runner.substring(1);
if (!(runner in (preCommitRunners + nonPreCommitRunners))) {
throw new GradleException("Unsupported runner: " + runner)
}
}
}
if (runner) {
classpath = sourceSets.main.runtimeClasspath + configurations."${runner}PreCommit"
} else {
classpath = sourceSets.main.runtimeClasspath
}
systemProperties System.getProperties()
args execArgs ? execArgs.split() : []
}