Fix tests

This commit is contained in:
Tyler Benson 2017-08-18 10:25:07 -06:00
parent 988a3d0fdf
commit aad3746c2b
7 changed files with 67 additions and 29 deletions

View File

@ -38,9 +38,10 @@ class VersionScanPlugin implements Plugin<Project> {
description = "Queries for all versions of configured modules and finds key classes"
}
if (!project.gradle.startParameter.taskNames.each { it.endsWith('scanVersions') }.any()) {
if (!project.gradle.startParameter.taskNames.contains('scanVersions')) {
return
}
println "Adding scan tasks for $project"
Set<String> allInclude = Sets.newConcurrentHashSet()
Set<String> allExclude = Sets.newConcurrentHashSet()

View File

@ -17,6 +17,8 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
'com.datadoghq.trace.agent.InstrumentationChecker',
'com.datadoghq.trace.agent.DDJavaAgentInfo',
'io.opentracing.contrib.mongo.TracingCommandListenerFactory',
'com.datadoghq.trace.agent.InstrumentationChecker.1',
'com.datadoghq.trace.agent.InstrumentationChecker.ArtifactSupport',
]
dependencies {

View File

@ -42,7 +42,7 @@ public class InstrumentationChecker {
this.classLoader = classLoader;
rules =
FactoryUtils.loadConfigFromResource(
CONFIG_FILE, new TypeReference<Map<String, List<Map<String, String>>>>() {});
CONFIG_FILE, new TypeReference<Map<String, List<ArtifactSupport>>>() {});
frameworks = scanLoadedLibraries();
}

View File

@ -37,7 +37,7 @@ opentracing-cassandra-driver:
opentracing-web-servlet-filter:
- artifact: jetty-server
supported_version: (8\.|9\.).*
identifying_present_classes:
# identifying_present_classes:
- artifact: tomcat_catalina
supported_version: (8\.|9\.).*
@ -65,7 +65,7 @@ opentracing-okhttp3:
opentracing-jms-2:
- artifact: javax.jms-api
supported_version: 2\..*
identifying_present_classes
identifying_present_classes:
- javax.jms.JMSContext
- javax.jms.CompletionListener

View File

@ -7,7 +7,7 @@ import spock.lang.Specification
class InstrumentationCheckerTest extends Specification {
Map<String, List<Map<String, String>>> rules =
FactoryUtils.loadConfigFromResource("supported-version-test", new TypeReference<Map<String, List<InstrumentationChecker.ArtifactSupport>>>() {
});
})
Map<String, String> frameworks = [
"artifact-1": "1.2.3.1232",
"artifact-2": "4.y.z",
@ -18,7 +18,7 @@ class InstrumentationCheckerTest extends Specification {
def "test rules"() {
setup:
def rules = InstrumentationChecker.getUnsupportedRules(java.lang.ClassLoader.getSystemClassLoader());
def rules = InstrumentationChecker.getUnsupportedRules(java.lang.ClassLoader.getSystemClassLoader())
expect:
rules.size() == 3

View File

@ -15,6 +15,7 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
'com.datadoghq.trace.DDTags',
'com.datadoghq.trace.DDTraceInfo',
'com.datadoghq.trace.util.Clock',
'com.datadoghq.trace.resolver.FactoryUtils',
]
dependencies {

View File

@ -15,8 +15,18 @@ public class FactoryUtils {
public static <A> A loadConfigFromFilePropertyOrResource(
final String systemProperty, final String resourceName, final Class<A> targetClass) {
return loadConfigFromFilePropertyOrResource(
systemProperty, resourceName, new TypeReference<A>() {});
final String filePath = System.getProperty(systemProperty);
if (filePath != null) {
try {
log.info("Loading config from file " + filePath);
return objectMapper.readValue(new File(filePath), targetClass);
} catch (final Exception e) {
log.error(
"Cannot read provided configuration file " + filePath + ". Using the default one.", e);
}
}
return loadConfigFromResource(resourceName, targetClass);
}
public static <A> A loadConfigFromFilePropertyOrResource(
@ -37,7 +47,31 @@ public class FactoryUtils {
public static <A> A loadConfigFromResource(
final String resourceName, final Class<A> targetClass) {
return loadConfigFromResource(resourceName, new TypeReference<A>() {});
A config = null;
// Try loading both suffixes
if (!resourceName.endsWith(".yaml") && !resourceName.endsWith(".yml")) {
config = loadConfigFromResource(resourceName + ".yaml", targetClass);
if (config == null) {
config = loadConfigFromResource(resourceName + ".yml", targetClass);
}
if (config != null) {
return config;
}
}
try {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final URL resource = classLoader.getResource(resourceName);
if (resource != null) {
log.info("Loading config from resource " + resource);
config = objectMapper.readValue(resource.openStream(), targetClass);
}
} catch (final IOException e) {
log.warn("Could not load configuration file {}.", resourceName);
log.error("Error when loading config file", e);
}
return config;
}
public static <A> A loadConfigFromResource(final String resourceName, final TypeReference type) {