Class AbstractGitMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    AbstractGitOutputMojo, BranchMojo, CheckMojo, CommitMojo, InfoClassMojo, TagMojo

    abstract class AbstractGitMojo
    extends org.apache.maven.plugin.AbstractMojo
    This abstract Mojo implements initializing a JGit Repository and provides this Repository instance to subclasses.
    Since:
    0.1.0
    Author:
    Sebastian Staudt
    See Also:
    GitRepository
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) File baseDir
      The working tree of the Git repository.
      protected String dateFormat
      The date format to use for various dates
      (package private) String dirtyFlag
      The flag to append to refs if there are changes in the index or working tree
      (package private) boolean dirtyIgnoreUntracked
      Specifies if the dirty flag should also be appended if there are untracked files
      (package private) boolean failGracefully
      Specifies if a failed execution of the mojo will stop the build process
      (package private) File gitDir
      The GIT_DIR path of the Git repository
      (package private) String head
      The commit or ref to use as starting point for operations
      protected org.apache.maven.project.MavenProject project
      The Maven project
      (package private) String[] propertyPrefixes
      The prefixes to prepend to property keys
      (package private) boolean skip
      Skip the plugin execution
      (package private) boolean skipNoGit
      Skip the plugin execution if not inside a Git repository
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractGitMojo()  
    • Field Detail

      • dateFormat

        @Parameter(property="mavanagaiata.dateFormat",
                   defaultValue="MM/dd/yyyy hh:mm a Z")
        protected String dateFormat
        The date format to use for various dates
      • baseDir

        @Parameter(property="mavanagaiata.baseDir",
                   defaultValue="${project.basedir}")
        File baseDir
        The working tree of the Git repository.

        If there is only one project inside the Git repository this is probably ${project.basedir} (default).

        Note: The GIT_DIR can be found automatically even if this is not the real working tree but one of its subdirectories. But Mavanagaiata cannot determine the state of the working tree (e.g. for the dirty flag) if this is not set correctly.

      • dirtyFlag

        @Parameter(property="mavanagaiata.dirtyFlag",
                   defaultValue="-dirty")
        String dirtyFlag
        The flag to append to refs if there are changes in the index or working tree

        Setting this to either "false" or "null" will disable flagging refs as dirty.

        Since:
        0.4.0
      • dirtyIgnoreUntracked

        @Parameter(property="mavanagaiata.dirtyIgnoreUntracked",
                   defaultValue="false")
        boolean dirtyIgnoreUntracked
        Specifies if the dirty flag should also be appended if there are untracked files

        If false only modified files that are already known to Git will cause the dirty flag to be appended.

        Warning: Do not enable this if builds should be reproducible.

        Since:
        0.5.0
      • failGracefully

        @Parameter(property="mavanagaiata.failGracefully",
                   defaultValue="false")
        boolean failGracefully
        Specifies if a failed execution of the mojo will stop the build process

        If true a failure during mojo execution will not stop the build process.

        Since:
        0.6.0
      • gitDir

        @Parameter(property="mavanagaiata.gitDir")
        File gitDir
        The GIT_DIR path of the Git repository

        Warning: Do not set this when you don't have a good reason to do so. The GIT_DIR can be found automatically if your project resides somewhere in a usual Git repository.

      • head

        @Parameter(property="mavanagaiata.head",
                   defaultValue="HEAD")
        String head
        The commit or ref to use as starting point for operations
      • skip

        @Parameter(property="mavanagaiata.skip",
                   defaultValue="false")
        boolean skip
        Skip the plugin execution
        Since:
        0.5.0
      • skipNoGit

        @Parameter(property="mavanagaiata.skipNoGit",
                   defaultValue="false")
        boolean skipNoGit
        Skip the plugin execution if not inside a Git repository
        Since:
        0.5.0
      • project

        @Parameter(defaultValue="${project}",
                   readonly=true)
        protected org.apache.maven.project.MavenProject project
        The Maven project
      • propertyPrefixes

        @Parameter(property="mavanagaiata.propertyPrefixes",
                   defaultValue="mavanagaiata,mvngit")
        String[] propertyPrefixes
        The prefixes to prepend to property keys
    • Constructor Detail

      • AbstractGitMojo

        AbstractGitMojo()
    • Method Detail

      • execute

        public final void execute()
                           throws org.apache.maven.plugin.MojoExecutionException,
                                  org.apache.maven.plugin.MojoFailureException
        Generic execution sequence for a Mavanagaiata mojo

        Will initialize any needed resources, run the actual mojo code and cleanup afterwards.

        Throws:
        org.apache.maven.plugin.MojoExecutionException - if the mojo execution fails and failGracefully is false
        org.apache.maven.plugin.MojoFailureException - if the mojo execution fails and failGracefully is true
        See Also:
        init(), run(com.github.koraktor.mavanagaiata.git.GitRepository)
      • addProperty

        void addProperty​(String name,
                         String value)
        Saves a property with the given name into the project's properties The value will be stored two times – with "mavanagaiata" and "mvngit" as a prefix.
        Parameters:
        name - The property name
        value - The value of the property
      • init

        protected GitRepository init()
                              throws MavanagaiataMojoException
        Generic initialization for all Mavanagaiata mojos

        This will initialize the JGit repository instance for further usage by the mojo.

        Returns:
        false if the execution should be skipped
        Throws:
        MavanagaiataMojoException - if the repository cannot be initialized
      • prepareParameters

        void prepareParameters()
        Prepares and validates user-supplied parameters