org.apache.maven.plugin

## Class AbstractMojo

- java.lang.Object
- - org.apache.maven.plugin.AbstractMojo

- All Implemented Interfaces:
    ContextEnabled, Mojo
  Direct Known Subclasses:
    AntMojoWrapper, BeanshellMojoAdapter

      public abstract class AbstractMojo
      extends java.lang.Object
      implements Mojo, ContextEnabled

  Abstract class to provide most of the infrastructure required to implement a `Mojo` except for the execute method.
  The implementation should have a `goal` annotation in the class-level javadoc annotation:

       /**
        * @goal goalName
        */

  There are also a number of class-level javadoc annotations which can be used to control how and when the `Mojo` is executed:

  Descriptor Element | Annotation | Required? | Notes
  --- | --- | --- | ---
  goal | @goal <goalName> | Yes | The name for the Mojo that users will reference from the command line to execute the Mojo directly, or inside a POM in order to provide Mojo-specific configuration.
  implementation | none (detected) | Yes | The Mojo's fully-qualified class name (or script path in the case of non-Java Mojos).
  language | none (detected) | No. Default: `java` | The implementation language for this Mojo (Java, beanshell, etc.).

  configurator

  @configurator <roleHint>

  No

  The configurator type to use when injecting parameter values into this Mojo. The value is normally deduced from the Mojo's implementation language, but can be specified to allow a custom ComponentConfigurator implementation to be used.
  NOTE: This will only be used in very special cases, using a highly controlled vocabulary of possible values. (Elements like this are why it's a good idea to use the descriptor tools.)

  phase | @phase <phaseName> | No | Binds this Mojo to a particular phase of the standard build lifecycle, if specified. NOTE: This is only required if this Mojo is to participate in the standard build process.

  execute

  @execute [phase=<phaseName>|goal=<goalName>] [lifecycle=<lifecycleId>]

  No

  When this goal is invoked, it will first invoke a parallel lifecycle, ending at the given phase. If a goal is provided instead of a phase, that goal will be executed in isolation. The execution of either will not affect the current project, but instead make available the `${executedProject}` expression if required. An alternate lifecycle can also be provided: for more information see the documentation on the build lifecycle.

  requiresDependencyResolution | @requiresDependencyResolution <requiredScope> | No | Flags this Mojo as requiring the dependencies in the specified scope (or an implied scope) to be resolved before it can execute. NOTE: Currently supports compile, runtime, and test scopes.
  description | none (detected) | No | The description of this Mojo's functionality. Using the toolset, this will be the class-level Javadoc description provided. NOTE: While this is not a required part of the Mojo specification, it SHOULD be provided to enable future tool support for browsing, etc. and for clarity.
  parameters | N/A | No | Specifications for the parameters which this Mojo uses will be provided in parameter sub-elements in this section. NOTE: Parameters are discussed in more detail below.

  Version:
    $Id: AbstractMojo.java 612012 2008-01-15 04:17:35Z vsiveton $
  Author:
    Brett Porter, jdcasey, Vincent Siveton
  See Also:
    Guide to Developing Java Plugins, Guide to Configuring Plug-ins, Mojo API Specification

- - ### Field Summary

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

      `ROLE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractMojo()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Log` | `getLog()` Returns the logger that has been injected into this mojo.
    `java.util.Map` | `getPluginContext()`
    `void` | `setLog(Log log)` Inject a standard `Maven` logging mechanism to allow this `Mojo` to communicate events and feedback to the user.
    `void` | `setPluginContext(java.util.Map pluginContext)` Set a new shared context `Map` to a mojo before executing it.

    - ### 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`

- - ### Constructor Detail

    - #### AbstractMojo

          public AbstractMojo()

  - ### Method Detail

    - #### setLog

          public void setLog(Log log)

      Description copied from interface: `Mojo`
      Inject a standard `Maven` logging mechanism to allow this `Mojo` to communicate events and feedback to the user.
      Specified by:
        `setLog` in interface `Mojo`
      Parameters:
        `log` - a new logger
      See Also:
        `Mojo.setLog(org.apache.maven.plugin.logging.Log)`

    - #### getLog

          public Log getLog()

      Returns the logger that has been injected into this mojo. If no logger has been setup yet, a `SystemStreamLog` logger will be created and returned.
      Note: The logger returned by this method must not be cached in an instance field during the construction of the mojo. This would cause the mojo to use a wrongly configured default logger when being run by Maven. The proper logger gets injected by the Plexus container after the mojo has been constructed. Therefore, simply call this method directly whenever you need the logger, it is fast enough and needs no caching.
      Specified by:
        `getLog` in interface `Mojo`
      Returns:
        a log4j-like logger object which allows plugins to create messages at levels of `"debug"`, `"info"`, `"warn"`, and `"error"`. This logger is the accepted means to display information to the user.
      See Also:
        `Mojo.getLog()`

    - #### getPluginContext

          public java.util.Map getPluginContext()

      Specified by:
        `getPluginContext` in interface `ContextEnabled`
      Returns:
        a `Map` stored in the plugin container's context.
      See Also:
        `ContextEnabled.getPluginContext()`

    - #### setPluginContext

          public void setPluginContext(java.util.Map pluginContext)

      Description copied from interface: `ContextEnabled`
      Set a new shared context `Map` to a mojo before executing it.
      Specified by:
        `setPluginContext` in interface `ContextEnabled`
      Parameters:
        `pluginContext` - a new `Map`
      See Also:
        `ContextEnabled.setPluginContext(java.util.Map)`