use of net.bytebuddy.build.EntryPoint in project byte-buddy by raphw.
the class TransformationAction method processOutputDirectory.
/**
* Processes all class files within the given directory.
*
* @param root The root directory to process.
* @param classPath A list of class path elements expected by the processed classes.
* @throws IOException If an I/O exception occurs.
*/
private void processOutputDirectory(File root, Iterable<? extends File> classPath) throws IOException {
if (!root.isDirectory()) {
throw new GradleException("Target location does not exist or is no directory: " + root);
}
ClassLoaderResolver classLoaderResolver = new ClassLoaderResolver();
try {
List<Plugin> plugins = new ArrayList<Plugin>(byteBuddyExtension.getTransformations().size());
for (Transformation transformation : byteBuddyExtension.getTransformations()) {
String plugin = transformation.getPlugin();
try {
plugins.add((Plugin) Class.forName(plugin, false, classLoaderResolver.resolve(transformation.getClassPath(root, classPath))).getDeclaredConstructor().newInstance());
project.getLogger().info("Created plugin: {}", plugin);
} catch (Exception exception) {
if (exception instanceof GradleException) {
throw (GradleException) exception;
}
throw new GradleException("Cannot create plugin: " + transformation.getRawPlugin(), exception);
}
}
EntryPoint entryPoint = byteBuddyExtension.getInitialization().getEntryPoint(classLoaderResolver, root, classPath);
project.getLogger().info("Resolved entry point: {}", entryPoint);
transform(root, classPath, entryPoint, plugins);
} finally {
classLoaderResolver.close();
}
}
use of net.bytebuddy.build.EntryPoint in project byte-buddy by raphw.
the class ByteBuddyMojo method processOutputDirectory.
/**
* Processes all class files within the given directory.
*
* @param root The root directory to process.
* @param classPath A list of class path elements expected by the processed classes.
* @throws MojoExecutionException If the user configuration results in an error.
* @throws MojoFailureException If the plugin application raises an error.
* @throws IOException If an I/O exception occurs.
*/
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Applies Maven exception wrapper")
private void processOutputDirectory(File root, List<? extends String> classPath) throws MojoExecutionException, MojoFailureException, IOException {
if (!root.isDirectory()) {
throw new MojoExecutionException("Target location does not exist or is no directory: " + root);
}
ClassLoaderResolver classLoaderResolver = new ClassLoaderResolver(getLog(), repositorySystem, repositorySystemSession, remoteRepositories);
try {
List<Plugin> plugins = new ArrayList<Plugin>(transformations.size());
for (Transformation transformation : transformations) {
String plugin = transformation.getPlugin();
try {
plugins.add((Plugin) Class.forName(plugin, false, classLoaderResolver.resolve(transformation.asCoordinate(groupId, artifactId, version))).getDeclaredConstructor().newInstance());
getLog().info("Created plugin: " + plugin);
} catch (Exception exception) {
throw new MojoExecutionException("Cannot create plugin: " + transformation.getRawPlugin(), exception);
}
}
EntryPoint entryPoint = (initialization == null ? Initialization.makeDefault() : initialization).getEntryPoint(classLoaderResolver, groupId, artifactId, version);
getLog().info("Resolved entry point: " + entryPoint);
transform(root, entryPoint, classPath, plugins);
} finally {
classLoaderResolver.close();
}
}
use of net.bytebuddy.build.EntryPoint in project byte-buddy by raphw.
the class AgentBuilderDefaultTest method testBuildPluginWithEntryPoint.
@Test
public void testBuildPluginWithEntryPoint() throws Exception {
Plugin plugin = mock(Plugin.class);
EntryPoint entryPoint = mock(EntryPoint.class);
ByteBuddy byteBuddy = mock(ByteBuddy.class);
when(entryPoint.getByteBuddy()).thenReturn(byteBuddy);
assertThat(AgentBuilder.Default.of(entryPoint, plugin), is((AgentBuilder) new AgentBuilder.Default(byteBuddy).with(new AgentBuilder.TypeStrategy.ForBuildEntryPoint(entryPoint)).type(plugin).transform(new AgentBuilder.Transformer.ForBuildPlugin(plugin))));
}
Aggregations