diff --git a/.circleci/save_artifacts.sh b/.circleci/save_artifacts.sh index 88b9996666..1300223c27 100755 --- a/.circleci/save_artifacts.sh +++ b/.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 diff --git a/dd-java-agent/testing/src/main/java/datadog/trace/agent/test/SpockRunner.java b/dd-java-agent/testing/src/main/java/datadog/trace/agent/test/SpockRunner.java index 161dbd501e..1017622b1d 100644 --- a/dd-java-agent/testing/src/main/java/datadog/trace/agent/test/SpockRunner.java +++ b/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 bootstrapClasses = new HashSet(); for (ClassPath.ClassInfo info : testCP.getAllClasses()) { diff --git a/dd-java-agent/testing/src/test/groovy/AgentTestRunnerTest.groovy b/dd-java-agent/testing/src/test/groovy/AgentTestRunnerTest.groovy index aa52fa44b7..e5fd759300 100644 --- a/dd-java-agent/testing/src/test/groovy/AgentTestRunnerTest.groovy +++ b/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 diff --git a/gradle/java.gradle b/gradle/java.gradle index 04e789656f..a8283d3257 100644 --- a/gradle/java.gradle +++ b/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' + } +}