1*e07d83d3SAndroid Build Coastguard Workerplugins { 2*e07d83d3SAndroid Build Coastguard Worker id "java-library" 3*e07d83d3SAndroid Build Coastguard Worker id "maven-publish" 4*e07d83d3SAndroid Build Coastguard Worker} 5*e07d83d3SAndroid Build Coastguard Worker 6*e07d83d3SAndroid Build Coastguard Workerdescription = "gRPC: Servlet" 7*e07d83d3SAndroid Build Coastguard Worker 8*e07d83d3SAndroid Build Coastguard Worker// javax.servlet-api 4.0 requires a minimum of Java 8, so we might as well use that source level 9*e07d83d3SAndroid Build Coastguard WorkersourceCompatibility = 1.8 10*e07d83d3SAndroid Build Coastguard WorkertargetCompatibility = 1.8 11*e07d83d3SAndroid Build Coastguard Worker 12*e07d83d3SAndroid Build Coastguard Workerdef jettyVersion = '10.0.7' 13*e07d83d3SAndroid Build Coastguard Worker 14*e07d83d3SAndroid Build Coastguard Workerconfigurations { 15*e07d83d3SAndroid Build Coastguard Worker itImplementation.extendsFrom(implementation) 16*e07d83d3SAndroid Build Coastguard Worker undertowTestImplementation.extendsFrom(itImplementation) 17*e07d83d3SAndroid Build Coastguard Worker tomcatTestImplementation.extendsFrom(itImplementation) 18*e07d83d3SAndroid Build Coastguard Worker jettyTestImplementation.extendsFrom(itImplementation) 19*e07d83d3SAndroid Build Coastguard Worker} 20*e07d83d3SAndroid Build Coastguard Worker 21*e07d83d3SAndroid Build Coastguard WorkersourceSets { 22*e07d83d3SAndroid Build Coastguard Worker // Create a test sourceset for each classpath - could be simplified if we made new test directories 23*e07d83d3SAndroid Build Coastguard Worker undertowTest {} 24*e07d83d3SAndroid Build Coastguard Worker tomcatTest {} 25*e07d83d3SAndroid Build Coastguard Worker 26*e07d83d3SAndroid Build Coastguard Worker // Only compile these tests if java 11+ is being used 27*e07d83d3SAndroid Build Coastguard Worker if (JavaVersion.current().isJava11Compatible()) { 28*e07d83d3SAndroid Build Coastguard Worker jettyTest {} 29*e07d83d3SAndroid Build Coastguard Worker } 30*e07d83d3SAndroid Build Coastguard Worker} 31*e07d83d3SAndroid Build Coastguard Worker 32*e07d83d3SAndroid Build Coastguard Workerdependencies { 33*e07d83d3SAndroid Build Coastguard Worker api project(':grpc-api') 34*e07d83d3SAndroid Build Coastguard Worker compileOnly 'javax.servlet:javax.servlet-api:4.0.1', 35*e07d83d3SAndroid Build Coastguard Worker libraries.javax.annotation // java 9, 10 needs it 36*e07d83d3SAndroid Build Coastguard Worker 37*e07d83d3SAndroid Build Coastguard Worker implementation project(':grpc-core'), 38*e07d83d3SAndroid Build Coastguard Worker libraries.guava 39*e07d83d3SAndroid Build Coastguard Worker 40*e07d83d3SAndroid Build Coastguard Worker testImplementation 'javax.servlet:javax.servlet-api:4.0.1', 41*e07d83d3SAndroid Build Coastguard Worker 'org.jetbrains.kotlinx:lincheck:2.14.1' 42*e07d83d3SAndroid Build Coastguard Worker 43*e07d83d3SAndroid Build Coastguard Worker itImplementation project(':grpc-servlet'), 44*e07d83d3SAndroid Build Coastguard Worker project(':grpc-netty'), 45*e07d83d3SAndroid Build Coastguard Worker project(':grpc-core').sourceSets.test.runtimeClasspath, 46*e07d83d3SAndroid Build Coastguard Worker libraries.junit 47*e07d83d3SAndroid Build Coastguard Worker itImplementation(project(':grpc-interop-testing')) { 48*e07d83d3SAndroid Build Coastguard Worker // Avoid grpc-netty-shaded dependency 49*e07d83d3SAndroid Build Coastguard Worker exclude group: 'io.grpc', module: 'grpc-alts' 50*e07d83d3SAndroid Build Coastguard Worker exclude group: 'io.grpc', module: 'grpc-xds' 51*e07d83d3SAndroid Build Coastguard Worker } 52*e07d83d3SAndroid Build Coastguard Worker 53*e07d83d3SAndroid Build Coastguard Worker undertowTestImplementation 'io.undertow:undertow-servlet:2.2.14.Final' 54*e07d83d3SAndroid Build Coastguard Worker 55*e07d83d3SAndroid Build Coastguard Worker tomcatTestImplementation 'org.apache.tomcat.embed:tomcat-embed-core:9.0.56' 56*e07d83d3SAndroid Build Coastguard Worker 57*e07d83d3SAndroid Build Coastguard Worker jettyTestImplementation "org.eclipse.jetty:jetty-servlet:${jettyVersion}", 58*e07d83d3SAndroid Build Coastguard Worker "org.eclipse.jetty.http2:http2-server:${jettyVersion}", 59*e07d83d3SAndroid Build Coastguard Worker "org.eclipse.jetty:jetty-client:${jettyVersion}" 60*e07d83d3SAndroid Build Coastguard Worker project(':grpc-testing') 61*e07d83d3SAndroid Build Coastguard Worker} 62*e07d83d3SAndroid Build Coastguard Worker 63*e07d83d3SAndroid Build Coastguard Workertest { 64*e07d83d3SAndroid Build Coastguard Worker if (JavaVersion.current().isJava9Compatible()) { 65*e07d83d3SAndroid Build Coastguard Worker jvmArgs += [ 66*e07d83d3SAndroid Build Coastguard Worker // required for Lincheck 67*e07d83d3SAndroid Build Coastguard Worker '--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED', 68*e07d83d3SAndroid Build Coastguard Worker '--add-exports=java.base/jdk.internal.util=ALL-UNNAMED', 69*e07d83d3SAndroid Build Coastguard Worker ] 70*e07d83d3SAndroid Build Coastguard Worker } 71*e07d83d3SAndroid Build Coastguard Worker} 72*e07d83d3SAndroid Build Coastguard Worker 73*e07d83d3SAndroid Build Coastguard Worker// Set up individual classpaths for each test, to avoid any mismatch, 74*e07d83d3SAndroid Build Coastguard Worker// and ensure they are only used when supported by the current jvm 75*e07d83d3SAndroid Build Coastguard Workercheck.dependsOn(tasks.register('undertowTest', Test) { 76*e07d83d3SAndroid Build Coastguard Worker classpath = sourceSets.undertowTest.runtimeClasspath 77*e07d83d3SAndroid Build Coastguard Worker testClassesDirs = sourceSets.undertowTest.output.classesDirs 78*e07d83d3SAndroid Build Coastguard Worker}) 79*e07d83d3SAndroid Build Coastguard Workercheck.dependsOn(tasks.register('tomcat9Test', Test) { 80*e07d83d3SAndroid Build Coastguard Worker classpath = sourceSets.tomcatTest.runtimeClasspath 81*e07d83d3SAndroid Build Coastguard Worker testClassesDirs = sourceSets.tomcatTest.output.classesDirs 82*e07d83d3SAndroid Build Coastguard Worker 83*e07d83d3SAndroid Build Coastguard Worker // Provide a temporary directory for tomcat to be deleted after test finishes 84*e07d83d3SAndroid Build Coastguard Worker def tomcatTempDir = "$buildDir/tomcat_catalina_base" 85*e07d83d3SAndroid Build Coastguard Worker systemProperty 'catalina.base', tomcatTempDir 86*e07d83d3SAndroid Build Coastguard Worker doLast { 87*e07d83d3SAndroid Build Coastguard Worker file(tomcatTempDir).deleteDir() 88*e07d83d3SAndroid Build Coastguard Worker } 89*e07d83d3SAndroid Build Coastguard Worker 90*e07d83d3SAndroid Build Coastguard Worker // tomcat-embed-core 9 presently performs illegal reflective access on 91*e07d83d3SAndroid Build Coastguard Worker // java.io.ObjectStreamClass$Caches.localDescs and sun.rmi.transport.Target.ccl, 92*e07d83d3SAndroid Build Coastguard Worker // see https://lists.apache.org/thread/s0xr7tk2kfkkxfjps9n7dhh4cypfdhyy 93*e07d83d3SAndroid Build Coastguard Worker if (JavaVersion.current().isJava9Compatible()) { 94*e07d83d3SAndroid Build Coastguard Worker jvmArgs += ['--add-opens=java.base/java.io=ALL-UNNAMED', '--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED'] 95*e07d83d3SAndroid Build Coastguard Worker } 96*e07d83d3SAndroid Build Coastguard Worker}) 97*e07d83d3SAndroid Build Coastguard Worker 98*e07d83d3SAndroid Build Coastguard Worker// Only run these tests if java 11+ is being used 99*e07d83d3SAndroid Build Coastguard Workerif (JavaVersion.current().isJava11Compatible()) { 100*e07d83d3SAndroid Build Coastguard Worker check.dependsOn(tasks.register('jettyTest', Test) { 101*e07d83d3SAndroid Build Coastguard Worker classpath = sourceSets.jettyTest.runtimeClasspath 102*e07d83d3SAndroid Build Coastguard Worker testClassesDirs = sourceSets.jettyTest.output.classesDirs 103*e07d83d3SAndroid Build Coastguard Worker }) 104*e07d83d3SAndroid Build Coastguard Worker} 105*e07d83d3SAndroid Build Coastguard Worker 106*e07d83d3SAndroid Build Coastguard WorkerjacocoTestReport { 107*e07d83d3SAndroid Build Coastguard Worker executionData undertowTest, tomcat9Test 108*e07d83d3SAndroid Build Coastguard Worker if (JavaVersion.current().isJava11Compatible()) { 109*e07d83d3SAndroid Build Coastguard Worker executionData jettyTest 110*e07d83d3SAndroid Build Coastguard Worker } 111*e07d83d3SAndroid Build Coastguard Worker} 112