Class AbstractPlugin
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo, Plugin
-
Nested Class Summary
Nested classes/interfaces inherited from interface Plugin
Plugin.InitState, Plugin.Packaging -
Field Summary
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptPackaging(Plugin.Packaging... packages) Accept the project's packaging between some given.protected voidaddCompileSourceRoots(File srcDir) Add a given directory in maven project's compile source roots (if not already present).protected voidAdd the givendirectoryinurlsif not already included.protected voidaddResourceDir(File dir, String... includes) Add a new resource location to the maven project (in not already present).protected voidaddTestCompileSourceRoots(File srcDir) Add a given directory in maven project's test compile source roots (if not already present).protected voidaddTestResourceDir(File dir, String... includes) Add a new test resource location to the maven project (in not already present).protected voidAdd the givenurlinurlsif not already included.protected voidA call back to execute after theexecute()is doneprotected voidbackupFile(File f) Backups the given file using thegetBackupFile(File)as destination file.protected voidMethod to be invoked in init phase to check sanity ofPluginWithEncoding.getEncoding().protected booleanCheck if the project packaging is acceptable for the mojo.protected voidCheck that the given resource exists in a simple fs file or in the classPath.protected booleancheckRunOnceDone(boolean runOnce, boolean onlyForRoot, Date buildStartTime, Date newStartTime) Deprecated.protected booleanChecks if the mojo execution should be skipped.voidCopy a file to a given locationand logging.protected voidCreate the directory if necessary.protected voidcreateNewFile(File file) Create a new file.protected voiddeleteFile(File file) Delete the given file.protected abstract voiddoAction()Do plugin action.final voidexecute()getBackupFile(File file) getFileFromBasedir(String... paths) Recupere le fichier donnée à partir de son chemin relatif sur le basedir du projet maven.getFilesToTreate(String[] includes, String[] excludes, File srcDir, MirroredFileUpdater updater) Collect to some files with a mirror.protected voidgetFilesToTreateForRoots(String[] includes, String[] excludes, List<String> roots, Map<File, String[]> files, MirroredFileUpdater updater) Collects some file.protected org.apache.maven.project.MavenProjectgetRootProject(org.apache.maven.project.MavenProject project, List<?> reactors) protected URLgetTemplate(File f) Obtain the url of a file, if file does not exist, try in the classPath.protected booleanprotected abstract voidinit()Method to initialize the mojo before doing any concrete actions.protected URLClassLoaderinitClassLoader(org.apache.maven.project.MavenProject project, File src, boolean addSourcesToClassPath, boolean testPhase, boolean addResourcesToClassPath, boolean addCompileClassPath, boolean addProjectClassPath) Init mojo classLoader.protected booleanprotected booleanTest if a file exists and is newer than the pom file.protected booleanneedInvoke(boolean runOnce, boolean onlyForRoot, String key) Check if an execution should be done or not according to the given parameters.protected booleanneedInvoke(boolean runOnce, boolean onlyForRoot, Date buildStartTime, Date newStartTime) Check if an execution should be done or not according to the given parameters.protected booleanrejectPackaging(Plugin.Packaging... packages) Accept the project's packaging if not in given one.protected voidremoveCompileSourceRoots(File srcDir) Remove a given directory in maven project's compile source roots (if present).protected voidremoveTestCompileSourceRoots(File srcDir) Remove a given directory in maven project's test compile source roots (if present).protected voidrenameFile(File file, File destination) Rename the given file to the destination one.voidWrite acontentinto the given destination file for the givenencoding.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContextMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.maven.plugin.Mojo
getLog, setLogMethods inherited from interface Plugin
getProject, isVerbose, setProject, setVerbose
-
Constructor Details
-
AbstractPlugin
public AbstractPlugin()
-
-
Method Details
-
init
Method to initialize the mojo before doing any concrete actions.Note: The method is invoked before the
doAction()method.- Throws:
Exception- if any
-
doAction
Do plugin action.The method
execute()invoke this method only and only if :checkPackaging()returnstrue.- method
init()returnstrue.
- Throws:
Exception- if any
-
execute
public final void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Specified by:
executein interfaceorg.apache.maven.plugin.Mojo- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
afterExecute
protected void afterExecute()A call back to execute after theexecute()is done -
checkPackaging
protected boolean checkPackaging()Check if the project packaging is acceptable for the mojo.By default, accept all packaging types.
Note: This method is the first instruction to be executed in the
execute().Tip: There is two method to simplify the packaging check :
acceptPackaging(Plugin.Packaging...)andrejectPackaging(Plugin.Packaging...)- Returns:
trueif can execute the goal for the packaging of the project,falseotherwise.
-
checkSkip
protected boolean checkSkip()Checks if the mojo execution should be skipped.- Returns:
falseif the mojo should not be executed.
-
acceptPackaging
Accept the project's packaging between some given.- Parameters:
packages- the accepted packaging- Returns:
trueif the project's packaging is one of the given ones.
-
rejectPackaging
Accept the project's packaging if not in given one.- Parameters:
packages- the rejecting packagings- Returns:
trueif the project's packaging is not in the given ones.
-
isExecutionRoot
protected boolean isExecutionRoot()- Returns:
trueif project is the root execution project
-
checkRunOnceDone
@Deprecated protected boolean checkRunOnceDone(boolean runOnce, boolean onlyForRoot, Date buildStartTime, Date newStartTime) Deprecated.since 2.1, prefer use nowneedInvoke(boolean, boolean, Date, Date)Check if an execution was already done according to the given parameters based on a timestamp.- Parameters:
runOnce- the flagonlyForRoot- a flag tobuildStartTime- the build statrt time (if none means must do it)newStartTime- the current build start time- Returns:
trueif the goal was already invoked,falseotherwise (means should run it now!).
-
needInvoke
protected boolean needInvoke(boolean runOnce, boolean onlyForRoot, Date buildStartTime, Date newStartTime) Check if an execution should be done or not according to the given parameters.- Parameters:
runOnce- the flagonlyForRoot- a flag tobuildStartTime- the build statrt time (if none means must do it)newStartTime- the current build start timetrueif the goal should be invoked,falseotherwise.- Returns:
trueif should be invoked,falseotherwise.- Since:
- 2.1
-
needInvoke
Check if an execution should be done or not according to the given parameters.Will search if the given
keyis found in project, if not then means that the plugin was not invoked.- Parameters:
runOnce- always return true if not setonlyForRoot- flag to only accept root projectkey- key to check over project (first time will put it in project properties)- Returns:
trueif the goal should be invoked,falseotherwise.- Since:
- 2.1
-
getFileFromBasedir
-
copyFile
Copy a file to a given locationand logging.- Parameters:
srcFile- represents the file to copy.destFile- file name of destination file.- Throws:
IOException- if could not copy file.
-
writeFile
Write acontentinto the given destination file for the givenencoding.- Parameters:
destFile- location where to write the contentcontent- content ot write in the fileencoding- the enconding of the file- Throws:
IOException- if any pb while writing the content into the file
-
isFileNewerThanPomFile
Test if a file exists and is newer than the pom file.- Parameters:
f- the file to test- Returns:
trueif file exists and is newer than the pom file,falseotherwise.
-
getFilesToTreateForRoots
protected void getFilesToTreateForRoots(String[] includes, String[] excludes, List<String> roots, Map<File, String[]> files, MirroredFileUpdater updater) Collects some file.- Parameters:
includes- includesexcludes- excludesroots- root directories to treatefiles- cache of file detected indexed by their root directoryupdater- the updater used to detect changes (if none, will get all the files)
-
getFilesToTreate
protected Map<String,String> getFilesToTreate(String[] includes, String[] excludes, File srcDir, MirroredFileUpdater updater) Collect to some files with a mirror.- Parameters:
includes- includesexcludes- excludessrcDir- the directory to treateupdater- an updater (will give the mirrored files)- Returns:
- the map of mirrored files associated to their files in srcDir
-
addCompileSourceRoots
Add a given directory in maven project's compile source roots (if not already present).- Parameters:
srcDir- the location to include in compile source roots
-
removeCompileSourceRoots
Remove a given directory in maven project's compile source roots (if present).- Parameters:
srcDir- the location to remove from compile source roots
-
addTestCompileSourceRoots
Add a given directory in maven project's test compile source roots (if not already present).- Parameters:
srcDir- the location to include in test compile source roots
-
removeTestCompileSourceRoots
Remove a given directory in maven project's test compile source roots (if present).- Parameters:
srcDir- the location to remove from test compile source roots
-
addResourceDir
-
addTestResourceDir
-
createDirectoryIfNecessary
Create the directory if necessary.- Parameters:
dir- the directory to create if not already existing- Throws:
IOException- if could not create the directory- Since:
- 1.1.1
-
createNewFile
Create a new file.- Parameters:
file- the file to create- Throws:
IOException- if could not create the file- Since:
- 1.1.1
-
deleteFile
Delete the given file.- Parameters:
file- the file to delete- Throws:
IOException- if could not delete the file- Since:
- 1.1.1
-
renameFile
Rename the given file to the destination one.- Parameters:
file- the file to renamedestination- the destination of the file- Throws:
IOException- if could not delete the file- Since:
- 1.2.0
-
getBackupFile
-
backupFile
Backups the given file using thegetBackupFile(File)as destination file.- Parameters:
f- the file to backup- Throws:
IOException- if any pb while copying the file
-
initClassLoader
protected URLClassLoader initClassLoader(org.apache.maven.project.MavenProject project, File src, boolean addSourcesToClassPath, boolean testPhase, boolean addResourcesToClassPath, boolean addCompileClassPath, boolean addProjectClassPath) throws MalformedURLException Init mojo classLoader.- Parameters:
project- the maven projectsrc- the source directoryaddSourcesToClassPath- a flag to a maven sources to classLoadertestPhase- a flag to specify if we are in a test phase (changes the classLoader)addResourcesToClassPath- flag to add maven's resources to classLoaderaddCompileClassPath- flag to add maven's project compile classPath to classLoaderaddProjectClassPath- flag to add maven'es project dependecies to classLoader- Returns:
- the new classLoader
- Throws:
MalformedURLException- if an url was not correct
-
addDirectoryToUrlsList
protected void addDirectoryToUrlsList(File directory, List<URL> urls, Set<String> done) throws MalformedURLException Add the givendirectoryinurlsif not already included.Note: We use a extra list to store file string representation, since we do NOT want any url resolution and the
URL.equals(Object)is doing some...- Parameters:
directory- the directory to insert inurlsurls- list of urlsdone- list of string representation of urls- Throws:
MalformedURLException- if pb while converting file to url- Since:
- 1.1.0
-
addUrlToUrlsList
Add the givenurlinurlsif not already included.Note: We use a extra list to store file string representation, since we do NOT want any url resolution and the
URL.equals(Object)is doing some..- Parameters:
url- the url to insert inurlsurls- list of urlsdone- list of string representation of urls- Since:
- 1.1.0
-
getTemplate
Obtain the url of a file, if file does not exist, try in the classPath.- Parameters:
f- the required resource file.- Returns:
- the url of the resource
- Throws:
IOException- for any error while looking up for the url of the resources
-
checkResource
Check that the given resource exists in a simple fs file or in the classPath.- Parameters:
f- the required resource file.- Throws:
IOException- for any error while looking up for the resources content.
-
getRootProject
protected org.apache.maven.project.MavenProject getRootProject(org.apache.maven.project.MavenProject project, List<?> reactors) -
checkEncoding
protected void checkEncoding()Method to be invoked in init phase to check sanity ofPluginWithEncoding.getEncoding().If no encoding was filled, then use the default for system (via
file.encodingenvironement property).Note: If mojo is not implementing
PluginWithEncoding, nothing is done.- Since:
- 1.26
-
hasClassPath
protected boolean hasClassPath()- Returns:
trueif project is not a pom,falseotherwise.- Since:
- 1.2.6
-
needInvoke(boolean, boolean, Date, Date)