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:
AbstractActMojo, 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 and session context, scanner inputs, and GenAI provider credentials before executing a scan. It loads configuration from a file, optionally merges a Maven <server> configuration, and finally applies explicit plugin parameters. Concrete goals create the processor and invoke scanDocuments(GuidanceProcessor).

Maven parameters

  • model: provider/model identifier; for example, -Dgenai.model=openai:gpt-4o-mini.
  • basedir: module directory, automatically injected from ${basedir}.
  • path: file, directory, glob, or pattern to scan; for example, -Dgenai.path=src/main/java.
  • instructions: extra workflow instructions; for example, -Dgenai.instructions="Keep public APIs compatible".
  • excludes: skipped paths or patterns; for example, -Dgenai.excludes=target,build.
  • project: current project, injected from ${project}.
  • session: current session, injected from ${session}.
  • settings: Maven settings, injected from ${settings}.
  • serverId: credentials server id; for example, -Dgenai.serverId=machai-ai.
  • params: configuration map; for example, <params><endpoint>https://api.example.test</endpoint></params>.
  • configFile: configuration file; for example, -Dgenai.config=machai.properties.

Literal closing Javadoc delimiters in documentation must be written as *&#47;.

Since:
1.1.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected File
    Maven module base directory injected from the ${basedir} expression.
    Tool set exposed to the processor for class-related project introspection when Maven is executing with a project.
    protected File
    Optional configuration file loaded before Maven server and explicit parameter values are applied.
    protected String[]
    Paths or patterns skipped during scanning.
    protected String
    Additional instructions passed to the workflow before scanning.
    (package private) static final org.slf4j.Logger
    Logger shared by Maven goal implementations in this package.
    protected String
    Provider/model identifier to pass to the workflow, optionally supplied with the "gw.model" Maven property.
    protected Map<String,String>
    Additional key-value configuration entries merged into the processor configuration.
    protected String
    Optional scan root override.
    protected org.apache.maven.project.MavenProject
    Current Maven project, used to determine the module base directory and whether project-aware tools should be registered.
    protected String
    Maven server id used to resolve GenAI credentials and custom server configuration.
    static final String
    Maven property name for the target GenAI server identifier.
    protected org.apache.maven.execution.MavenSession
    Current Maven session, used to obtain execution-root and request context.
    protected org.apache.maven.settings.Settings
    Maven settings used to resolve credentials and custom configuration 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.
    void
    setBasedir(File basedir)
    Sets the Maven module base directory.
    void
    setConfigFile(File configFile)
    Sets the optional configuration file to load.
    void
    setExcludes(String[] excludes)
    Sets paths or patterns excluded from document scanning.
    void
    setInstructions(String instructions)
    Sets additional instructions for the workflow.
    void
    Sets the provider or model identifier passed to the workflow.
    void
    Sets explicit key-value configuration entries.
    void
    Sets the optional file, directory, glob, or pattern to scan.
    void
    setProject(org.apache.maven.project.MavenProject project)
    Sets the current Maven project.
    void
    setServerId(String serverId)
    Sets the Maven server id used to obtain GenAI credentials.
    void
    setSession(org.apache.maven.execution.MavenSession session)
    Sets the Maven session that supplies the execution root and request context.
    void
    setSettings(org.apache.maven.settings.Settings settings)
    Sets Maven settings used to look up the configured GenAI server.

    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
      Logger shared by Maven goal implementations in this package. It records configuration and scanning lifecycle events.
    • SERVERID_PROP_NAME

      public static final String SERVERID_PROP_NAME
      Maven property name for the target GenAI server identifier. Supply its value with -Dgenai.serverId=server-id.
      See Also:
    • model

      protected String model
      Provider/model identifier to pass to the workflow, optionally supplied with the "gw.model" Maven property.
    • basedir

      protected File basedir
      Maven module base directory injected from the ${basedir} expression.
    • path

      protected String path
      Optional scan root override. When absent, scanning starts at the Maven execution root directory.
    • instructions

      protected String instructions
      Additional instructions passed to the workflow before scanning.
    • excludes

      protected String[] excludes
      Paths or patterns skipped during scanning.
    • project

      protected org.apache.maven.project.MavenProject project
      Current Maven project, used to determine the module base directory and whether project-aware tools should be registered.
    • session

      protected org.apache.maven.execution.MavenSession session
      Current Maven session, used to obtain execution-root and request context.
    • settings

      protected org.apache.maven.settings.Settings settings
      Maven settings used to resolve credentials and custom configuration from settings.xml.
    • serverId

      protected String serverId
      Maven server id used to resolve GenAI credentials and custom server configuration.
    • params

      protected Map<String,String> params
      Additional key-value configuration entries merged into the processor configuration.

      For example, plugin XML can provide <params><timeout>30</timeout></params>.

    • configFile

      protected File configFile
      Optional configuration file loaded before Maven server and explicit parameter values are applied. For example, -D followed by GWConstants.CONFIG_PROP_NAME followed by =machai.properties selects a custom configuration file.
    • classFunctionTools

      protected ClassFunctionalTools classFunctionTools
      Tool set exposed to the processor for class-related project introspection when Maven is executing with a project.
  • 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.

      Configuration is loaded first from the explicitly configured file, or from the default workflow configuration file when no file is supplied. Values from the selected Maven server and then params are applied in that order, so explicit plugin parameters take precedence over earlier sources.

      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:
      a configurator containing the resolved workflow properties
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if a specified configuration file cannot be loaded, Maven settings are unavailable for a configured server id, or that 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 non-null processor to configure and execute
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if project scanning or document processing fails; the original failure is retained as the exception cause
    • setSettings

      @Parameter(readonly=true, defaultValue="${settings}") public void setSettings(org.apache.maven.settings.Settings settings)
      Sets Maven settings used to look up the configured GenAI server.
      Parameters:
      settings - Maven settings injected by the plugin runtime; may be null outside normal Maven execution
    • setSession

      @Parameter(defaultValue="${session}", readonly=true, required=true) public void setSession(org.apache.maven.execution.MavenSession session)
      Sets the Maven session that supplies the execution root and request context.
      Parameters:
      session - Maven session injected by the plugin runtime
    • setModel

      @Parameter(property="gw.model") public void setModel(String model)
      Sets the provider or model identifier passed to the workflow.
      Parameters:
      model - provider/model identifier, or null to use configured defaults
    • setBasedir

      @Parameter(defaultValue="${basedir}", required=true) public void setBasedir(File basedir)
      Sets the Maven module base directory.
      Parameters:
      basedir - module base directory injected by Maven
    • setPath

      @Parameter(property="gw.path", name="path") public void setPath(String path)
      Sets the optional file, directory, glob, or pattern to scan.
      Parameters:
      path - scan input, or null to scan from the execution root
    • setInstructions

      @Parameter(property="gw.instructions", name="instructions") public void setInstructions(String instructions)
      Sets additional instructions for the workflow.
      Parameters:
      instructions - workflow instructions, or null when none are provided
    • setExcludes

      @Parameter(property="gw.excludes", name="excludes") public void setExcludes(String[] excludes)
      Sets paths or patterns excluded from document scanning.
      Parameters:
      excludes - excluded paths or patterns, or null for no explicit exclusions
    • setProject

      @Parameter(readonly=true, defaultValue="${project}") public void setProject(org.apache.maven.project.MavenProject project)
      Sets the current Maven project.
      Parameters:
      project - Maven project injected by the plugin runtime
    • setServerId

      @Parameter(property="genai.serverId", required=false) public void setServerId(String serverId)
      Sets the Maven server id used to obtain GenAI credentials.
      Parameters:
      serverId - id of a <server> entry in settings.xml, or null to rely on file-based configuration
    • setParams

      @Parameter public void setParams(Map<String,String> params)
      Sets explicit key-value configuration entries. These values override values loaded from the configuration file and Maven server configuration.
      Parameters:
      params - configuration entries, or null when none are supplied
    • setConfigFile

      @Parameter(property="gw.config", required=false) public void setConfigFile(File configFile)
      Sets the optional configuration file to load.
      Parameters:
      configFile - configuration file, or null to use the default workflow configuration file when available