Class ServiceloaderMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
eu.somatik.maven.serviceloader.ServiceloaderMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
@Mojo(name="generate",
defaultPhase=COMPILE,
requiresDependencyResolution=COMPILE,
requiresProject=true,
threadSafe=true)
public class ServiceloaderMojo
extends org.apache.maven.plugin.AbstractMojo
Goal that generates the services files
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.sonatype.plexus.build.incremental.BuildContextprivate Fileprivate String[]private booleanprivate String[]private Fileprotected org.apache.maven.project.MavenProjectMaven Internal: Project to interact with.private String[]The service interfaces to generate service files forFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()The main entry point for this Mojo.findImplementations(ClassLoader loader, List<Class<?>> interfaceClasses) Finds all implementations of interfaces in a folderprivate URL[]Generates a URL[] with the project class path (can be used by a URLClassLoader)private Fileprivate Fileorg.apache.maven.project.MavenProjectString[]listCompiledClasses(File classFolder) Walks the classFolder and finds all classeslistCompiledClassesRegex(File classFolder) Walks the classFolder and finds all .class filesloadServiceClasses(ClassLoader loader) Loads all interfaces using the provided ClassLoadervoidsetBuildContext(org.sonatype.plexus.build.incremental.BuildContext buildContext) private booleanprivate voidwriteServiceFiles(Map<String, List<String>> serviceImplementations) Writes the output for the service files to diskMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
buildContext
@Component private org.sonatype.plexus.build.incremental.BuildContext buildContext -
project
@Parameter(property="project", required=true, readonly=true) protected org.apache.maven.project.MavenProject projectMaven Internal: Project to interact with. -
classFolder
@Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) private File classFolder -
compileClasspath
-
outputDirectory
@Parameter(defaultValue="${project.build.outputDirectory}/META-INF/services", required=true) private File outputDirectory -
services
The service interfaces to generate service files for -
includes
-
excludes
-
failOnMissingServiceClass
@Parameter(defaultValue="true") private boolean failOnMissingServiceClass
-
-
Constructor Details
-
ServiceloaderMojo
public ServiceloaderMojo()
-
-
Method Details
-
getProject
public org.apache.maven.project.MavenProject getProject() -
getServices
-
getClassFolder
-
getCompileClasspath
-
getOutputDirectory
-
setBuildContext
public void setBuildContext(org.sonatype.plexus.build.incremental.BuildContext buildContext) -
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionExceptionThe main entry point for this Mojo.- Throws:
org.apache.maven.plugin.MojoExecutionException- when an exception occurred during the execution of this plugin
-
writeServiceFiles
-
loadServiceClasses
private List<Class<?>> loadServiceClasses(ClassLoader loader) throws org.apache.maven.plugin.MojoExecutionException Loads all interfaces using the provided ClassLoader- Parameters:
loader- the classloader- Returns:
- thi List of Interface classes
- Throws:
org.apache.maven.plugin.MojoExecutionException- is the interfaces are not interfaces or can not be found on the classpath
-
findImplementations
private Map<String, List<String>> findImplementations(ClassLoader loader, List<Class<?>> interfaceClasses) throws org.apache.maven.plugin.MojoExecutionException Finds all implementations of interfaces in a folder- Parameters:
loader-interfaceClasses-- Returns:
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
listCompiledClasses
-
listCompiledClassesRegex
-
generateClassPathUrls
Generates a URL[] with the project class path (can be used by a URLClassLoader)- Returns:
- the array of classpath URL's
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
skipProject
private boolean skipProject()
-