Provide Java compiler with bootstrap classes for Java7
when compiling Java7-compatible sources.
MODIFY
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsClientInstrumentation.java
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsClientInstrumentation.java
@@ -37,7 +37,7 @@ public final class AwsClientInstrumentation extends AbstractAwsClientInstrumenta
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(@Advice.This final SdkClientBuilder thiz) {
- thiz.overrideConfiguration(TracingExecutionInterceptor.getOverrideConfigurationConsumer());
+ TracingExecutionInterceptor.overrideConfiguration(thiz);
}
}
}

MODIFY
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsHttpClientInstrumentation.java
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java/datadog/trace/instrumentation/aws/v2/AwsHttpClientInstrumentation.java
@@ -81,7 +81,7 @@ public final class AwsHttpClientInstrumentation extends AbstractAwsClientInstrum
* this instrumentation when TracingExecutionInterceptor would not work.
*/
public static void muzzleCheck() {
- TracingExecutionInterceptor.getOverrideConfigurationConsumer();
+ TracingExecutionInterceptor.muzzleCheck();
}
}
}

MODIFY
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java8/datadog/trace/instrumentation/aws/v2/TracingExecutionInterceptor.java
dd-java-agent/instrumentation/aws-java-sdk-2.2/src/main/java8/datadog/trace/instrumentation/aws/v2/TracingExecutionInterceptor.java
@@ -10,6 +10,7 @@ import io.opentracing.util.GlobalTracer;
import java.util.Iterator;
import java.util.Map;
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.interceptor.Context;
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
}
/**

MODIFY
gradle/java.gradle
gradle/java.gradle
@@ -14,6 +14,23 @@ if (applyCodeCoverage) {
sourceCompatibility = 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"
lombok { // optional: values below are the defaults

Provide Java compiler with bootstrap classes for Java7

when compiling Java7-compatible sources.