Class ActMojo

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

@Mojo(name="act", aggregator=true, threadSafe=true, requiresProject=false, requiresDependencyResolution=COMPILE_PLUS_RUNTIME) public class ActMojo extends AbstractGWMojo
Maven goal that executes a Ghostwriter act against project files.

This goal creates an ActProcessor, resolves configuration from Maven parameters, user properties and Ghostwriter configuration files, and then scans the selected path. The goal is an aggregator, is thread-safe, and can run without a pom.xml. When a Maven project is present, inherited behavior from AbstractGWMojo contributes common Ghostwriter parameters such as the base directory, model, path, instructions, excludes and shared class-scanning tools.

Processing order for gw:act

Files are processed in reverse order, matching the Ghostwriter CLI behavior: sub-modules are processed first and parent modules are processed afterward. When Maven parallel execution is enabled, modules are processed by Ghostwriter rather than by the Maven reactor. For improved performance, run for example:


 mvn -T 4 gw:act
 

Parameters declared by this goal

  • gw.act: action prompt text or predefined act name. Examples:
    
     mvn gw:act -Dgw.act="Add missing Javadocs"
     mvn gw:act -Dgw.act=review
     
  • gw.acts: optional directory or path containing predefined act definitions. Examples:
    
     mvn gw:act -Dgw.acts=.ghostwriter/acts -Dgw.act=review
     mvn gw:act -Dgw.acts=src/gw/acts -Dgw.act=documentation
     

Common inherited parameters

The following commonly used parameters are inherited from AbstractGWMojo and are honored by this goal when present:

  • gw.path: file, directory, glob or other supported path expression to scan. Example:
    
     mvn gw:act -Dgw.act=review -Dgw.path=src/main/java
     
  • gw.model: AI model override. Example:
    
     mvn gw:act -Dgw.act=review -Dgw.model=gpt-4.1
     
  • gw.instructions: additional instructions supplied to the act. Example:
    
     mvn gw:act -Dgw.act=review -Dgw.instructions="Focus on public API compatibility"
     
  • gw.excludes: comma-separated exclusions. Example:
    
     mvn gw:act -Dgw.act=review -Dgw.excludes=target,*.class
     
  • gw.interactive: enables or disables interactive prompting when configuration is incomplete. Example:
    
     mvn gw:act -Dgw.interactive=false -Dgw.act=review
     

If Javadoc text needs to mention the literal closing tag, write it as */ so generated documentation does not terminate the comment early.

Since:
1.1.2
  • Field Details

    • prompter

      @Component protected org.codehaus.plexus.components.interactivity.Prompter prompter
      Interactive prompt provider used to collect action input.
    • actPrompt

      @Parameter(property="gw.act", required=false) protected String actPrompt
      Action prompt text or predefined act name, supplied by the gw.act Maven property.

      When this parameter is not supplied, the goal first checks configured properties 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 or path 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
  • Constructor Details

    • ActMojo

      public ActMojo()
  • Method Details

    • execute

      public void execute() 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.

      Throws:
      org.apache.maven.plugin.MojoExecutionException - if configuration, prompting, or file processing fails
    • updateMavenProjectLayout

      private void updateMavenProjectLayout(org.machanism.machai.project.layout.MavenProjectLayout mavenProjectLayout, org.apache.maven.model.Model model)
    • process

      protected void process(ActProcessor actProcessor) throws org.apache.maven.plugin.MojoExecutionException
      Applies runtime configuration to the supplied act processor and starts document scanning.
      Parameters:
      actProcessor - the act processor to configure and execute
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if scanning fails because of I/O or prompting errors
    • configureAndScan

      public void configureAndScan(ActProcessor actProcessor) 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
      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.
      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
      Throws:
      org.codehaus.plexus.components.interactivity.PrompterException - if prompting fails