@Test public void testRedefinitionChunkedStrategyIsNotRetransforming() throws Exception { Instrumentation instrumentation = mock(Instrumentation.class); when(instrumentation.isRedefineClassesSupported()).thenReturn(true); assertThat( AgentBuilder.RedefinitionStrategy.REDEFINITION_CHUNKED.isRetransforming(instrumentation), is(false)); }
public static void agentmain(@SuppressWarnings("unused") String args, Instrumentation inst) throws Exception { if (inst.isRedefineClassesSupported() && inst.isRetransformClassesSupported()) { inst.addTransformer(new FooTransformer(), true); Class<?>[] allClasses = inst.getAllLoadedClasses(); for (int i = 0; i < allClasses.length; i++) { Class<?> c = allClasses[i]; if (c == Foo.class) { inst.retransformClasses(new Class<?>[] {c}); } } } }
public static synchronized void premain(String agentArguments, Instrumentation instrumentation) { String[] arguments = agentArguments.split(";"); String[] includes = arguments[0].split(","); String[] excludes = arguments[1].split(","); if (Boolean.getBoolean("junit.code.coverage")) { final CoberturaClassFileTransformer coberturaClassFileTransformer = new CoberturaClassFileTransformer(includes, excludes); instrumentation.addTransformer(coberturaClassFileTransformer); Runtime runtime = Runtime.getRuntime(); runtime.addShutdownHook( new Thread() { @Override public void run() { ProjectDataUtil.runMergeHooks(); } }); } else if (instrumentation.isRedefineClassesSupported() && instrumentation.isRetransformClassesSupported()) { _instrumentation = instrumentation; _includes = includes; _excludes = excludes; // Forcibly clear the data file to make sure that the coverage // assert is based on the current test File dataFile = CoverageDataFileHandler.getDefaultDataFile(); dataFile.delete(); } else { StringBuilder sb = new StringBuilder(); sb.append("Current JVM is not capable for dynamic "); sb.append("instrumententation. Instrumentation "); if (instrumentation.isRetransformClassesSupported()) { sb.append("supports "); } else { sb.append("does not support "); } sb.append("restranforming classes. Instrumentation "); if (instrumentation.isRedefineClassesSupported()) { sb.append("supports "); } else { sb.append("does not support "); } sb.append("redefining classes. Dynamic instrumententation is "); sb.append("disabled."); System.out.println(sb.toString()); } }