use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfig method getExtensionPointCuts.
public static Collection<ExtensionClassAndMethodMatcher> getExtensionPointCuts(Extension extension, Map instrumentation) {
Collection<ExtensionClassAndMethodMatcher> list = new ArrayList<>();
if (instrumentation != null) {
list.addAll(addInstrumentation(extension, instrumentation));
}
if (Agent.LOG.isLoggable(Level.FINEST)) {
for (ExtensionClassAndMethodMatcher pc : list.toArray(new ExtensionClassAndMethodMatcher[0])) {
String msg = MessageFormat.format("Extension instrumentation point: {0} {1}", pc.getClassMatcher(), pc.getMethodMatcher());
Agent.LOG.finest(msg);
}
}
return list;
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class XmlInstrumentValidator method validateInstrumentation.
/**
* Validates the instrumentation.
*
* @param params The command line parameters.
* @throws ClassNotFoundException Thrown if the class is not found.
* @throws RuntimeException Thrown if a problem when converting the xml.
* @throws IllegalArgumentException Thrown when the method or class can not be found on the class path.
* @throws IOException Thrown if the file can not be read.
* @throws SAXException Thrown if a problem parsing the document.
*/
protected static void validateInstrumentation(final XmlInstrumentParams params) throws Exception {
// read in the file - DOM Exception potentially thrown
Extension extension = ExtensionDomParser.readFile(params.getFile());
if (params.isDebug()) {
System.out.println("Xml was successfully read. Starting processing.");
}
// attempt to convert to point cuts - RuntimeException
// potentially thrown
List<ExtensionClassAndMethodMatcher> convertedPcs = ExtensionConversionUtility.convertToPointCutsForValidation(extension);
Instrumentation inst = extension.getInstrumentation();
// this really has already been checked
if (inst == null) {
throw new RuntimeException("The instrumentation propery must be set for the extension.");
}
List<Pointcut> origPcs = inst.getPointcut();
if (convertedPcs.size() != origPcs.size()) {
throw new IllegalArgumentException("The processed number of point cuts does not match the" + "original number of point cuts in the xml. Remove duplicates.");
}
for (int i = 0; i < convertedPcs.size(); i++) {
MethodHolder holder = sortData(origPcs.get(i), params.isDebug());
verifyPointCut(convertedPcs.get(i), holder);
verifyAllMethodsAccounted(holder);
}
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher 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.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionServiceTest method testXMLExtensionWithYMLSameName.
/**
* Verifies that the xml file gets read in instead of the yml since the files have the same name.
*/
@Test
public void testXMLExtensionWithYMLSameName() throws Exception {
setupFiles(true, XML_FILE_PATH_1, YML_FILE_PATH_1_1);
List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
assertNotNull(pcs);
assertEquals(3, pcs.size());
List<String> classNames = new ArrayList<>();
for (ExtensionClassAndMethodMatcher pc : pcs) {
classNames.addAll(pc.getClassMatcher().getClassNames());
}
// verify that classes
assertEquals(3, classNames.size());
assertTrue(classNames.contains("test/CustomExtensionTest$1"));
assertTrue(classNames.contains("test/AbstractCustomExtensionTest"));
assertTrue(classNames.contains("test/CustomExtensionTest"));
}
use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher 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