org.nuiton.plugin
Class PluginHelper

java.lang.Object
  extended by org.nuiton.plugin.PluginHelper

public class PluginHelper
extends Object

Une classe pour mutualiser toutes les méthodes utiles pour un plugin.

Author:
tchemit

Field Summary
protected static double[] memoryFactors
           
protected static String[] memoryUnites
           
static String SNAPSHOT_SUFFIX
           
protected static double[] timeFactors
           
protected static String[] timeUnites
           
 
Constructor Summary
PluginHelper()
           
 
Method Summary
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.
static boolean addResourceDir(File dir, org.apache.maven.project.MavenProject project, String... includes)
          Add the directory as a resource of the given project.
static boolean addTestResourceDir(File dir, org.apache.maven.project.MavenProject project, String... includes)
          Add thedirectory as a test resource of the given project.
static void checkEncoding(PluginWithEncoding mojo)
          Method to be invoked in init phase to check sanity of PluginWithEncoding.getEncoding().
static String convert(long value, double[] factors, String[] unites)
           
static String convertMemory(long value)
           
static String convertTime(long value)
           
static String convertTime(long value, long value2)
           
static void copy(File source, File target)
          Permet de copier le fichier source vers le fichier cible.
static void copyFiles(File src, File dst, String[] includes, String[] excludes, boolean overwrite)
           
static void copyFiles(PluginIOContext p, String[] includes, String[] excludes, boolean overwrite)
           
static boolean createDirectoryIfNecessary(File dir)
          Cretae the directory (and his parents) if necessary.
static void createNewFile(File file)
          Create the given file.
static void deleteFile(File file)
          Delete the given file.
static void expandFile(File src, File dst, String[] includes, boolean overwrite)
           
static void expandFiles(PluginIOContext p, String[] includes, String[] excludes, String[] zipIncludes, boolean overwrite)
           
static SortedSet<String> getEmptyKeys(Map<?,?> map)
          Obtenir les clefs de toutes les valeurs nulles ou vide a partir d'un dictionnaire donne.
static File getFile(File base, String... paths)
           
static List<File> getIncludedFiles(File dir, String[] includes, String[] excludes)
           
static String[] getLines(File src)
           
static File[] getLinesAsFiles(File src)
           
static URL[] getLinesAsURL(File src)
           
static String getRelativePath(File base, File file)
           
static URL getUrl(URL baseUrl, String suffix)
          suffix a given baseUrl with the given suffix
static String prefixLines(String prefix, String prefixForEmpty, String content)
          Prefix the lines of the given content with a given prefix.
static String readAsString(File file, String encoding)
          Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres
static String readAsString(Reader reader)
          Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres
static String removeSnapshotSuffix(String versionId)
           
static void renameFile(File file, File destination)
          Rename the given file to a new destination.
static void setLastModified(File file, long lastModified)
           
static String[] splitAndTrim(String txt, String separator)
          Split the given text using the separator and 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 void writeString(File file, String content, String encoding)
          Sauvegarde un contenu dans un fichier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SNAPSHOT_SUFFIX

public static final String SNAPSHOT_SUFFIX
See Also:
Constant Field Values

timeFactors

protected static final double[] timeFactors

timeUnites

protected static final String[] timeUnites

memoryFactors

protected static final double[] memoryFactors

memoryUnites

protected static final String[] memoryUnites
Constructor Detail

PluginHelper

public PluginHelper()
Method Detail

removeSnapshotSuffix

public static String removeSnapshotSuffix(String versionId)

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 convertir
type - 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

public static String convertMemory(long value)

convertTime

public static String convertTime(long value)

convertTime

public static String convertTime(long value,
                                 long value2)

convert

public static String convert(long value,
                             double[] factors,
                             String[] unites)

splitAndTrim

public static String[] splitAndTrim(String txt,
                                    String separator)
Split the given text using the separator and trim each part of result.

