Class AbstractActMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractActPerModuleMojo,ActMojo
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 Summary
FieldsModifier and TypeFieldDescriptionprotected StringAction prompt text or predefined act name, supplied by thegw.actMaven property.private StringOptional directory, path, or URL containing predefined action definitions, supplied by thegw.actsMaven property.private static final ObjectMonitor that serializes access to Maven's shared user-property map while an act prompt is resolved.protected org.codehaus.plexus.components.interactivity.PrompterInteractive prompt provider used to collect act input when it is not available from Maven user properties or configuration.Fields inherited from class org.machanism.machai.gw.maven.AbstractGWMojo
basedir, classFunctionTools, configFile, excludes, instructions, logger, model, params, path, project, serverId, SERVERID_PROP_NAME, session, settingsFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyActPrompt(Configurator conf) Ensures an act prompt is stored in Maven user properties.voidconfigureAndScan(ActProcessor actProcessor, String savedAct) Resolves the effective act prompt and scans documents when an act is available.org.codehaus.plexus.components.interactivity.PrompterReturns the interactive prompt provider.voidperformAct(String actPrompt) Executes the configured act goal.protected voidprocess(ActProcessor actProcessor, String actPrompt) Applies runtime configuration to the supplied act processor and starts document scanning.Reads multi-line input from the interactivePrompter.protected voidscanDocuments(ActProcessor actProcessor) Scans the resolved project path with the configured act processor.voidsetPrompter(org.codehaus.plexus.components.interactivity.Prompter prompter) Sets the interactive prompt provider injected by Plexus.protected voidupdateMavenProjectLayout(org.machanism.machai.project.layout.MavenProjectLayout mavenProjectLayout, org.apache.maven.model.Model model) Updates Maven project layout metadata with the matching reactor project.Methods inherited from class org.machanism.machai.gw.maven.AbstractGWMojo
getConfiguration, scanDocuments, setBasedir, setConfigFile, setExcludes, setInstructions, setModel, setParams, setPath, setProject, setServerId, setSession, setSettingsMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.maven.plugin.Mojo
execute
-
Field Details
-
prompter
protected org.codehaus.plexus.components.interactivity.Prompter prompterInteractive prompt provider used to collect act input when it is not available from Maven user properties or configuration. -
act
Action prompt text or predefined act name, supplied by thegw.actMaven 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.configand then prompts the user interactively. Multi-line input is supported by ending each continued line withGWConstants.MULTIPLE_LINES_BREAKER.mvn gw:act -Dgw.act="Add missing Javadocs" mvn gw:act -Dgw.act=commit -
acts
Optional directory, path, or URL containing predefined action definitions, supplied by thegw.actsMaven 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
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 updatedmodel- model used to identify the reactor project
-
performAct
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-codeProcessTerminationExceptionis treated as normal termination.- Parameters:
actPrompt- configured act prompt, ornullto resolve one from Maven properties, configuration, or interactive input- Throws:
org.apache.maven.plugin.MojoExecutionException- if configuration, prompting, or file processing failsProcessTerminationException- 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 executeactPrompt- configured act prompt, ornullto 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 actsavedAct- configured act prompt, ornullto resolve one- Throws:
org.apache.maven.plugin.MojoExecutionException- if interactive prompt collection failsIOException- 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
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 interactivePrompter.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
nullimmediately - 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
-