Provide Java compiler with bootstrap classes for Java7

when compiling Java7-compatible sources.
This commit is contained in:
Nikolay Martynov 2019-03-29 10:59:18 -04:00
parent 4c8a790c3b
commit 212d4d3c71
4 changed files with 30 additions and 4 deletions

View File

@ -37,7 +37,7 @@ public final class AwsClientInstrumentation extends AbstractAwsClientInstrumenta
@Advice.OnMethodEnter(suppress = Throwable.class) @Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(@Advice.This final SdkClientBuilder thiz) { public static void methodEnter(@Advice.This final SdkClientBuilder thiz) {
thiz.overrideConfiguration(TracingExecutionInterceptor.getOverrideConfigurationConsumer()); TracingExecutionInterceptor.overrideConfiguration(thiz);
} }
} }
} }

View File

@ -81,7 +81,7 @@ public final class AwsHttpClientInstrumentation extends AbstractAwsClientInstrum
* this instrumentation when TracingExecutionInterceptor would not work. * this instrumentation when TracingExecutionInterceptor would not work.
*/ */
public static void muzzleCheck() { public static void muzzleCheck() {
TracingExecutionInterceptor.getOverrideConfigurationConsumer(); TracingExecutionInterceptor.muzzleCheck();
} }
} }
} }

View File

@ -10,6 +10,7 @@ import io.opentracing.util.GlobalTracer;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import software.amazon.awssdk.core.client.builder.SdkClientBuilder;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.interceptor.Context; import software.amazon.awssdk.core.interceptor.Context;
import software.amazon.awssdk.core.interceptor.ExecutionAttribute; import software.amazon.awssdk.core.interceptor.ExecutionAttribute;
@ -84,8 +85,16 @@ public class TracingExecutionInterceptor implements ExecutionInterceptor {
} }
} }
public static Consumer<ClientOverrideConfiguration.Builder> getOverrideConfigurationConsumer() { /**
return OVERRIDE_CONFIGURATION_CONSUMER; * We keep this method here because it references Java8 classes and we would like to avoid
* compiling this for instrumentation code that should load into Java7.
*/
public static void overrideConfiguration(final SdkClientBuilder client) {
client.overrideConfiguration(OVERRIDE_CONFIGURATION_CONSUMER);
}
public static void muzzleCheck() {
// Noop
} }
/** /**

View File

@ -14,6 +14,23 @@ if (applyCodeCoverage) {
sourceCompatibility = 1.7 sourceCompatibility = 1.7
targetCompatibility = 1.7 targetCompatibility = 1.7
[JavaCompile, ScalaCompile].each { type ->
tasks.withType(type) {
doFirst {
// We do this specifically for Java7 bytecode generation because we would like to be able to compile
// with Java8+ compiler. This likely would require some modifications when we switch to java11 compiler.
// Using proper Java7 bootstrap and extentions allows to be sure our code will run on real Java7.
if (JavaVersion.toVersion(sourceCompatibility) == JavaVersion.VERSION_1_7
&& JavaVersion.current() != JavaVersion.VERSION_1_7
&& System.env.JAVA_7_HOME != null) {
options.fork = true
options.bootstrapClasspath = fileTree(include: ['*.jar'], dir: "${System.env.JAVA_7_HOME}/jre/lib/")
options.extensionDirs = "${System.env.JAVA_7_HOME}/jre/lib/ext/"
}
}
}
}
apply plugin: "io.franzbecker.gradle-lombok" apply plugin: "io.franzbecker.gradle-lombok"
lombok { // optional: values below are the defaults lombok { // optional: values below are the defaults