Parameters:
txt - text to split
separator - 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 text
prefixForEmpty - prefix to add for empty lines
content - the text to treate
Returns:
the text transformed
Throws:
IOException - if any reading problem

getEmptyKeys

public static SortedSet<String> getEmptyKeys(Map<?,?> map)
Obtenir les clefs de toutes les valeurs nulles ou vide a partir d'un dictionnaire donne.

Parameters:
map - le dictionner a 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 add
project - the project to update
includes - the includes of the resource
Returns:
true if 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 thedirectory as a test resource of the given project.

Parameters:
dir - the directory to add
project - the project to update
includes - the includes of the resource
Returns:
true if 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 add
project - the project involved
resources - the list of existing resources
includes - includes of the new resources
Returns:
true if the resource was added (not already existing)
Since:
1.1.1

createDirectoryIfNecessary

public static boolean createDirectoryIfNecessary(File dir)
                                          throws IOException
Cretae the directory (and his parents) if necessary.

Parameters:
dir - the directory to create if not exisiting
Returns:
true if directory was created, false if was no need to create it
Throws:
IOException - if could not create directory
Since:
1.1.1

createNewFile

public static void createNewFile(File file)
                          throws IOException
Create the given file.

Parameters:
file - the file to create
Throws:
IOException - if could not create the file
Since:
1.1.1

deleteFile

public static void deleteFile(File file)
                       throws IOException
Delete the given file.

Parameters:
file - the file to delete
Throws:
IOException - if could not delete the file
Since:
1.1.1

renameFile

public static void renameFile(File file,
                              File destination)
                       throws IOException
Rename the given file to a new destination.

Parameters:
file - the file to rename
destination - the destination file
Throws:
IOException - if could not rename the file
Since:
1.2.0

setLastModified

public static void setLastModified(File file,
                                   long lastModified)
                            throws IOException
Throws:
IOException

copy

public static void copy(File source,
                        File target)
                 throws IOException
Permet de copier le fichier source vers le fichier cible.

Parameters:
source - le fichier source
target - le fichier cible
Throws:
IOException - Erreur de copie

readAsString

public static String readAsString(File file,
                                  String encoding)
                           throws IOException
Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres

Parameters:
file - le fichier a lire
encoding - encoding to read file
Returns:
the content of the file
Throws:
IOException - if IO pb

readAsString

public static String readAsString(Reader reader)
                           throws IOException
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

public static void writeString(File file,
                               String content,
                               String encoding)
                        throws IOException
Sauvegarde un contenu dans un fichier.

Parameters:
file - le fichier a ecrire
content - le contenu du fichier
encoding - l'encoding d'ecriture
Throws:
IOException - if IO pb

getIncludedFiles

public static List<File> getIncludedFiles(File dir,
                                          String[] includes,
                                          String[] excludes)

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

public static File getFile(File base,
                           String... paths)

getRelativePath

public static String getRelativePath(File base,
                                     File file)

expandFile

public static void expandFile(File src,
                              File dst,
                              String[] includes,
                              boolean overwrite)
                       throws IOException
Throws:
IOException

getLines

public static String[] getLines(File src)
                         throws IOException
Parameters:
src - the source file to read
Returns:
the lines of the source file.
Throws:
IOException - if any pb while reading file

getLinesAsFiles

public static File[] getLinesAsFiles(File src)
                              throws IOException
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

public static URL[] getLinesAsURL(File src)
                           throws IOException
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

public static URL getUrl(URL baseUrl,
                         String suffix)
                  throws IllegalArgumentException
suffix a given baseUrl with the given suffix

Parameters:
baseUrl - base url to use
suffix - suffix to add
Returns:
the new url
Throws:
IllegalArgumentException - if malformed url.
Since:
1.2.3

checkEncoding

public static void checkEncoding(PluginWithEncoding mojo)
Method to be invoked in init phase to check sanity of 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.

Parameters:
mojo - the mojo to check.
Since:
1.2.6


Copyright © 2009-2012 CodeLutin. All Rights Reserved.