private static void configure() { String configClass = System.getProperty("com.google.java.contract.configurator"); if (configClass != null) { try { Class<?> clazz = Class.forName(configClass); Object instance = clazz.newInstance(); clazz .getMethod("configure", ContractEnvironment.class) .invoke(instance, new AgentContractEnvironment()); } catch (ClassNotFoundException e) { DebugUtils.warn("agent", "cannot find configurator class"); } catch (NoSuchMethodException e) { DebugUtils.warn("agent", "cannot find configure method"); } catch (InvocationTargetException e) { DebugUtils.warn( "agent", "configure method threw an exception: " + e.getTargetException().toString()); } catch (Exception e) { DebugUtils.warn("agent", "error during configure method: " + e.toString()); } } }
@Override public byte[] transform( ClassLoader loader, String className, Class<?> redefinedClass, ProtectionDomain protectionDomain, byte[] bytecode) throws IllegalClassFormatException { byte[] data = transformer.transform(loader, className, redefinedClass, protectionDomain, bytecode); if (data != null) { DebugUtils.dump(className, data, Kind.CLASS); } return data; }
@Requires({"parent != null", "dumpDir != null"}) public DumpClassFileTransformer(ClassFileTransformer parent, String dumpDir) { transformer = parent; DebugUtils.setDumpDirectory(dumpDir); }