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 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 project
      Maven Internal: Project to interact with.
    • classFolder

      @Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) private File classFolder
    • compileClasspath

      @Parameter(defaultValue="${project.compileClasspathElements}", required=true, readonly=true) private List<String> compileClasspath
    • outputDirectory

      @Parameter(defaultValue="${project.build.outputDirectory}/META-INF/services", required=true) private File outputDirectory
    • services

      @Parameter private String[] services
      The service interfaces to generate service files for
    • includes

      @Parameter private String[] includes
    • excludes

      @Parameter private String[] excludes
    • failOnMissingServiceClass

      @Parameter(defaultValue="true") private boolean failOnMissingServiceClass
  • Constructor Details

    • ServiceloaderMojo

      public ServiceloaderMojo()
  • Method Details

    • getProject

      public org.apache.maven.project.MavenProject getProject()
    • getServices

      public String[] getServices()
    • getClassFolder

      private File getClassFolder()
    • getCompileClasspath

      public List<String> getCompileClasspath()
    • getOutputDirectory

      private File getOutputDirectory()
    • setBuildContext

      public void setBuildContext(org.sonatype.plexus.build.incremental.BuildContext buildContext)
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      The 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.MojoExecutionException
      Writes 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

      List<String> listCompiledClasses(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 List<String> listCompiledClassesRegex(File classFolder)
      Walks the classFolder and finds all .class files
      Parameters:
      classFolder -
      Returns:
      the list of available class names
    • generateClassPathUrls

      private URL[] generateClassPathUrls() throws org.apache.maven.plugin.MojoExecutionException
      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()