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.AbstractMojo
Base tentackle mojo.
- Author:
- harald
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe encoding to read and write files.static final StringName of the default JDK toolchain.protected StringThe minimum loggingLevelto redirect java.util logging to the maven logger.protected StringThe verbosity.
One of "default", "info" or "debug".protected org.wurbelizer.misc.Verbositymapped verbosity level.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.maven.shared.model.fileset.util.FileSetManagercreateFileSetManager(boolean verbose) Creates a fileset manager.protected Map<String,PackageInfo> createPackageMap(boolean resourceRoots) Creates a map of package names to package infos.voidDetermines the encode charset.determineJavaToolVersion(File javaTool) Determines the version number string of a given java tool.
Invokes the tool with--version.
Skips noise likeWARNING: Using incubator modules.voidsets the verbosity.final voidexecute()abstract voidImplements the execution.
TT-mojos must override this method instead ofexecute().voidFinishes the execution.
The method is invoked afterexecuteImpl().getCanonicalPath(File dir) Gets the canonical path of diven directory.Gets the hostname.String[]getIncludedFiles(org.apache.maven.shared.model.fileset.FileSet fileSet) Gets the filenames included by given fileset.getJavaHome(org.apache.maven.toolchain.Toolchain toolchain) Gets the java home directory from a toolchain.intgetMajorVersion(String version) Determines the major version number integer of a given version string.org.apache.maven.project.MavenProjectGets the maven project.org.apache.maven.execution.MavenSessionGets the maven session.org.apache.maven.plugin.MojoExecutionGets the mojo execution.Gets the path relative to the basedir.
Parent dirs of the basedir will also be tried.getResourceDir(File file, boolean test) Checks if given file resides in a resource directory.getResourceDirs(boolean test) Gets the names of all resource directories.org.apache.maven.settings.SettingsGets the maven settings.org.apache.maven.settings.crypto.SettingsDecrypterDecrypter for credentials in settings.xml.org.apache.maven.toolchain.ToolchainGets the"jdk"toolchain.org.apache.maven.toolchain.ToolchaingetToolchain(String type) Gets the toolchain for a given type.org.apache.maven.toolchain.ToolchaingetToolchain(String type, Map<String, String> selector) Gets a toolchain for given type and selector.org.apache.maven.toolchain.ToolchainManagerGets the toolchain manager.Gets the default toolfinder to locate tools like java, jdeps, jlink, etc.voidInstalls a java.util log handler that redirects to the maven logger.protected booleanReturns whether reactor execution is recursive.protected booleanDetermines whether mojo should be skipped by default.Loads a resource file into a string.voidPrepares the execution.
Invoked before validate().toDescriptorName(File file) Creates a descriptor name from an artifact file.protected booleanvalidate()Checks the configuration.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
JDK_TOOLCHAIN
Name of the default JDK toolchain.- See Also:
-
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
The encoding to read and write files. -
minLogLevel
The minimum loggingLevelto redirect java.util logging to the maven logger. -
verbosityLevel
protected org.wurbelizer.misc.Verbosity verbosityLevelmapped verbosity level.
-
-
Constructor Details
-
AbstractTentackleMojo
public AbstractTentackleMojo()
-
-
Method Details
-
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(String type, Map<String, 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(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
-
getJavaHome
public File getJavaHome(org.apache.maven.toolchain.Toolchain toolchain) throws org.apache.maven.plugin.MojoExecutionException Gets the java home directory from a toolchain.- Parameters:
toolchain- the toolchain- Returns:
- the java home directory, null if not a
DefaultJavaToolChainor undefined by the toolchain - Throws:
org.apache.maven.plugin.MojoExecutionException- if the given directory does not exist or is not a directory
-
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:
-
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
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
-
getResourceDirs
Gets the names of all resource directories.- Parameters:
test- true if load test resource directories- Returns:
- the names provided by the maven project model, never null
-
getResourceDir
public File getResourceDir(File file, boolean test) throws org.apache.maven.plugin.MojoExecutionException Checks if given file resides in a resource directory.- Parameters:
file- the filetest- true if load test resource directories- Returns:
- the resource dir, null if not a resource
- Throws:
org.apache.maven.plugin.MojoExecutionException- if calculating a canonical pathname failed
-
getCanonicalPath
Gets the canonical path of diven directory.- Parameters:
dir- the directory- Returns:
- the path
- Throws:
org.apache.maven.plugin.MojoExecutionException- if failed
-
getToolFinder
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 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
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
-
toDescriptorName
Creates a descriptor name from an artifact file.- Parameters:
file- the artifact file- Returns:
- the descriptor name
-
createFileSetManager
public org.apache.maven.shared.model.fileset.util.FileSetManager createFileSetManager(boolean verbose) Creates a fileset manager.- Returns:
- the fileset manager.
-
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 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
-