use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.
the class AgentBuilderLocationStrategySimpleTest method testLocation.
@Test
public void testLocation() throws Exception {
ClassFileLocator classFileLocator = mock(ClassFileLocator.class);
assertThat(new AgentBuilder.LocationStrategy.Simple(classFileLocator).classFileLocator(mock(ClassLoader.class), mock(JavaModule.class)), is(classFileLocator));
}
use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.
the class AdviceTest method testIOExceptionOnRead.
@Test(expected = IllegalStateException.class)
public void testIOExceptionOnRead() throws Exception {
ClassFileLocator classFileLocator = mock(ClassFileLocator.class);
when(classFileLocator.locate(TrivialAdvice.class.getName())).thenThrow(new IOException());
Advice.to(TrivialAdvice.class, classFileLocator);
}
use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.
the class TransformationAction method transform.
/**
* Applies all registered transformations.
*
* @param root The root directory to process.
* @param entryPoint The transformation's entry point.
* @param classPath A list of class path elements expected by the processed classes.
* @param plugins The plugins to apply.
* @throws IOException If an I/O exception occurs.
*/
private void transform(File root, Iterable<? extends File> classPath, EntryPoint entryPoint, List<Plugin> plugins) throws IOException {
List<ClassFileLocator> classFileLocators = new ArrayList<ClassFileLocator>();
classFileLocators.add(new ClassFileLocator.ForFolder(root));
for (File artifact : classPath) {
classFileLocators.add(artifact.isFile() ? ClassFileLocator.ForJarFile.of(artifact) : new ClassFileLocator.ForFolder(artifact));
}
ClassFileLocator classFileLocator = new ClassFileLocator.Compound(classFileLocators);
try {
TypePool typePool = new TypePool.Default.WithLazyResolution(new TypePool.CacheProvider.Simple(), classFileLocator, TypePool.Default.ReaderMode.FAST, TypePool.ClassLoading.ofBootPath());
project.getLogger().info("Processing class files located in in: {}", root);
ByteBuddy byteBuddy;
try {
byteBuddy = entryPoint.getByteBuddy();
} catch (Throwable throwable) {
throw new GradleException("Cannot create Byte Buddy instance", throwable);
}
processDirectory(root, root, byteBuddy, entryPoint, byteBuddyExtension.getMethodNameTransformer(), classFileLocator, typePool, plugins);
} finally {
classFileLocator.close();
}
}
use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.
the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperClassNavigatedHierarchyResolutionIsLazy.
@Test
public void testGenericSuperClassNavigatedHierarchyResolutionIsLazy() throws Exception {
ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getSuperClass().getSuperClass().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SuperClass.class)));
verify(classFileLocator).locate(GenericType.class.getName());
verify(classFileLocator).locate(SampleGenericClass.class.getName());
verifyNoMoreInteractions(classFileLocator);
}
use of net.bytebuddy.dynamic.ClassFileLocator in project byte-buddy by raphw.
the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperClassHierarchyResolutionIsLazy.
@Test
public void testGenericSuperClassHierarchyResolutionIsLazy() throws Exception {
ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getSuperClass().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SampleGenericClass.class)));
verify(classFileLocator).locate(GenericType.class.getName());
verifyNoMoreInteractions(classFileLocator);
}
Aggregations