Class AbstractActMojo

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

public abstract class AbstractActMojo extends AbstractGWMojo
Abstract base Maven mojo for goals that execute Ghostwriter acts.

This class resolves act input and runtime configuration, prepares an ActProcessor, and scans the selected project documents. Subclasses provide the Maven goal-specific execution entry point while reusing the common interactive prompting, act resolution, and scanning behavior.

Prompt resolution synchronizes access to Maven's user properties because Maven may execute goals concurrently. Other mutable state is configured during goal execution and follows Maven's normal mojo lifecycle.

  • Field Details

    • prompter

      protected org.codehaus.plexus.components.interactivity.Prompter prompter
      Interactive prompt provider used to collect act input when it is not available from Maven user properties or configuration.
    • act

      @Parameter(property="gw.act", required=false) protected String act
      Action prompt text or predefined act name, supplied by the gw.act Maven property. The resolved value is passed to the act processor and can therefore be either a free-form instruction or the name of a reusable act.

      When this parameter is not supplied, the goal first checks configured gw.config and then prompts the user interactively. Multi-line input is supported by ending each continued line with GWConstants.MULTIPLE_LINES_BREAKER.

      
       mvn gw:act -Dgw.act="Add missing Javadocs"
       mvn gw:act -Dgw.act=commit
       
    • acts

      @Parameter(property="gw.acts", required=false) private String acts
      Optional directory, path, or URL containing predefined action definitions, supplied by the gw.acts Maven property.

      When provided, this value overrides the default act lookup location used by ActProcessor. It may point to a project-relative directory containing reusable act templates.

      
       mvn gw:act -Dgw.acts=acts -Dgw.act=site
       mvn gw:act -Dgw.acts=https://raw.githubusercontent.com/machanism-org/machai/refs/heads/main/acts -Dgw.act=site
       
    • MONITOR

      private static final Object MONITOR
      Monitor that serializes access to Maven's shared user-property map while an act prompt is resolved. It is shared by all mojo instances in the current class loader.
  • Constructor Details

    • AbstractActMojo

      public AbstractActMojo()
      Creates an act mojo.

      Maven injects the remaining goal dependencies and parameters after construction.

  • Method Details

    • updateMavenProjectLayout

      protected void updateMavenProjectLayout(org.machanism.machai.project.layout.MavenProjectLayout mavenProjectLayout, org.apache.maven.model.Model model)
      Updates Maven project layout metadata with the matching reactor project. Each available reactor project is optionally scanned for class metadata before the project with the same artifact identifier supplies the layout model.
      Parameters:
      mavenProjectLayout - layout whose model should be updated
      model - model used to identify the reactor project
    • performAct

      public void performAct(String actPrompt) throws org.apache.maven.plugin.MojoExecutionException
      Executes the configured act goal.

      The method creates and configures an ActProcessor, resolves Maven and Ghostwriter configuration values, applies inherited parameters such as path, model, instructions, excludes, and interactive mode, and then scans the selected documents. A zero-code ProcessTerminationException is treated as normal termination.

      Parameters:
      actPrompt - configured act prompt, or null to resolve one from Maven properties, configuration, or interactive input
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if configuration, prompting, or file processing fails
      ProcessTerminationException - if processing requests abnormal termination with a non-zero exit code
    • process

      protected void process(ActProcessor actProcessor, String actPrompt) throws org.apache.maven.plugin.MojoExecutionException
      Applies runtime configuration to the supplied act processor and starts document scanning. Usage statistics are initialized before configuration and logged even when scanning fails.
      Parameters:
      actProcessor - the act processor to configure and execute
      actPrompt - configured act prompt, or null to resolve one
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if scanning fails because of I/O errors; prompt failures are propagated by invoked configuration methods
    • configureAndScan

      public void configureAndScan(ActProcessor actProcessor, String savedAct) throws org.apache.maven.plugin.MojoExecutionException, IOException
      Resolves the effective act prompt and scans documents when an act is available.
      Parameters:
      actProcessor - the act processor that receives the resolved act
      savedAct - configured act prompt, or null to resolve one
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if interactive prompt collection fails
      IOException - if document scanning fails
    • applyActPrompt

      protected void applyActPrompt(Configurator conf) throws org.apache.maven.plugin.MojoExecutionException
      Ensures an act prompt is stored in Maven user properties. A configured value takes precedence over interactive input; entering the exit command leaves no new act property in the session.
      Parameters:
      conf - configuration used to look up a non-interactive act value before prompting
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if interactive prompt collection fails
    • scanDocuments

      protected void scanDocuments(ActProcessor actProcessor) throws IOException
      Scans the resolved project path with the configured act processor.
      Parameters:
      actProcessor - the processor used to scan documents
      Throws:
      IOException - if reading or writing project files fails
    • readText

      public String readText(String prompt) throws org.codehaus.plexus.components.interactivity.PrompterException
      Reads multi-line input from the interactive Prompter.

      The user can enter multiple lines by ending a line with GWConstants.MULTIPLE_LINES_BREAKER. Input collection stops when a line does not end with the breaker.

      Parameters:
      prompt - the initial prompt label displayed to the user
      Returns:
      the collected text, including line separators for continued input, or an empty string when the prompter returns null immediately
      Throws:
      org.codehaus.plexus.components.interactivity.PrompterException - if prompting fails
    • getPrompter

      public org.codehaus.plexus.components.interactivity.Prompter getPrompter()
      Returns the interactive prompt provider.
      Returns:
      the prompter used to collect interactive input
    • setPrompter

      @Inject public void setPrompter(org.codehaus.plexus.components.interactivity.Prompter prompter)
      Sets the interactive prompt provider injected by Plexus.
      Parameters:
      prompter - the prompter used to collect interactive input