use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtility method getParameterAttributeNames.
private static List<ParameterAttributeName> getParameterAttributeNames(List<Method> methods) {
List<ParameterAttributeName> reportedParams = new ArrayList<>();
for (Method m : methods) {
if (m.getParameters() != null && m.getParameters().getType() != null) {
for (int i = 0; i < m.getParameters().getType().size(); i++) {
com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method.Parameters.Type t = m.getParameters().getType().get(i);
if (t.getAttributeName() != null) {
try {
MethodMatcher methodMatcher = MethodMatcherUtility.createMethodMatcher("DummyClassName", m, new HashMap<String, MethodMapper>(), "");
ParameterAttributeName reportedParam = new ParameterAttributeName(i, t.getAttributeName(), methodMatcher);
reportedParams.add(reportedParam);
} catch (Exception e) {
Agent.LOG.log(Level.FINEST, e, e.getMessage());
}
}
}
}
}
return reportedParams;
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionConversionUtility method createPointCut.
/**
* Converts the xml point cut into a java agent point cut.
*
* @return The point cut object with the matchers set.
*/
private static ExtensionClassAndMethodMatcher createPointCut(Extension extension, final Pointcut cut, final String metricPrefix, final String pName, final Map<String, MethodMapper> classesToMethods, boolean custom, InstrumentationType type, boolean isAttsEnabled) throws XmlException {
ClassMatcher classMatcher;
if (cut.getMethodAnnotation() != null) {
classMatcher = new AllClassesMatcher();
} else {
classMatcher = createClassMatcher(cut, pName);
}
MethodMatcher methodMatcher = createMethodMatcher(cut, pName, classesToMethods);
List<ParameterAttributeName> reportedParams = null;
if (!isAttsEnabled) {
// looks like this could be modified later
reportedParams = new ArrayList<>();
} else {
reportedParams = getParameterAttributeNames(cut.getMethod());
}
return new ExtensionClassAndMethodMatcher(extension, cut, metricPrefix, classMatcher, methodMatcher, custom, reportedParams, type);
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutFactory method getMethodMatcher.
static MethodMatcher getMethodMatcher(Object yaml) {
MethodMatcher matcher = null;
if (yaml instanceof MethodMatcher) {
matcher = (MethodMatcher) yaml;
} else if (yaml instanceof List) {
List list = (List) yaml;
if (!list.isEmpty() && list.get(0) instanceof String && list.get(0).toString().indexOf('(') < 0) {
return createExactMethodMatcher(list.get(0).toString().trim(), Strings.trim(list.subList(1, list.size())));
}
return OrMethodMatcher.getMethodMatcher(getMethodMatchers(list));
} else if (yaml instanceof String) {
String text = yaml.toString().trim();
int index = text.indexOf('(');
if (index > 0) {
String methodName = text.substring(0, index);
String methodDesc = text.substring(index);
return createExactMethodMatcher(methodName, methodDesc);
} else {
return new ExactMethodMatcher(text);
}
}
return matcher;
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionServiceTest method testXMLExtensionWithDuplicates.
@Test
public void testXMLExtensionWithDuplicates() throws Exception {
setupFiles(true, XML_DUPS);
List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
assertNotNull(pcs);
assertEquals(3, pcs.size());
List<String> classNames = new ArrayList<>();
List<MethodMatcher> mms = new ArrayList<>();
for (ExtensionClassAndMethodMatcher pc : pcs) {
classNames.addAll(pc.getClassMatcher().getClassNames());
mms.add(pc.getMethodMatcher());
}
// verify classes
assertEquals(3, classNames.size());
assertTrue(classNames.contains("test/TheClass"));
assertTrue(classNames.contains("test/TheOtherClass"));
// verify the methods
assertEquals(3, mms.size());
verifyMatch("run", "()Ljava/lang/String;", mms);
verifyMatch("merge", "()Ljava/lang/String;", mms);
verifyMatch("migrate", "()Ljava/lang/String;", mms);
verifyMatch("run", "()Ljava/lang/String;", mms);
verifyMatch("merge", "()Ljava/lang/String;", mms);
verifyMatch("run", "(Ljava/lang/String;J)Ljava/lang/String;", mms);
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionServiceTest method testYMLExtensionIneFile.
@Test
public void testYMLExtensionIneFile() throws Exception {
setupFiles(true, YML_FILE_PATH_1_1);
List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
assertNotNull(pcs);
assertEquals(1, pcs.size());
List<String> classNames = new ArrayList<>();
List<MethodMatcher> mms = new ArrayList<>();
for (ExtensionClassAndMethodMatcher pc : pcs) {
classNames.addAll(pc.getClassMatcher().getClassNames());
assertEquals(ExactClassMatcher.class, pc.getClassMatcher().getClass());
mms.add(pc.getMethodMatcher());
}
// verify that classes
assertEquals(1, classNames.size());
assertTrue(classNames.contains("java/lang/instrument/Instrumentation/Agent"));
// verify method matcher
assertEquals(1, mms.size());
assertTrue(mms.get(0).matches(MethodMatcher.UNSPECIFIED_ACCESS, "getVersion", "()Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
}
Aggregations