Package org.nuiton.plugin
Class PluginHelper
java.lang.Object
org.nuiton.plugin.PluginHelper
Une classe pour mutualiser toutes les méthodes utiles pour un plugin.
- Author:
- Tony Chemit - chemit@codelutin.com
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddResourceDir(File dir, org.apache.maven.project.MavenProject project, String... includes) Add the directory as a resource of the given project.static booleanaddResourceDir(File dir, org.apache.maven.project.MavenProject project, List<?> resources, String... includes) Add the directory as a resource in the given resource list.static booleanaddTestResourceDir(File dir, org.apache.maven.project.MavenProject project, String... includes) Add the directory as a test resource of the given project.static voidMethod to be invoked in init phase to check sanity ofPluginWithEncoding.getEncoding().static Stringstatic StringconvertMemory(long value) static StringconvertTime(long value) static StringconvertTime(long value, long value2) static voidPermet de copier le fichier source vers le fichier cible.static voidstatic voidcopyFiles(PluginIOContext p, String[] includes, String[] excludes, boolean overwrite) static booleanCretae the directory (and his parents) if necessary.static voidcreateNewFile(File file) Create the given file.static voiddeleteFile(File file) Delete the given file.static voidexpandFile(File src, File dst, String[] includes, boolean overwrite) static voidexpandFiles(PluginIOContext p, String[] includes, String[] excludes, String[] zipIncludes, boolean overwrite) getEmptyKeys(Map<?, ?> map) Obtenir les clefs de toutes les valeurs nulles ou vide à partir d'un dictionnaire donne.static FilegetIncludedFiles(File dir, String[] includes, String[] excludes) static String[]static File[]getLinesAsFiles(File src) static URL[]getLinesAsURL(File src) static StringgetRelativePath(File base, File file) static URLsuffix a givenbaseUrlwith the givensuffixstatic StringprefixLines(String prefix, String prefixForEmpty, String content) Prefix the lines of the given content with a given prefix.static StringreadAsString(File file, String encoding) Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateresstatic StringreadAsString(Reader reader) Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateresstatic StringremoveSnapshotSuffix(String versionId) static voidrenameFile(File file, File destination) Rename the given file to a new destination.static voidsetLastModified(File file, long lastModified) static String[]splitAndTrim(String txt, String separator) Split the giventextusing theseparatorand trim each part of result.static <O> List<O>toGenericList(List<?> list, Class<O> type) Permet de convertir une liste non typee, en une liste typee.static voidwriteString(File file, String content, String encoding) Sauvegarde un contenu dans un fichier.
-
Field Details
-
SNAPSHOT_SUFFIX
- See Also:
-
timeFactors
protected static final double[] timeFactors -
timeUnites
-
memoryFactors
protected static final double[] memoryFactors -
memoryUnites
-
-
Constructor Details
-
PluginHelper
public PluginHelper()
-
-
Method Details
-
removeSnapshotSuffix
-
toGenericList
public static <O> List<O> toGenericList(List<?> list, Class<O> type) throws IllegalArgumentException Permet de convertir une liste non typee, en une liste typee.La liste en entree en juste bien castee.
On effectue une verification sur le typage des elements de la liste.
Note : Aucune liste n'est creee, ni recopiee
- Type Parameters:
O- le type des objets de la liste- Parameters:
list- la liste a convertirtype- le type des elements de la liste- Returns:
- la liste typee
- Throws:
IllegalArgumentException- si un element de la liste en entree n'est pas en adequation avec le type voulue.
-
convertMemory
-
convertTime
-
convertTime
-
convert
-
splitAndTrim
Split the giventextusing theseparatorand trim each part of result.- Parameters:
txt- text to splitseparator- the split separator- Returns:
- the splited text with trimmed parts.
- Since:
- 1.1.0
-
prefixLines
public static String prefixLines(String prefix, String prefixForEmpty, String content) throws IOException Prefix the lines of the given content with a given prefix.- Parameters:
prefix- prefix to add on each line of textprefixForEmpty- prefix to add for empty linescontent- the text to treate- Returns:
- the text transformed
- Throws:
IOException- if any reading problem
-
getEmptyKeys
Obtenir les clefs de toutes les valeurs nulles ou vide à partir d'un dictionnaire donne.- Parameters:
map- le dictionnaire à parcourir- Returns:
- la liste des clefs dont la valeur est nulle ou vide
-
addResourceDir
public static boolean addResourceDir(File dir, org.apache.maven.project.MavenProject project, String... includes) Add the directory as a resource of the given project.- Parameters:
dir- the directory to addproject- the project to updateincludes- the includes of the resource- Returns:
trueif the resources was added (not already existing)- Since:
- 1.1.1
-
addTestResourceDir
public static boolean addTestResourceDir(File dir, org.apache.maven.project.MavenProject project, String... includes) Add the directory as a test resource of the given project.- Parameters:
dir- the directory to addproject- the project to updateincludes- the includes of the resource- Returns:
trueif the resources was added (not already existing)- Since:
- 1.1.1
-
addResourceDir
public static boolean addResourceDir(File dir, org.apache.maven.project.MavenProject project, List<?> resources, String... includes) Add the directory as a resource in the given resource list.- Parameters:
dir- the directory to addproject- the project involvedresources- the list of existing resourcesincludes- includes of the new resources- Returns:
trueif the resource was added (not already existing)- Since:
- 1.1.1
-
createDirectoryIfNecessary
Cretae the directory (and his parents) if necessary.- Parameters:
dir- the directory to create if not exisiting- Returns:
trueif directory was created,falseif was no need to create it- Throws:
IOException- if could not create directory- Since:
- 1.1.1
-
createNewFile
Create the given 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 a new destination.- Parameters:
file- the file to renamedestination- the destination file- Throws:
IOException- if could not rename the file- Since:
- 1.2.0
-
setLastModified
- Throws:
IOException
-
copy
Permet de copier le fichier source vers le fichier cible.- Parameters:
source- le fichier sourcetarget- le fichier cible- Throws:
IOException- Erreur de copie
-
readAsString
Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres- Parameters:
file- le fichier a lireencoding- encoding to read file- Returns:
- the content of the file
- Throws:
IOException- if IO pb
-
readAsString
Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres- Parameters:
reader- la source alire- Returns:
- the content of the file
- Throws:
IOException- if IO pb
-
writeString
Sauvegarde un contenu dans un fichier.- Parameters:
file- le fichier a ecrirecontent- le contenu du fichierencoding- l'encoding d'ecriture- Throws:
IOException- if IO pb
-
getIncludedFiles
-
copyFiles
public static void copyFiles(File src, File dst, String[] includes, String[] excludes, boolean overwrite) throws IOException - Throws:
IOException
-
copyFiles
public static void copyFiles(PluginIOContext p, String[] includes, String[] excludes, boolean overwrite) throws IOException - Throws:
IOException
-
expandFiles
public static void expandFiles(PluginIOContext p, String[] includes, String[] excludes, String[] zipIncludes, boolean overwrite) throws IOException - Throws:
IOException
-
getFile
-
getRelativePath
-
expandFile
public static void expandFile(File src, File dst, String[] includes, boolean overwrite) throws IOException - Throws:
IOException
-
getLines
- Parameters:
src- the source file to read- Returns:
- the lines of the source file.
- Throws:
IOException- if any pb while reading file
-
getLinesAsFiles
- Parameters:
src- the source file to read- Returns:
- the files instanciate from lines of the source file.
- Throws:
IOException- if any pb while reading file
-
getLinesAsURL
- Parameters:
src- the source file to read- Returns:
- the url instanciated from lines of the source file.
- Throws:
IOException- if any pb while reading file
-
getUrl
suffix a givenbaseUrlwith the givensuffix- Parameters:
baseUrl- base url to usesuffix- suffix to add- Returns:
- the new url
- Throws:
IllegalArgumentException- if malformed url.- Since:
- 1.2.3
-
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.- Parameters:
mojo- the mojo to check.- Since:
- 1.2.6
-