Fix java9 test setup
MODIFY
.circleci/save_artifacts.sh
.circleci/save_artifacts.sh
@@ -32,6 +32,7 @@ function save_libs () {
save_reports dd-java-agent
save_reports dd-java-agent/tooling
+save_reports dd-java-agent/testing
# Save reports for all instrumentation projects
for integration_path in dd-java-agent/instrumentation/*; do
save_reports $integration_path

MODIFY
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/SpockRunner.java
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/SpockRunner.java
@@ -6,6 +6,8 @@ import com.google.common.reflect.ClassPath;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -96,7 +98,24 @@ public class SpockRunner extends Sputnik {
}
private static File createBootstrapJar() throws IOException {
- final ClassLoader loader = AgentTestRunner.class.getClassLoader();
+ ClassLoader loader = AgentTestRunner.class.getClassLoader();
+ if (!(loader instanceof URLClassLoader)) {
+ // java9's system loader does not extend URLClassLoader
+ // which breaks google ClassPath lookup
+ Field f = null;
+ try {
+ f = loader.getClass().getDeclaredField("ucp");
+ f.setAccessible(true);
+ Object ucp = f.get(loader);
+ loader = new URLClassLoader((URL[]) ucp.getClass().getMethod("getURLs").invoke(ucp), null);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (null != f) {
+ f.setAccessible(false);
+ }
+ }
+ }
final ClassPath testCP = ClassPath.from(loader);
Set<String> bootstrapClasses = new HashSet<String>();
for (ClassPath.ClassInfo info : testCP.getAllClasses()) {

MODIFY
dd-java-agent/testing/src/test/groovy/AgentTestRunnerTest.groovy
dd-java-agent/testing/src/test/groovy/AgentTestRunnerTest.groovy
@@ -6,20 +6,19 @@ import datadog.trace.agent.test.AgentTestRunner
class AgentTestRunnerTest extends AgentTestRunner {
private static final ClassLoader BOOTSTRAP_CLASSLOADER = null
- private static final boolean OT_LOADED_IN_CLINIT
+ private static final ClassLoader OT_LOADER
private static final boolean AGENT_INSTALLED_IN_CLINIT
static {
// when test class initializes, opentracing should be set up, but not the agent.
- OT_LOADED_IN_CLINIT = io.opentracing.Tracer.getClassLoader() == BOOTSTRAP_CLASSLOADER
+ OT_LOADER = io.opentracing.Tracer.getClassLoader()
AGENT_INSTALLED_IN_CLINIT = getAgentTransformer() != null
}
def "classpath setup"() {
expect:
- OT_LOADED_IN_CLINIT
+ OT_LOADER == BOOTSTRAP_CLASSLOADER
!AGENT_INSTALLED_IN_CLINIT
- io.opentracing.Tracer.getClassLoader() == BOOTSTRAP_CLASSLOADER
TEST_TRACER == TestUtils.getUnderlyingGlobalTracer()
getAgentTransformer() != null
datadog.trace.api.Trace.getClassLoader() == BOOTSTRAP_CLASSLOADER

MODIFY
gradle/java.gradle
gradle/java.gradle
@@ -114,3 +114,11 @@ plugins.withType(BasePlugin) {
otherTasks*.mustRunAfter deleteTasks
}
}
+
+if (JavaVersion.current().isJava9Compatible()) {
+ // required to allow reflection into java9 for testing
+ test {
+ jvmArgs '--add-opens'
+ jvmArgs 'java.base/jdk.internal.loader=ALL-UNNAMED'
+ }
+}

Fix java9 test setup