|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.maven.plugin.AbstractMojo
org.nuiton.plugin.AbstractPlugin
public abstract class AbstractPlugin
Base mojo with usefull methods and implementing Plugin contract.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.nuiton.plugin.Plugin |
|---|
Plugin.InitState, Plugin.Packaging |
| Field Summary |
|---|
| Fields inherited from interface org.apache.maven.plugin.Mojo |
|---|
ROLE |
| Constructor Summary | |
|---|---|
AbstractPlugin()
|
|
| Method Summary | |
|---|---|
protected boolean |
acceptPackaging(Plugin.Packaging... packages)
Accept the project's packaging between some given. |
protected void |
addCompileSourceRoots(File srcDir)
Add a given directory in maven project's compile source roots (if not already present). |
protected void |
addDirectoryToUrlsList(File directory,
List<URL> urls,
Set<String> done)
Add the given directory in urls if not already included. |
protected void |
addResourceDir(File dir,
String... includes)
Add a new resource location to the maven project (in not already present). |
protected void |
addTestCompileSourceRoots(File srcDir)
Add a given directory in maven project's test compile source roots (if not already present). |
protected void |
addTestResourceDir(File dir,
String... includes)
Add a new test resource location to the maven project (in not already present). |
protected void |
addUrlToUrlsList(URL url,
List<URL> urls,
Set<String> done)
Add the given url in urls if not already included. |
protected void |
afterExecute()
A call back to execute after the execute() is done |
protected void |
backupFile(File f)
Backups the given file using the getBackupFile(File) as
destination file. |
protected void |
checkEncoding()
Method to be invoked in init phase to check sanity of PluginWithEncoding.getEncoding(). |
protected boolean |
checkPackaging()
Check if the project packaging is acceptable for the mojo. |
protected void |
checkResource(File f)
Check that the given resource exists in a simple fs file or in the classPath. |
protected boolean |
checkRunOnceDone(boolean runOnce,
boolean onlyForRoot,
Date buildStartTime,
Date newStartTime)
Check if an execution was already done according to the given parameters. |
protected boolean |
checkSkip()
Checks if the mojo execution should be skipped. |
void |
copyFile(File srcFile,
File destFile)
Copy a file to a given locationand logging. |
protected void |
createDirectoryIfNecessary(File dir)
Create the directory if necessary. |
protected void |
createNewFile(File file)
Create a new file. |
protected void |
deleteFile(File file)
Delete the given file. |
protected abstract void |
doAction()
Do plugin action. |
void |
execute()
|
File |
getBackupFile(File file)
|
File |
getFileFromBasedir(String... paths)
Recupere le fichier donnée à partir de son chemin relatif sur le basedir du projet maven. |
protected Map<String,String> |
getFilesToTreate(String[] includes,
String[] excludes,
File srcDir,
MirroredFileUpdater updater)
Collect to some files with a mirror. |
protected void |
getFilesToTreateForRoots(String[] includes,
String[] excludes,
List<String> roots,
Map<File,String[]> files,
MirroredFileUpdater updater)
Collects some file. |
protected org.apache.maven.project.MavenProject |
getRootProject(org.apache.maven.project.MavenProject project,
List<?> reactors)
|
protected URL |
getTemplate(File f)
Obtain the url of a file, if file does not exist, try in the classPath. |
protected boolean |
hasClassPath()
|
protected abstract void |
init()
Method to initialize the mojo before doing any concrete actions. |
protected URLClassLoader |
initClassLoader(org.apache.maven.project.MavenProject project,
File src,
boolean addSourcesToClassPath,
boolean testPhase,
boolean addResourcesToClassPath,
boolean addCompileClassPath,
boolean addProjectClassPath)
Init mojo classLoader. |
protected boolean |
isExecutionRoot()
|
protected boolean |
isFileNewerThanPomFile(File f)
Test if a file exists and is newer than the pom file. |
protected boolean |
rejectPackaging(Plugin.Packaging... packages)
Accept the project's packaging if not in given one. |
protected void |
removeCompileSourceRoots(File srcDir)
Remove a given directory in maven project's compile source roots (if present). |
protected void |
removeTestCompileSourceRoots(File srcDir)
Remove a given directory in maven project's test compile source roots (if present). |
protected void |
renameFile(File file,
File destination)
Rename the given file to the destination one. |
void |
writeFile(File destFile,
String content,
String encoding)
Write a content into the given destination file for the given
encoding. |
| 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 |
| Methods inherited from interface org.nuiton.plugin.Plugin |
|---|
getProject, isVerbose, setProject, setVerbose |
| Methods inherited from interface org.apache.maven.plugin.Mojo |
|---|
getLog, setLog |
| Constructor Detail |
|---|
public AbstractPlugin()
| Method Detail |
|---|
protected abstract void init()
throws Exception
doAction() method.
Exception - if any
protected abstract void doAction()
throws Exception
execute() invoke this method only and only if :
checkPackaging() returns true.init() returns true.
Exception - if any
public final void execute()
throws org.apache.maven.plugin.MojoExecutionException,
org.apache.maven.plugin.MojoFailureException
execute in interface org.apache.maven.plugin.Mojoorg.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureExceptionprotected void afterExecute()
execute() is done
protected boolean checkPackaging()
execute().
Tip: There is two method to simplify the packaging check :
acceptPackaging(Plugin.Packaging...)
and
rejectPackaging(Plugin.Packaging...)
true if can execute the goal for the packaging of the
project, false otherwise.protected boolean checkSkip()
false if the mojo should not be executed.protected boolean acceptPackaging(Plugin.Packaging... packages)
packages - the accepted packaging
true if the project's packaging is one of the given ones.protected boolean rejectPackaging(Plugin.Packaging... packages)
packages - the rejecting packagings
true if the project's packaging is not in the given ones.protected boolean isExecutionRoot()
true if project is the root execution project
protected boolean checkRunOnceDone(boolean runOnce,
boolean onlyForRoot,
Date buildStartTime,
Date newStartTime)
runOnce - the flagonlyForRoot - a flag tobuildStartTime - the build statrt time (if none means must do it)newStartTime - the current build start time
true if the goal was already invokedpublic File getFileFromBasedir(String... paths)
paths - les paths pour atteindre le fichier ou le répertoire
public void copyFile(File srcFile,
File destFile)
throws IOException
srcFile - represents the file to copy.destFile - file name of destination file.
IOException - if could not copy file.
public void writeFile(File destFile,
String content,
String encoding)
throws IOException
content into the given destination file for the given
encoding.
destFile - location where to write the contentcontent - content ot write in the fileencoding - the enconding of the file
IOException - if any pb while writing the content into the fileprotected boolean isFileNewerThanPomFile(File f)
f - the file to test
true if file exists and is newer than the pom file,
false otherwise.
protected void getFilesToTreateForRoots(String[] includes,
String[] excludes,
List<String> roots,
Map<File,String[]> files,
MirroredFileUpdater updater)
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)
protected Map<String,String> getFilesToTreate(String[] includes,
String[] excludes,
File srcDir,
MirroredFileUpdater updater)
includes - includesexcludes - excludessrcDir - the directory to treateupdater - an updater (will give the mirrored files)
protected void addCompileSourceRoots(File srcDir)
srcDir - the location to include in compile source rootsprotected void removeCompileSourceRoots(File srcDir)
srcDir - the location to remove from compile source rootsprotected void addTestCompileSourceRoots(File srcDir)
srcDir - the location to include in test compile source rootsprotected void removeTestCompileSourceRoots(File srcDir)
srcDir - the location to remove from test compile source roots
protected void addResourceDir(File dir,
String... includes)
dir - the new resource location to addincludes - files to include
protected void addTestResourceDir(File dir,
String... includes)
dir - the new resource location to addincludes - files to include
protected void createDirectoryIfNecessary(File dir)
throws IOException
dir - the directory to create if not already existing
IOException - if could not create the directory
protected void createNewFile(File file)
throws IOException
file - the file to create
IOException - if could not create the file
protected void deleteFile(File file)
throws IOException
file - the file to delete
IOException - if could not delete the file
protected void renameFile(File file,
File destination)
throws IOException
file - the file to renamedestination - the destination of the file
IOException - if could not delete the filepublic File getBackupFile(File file)
file - the source file
protected void backupFile(File f)
throws IOException
getBackupFile(File) as
destination file.
f - the file to backup
IOException - if any pb while copying the file
protected URLClassLoader initClassLoader(org.apache.maven.project.MavenProject project,
File src,
boolean addSourcesToClassPath,
boolean testPhase,
boolean addResourcesToClassPath,
boolean addCompileClassPath,
boolean addProjectClassPath)
throws MalformedURLException
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
MalformedURLException - if an url was not correct
protected void addDirectoryToUrlsList(File directory,
List<URL> urls,
Set<String> done)
throws MalformedURLException
directory in urls if 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...
directory - the directory to insert in urlsurls - list of urlsdone - list of string representation of urls
MalformedURLException - if pb while converting file to url
protected void addUrlToUrlsList(URL url,
List<URL> urls,
Set<String> done)
url in urls if 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..
url - the url to insert in urlsurls - list of urlsdone - list of string representation of urls
protected URL getTemplate(File f)
throws IOException
f - the required resource file.
IOException - for any error while looking up for the url of
the resources
protected void checkResource(File f)
throws IOException
f - the required resource file.
IOException - for any error while looking up for the resources
content.
protected org.apache.maven.project.MavenProject getRootProject(org.apache.maven.project.MavenProject project,
List<?> reactors)
protected void checkEncoding()
PluginWithEncoding.getEncoding().
If no encoding was filled, then use the default for system
(via file.encoding environement property).
Note: If mojo is not implementing PluginWithEncoding,
nothing is done.
protected boolean hasClassPath()
true if project is not a pom, false otherwise.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||