Class AbstractGWMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.machanism.machai.gw.maven.AbstractGWMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
ActMojo, GWMojo, GWPerModuleMojo

public abstract class AbstractGWMojo extends org.apache.maven.plugin.AbstractMojo
Base class for Maven goals that scan project files for guidance comments and delegate processing to a GuidanceProcessor.

The mojo resolves Maven project/session context, optional scanner inputs, and GenAI provider credentials from Maven settings before executing the scan. It is intended to be extended by concrete plugin goals that create and configure the processor instance.

Parameters

  • model: Provider or model identifier supplied with -D followed by GWConstants.MODEL_PROP_NAME; for example, mvn machai:goal -D followed by GWConstants.MODEL_PROP_NAME followed by =openai:gpt-4o-mini.
  • basedir: Maven module base directory. The default value is the Maven expression ${basedir}; for example, Maven injects the current module directory automatically during normal plugin execution.
  • path: Optional file, directory, glob, or pattern to scan, supplied with -D followed by GWConstants.PATH_PROP_NAME; for example, mvn machai:goal -D followed by GWConstants.PATH_PROP_NAME followed by =src/main/java.
  • instructions: Additional workflow instructions, supplied with -D followed by GWConstants.INSTRUCTIONS_PROP_NAME; for example, mvn machai:goal -D followed by GWConstants.INSTRUCTIONS_PROP_NAME followed by ="Keep public APIs backward compatible".
  • excludes: Paths or patterns excluded from scanning, supplied with -D followed by GWConstants.EXCLUDES_PROP_NAME; for example, mvn machai:goal -D followed by GWConstants.EXCLUDES_PROP_NAME followed by =target,build.
  • project: Current Maven project injected from the Maven expression ${project}; for example, this is used automatically to locate the project base directory.
  • session: Current Maven session injected from the Maven expression ${session}; for example, this is used automatically to resolve the execution root directory.
  • settings: Maven settings injected from the Maven expression ${settings}; for example, this is used automatically to look up server credentials from settings.xml.
  • serverId: Maven server id for GenAI credentials, supplied with -D followed by AbstractAIProvider.SERVERID_PROP_NAME; for example, mvn machai:goal -D followed by AbstractAIProvider.SERVERID_PROP_NAME followed by =machai-ai. The corresponding <server> entry may define username, password, and custom configuration values.
  • reactorProjects: Reactor projects injected from the Maven expression ${reactorProjects}; for example, this is used automatically during multi-module builds.

When documenting XML snippets in this Javadoc, write any literal closing Javadoc delimiter as *&#47; rather than the raw delimiter.

Since:
1.1.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected File
    The Maven module base directory.
    Tool set exposed to the processor for class-related project introspection.
    protected String[]
    Exclude patterns or path skipped during scanning.
    protected String
    Instruction locations consumed by the workflow.
    (package private) static final org.slf4j.Logger
     
    protected String
    Provider/model identifier to pass to the workflow.
    (package private) String
    Optional scan root override.
    protected org.apache.maven.project.MavenProject
    The current Maven project.
    protected List<org.apache.maven.project.MavenProject>
    Reactor projects available in the current Maven session.
    private String
    Maven server id used to resolve GenAI credentials.
    protected org.apache.maven.execution.MavenSession
    The current Maven session.
    private org.apache.maven.settings.Settings
    Maven settings used to resolve credentials from settings.xml.

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

    ROLE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates the base mojo instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Builds the processor configuration.
    protected void
    Configures and executes document scanning for the current project context.

    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

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

    execute
  • Field Details

    • logger

      static final org.slf4j.Logger logger
    • model

      @Parameter(property="gw.model") protected String model
      Provider/model identifier to pass to the workflow.
    • basedir

      @Parameter(defaultValue="${basedir}", required=true) protected File basedir
      The Maven module base directory.
    • path

      @Parameter(property="gw.path") String path
      Optional scan root override.
    • instructions

      @Parameter(property="gw.instructions", name="instructions") protected String instructions
      Instruction locations consumed by the workflow.
    • excludes

      @Parameter(property="gw.excludes", name="excludes") protected String[] excludes
      Exclude patterns or path skipped during scanning.
    • project

      @Parameter(readonly=true, defaultValue="${project}") protected org.apache.maven.project.MavenProject project
      The current Maven project.
    • session

      @Parameter(defaultValue="${session}", readonly=true, required=true) protected org.apache.maven.execution.MavenSession session
      The current Maven session.
    • settings

      @Parameter(readonly=true, defaultValue="${settings}") private org.apache.maven.settings.Settings settings
      Maven settings used to resolve credentials from settings.xml.
    • serverId

      @Parameter(property="genai.serverId", required=false) private String serverId
      Maven server id used to resolve GenAI credentials.
    • reactorProjects

      @Parameter(defaultValue="${reactorProjects}", readonly=true) protected List<org.apache.maven.project.MavenProject> reactorProjects
      Reactor projects available in the current Maven session.
    • classFunctionTools

      protected ClassFunctionalTools classFunctionTools
      Tool set exposed to the processor for class-related project introspection.
  • Constructor Details

    • AbstractGWMojo

      protected AbstractGWMojo()
      Creates the base mojo instance.
  • Method Details

    • getConfiguration

      protected PropertiesConfigurator getConfiguration() throws org.apache.maven.plugin.MojoExecutionException
      Builds the processor configuration.

      If a Maven server id is configured, this method reads the matching server entry from settings.xml and copies its username, password, and any custom XML configuration values into the returned configurator.

      Returns:
      configuration for downstream workflow execution
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if Maven settings are unavailable or the configured server cannot be found
    • scanDocuments

      protected void scanDocuments(GuidanceProcessor processor) throws org.apache.maven.plugin.MojoExecutionException
      Configures and executes document scanning for the current project context.

      This method applies configured excludes, optional instructions, input logging, and scan directory selection before invoking AIFileProcessor.scanDocuments(File, String). When a Maven project is present in the request, class-related helper tools are also registered with the processor.

      Parameters:
      processor - the processor to configure and execute
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if scanning or processing fails