Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THRIFT-5584: use gradle toolchain to specify Java 11 with --release 8 #2606

Merged
merged 14 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
id 'pmd'
id 'com.github.johnrengelman.shadow' version '6.1.0'
id "com.github.spotbugs" version "4.7.1"
id "com.diffplug.spotless" version "6.5.2"
Expand Down
4 changes: 2 additions & 2 deletions lib/java/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ maven-repository-id=apache.releases.https
# Dependency versions
httpclient.version=4.5.13
httpcore.version=4.4.15
slf4j.version=1.7.35
slf4j.version=1.7.36
servlet.version=4.0.1
tomcat.embed.version=9.0.43
junit.version=5.8.2
mockito.version=1.10.19
javax.annotation.version=1.3.2
commons-lang3.version=3.12
commons-lang3.version=3.12.0
10 changes: 2 additions & 8 deletions lib/java/gradle/codeQualityChecks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

dependencies {
spotbugs configurations.spotbugsPlugins.dependencies
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0'
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
}

apply plugin: 'com.github.spotbugs'

// see https://spotbugs-gradle-plugin.netlify.app/com/github/spotbugs/snom/spotbugsextension
spotbugs {
ignoreFailures = true
Expand All @@ -28,8 +26,6 @@ spotbugsMain {
}
}

apply plugin: 'pmd'

pmd {
ignoreFailures = true
toolVersion = '6.0.0'
Expand All @@ -46,9 +42,7 @@ tasks.withType(Pmd) {

spotless {
java {
target project.fileTree(project.rootDir) {
include 'src/**/*.java'
}
target 'src/**/*.java'
googleJavaFormat()
}
}
12 changes: 4 additions & 8 deletions lib/java/gradle/environment.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ if (hasProperty('build.dir')) {
ext.installPath = property('install.path')
ext.installJavadocPath = property('install.javadoc.path')

ext.thriftRoot = file('../..')

if (hasProperty('thrift.compiler')) {
ext.thriftCompiler = property('thrift.compiler')
} else {
ext.thriftCompiler = "$thriftRoot/compiler/cpp/thrift"
}
ext.thriftRoot = rootProject.file('../..')
ext.thriftCompiler = findProperty('thrift.compiler') ?: "$thriftRoot/compiler/cpp/thrift"

ext.mvnRepo = property('mvn.repo')
ext.apacheRepo = property('apache.repo')
Expand All @@ -50,6 +45,7 @@ ext.slf4jVersion = property('slf4j.version')
ext.junitVersion = property('junit.version')
ext.mockitoVersion = property('mockito.version')
ext.javaxAnnotationVersion = property('javax.annotation.version')
ext.commonsLang3Version = property('commons-lang3.version')

// In this section you declare where to find the dependencies of your project
repositories {
Expand All @@ -69,7 +65,7 @@ dependencies {
implementation "org.apache.httpcomponents:httpcore:${httpcoreVersion}"
implementation "javax.servlet:javax.servlet-api:${servletVersion}"
implementation "javax.annotation:javax.annotation-api:${javaxAnnotationVersion}"
implementation "org.apache.commons:commons-lang3:3.12.0"
implementation "org.apache.commons:commons-lang3:${commonsLang3Version}"

testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
testImplementation "org.mockito:mockito-all:${mockitoVersion}"
Expand Down
28 changes: 17 additions & 11 deletions lib/java/gradle/sourceConfiguration.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@
// ----------------------------------------------------------------------------
// Compiler configuration details

// These two properties are still needed on JDK8, and possibly used directly by
// plugins. However, the '--release' option added below makes these two
// properties redundant when building with JDK9 or later.
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
// We are using Java 11 toolchain to compile.
// This enables decoupling from the Java version that gradle runs, from
// the actual JDK version for the project. For more details, see
// https://docs.gradle.org/current/userguide/toolchains.html
//
// The '--release' option added below makes sure that even if we are using
// the toolchain version > 8, the final artifact is at version 8. There is
// also a runtime CI that's based on Java 8 to ensure that.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.debug = true
options.deprecation = true
// the following is to build with Java 8 specifications, even when building with JDK9 or later
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
options.compilerArgs.addAll(['--release', '8'])
}
options.compilerArgs.addAll([
options.release = 8
options.compilerArgs += [
'-Werror',
'-Xlint:deprecation',
'-Xlint:cast',
Expand All @@ -44,7 +50,7 @@ tasks.withType(JavaCompile) {
'-Xlint:finally',
'-Xlint:overrides',
// we can't enable -Xlint:unchecked just yet
])
]
}

// ----------------------------------------------------------------------------
Expand Down
27 changes: 9 additions & 18 deletions lib/java/src/crossTest/java/org/apache/thrift/test/TestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

package org.apache.thrift.test;

import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.IntStream;
import org.apache.http.impl.client.HttpClients;
import org.apache.thrift.TApplicationException;
import org.apache.thrift.TException;
Expand Down Expand Up @@ -299,24 +301,7 @@ public static void main(String[] args) {
/** BINARY TEST */
try {
System.out.print("testBinary(-128...127) = ");
byte[] data =
new byte[] {
-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115,
-114, -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101,
-100, -99, -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85,
-84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, -68,
-67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53, -52, -51,
-50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34,
-33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17,
-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127
};
byte[] data = getBytesData();
ByteBuffer bin = testClient.testBinary(ByteBuffer.wrap(data));
bin.mark();
byte[] bytes = new byte[bin.limit() - bin.position()];
Expand Down Expand Up @@ -823,4 +808,10 @@ public static void main(String[] args) {

System.exit(returnCode);
}

private static byte[] getBytesData() {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(256);
IntStream.range(-128, 128).forEach(byteArrayOutputStream::write);
return byteArrayOutputStream.toByteArray();
}
}