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.AbstractMojoGoal that generates the services files
-
-
Field Summary
Fields Modifier and Type Field Description private org.sonatype.plexus.build.incremental.BuildContextbuildContextprivate java.io.FileclassFolderprivate java.util.List<java.lang.String>compileClasspathprivate java.lang.String[]excludesprivate booleanfailOnMissingServiceClassprivate java.lang.String[]includesprivate java.io.FileoutputDirectoryprotected org.apache.maven.project.MavenProjectprojectMaven Internal: Project to interact with.private java.lang.String[]servicesThe service interfaces to generate service files for
-
Constructor Summary
Constructors Constructor Description ServiceloaderMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute()The main entry point for this Mojo.private java.util.Map<java.lang.String,java.util.List<java.lang.String>>findImplementations(java.lang.ClassLoader loader, java.util.List<java.lang.Class<?>> interfaceClasses)Finds all implementations of interfaces in a folderprivate java.net.URL[]generateClassPathUrls()Generates a URL[] with the project class path (can be used by a URLClassLoader)private java.io.FilegetClassFolder()java.util.List<java.lang.String>getCompileClasspath()private java.io.FilegetOutputDirectory()org.apache.maven.project.MavenProjectgetProject()java.lang.String[]getServices()(package private) java.util.List<java.lang.String>listCompiledClasses(java.io.File classFolder)Walks the classFolder and finds all classesprivate java.util.List<java.lang.String>listCompiledClassesRegex(java.io.File classFolder)Walks the classFolder and finds all .class filesprivate java.util.List<java.lang.Class<?>>loadServiceClasses(java.lang.ClassLoader loader)Loads all interfaces using the provided ClassLoadervoidsetBuildContext(org.sonatype.plexus.build.incremental.BuildContext buildContext)private booleanskipProject()private voidwriteServiceFiles(java.util.Map<java.lang.String,java.util.List<java.lang.String>> serviceImplementations)Writes the output for the service files to disk
-
-
-
Field Detail
-
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 java.io.File classFolder
-
compileClasspath
@Parameter(defaultValue="${project.compileClasspathElements}", required=true, readonly=true) private java.util.List<java.lang.String> compileClasspath
-
outputDirectory
@Parameter(defaultValue="${project.build.outputDirectory}/META-INF/services", required=true) private java.io.File outputDirectory
-
services
@Parameter private java.lang.String[] services
The service interfaces to generate service files for
-
includes
@Parameter private java.lang.String[] includes
-
excludes
@Parameter private java.lang.String[] excludes
-
failOnMissingServiceClass
@Parameter(defaultValue="true") private boolean failOnMissingServiceClass
-
-
Method Detail
-
getProject
public org.apache.maven.project.MavenProject getProject()
-
getServices
public java.lang.String[] getServices()
-
getClassFolder
private java.io.File getClassFolder()
-
getCompileClasspath
public java.util.List<java.lang.String> getCompileClasspath()
-
getOutputDirectory
private java.io.File 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(java.util.Map<java.lang.String,java.util.List<java.lang.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 java.util.List<java.lang.Class<?>> loadServiceClasses(java.lang.ClassLoader loader) throws org.apache.maven.plugin.MojoExecutionExceptionLoads 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 java.util.Map<java.lang.String,java.util.List<java.lang.String>> findImplementations(java.lang.ClassLoader loader, java.util.List<java.lang.Class<?>> interfaceClasses) throws org.apache.maven.plugin.MojoExecutionExceptionFinds all implementations of interfaces in a folder- Parameters:
loader-interfaceClasses-- Returns:
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
listCompiledClasses
java.util.List<java.lang.String> listCompiledClasses(java.io.File classFolder)
Walks the classFolder and finds all classes- Parameters:
classFolder- the folder to scan for .class files- Returns:
- the list of available class names
-
listCompiledClassesRegex
private java.util.List<java.lang.String> listCompiledClassesRegex(java.io.File classFolder)
Walks the classFolder and finds all .class files- Parameters:
classFolder-- Returns:
- the list of available class names
-
generateClassPathUrls
private java.net.URL[] generateClassPathUrls() throws org.apache.maven.plugin.MojoExecutionExceptionGenerates 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()
-
-