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 Detail

      • verbosity

        @Parameter(defaultValue="${tentackle.verbosity}")
        protected 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 String charset
        The encode used to read and write files.
      • minLogLevel

        @Parameter(defaultValue="WARNING")
        protected 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 List<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​(String type,
                                                                 Map<String,​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​(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 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 String getPathRelativeToBasedir​(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 String getResourceDirName​(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 String getCanonicalPath​(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 String determineJavaToolVersion​(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​(String version)
        Determines the major version number integer of a given version string.
        Parameters:
        version - the version string
        Returns:
        the version number
      • loadResourceFileIntoString

        public String loadResourceFileIntoString​(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 Map<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