Class ByteBuddyMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- net.bytebuddy.build.maven.ByteBuddyMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
ByteBuddyMojo.ForProductionTypes,ByteBuddyMojo.ForTestTypes
public abstract class ByteBuddyMojo extends org.apache.maven.plugin.AbstractMojoA Maven plugin for applying Byte Buddy transformations during a build.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classByteBuddyMojo.FilePrefixMatcherMatches elements which represent a Java class that is represented in the list or an inner class of the classes represented in the list.static classByteBuddyMojo.ForProductionTypesA Byte Buddy plugin that transforms a project's production class files.static classByteBuddyMojo.ForTestTypesA Byte Buddy plugin that transforms a project's test class files.protected static classByteBuddyMojo.MavenBuildLoggerABuildLoggerimplementation for a MavenLog.protected static classByteBuddyMojo.TransformationLoggerAPlugin.Engine.Listenerthat logs several relevant events during the build.protected static classByteBuddyMojo.TransformerA transformer that is applied during the plugin's execution.
-
Field Summary
Fields Modifier and Type Field Description org.sonatype.plexus.build.incremental.BuildContextcontextThe build context to support incremental builds.booleandiscoverDetermines if the build should discover Byte Buddy build plugins on this Maven plugin's class loader.booleanextendedParsingWhen set totrue, the debug information of class files should be parsed to extract parameter names.booleanfailFastWhen set totrue, this mojo fails immediately if a plugin cannot be applied.booleanfailOnLiveInitializerWhen transforming classes during build time, it is not possible to apply any transformations which require a class in its loaded state.booleanincrementalDetermines if plugins are attempted to be built incrementally.InitializationinitializationThe initializer used for creating aByteBuddyinstance and for applying a transformation.private static java.lang.StringJAVA_CLASS_EXTENSIONThe file extension for Java class files.private static java.lang.StringJAVA_FILE_EXTENSIONThe file extension for Java source files.org.apache.maven.project.MavenProjectprojectThe Maven project.org.eclipse.aether.RepositorySystemrepositorySystemThe currently used repository system.org.eclipse.aether.RepositorySystemSessionrepositorySystemSessionThe currently used system session for the repository system.booleanskipWhen set totrue, this mojo is not applied to the current module.java.lang.StringsuffixSpecifies the method name suffix that is used when type's method need to be rebased.intthreadsIndicates the amount of threads used for parallel type processing or0for serial processing.java.util.List<Transformation>transformationsThe list of transformations.booleanwarnOnEmptyTypeSetWhen set totrue, this mojo warns of not having transformed any types.booleanwarnOnMissingOutputDirectoryWhen set totrue, this mojo warns of an non-existent output directory.
-
Constructor Summary
Constructors Constructor Description ByteBuddyMojo()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private Plugin.Engine.Summaryapply(java.io.File root, java.util.List<? extends java.lang.String> classPath, java.util.List<ByteBuddyMojo.Transformer> transformers, Plugin.Engine.Source source)Applies the instrumentation.voidexecute()private static java.lang.StringfindJavaVersionString(org.apache.maven.project.MavenProject project)Makes a best effort of locating the configured Java target version.protected abstract java.util.List<java.lang.String>getClassPathElements()Returns the class path elements of the relevant output directory.protected abstract java.lang.StringgetOutputDirectory()Returns the output directory to search for class files.protected abstract java.lang.StringgetSourceDirectory()Returns the source directory that determines the class files to process.
-
-
-
Field Detail
-
JAVA_FILE_EXTENSION
private static final java.lang.String JAVA_FILE_EXTENSION
The file extension for Java source files.- See Also:
- Constant Field Values
-
JAVA_CLASS_EXTENSION
private static final java.lang.String JAVA_CLASS_EXTENSION
The file extension for Java class files.- See Also:
- Constant Field Values
-
context
@Component public org.sonatype.plexus.build.incremental.BuildContext context
The build context to support incremental builds.
-
project
@Parameter(defaultValue="${project}", readonly=true) public org.apache.maven.project.MavenProject projectThe Maven project.
-
repositorySystem
@Component public org.eclipse.aether.RepositorySystem repositorySystem
The currently used repository system.
-
repositorySystemSession
@Parameter(defaultValue="${repositorySystemSession}", readonly=true) public org.eclipse.aether.RepositorySystemSession repositorySystemSessionThe currently used system session for the repository system.
-
transformations
@Parameter public java.util.List<Transformation> transformations
The list of transformations. A transformation must specify the
pluginproperty, containing the name of a class to apply. Additionally, it is possible to optionally specify Maven coordinates for a project that contains this plugin class asgroupId,artifactIdandversion. If any of the latter properties is not set, this projects coordinate is used.For example, the following configuration applies the
foo.Barclass which must implementPluginfrom artifacttransform-artifactwith this project's group and version:<transformations> <transformation> <plugin>foo.Bar< /plugin> <artifactId>transform-artifact< /artifactId> < /transformation> < /transformations>If the list of
transformationsis empty or is not supplied at all, this plugin does not apply but prints a warning.
-
initialization
@Parameter public Initialization initialization
The initializer used for creating a
ByteBuddyinstance and for applying a transformation. By default, a type is rebased. The initializer'sentryPointproperty can be set to any constant name ofEntryPoint.Defaultor to a class name. If the latter applies, it is possible to set Maven coordinates for a Maven plugin which defines this class where any property defaults to this project's coordinates.For example, the following configuration applies the
foo.Quxclass which must implementEntryPointfrom artifactinitialization-artifactwith this project's group and version:<initialization> <entryPoint>foo.Qux< /entryPoint> <artifactId>initialization-artifact< /artifactId> < /initialization>
-
suffix
@Parameter public java.lang.String suffix
Specifies the method name suffix that is used when type's method need to be rebased. If this property is not set or is empty, a random suffix will be appended to any rebased method. If this property is set, the supplied value is appended to the original method name.
-
failOnLiveInitializer
@Parameter(defaultValue="true", required=true) public boolean failOnLiveInitializerWhen transforming classes during build time, it is not possible to apply any transformations which require a class in its loaded state. Such transformations might imply setting a type's static field to a user interceptor or similar transformations. If this property is set tofalse, this plugin does not throw an exception if such a live initializer is defined during a transformation process.
-
skip
@Parameter(defaultValue="false", required=true) public boolean skipWhen set totrue, this mojo is not applied to the current module.
-
warnOnMissingOutputDirectory
@Parameter(defaultValue="true", required=true) public boolean warnOnMissingOutputDirectoryWhen set totrue, this mojo warns of an non-existent output directory.
-
warnOnEmptyTypeSet
@Parameter(defaultValue="true", required=true) public boolean warnOnEmptyTypeSetWhen set totrue, this mojo warns of not having transformed any types.
-
failFast
@Parameter(defaultValue="true", required=true) public boolean failFastWhen set totrue, this mojo fails immediately if a plugin cannot be applied.
-
extendedParsing
@Parameter(defaultValue="false", required=true) public boolean extendedParsingWhen set totrue, the debug information of class files should be parsed to extract parameter names.
-
discover
@Parameter(defaultValue="true", required=true) public boolean discoverDetermines if the build should discover Byte Buddy build plugins on this Maven plugin's class loader. Discovered plugins are stored by their name in the /META-INF/net.bytebuddy/build.plugins file where each line contains the fully qualified class name. Discovered plugins are not provided with any explicit constructor arguments.
-
threads
@Parameter(defaultValue="0", required=true) public int threadsIndicates the amount of threads used for parallel type processing or0for serial processing.
-
incremental
@Parameter(defaultValue="false", required=true) public boolean incrementalDetermines if plugins are attempted to be built incrementally.
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
getOutputDirectory
protected abstract java.lang.String getOutputDirectory()
Returns the output directory to search for class files.- Returns:
- The output directory to search for class files.
-
getSourceDirectory
protected abstract java.lang.String getSourceDirectory()
Returns the source directory that determines the class files to process.- Returns:
- The source directory that serves as an input for the transformation.
-
getClassPathElements
protected abstract java.util.List<java.lang.String> getClassPathElements() throws org.apache.maven.plugin.MojoFailureExceptionReturns the class path elements of the relevant output directory.- Returns:
- The class path elements of the relevant output directory.
- Throws:
org.apache.maven.plugin.MojoFailureException- If the class path cannot be resolved.
-
apply
private Plugin.Engine.Summary apply(java.io.File root, java.util.List<? extends java.lang.String> classPath, java.util.List<ByteBuddyMojo.Transformer> transformers, Plugin.Engine.Source source) throws org.apache.maven.plugin.MojoExecutionException, java.io.IOException
Applies the instrumentation.- Parameters:
root- The root folder that contains all class files.classPath- An iterable over all class path elements.transformers- The transformers to apply.source- The source for the plugin's application.- Returns:
- A summary of the applied transformation.
- Throws:
org.apache.maven.plugin.MojoExecutionException- If the plugin cannot be applied.java.io.IOException- If an I/O exception occurs.
-
findJavaVersionString
private static java.lang.String findJavaVersionString(org.apache.maven.project.MavenProject project)
Makes a best effort of locating the configured Java target version.- Parameters:
project- The relevant Maven project.- Returns:
- The Java version string of the configured build target version or
nullif no explicit configuration was detected.
-
-