Use CodeSource to test shadow package renames.
Forcing guava to version 18 prevented running the embedded ratpack
http server. Using codesource for the shadow test has the same effect
and doesn't require forcing a version of guava.
MODIFY
dd-java-agent-ittests/dd-java-agent-ittests.gradle
dd-java-agent-ittests/dd-java-agent-ittests.gradle
@@ -38,12 +38,6 @@ dependencies {
testCompile group: 'org.apache.derby', name: 'derby', version: '10.14.1.0'
}
-configurations.all {
- resolutionStrategy {
- force 'com.google.guava:guava:18.0' // Force to test package renaming in agent jar. (see ShadowPackageRenamingTest)
- }
-}
-
test {
jvmArgs "-Ddd.trace.configurationFile=${project.buildDir}/resources/test/dd-trace.yaml"
jvmArgs "-Ddd.slf4j.simpleLogger.defaultLogLevel=debug"

MODIFY
dd-java-agent-ittests/src/test/java/com/datadoghq/agent/ShadowPackageRenamingTest.java
dd-java-agent-ittests/src/test/java/com/datadoghq/agent/ShadowPackageRenamingTest.java
@@ -5,13 +5,29 @@ import org.junit.Assert;
import org.junit.Test;
public class ShadowPackageRenamingTest {
-
@Test
- public void test() {
- try {
- (new MapMaker()).softValues(); // this method exists in 18.0 but was removed in 20.0
- } catch (final NoSuchMethodError e) {
- Assert.fail("wrong class was loaded");
- }
+ public void agentDependenciesRenamed() throws Exception {
+ final Class<?> ddClass =
+ ClassLoader.getSystemClassLoader().loadClass("com.datadoghq.agent.TracingAgent");
+
+ final String userGuava =
+ MapMaker.class.getProtectionDomain().getCodeSource().getLocation().getFile();
+ final String agentGuavaDep =
+ ddClass
+ .getClassLoader()
+ .loadClass("dd.deps." + MapMaker.class.getName())
+ .getProtectionDomain()
+ .getCodeSource()
+ .getLocation()
+ .getFile();
+ final String agentSource =
+ ddClass.getProtectionDomain().getCodeSource().getLocation().getFile();
+
+ Assert.assertTrue(
+ "TracingAgent should reside in the -javaagent jar: " + agentSource,
+ agentSource.matches(".*/dd-java-agent[^/]*.jar"));
+ Assert.assertEquals("DD guava dep must be loaded from agent jar.", agentSource, agentGuavaDep);
+ Assert.assertNotEquals(
+ "User guava dep must not be loaded from agent jar.", agentSource, userGuava);
}
}

Use CodeSource to test shadow package renames.

Forcing guava to version 18 prevented running the embedded ratpack
http server. Using codesource for the shadow test has the same effect
and doesn't require forcing a version of guava.