Class AbstractTentackleMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    AbstractTentackleAnnotationProcessingMojo

    public abstract class AbstractTentackleMojo
    extends org.apache.maven.plugin.AbstractMojo
    Base tentackle mojo.
    Author:
    harald
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String charset
      The encode used to read and write files.
      static java.lang.String JDK_TOOLCHAIN
      Name of the default JDK toolchain.
      protected java.lang.String minLogLevel
      The minimum logging Level to redirect java.util logging to the maven logger.
      protected java.util.List<java.lang.String> resourceDirs
      List of resource dirs.
      protected java.lang.String verbosity
      The verbosity.
      One of "default", "info" or "debug".
      protected org.wurbelizer.misc.Verbosity verbosityLevel
      mapped verbosity level.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Map<java.lang.String,​PackageInfo> createPackageMap​(boolean resourceRoots)
      Creates a map of package names to package infos.
      void determineEncoding()
      Determines the encode charset.
      java.lang.String determineJavaToolVersion​(java.io.File javaTool)
      Determines the version number string of a given java tool.
      Invokes the tool with --version.
      Skips noise like WARNING: Using incubator modules.
      void determineVerbosity()
      sets the verbosity.
      void execute()  
      abstract void executeImpl()
      Implements the execution.
      TT-mojos must override this method instead of execute().
      void findResourceDirs()
      Finds all resource directories.
      void finishExecute()
      Finishes the execution.
      The method is invoked after executeImpl().
      java.lang.String getCanonicalPath​(java.io.File dir)
      Gets the canonical path of diven directory.
      java.lang.String getHostName()
      Gets the hostname.
      int getMajorVersion​(java.lang.String version)
      Determines the major version number integer of a given version string.
      org.apache.maven.project.MavenProject getMavenProject()
      Gets the maven project.
      org.apache.maven.execution.MavenSession getMavenSession()
      Gets the maven session.
      org.apache.maven.plugin.MojoExecution getMojoExecution()
      Gets the mojo execution.
      java.lang.String getPathRelativeToBasedir​(java.lang.String path)
      Gets the path relative to the basedir.
      Parent dirs of the basedir will also be tried.
      java.lang.String getResourceDirName​(java.lang.String dirName)
      Checks if given directory resides in resources.
      org.apache.maven.settings.Settings getSettings()
      Gets the maven settings.
      org.apache.maven.settings.crypto.SettingsDecrypter getSettingsDecrypter()
      Decrypter for credentials in settings.xml.
      org.apache.maven.toolchain.Toolchain getToolchain()
      Gets the "jdk" toolchain.
      org.apache.maven.toolchain.Toolchain getToolchain​(java.lang.String type)
      Gets the toolchain for a given type.
      org.apache.maven.toolchain.Toolchain getToolchain​(java.lang.String type, java.util.Map<java.lang.String,​java.lang.String> selector)
      Gets a toolchain for given type and selector.
      org.apache.maven.toolchain.ToolchainManager getToolchainManager()
      Gets the toolchain manager.
      JavaToolFinder getToolFinder()
      Gets the default toolfinder to locate tools like java, jdeps, jlink, etc.
      void installJavaLoggingHandler()
      Installs a java.util log handler that redirects to the maven logger.
      protected boolean isExecutionRecursive()
      Returns whether reactor execution is recursive.
      protected boolean isSkippedByDefault()
      Determines whether mojo should be skipped by default.
      java.lang.String loadResourceFileIntoString​(java.lang.String path)
      Loads a resource file into a string.
      void prepareExecute()
      Prepares the execution.
      Invoked before validate().
      protected boolean validate()
      Checks the configuration.
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • JDK_TOOLCHAIN

        public static final java.lang.String JDK_TOOLCHAIN
        Name of the default JDK toolchain.
        See Also:
        Constant Field Values
      • verbosity

        @Parameter(defaultValue="${tentackle.verbosity}")
        protected java.lang.String verbosity
        The verbosity.
        One of "default", "info" or "debug". Debug is also turned on (if not set explicitly) by Maven's global debug flag (see command line switch -X).
      • charset

        @Parameter(defaultValue="${project.build.sourceEncoding}")
        protected java.lang.String charset
        The encode used to read and write files.
      • minLogLevel

        @Parameter(defaultValue="WARNING")
        protected java.lang.String minLogLevel
        The minimum logging Level to redirect java.util logging to the maven logger.
      • verbosityLevel

        protected org.wurbelizer.misc.Verbosity verbosityLevel
        mapped verbosity level.
      • resourceDirs

        protected java.util.List<java.lang.String> resourceDirs
        List of resource dirs.
    • Constructor Detail

      • AbstractTentackleMojo

        public AbstractTentackleMojo()
    • Method Detail

      • installJavaLoggingHandler

        public void installJavaLoggingHandler()
        Installs a java.util log handler that redirects to the maven logger.
      • getMavenProject

        public org.apache.maven.project.MavenProject getMavenProject()
        Gets the maven project.
        Returns:
        the project, never null
      • getMojoExecution

        public org.apache.maven.plugin.MojoExecution getMojoExecution()
        Gets the mojo execution.
        Returns:
        the execution
      • getSettings

        public org.apache.maven.settings.Settings getSettings()
        Gets the maven settings.
        Returns:
        the settings from settings.xml
      • getSettingsDecrypter

        public org.apache.maven.settings.crypto.SettingsDecrypter getSettingsDecrypter()
        Decrypter for credentials in settings.xml.
        Returns:
        the settings decrypter
      • getMavenSession

        public org.apache.maven.execution.MavenSession getMavenSession()
        Gets the maven session.
        Returns:
        the session, never null
      • getToolchainManager

        public org.apache.maven.toolchain.ToolchainManager getToolchainManager()
        Gets the toolchain manager.
        Returns:
        the manager, never null
      • getToolchain

        public org.apache.maven.toolchain.Toolchain getToolchain()
                                                          throws org.apache.maven.plugin.MojoExecutionException
        Gets the "jdk" toolchain.
        Returns:
        the toolchain, null if none
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if toolchain specified but cannot be loaded
      • getToolchain

        public org.apache.maven.toolchain.Toolchain getToolchain​(java.lang.String type,
                                                                 java.util.Map<java.lang.String,​java.lang.String> selector)
                                                          throws org.apache.maven.plugin.MojoExecutionException
        Gets a toolchain for given type and selector.
        Parameters:
        type - the toolchain type
        selector - the selector map
        Returns:
        the toolchain, null if no match found
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if loading the toolchain failed
      • getToolchain

        public org.apache.maven.toolchain.Toolchain getToolchain​(java.lang.String type)
                                                          throws org.apache.maven.plugin.MojoExecutionException
        Gets the toolchain for a given type.
        Parameters:
        type - the toolchain type
        Returns:
        the toolchain, null if none
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if toolchain specified but cannot be loaded
      • getHostName

        public java.lang.String getHostName()
        Gets the hostname.
        Returns:
        the hostname
      • execute

        public final void execute()
                           throws org.apache.maven.plugin.MojoExecutionException,
                                  org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • prepareExecute

        public void prepareExecute()
                            throws org.apache.maven.plugin.MojoExecutionException,
                                   org.apache.maven.plugin.MojoFailureException
        Prepares the execution.
        Invoked before validate().
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if an unexpected problem occurs.
        org.apache.maven.plugin.MojoFailureException - if an expected problem occurs.
      • executeImpl

        public abstract void executeImpl()
                                  throws org.apache.maven.plugin.MojoExecutionException,
                                         org.apache.maven.plugin.MojoFailureException
        Implements the execution.
        TT-mojos must override this method instead of execute(). This method is only invoked if validation succeeds.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if an unexpected problem occurs
        org.apache.maven.plugin.MojoFailureException - if an expected problem (such as a compilation failure) occurs
        See Also:
        prepareExecute()
      • finishExecute

        public void finishExecute()
                           throws org.apache.maven.plugin.MojoExecutionException,
                                  org.apache.maven.plugin.MojoFailureException
        Finishes the execution.
        The method is invoked after executeImpl().
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if an unexpected problem occurs.
        org.apache.maven.plugin.MojoFailureException - if an expected problem occurs.
      • determineEncoding

        public void determineEncoding()
        Determines the encode charset.
      • determineVerbosity

        public void determineVerbosity()
        sets the verbosity.
      • getPathRelativeToBasedir

        public java.lang.String getPathRelativeToBasedir​(java.lang.String path)
        Gets the path relative to the basedir.
        Parent dirs of the basedir will also be tried.
        Parameters:
        path - the absolute path
        Returns:
        the shortened path
      • findResourceDirs

        public void findResourceDirs()
        Finds all resource directories.
      • getResourceDirName

        public java.lang.String getResourceDirName​(java.lang.String dirName)
        Checks if given directory resides in resources.
        Parameters:
        dirName - the directory name
        Returns:
        the resource dir, null if not a resource
      • getCanonicalPath

        public java.lang.String getCanonicalPath​(java.io.File dir)
                                          throws org.apache.maven.plugin.MojoExecutionException
        Gets the canonical path of diven directory.
        Parameters:
        dir - the directory
        Returns:
        the path
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if failed
      • getToolFinder

        public JavaToolFinder getToolFinder()
                                     throws org.apache.maven.plugin.MojoExecutionException
        Gets the default toolfinder to locate tools like java, jdeps, jlink, etc.
        Returns:
        the toolfinder, never null
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if toolchain cannot be loaded
      • determineJavaToolVersion

        public java.lang.String determineJavaToolVersion​(java.io.File javaTool)
                                                  throws org.apache.maven.plugin.MojoExecutionException
        Determines the version number string of a given java tool.
        Invokes the tool with --version.
        Skips noise like WARNING: Using incubator modules.
        Parameters:
        javaTool - the java tool
        Returns:
        the version string
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if the tool's output does not contain a java version
      • getMajorVersion

        public int getMajorVersion​(java.lang.String version)
        Determines the major version number integer of a given version string.
        Parameters:
        version - the version string
        Returns:
        the version number
      • loadResourceFileIntoString

        public java.lang.String loadResourceFileIntoString​(java.lang.String path)
                                                    throws org.apache.maven.plugin.MojoExecutionException
        Loads a resource file into a string.
        Parameters:
        path - the path to the resource file
        Returns:
        the contents
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if no such resource
      • isExecutionRecursive

        protected boolean isExecutionRecursive()
        Returns whether reactor execution is recursive.
        Returns:
        true if recursive, false if non-recursive (--non-recursive or -N option set, or plugin is an aggregator)
      • isSkippedByDefault

        protected boolean isSkippedByDefault()
        Determines whether mojo should be skipped by default.
        Returns:
        true if mojo should be skipped by default
      • validate

        protected boolean validate()
                            throws org.apache.maven.plugin.MojoExecutionException
        Checks the configuration.
        Returns:
        true if continue with execution, false to skip
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if validation failed
      • createPackageMap

        protected java.util.Map<java.lang.String,​PackageInfo> createPackageMap​(boolean resourceRoots)
                                                                              throws org.apache.maven.plugin.MojoExecutionException
        Creates a map of package names to package infos.
        Parameters:
        resourceRoots - true if collect all resource roots, else all source roots
        Returns:
        the packages
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if split package detected