Class AbstractMetaschemaMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
dev.metaschema.maven.plugin.AbstractMetaschemaMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
GenerateSchemaMojo, GenerateSourcesMojo

public abstract class AbstractMetaschemaMojo extends org.apache.maven.plugin.AbstractMojo
Abstract base class for Metaschema Maven plugin goals.

This class provides common functionality for loading Metaschema modules, managing constraint sets, handling incremental builds, and performing code/schema generation. Concrete implementations should override the generate(Set) method to provide specific generation behavior.

The plugin supports:

  • Loading multiple Metaschema modules from a configured directory
  • Applying external constraint sets to modules
  • Incremental build support through stale file tracking
  • Configurable file encoding for generated sources
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected final class 
    A validation result handler that logs validation findings using the Maven plugin logger.
    class 
    A module binding generator that generates and compiles Java classes for Metaschema modules during plugin execution.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String[]
    A set of exclusion patterns used to prevent certain files from being processed.
    protected String[]
    A set of inclusion patterns used to select which Metaschema modules are to be processed.
    protected File
    The directory where the staleFile is found.

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    createStaleFile(File staleFile)
    Create or update the stale file to record the current build time.
    void
     
    protected abstract List<File>
    generate(Set<dev.metaschema.core.model.IModule> modules)
    Perform the generation operation.
    protected final org.sonatype.plexus.build.incremental.BuildContext
    The BuildContext is used to identify which files or directories were modified since last build.
    protected Set<String>
    Retrieve the combined classpath containing both project dependencies and plugin artifacts.
    protected List<dev.metaschema.core.model.constraint.IConstraintSet>
    Get the configured collection of constraints.
    protected final String
    Gets the file encoding to use for generated classes.
    protected final org.apache.maven.project.MavenProject
    Retrieve the Maven project context.
    protected Stream<File>
    Retrieve a stream of Module file sources.
    protected Set<dev.metaschema.core.model.IModule>
    getModulesToGenerateFor(dev.metaschema.databind.IBindingContext bindingContext, dev.metaschema.core.model.IModuleLoader.IModulePostProcessor modulePostProcessor)
    Load and validate the Metaschema modules to generate sources or schemas for.
    org.apache.maven.plugin.MojoExecution
    Retrieve the mojo execution context.
    protected File
    Retrieve the directory where generated classes will be stored.
    protected final List<org.apache.maven.artifact.Artifact>
    Retrieve the plugin artifacts available to this mojo.
    protected final File
    Gets the staleFile for this execution.
    protected abstract String
    Get the name of the file that is used to detect staleness.
    protected boolean
    Determine if code generation is required.
    protected dev.metaschema.databind.IBindingContext
    newBindingContext(dev.metaschema.core.model.IModuleLoader.IModulePostProcessor modulePostProcessor)
    Create a new binding context configured with the specified module post processor.
    protected void
    setOutputDirectory(File outputDirectory)
    Set the directory where generated classes will be stored.
    protected boolean
    Determine if the execution of this mojo should be skipped.

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • staleFileDirectory

      @Parameter(defaultValue="${project.build.directory}/metaschema", readonly=true, required=true) protected File staleFileDirectory

      The directory where the staleFile is found. The staleFile is used to determine if re-generation of generated Java classes is needed, by recording when the last build occurred.

      This directory is expected to be located within the ${project.build.directory}, to ensure that code (re)generation occurs after cleaning the project.

    • includes

      @Parameter protected String[] includes
      A set of inclusion patterns used to select which Metaschema modules are to be processed. By default, all files are processed.
    • excludes

      @Parameter protected String[] excludes
      A set of exclusion patterns used to prevent certain files from being processed. By default, this set is empty such that no files are excluded.
  • Constructor Details

  • Method Details

    • getBuildContext

      protected final org.sonatype.plexus.build.incremental.BuildContext getBuildContext()
      The BuildContext is used to identify which files or directories were modified since last build. This is used to determine if Module-based generation must be performed again.
      Returns:
      the active Plexus BuildContext.
    • getMavenProject

      protected final org.apache.maven.project.MavenProject getMavenProject()
      Retrieve the Maven project context.
      Returns:
      The active MavenProject.
    • getPluginArtifacts

      protected final List<org.apache.maven.artifact.Artifact> getPluginArtifacts()
      Retrieve the plugin artifacts available to this mojo.
      Returns:
      the list of plugin artifacts
    • getMojoExecution

      public org.apache.maven.plugin.MojoExecution getMojoExecution()
      Retrieve the mojo execution context.
      Returns:
      The active MojoExecution.
    • getOutputDirectory

      protected File getOutputDirectory()
      Retrieve the directory where generated classes will be stored.
      Returns:
      the directory
    • setOutputDirectory

      protected void setOutputDirectory(File outputDirectory)
      Set the directory where generated classes will be stored.
      Parameters:
      outputDirectory - the directory to use
    • getEncoding

      protected final String getEncoding()
      Gets the file encoding to use for generated classes.

      The algorithm for finding the encoding to use is as follows (where the first non-null value found is used for encoding):

      1. If the configuration property is explicitly given within the plugin's configuration, use that value.
      2. If the Maven property project.build.sourceEncoding is defined, use its value.
      3. Otherwise use the value from the system property file.encoding.
      Returns:
      The encoding to be used by this AbstractJaxbMojo and its tools.
    • getModuleSources

      Retrieve a stream of Module file sources.
      Returns:
      the stream
    • newBindingContext

      @NonNull protected dev.metaschema.databind.IBindingContext newBindingContext(@NonNull dev.metaschema.core.model.IModuleLoader.IModulePostProcessor modulePostProcessor) throws IOException, dev.metaschema.core.model.MetaschemaException
      Create a new binding context configured with the specified module post processor.
      Parameters:
      modulePostProcessor - the post processor to apply to loaded modules
      Returns:
      the configured binding context
      Throws:
      IOException - if an I/O error occurs during context creation
      dev.metaschema.core.model.MetaschemaException - if an error occurs while processing the Metaschema module
    • getConstraints

      @NonNull protected List<dev.metaschema.core.model.constraint.IConstraintSet> getConstraints() throws org.apache.maven.plugin.MojoExecutionException
      Get the configured collection of constraints.
      Returns:
      the loaded constraints
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if an error occurred while loading the constraints
    • shouldExecutionBeSkipped

      protected boolean shouldExecutionBeSkipped()
      Determine if the execution of this mojo should be skipped.
      Returns:
      true if the mojo execution should be skipped, or false otherwise
    • getStaleFileName

      protected abstract String getStaleFileName()
      Get the name of the file that is used to detect staleness.
      Returns:
      the name
    • getStaleFile

      protected final File getStaleFile()
      Gets the staleFile for this execution.
      Returns:
      the staleFile
    • isGenerationRequired

      protected boolean isGenerationRequired()
      Determine if code generation is required. This is done by comparing the last modified time of each Module source file against the stale file managed by this plugin.
      Returns:
      true if the code generation is needed, or false otherwise
    • getClassPath

      protected Set<String> getClassPath() throws org.apache.maven.artifact.DependencyResolutionRequiredException
      Retrieve the combined classpath containing both project dependencies and plugin artifacts.
      Returns:
      a set of classpath elements as absolute paths
      Throws:
      org.apache.maven.artifact.DependencyResolutionRequiredException - if the project dependencies cannot be resolved
    • getModulesToGenerateFor

      @NonNull protected Set<dev.metaschema.core.model.IModule> getModulesToGenerateFor(@NonNull dev.metaschema.databind.IBindingContext bindingContext, @NonNull dev.metaschema.core.model.IModuleLoader.IModulePostProcessor modulePostProcessor) throws dev.metaschema.core.model.MetaschemaException, IOException, dev.metaschema.core.model.constraint.ConstraintValidationException
      Load and validate the Metaschema modules to generate sources or schemas for.
      Parameters:
      bindingContext - the binding context to use for module loading and validation
      modulePostProcessor - the post processor to apply to each loaded module
      Returns:
      the set of loaded and validated modules
      Throws:
      dev.metaschema.core.model.MetaschemaException - if an error occurs while processing the Metaschema module
      IOException - if an I/O error occurs while loading a module
      dev.metaschema.core.model.constraint.ConstraintValidationException - if constraint validation fails on a loaded module
    • createStaleFile

      protected void createStaleFile(@NonNull File staleFile) throws org.apache.maven.plugin.MojoExecutionException
      Create or update the stale file to record the current build time.
      Parameters:
      staleFile - the stale file to create or update
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if the stale file cannot be created
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • generate

      @NonNull protected abstract List<File> generate(@NonNull Set<dev.metaschema.core.model.IModule> modules) throws org.apache.maven.plugin.MojoExecutionException
      Perform the generation operation.
      Parameters:
      modules - the modules to generate resources/sources for
      Returns:
      the files generated during the operation
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if an error occurred while performing the generation operation