Package eu.somatik.maven.serviceloader
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.BuildContext
private File
private String[]
private boolean
private String[]
private File
protected org.apache.maven.project.MavenProject
Maven 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 TypeMethodDescriptionvoid
execute()
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 File
private File
org.apache.maven.project.MavenProject
String[]
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 ClassLoadervoid
setBuildContext
(org.sonatype.plexus.build.incremental.BuildContext buildContext) private boolean
private void
writeServiceFiles
(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
private void writeServiceFiles(Map<String, List<String>> serviceImplementations) throws org.apache.maven.plugin.MojoExecutionExceptionWrites the output for the service files to disk- Parameters:
serviceImplementations
-- Throws:
org.apache.maven.plugin.MojoExecutionException
-
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
Walks the classFolder and finds all classes- Parameters:
classFolder
- the folder to scan for .class files- Returns:
- the list of available class names
-
listCompiledClassesRegex
Walks the classFolder and finds all .class files- Parameters:
classFolder
-- Returns:
- the list of available class names
-
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()
-