Package org.tentackle.maven
Class AbstractTentackleMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.tentackle.maven.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.AbstractMojoBase tentackle mojo.- Author:
- harald
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringcharsetThe encode used to read and write files.static java.lang.StringJDK_TOOLCHAINName of the default JDK toolchain.protected java.lang.StringminLogLevelThe minimum loggingLevelto redirect java.util logging to the maven logger.protected java.util.List<java.lang.String>resourceDirsList of resource dirs.protected java.lang.StringverbosityThe verbosity.
One of "default", "info" or "debug".protected org.wurbelizer.misc.VerbosityverbosityLevelmapped verbosity level.
-
Constructor Summary
Constructors Constructor Description AbstractTentackleMojo()
-
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.voiddetermineEncoding()Determines the encode charset.java.lang.StringdetermineJavaToolVersion(java.io.File javaTool)Determines the version number string of a given java tool.
Invokes the tool with--version.
Skips noise likeWARNING: Using incubator modules.voiddetermineVerbosity()sets the verbosity.voidexecute()abstract voidexecuteImpl()Implements the execution.
TT-mojos must override this method instead ofexecute().voidfindResourceDirs()Finds all resource directories.voidfinishExecute()Finishes the execution.
The method is invoked afterexecuteImpl().java.lang.StringgetCanonicalPath(java.io.File dir)Gets the canonical path of diven directory.java.lang.StringgetHostName()Gets the hostname.intgetMajorVersion(java.lang.String version)Determines the major version number integer of a given version string.org.apache.maven.project.MavenProjectgetMavenProject()Gets the maven project.org.apache.maven.execution.MavenSessiongetMavenSession()Gets the maven session.org.apache.maven.plugin.MojoExecutiongetMojoExecution()Gets the mojo execution.java.lang.StringgetPathRelativeToBasedir(java.lang.String path)Gets the path relative to the basedir.
Parent dirs of the basedir will also be tried.java.lang.StringgetResourceDirName(java.lang.String dirName)Checks if given directory resides in resources.org.apache.maven.settings.SettingsgetSettings()Gets the maven settings.org.apache.maven.settings.crypto.SettingsDecryptergetSettingsDecrypter()Decrypter for credentials in settings.xml.org.apache.maven.toolchain.ToolchaingetToolchain()Gets the"jdk"toolchain.org.apache.maven.toolchain.ToolchaingetToolchain(java.lang.String type)Gets the toolchain for a given type.org.apache.maven.toolchain.ToolchaingetToolchain(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.ToolchainManagergetToolchainManager()Gets the toolchain manager.JavaToolFindergetToolFinder()Gets the default toolfinder to locate tools like java, jdeps, jlink, etc.voidinstallJavaLoggingHandler()Installs a java.util log handler that redirects to the maven logger.protected booleanisExecutionRecursive()Returns whether reactor execution is recursive.protected booleanisSkippedByDefault()Determines whether mojo should be skipped by default.java.lang.StringloadResourceFileIntoString(java.lang.String path)Loads a resource file into a string.voidprepareExecute()Prepares the execution.
Invoked before validate().protected booleanvalidate()Checks the configuration.
-
-
-
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 verbosityThe 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 charsetThe encode used to read and write files.
-
minLogLevel
@Parameter(defaultValue="WARNING") protected java.lang.String minLogLevel
The minimum loggingLevelto 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.
-
-
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.MojoExecutionExceptionGets 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.MojoExecutionExceptionGets a toolchain for given type and selector.- Parameters:
type- the toolchain typeselector- 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.MojoExecutionExceptionGets 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.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
prepareExecute
public void prepareExecute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionPrepares 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.MojoFailureExceptionImplements the execution.
TT-mojos must override this method instead ofexecute(). This method is only invoked if validation succeeds.- Throws:
org.apache.maven.plugin.MojoExecutionException- if an unexpected problem occursorg.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.MojoFailureExceptionFinishes the execution.
The method is invoked afterexecuteImpl().- 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.MojoExecutionExceptionGets 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.MojoExecutionExceptionDetermines the version number string of a given java tool.
Invokes the tool with--version.
Skips noise likeWARNING: 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.MojoExecutionExceptionLoads 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.MojoExecutionExceptionChecks 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
-
-