Package com.vaadin.flow.plugin.maven
Class Reflector
java.lang.Object
com.vaadin.flow.plugin.maven.Reflector
Helper class to deal with classloading of Flow plugin mojos.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReflector(URLClassLoader isolatedClassLoader) Creates a new reflector instance for the given classloader. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.maven.plugin.MojocreateMojo(BuildDevBundleMojo sourceMojo) Creates a copy of the given Flow mojo, loading classes the isolated classloader.Gets the isolated class loader.getResource(String name) Get a resource from the classpath of the isolated class loader.Class<?> Loads the class with the given name from the isolated classloader.static Reflectorof(org.apache.maven.project.MavenProject project, org.apache.maven.plugin.MojoExecution mojoExecution) Gets a newReflectorinstance for the current Mojo execution.
-
Field Details
-
INCLUDE_FROM_COMPILE_DEPS_REGEX
- See Also:
-
-
Constructor Details
-
Reflector
Creates a new reflector instance for the given classloader.- Parameters:
isolatedClassLoader- class loader to be used to create mojo instances.
-
-
Method Details
-
getIsolatedClassLoader
Gets the isolated class loader.- Returns:
- the isolated class loader.
-
loadClass
Loads the class with the given name from the isolated classloader.- Parameters:
className- the name of the class to load.- Returns:
- the class object.
- Throws:
ClassNotFoundException- if the class was not found.
-
getResource
Get a resource from the classpath of the isolated class loader.- Parameters:
name- class literal- Returns:
- the resource
-
createMojo
Creates a copy of the given Flow mojo, loading classes the isolated classloader.Loads the given mojo class from the isolated class loader and then creates a new instance for it and fills all field copying values from the original mojo. The input mojo must have a public no-args constructor. Mojo fields must reference types that can be safely loaded be the isolated class loader, such as JDK or Maven core API. It also creates and injects a
ClassFinder, based on the isolated class loader.- Parameters:
sourceMojo- The mojo for which to create the instance from the isolated class loader.- Returns:
- an instance of the mojo loaded from the isolated class loader.
- Throws:
Exception- if the mojo instance cannot be created.
-
of
public static Reflector of(org.apache.maven.project.MavenProject project, org.apache.maven.plugin.MojoExecution mojoExecution) Gets a newReflectorinstance for the current Mojo execution.An isolated class loader is created based on project and plugin dependencies, with the first ones having precedence over the seconds. The maven.api class realm is used as parent classloader, allowing usage of Maven core classes in the mojo.
- Parameters:
project- the maven project.mojoExecution- the current mojo execution.- Returns:
- a Reflector instance for the current maven execution.
-