use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method 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.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputMildCardClasses.
@Test
public void checkInputMildCardClasses() {
SampleObject obj = new SampleObject();
ReinstrumentResult result = new ReinstrumentResult();
obj.getClass().getClassLoader();
Set<ClassLoader> loaders = new HashSet<>();
loaders.add(this.getClass().getClassLoader());
Extension ext = new Extension();
Instrumentation inst = new Instrumentation();
ext.setInstrumentation(inst);
Pointcut pc = new Pointcut();
inst.getPointcut().add(pc);
setClassName(pc, SampleObject.class);
// this should match
Method m1 = new Method();
m1.setName("yada");
pc.getMethod().add(m1);
Map<String, Class<?>> daClasses = new HashMap<>();
daClasses.put(SampleObject.class.getName(), SampleObject.class);
ReinstrumentUtils.checkInputClasses(result, loaders, ext, daClasses);
Object actual = result.getStatusMap().get(ReinstrumentResult.ERROR_KEY);
Assert.assertNull("There should not have been an error. Errors: " + actual, actual);
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputMatchesClasses.
@Test
public void checkInputMatchesClasses() {
SampleObject obj = new SampleObject();
ReinstrumentResult result = new ReinstrumentResult();
obj.getClass().getClassLoader();
Set<ClassLoader> loaders = new HashSet<>();
loaders.add(this.getClass().getClassLoader());
Extension ext = new Extension();
Instrumentation inst = new Instrumentation();
ext.setInstrumentation(inst);
Pointcut pc = new Pointcut();
inst.getPointcut().add(pc);
setClassName(pc, SampleObject.class);
Method m1 = new Method();
m1.setName("getHello");
MethodParameters params1 = new MethodParameters(new ArrayList<String>());
m1.setParameters(params1);
Method m2 = new Method();
m2.setName("setHello");
MethodParameters params2 = new MethodParameters(Arrays.asList("boolean"));
m2.setParameters(params2);
Method m3 = new Method();
m3.setName("doTheWork");
MethodParameters params3 = new MethodParameters(Arrays.asList("java.lang.String", "int"));
m3.setParameters(params3);
pc.getMethod().addAll(Arrays.asList(m1, m2, m3));
Map<String, Class<?>> daClasses = new HashMap<>();
daClasses.put(SampleObject.class.getName(), SampleObject.class);
ReinstrumentUtils.checkInputClasses(result, loaders, ext, daClasses);
Object actual = result.getStatusMap().get(ReinstrumentResult.ERROR_KEY);
Assert.assertNull("There should not have been an error. Errors: " + actual, actual);
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.
the class MethodMatcherTests method createOrMethodMatcherNameOnly.
@Test
public void createOrMethodMatcherNameOnly() throws XmlException {
Method m1 = new Method();
m1.setName("m1");
Method m2 = new Method();
m2.setName("m2");
MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1, m2), new HashMap<String, MethodMapper>(), "EXT");
Assert.assertNotNull(matcher);
Assert.assertTrue(matcher + " not of type OrMethodMatcher", matcher instanceof OrMethodMatcher);
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.
the class MethodMatcherTests method createOrMethodMatcherMix.
@Test
public void createOrMethodMatcherMix() throws XmlException {
Method m1 = new Method();
m1.setName("m1");
m1.setParameters(new MethodParameters(Arrays.asList("int")));
Method m2 = new Method();
m2.setName("m2");
MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1, m2), new HashMap<String, MethodMapper>(), "EXT");
Assert.assertNotNull(matcher);
Assert.assertTrue(matcher + " not of type OrMethodMatcher", matcher instanceof OrMethodMatcher);
Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Aggregations