blob: c420d122c4436c7a086870fdc1b8100331894814 [file] [log] [blame]
Alex Volanis7004a612018-01-24 10:30:13 -05001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20// Following Gradle best practices to keep build logic organized
21
22// ----------------------------------------------------------------------------
23// Functional testing harness creation. This helps run the cross-check tests.
24// The Makefile precross target invokes the shadowJar task and the tests.json
25// code is changed to call runclient or runserver as needed.
26
27// ----------------------------------------------------------------------------
28// Cross Test sources are separated in their own sourceSet
29//
30sourceSets {
31 crossTest {
32 java {
33 srcDir 'test'
34 include '**/test/TestClient.java'
35 include '**/test/TestServer.java'
36 include '**/test/TestNonblockingServer.java'
37 }
38 }
39}
40
41configurations {
42 crossTestCompile { extendsFrom testCompile }
43 crossTestRuntime { extendsFrom crossTestCompile, testRuntime }
44}
45
46dependencies {
47 crossTestCompile sourceSets.main.output
48 crossTestCompile sourceSets.test.output
49}
50
51// I am using shadow plugin to make a self contained functional test Uber JAR that
52// eliminates startup problems with wrapping the cross-check harness in Gradle.
53// This is used by the runner scripts as the single classpath entry which
54// allows the process to be as lightweight as it can.
55shadowJar {
56 description = 'Assemble a test JAR file for cross-check execution'
57 // make sure the runners are created when this runs
58 dependsOn 'generateRunnerScriptForClient', 'generateRunnerScriptForServer', 'generateRunnerScriptForNonblockingServer'
59
60 baseName = 'functionalTest'
61 destinationDir = file("$buildDir/functionalTestJar")
62 classifier = null
63
64 // We do not need a version number for this internal jar
65 version = null
66
67 // Bundle the complete set of unit test classes including generated code
68 // and the runtime dependencies in one JAR to expedite execution.
69 from sourceSets.test.output
70 from sourceSets.crossTest.output
71 configurations = [project.configurations.testRuntime]
72}
73
74// Common script runner configuration elements
75def scriptExt = ''
76def execExt = ''
77def scriptHead = '#!/bin/bash'
78def args = '$*'
79
80// Although this is marked internal it is an available and stable interface
81if (org.gradle.internal.os.OperatingSystem.current().windows) {
82 scriptExt = '.bat'
83 execExt = '.exe'
84 scriptHead = '@echo off'
85 args = '%*'
86}
87
88// The Java executable to use with the runner scripts
89def javaExe = file("${System.getProperty('java.home')}/bin/java${execExt}").canonicalPath
90// The common Uber jar path
91def jarPath = shadowJar.archivePath.canonicalPath
92def trustStore = file('test/.truststore').canonicalPath
93def keyStore = file('test/.keystore').canonicalPath
94
95task generateRunnerScriptForClient(group: 'Build') {
96 description = 'Generate a runner script for cross-check tests with TestClient'
97
98 def clientFile = file("$buildDir/runclient${scriptExt}")
99
100 def runClientText = """\
101${scriptHead}
102
103"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.trustStore=$trustStore" -Djavax.net.ssl.trustStorePassword=thrift org.apache.thrift.test.TestClient $args
104"""
105 inputs.property 'runClientText', runClientText
106 outputs.file clientFile
107
108 doLast {
109 clientFile.parentFile.mkdirs()
110 clientFile.text = runClientText
111 clientFile.setExecutable(true, false)
112 }
113}
114
115task generateRunnerScriptForServer(group: 'Build') {
116 description = 'Generate a runner script for cross-check tests with TestServer'
117
118 def serverFile = file("$buildDir/runserver${scriptExt}")
119
120 def runServerText = """\
121${scriptHead}
122
123"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestServer $args
124"""
125
126 inputs.property 'runServerText', runServerText
127 outputs.file serverFile
128
129 doLast {
130 serverFile.parentFile.mkdirs()
131 serverFile.text = runServerText
132 serverFile.setExecutable(true, false)
133 }
134}
135
136task generateRunnerScriptForNonblockingServer(group: 'Build') {
137 description = 'Generate a runner script for cross-check tests with TestNonblockingServer'
138
139 def serverFile = file("$buildDir/runnonblockingserver${scriptExt}")
140
141 def runServerText = """\
142${scriptHead}
143
144"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestNonblockingServer $args
145"""
146
147 inputs.property 'runServerText', runServerText
148 outputs.file serverFile
149
150 doLast {
151 serverFile.parentFile.mkdirs()
152 serverFile.text = runServerText
153 serverFile.setExecutable(true, false)
154 }
155}