org.nuiton.plugin
Class PluginHelper

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

public class PluginHelper
extends java.lang.Object

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

Author:
chemit

Field Summary
protected static double[] memoryFactors
           
protected static java.lang.String[] memoryUnites
           
static java.lang.String SNAPSHOT_SUFFIX
           
protected static double[] timeFactors
           
protected static java.lang.String[] timeUnites
           
 
Constructor Summary
PluginHelper()
           
 
Method Summary
static boolean addResourceDir(java.io.File dir, org.apache.maven.project.MavenProject project, java.util.List<?> resources, java.lang.String... includes)
          Add the directory as a resource in the given resource list.
static boolean addResourceDir(java.io.File dir, org.apache.maven.project.MavenProject project, java.lang.String... includes)
          Add the directory as a resource of the given project.
static boolean addResourceDir(java.lang.String newresourceDir, org.apache.maven.project.MavenProject project)
          Deprecated. since 1.1.1, prefer use the addResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)
static boolean addResourceDir(java.lang.String newresourceDir, org.apache.maven.project.MavenProject project, java.util.List<?> resources)
          Deprecated. since 1.1.1, prefer use the addResourceDir(java.io.File, org.apache.maven.project.MavenProject, java.util.List, String...)
static boolean addTestResourceDir(java.io.File dir, org.apache.maven.project.MavenProject project, java.lang.String... includes)
          Add thedirectory as a test resource of the given project.
static boolean addTestResourceDir(java.lang.String newresourceDir, org.apache.maven.project.MavenProject project)
          Deprecated. since 1.1.1, prefer use the addTestResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)
static java.lang.String convert(long value, double[] factors, java.lang.String[] unites)
           
static java.lang.String convertMemory(long value)
           
static java.lang.String convertTime(long value)
           
static java.lang.String convertTime(long value, long value2)
           
static void copy(java.io.File source, java.io.File target)
          Permet de copier le fichier source vers le fichier cible.
static void copyFiles(java.io.File src, java.io.File dst, java.lang.String[] includes, java.lang.String[] excludes, boolean overwrite)
           
static void copyFiles(PluginIOContext p, java.lang.String[] includes, java.lang.String[] excludes, boolean overwrite)
           
static boolean createDirectoryIfNecessary(java.io.File dir)
          Cretae the directory (and his parents) if necessary.
static void createNewFile(java.io.File file)
          Create the given file.
static void deleteFile(java.io.File file)
          Delete the given file.
static void expandFile(java.io.File src, java.io.File dst, java.lang.String[] includes, boolean overwrite)
           
static void expandFiles(PluginIOContext p, java.lang.String[] includes, java.lang.String[] excludes, java.lang.String[] zipIncludes, boolean overwrite)
           
static java.util.SortedSet<java.lang.String> getEmptyKeys(java.util.Map<?,?> map)
          Obtenir les clefs de toutes les valeurs nulles ou vide a partir d'un dictionnaire donne.
static java.io.File getFile(java.io.File base, java.lang.String... paths)
           
static java.util.List<java.io.File> getIncludedFiles(java.io.File dir, java.lang.String[] includes, java.lang.String[] excludes)
           
static java.lang.String[] getLines(java.io.File src)
           
static java.io.File[] getLinesAsFiles(java.io.File src)
           
static java.lang.String getRelativePath(java.io.File base, java.io.File file)
           
static java.lang.String prefixLines(java.lang.String prefix, java.lang.String prefixForEmpty, java.lang.String content)
          Prefix the lines of the given content with a given prefix.
static java.lang.String readAsString(java.io.File file, java.lang.String encoding)
          Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres
static java.lang.String readAsString(java.io.Reader reader)
          Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres
static java.lang.String removeSnapshotSuffix(java.lang.String versionId)
           
static void renameFile(java.io.File file, java.io.File destination)
          Rename the given file to a new destination.
static java.lang.String[] splitAndTrim(java.lang.String txt, java.lang.String separator)
          Split the given text using the separator and trim each part of result.
static
<O> java.util.List<O>
toGenericList(java.util.List<?> list, java.lang.Class<O> type)
          Permet de convertir une liste non typee, en une liste typee.
static void writeString(java.io.File file, java.lang.String content, java.lang.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 java.lang.String SNAPSHOT_SUFFIX
See Also:
Constant Field Values

timeFactors

protected static final double[] timeFactors

timeUnites

protected static final java.lang.String[] timeUnites

memoryFactors

protected static final double[] memoryFactors

memoryUnites

protected static final java.lang.String[] memoryUnites
Constructor Detail

PluginHelper

public PluginHelper()
Method Detail

removeSnapshotSuffix

public static java.lang.String removeSnapshotSuffix(java.lang.String versionId)

toGenericList

public static <O> java.util.List<O> toGenericList(java.util.List<?> list,
                                                  java.lang.Class<O> type)
                                       throws java.lang.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:
java.lang.IllegalArgumentException - si un element de la liste en entree n'est pas en adequation avec le type voulue.

convertMemory

public static java.lang.String convertMemory(long value)

convertTime

public static java.lang.String convertTime(long value)

convertTime

public static java.lang.String convertTime(long value,
                                           long value2)

convert

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

splitAndTrim

public static java.lang.String[] splitAndTrim(java.lang.String txt,
                                              java.lang.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 java.lang.String prefixLines(java.lang.String prefix,
                                           java.lang.String prefixForEmpty,
                                           java.lang.String content)
                                    throws java.io.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:
java.io.IOException - if any reading problem

getEmptyKeys

public static java.util.SortedSet<java.lang.String> getEmptyKeys(java.util.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(java.io.File dir,
                                     org.apache.maven.project.MavenProject project,
                                     java.lang.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(java.io.File dir,
                                         org.apache.maven.project.MavenProject project,
                                         java.lang.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(java.io.File dir,
                                     org.apache.maven.project.MavenProject project,
                                     java.util.List<?> resources,
                                     java.lang.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

addResourceDir

@Deprecated
public static boolean addResourceDir(java.lang.String newresourceDir,
                                                org.apache.maven.project.MavenProject project)
Deprecated. since 1.1.1, prefer use the addResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)

Parameters:
newresourceDir - the new resource directory to add
project - the maven project to modifiy
Returns:
true if resources was added

addTestResourceDir

@Deprecated
public static boolean addTestResourceDir(java.lang.String newresourceDir,
                                                    org.apache.maven.project.MavenProject project)
Deprecated. since 1.1.1, prefer use the addTestResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)

Parameters:
newresourceDir - the new resource directory to add
project - the maven project to modifiy
Returns:
true if resources was added

addResourceDir

@Deprecated
public static boolean addResourceDir(java.lang.String newresourceDir,
                                                org.apache.maven.project.MavenProject project,
                                                java.util.List<?> resources)
Deprecated. since 1.1.1, prefer use the addResourceDir(java.io.File, org.apache.maven.project.MavenProject, java.util.List, String...)

Parameters:
newresourceDir - the new resource directory to add
project - the maven project to modifiy
resources - the known resources for the maven project
Returns:
true if resources was added

createDirectoryIfNecessary

public static boolean createDirectoryIfNecessary(java.io.File dir)
                                          throws java.io.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:
java.io.IOException - if could not create directory
Since:
1.1.1

createNewFile

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

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

deleteFile

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

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

renameFile

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

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

copy

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

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

readAsString

public static java.lang.String readAsString(java.io.File file,
                                            java.lang.String encoding)
                                     throws java.io.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:
java.io.IOException - if IO pb

readAsString

public static java.lang.String readAsString(java.io.Reader reader)
                                     throws java.io.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:
java.io.IOException - if IO pb

writeString

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

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

getIncludedFiles

public static java.util.List<java.io.File> getIncludedFiles(java.io.File dir,
                                                            java.lang.String[] includes,
                                                            java.lang.String[] excludes)

copyFiles

public static void copyFiles(java.io.File src,
                             java.io.File dst,
                             java.lang.String[] includes,
                             java.lang.String[] excludes,
                             boolean overwrite)
                      throws java.io.IOException
Throws:
java.io.IOException

copyFiles

public static void copyFiles(PluginIOContext p,
                             java.lang.String[] includes,
                             java.lang.String[] excludes,
                             boolean overwrite)
                      throws java.io.IOException
Throws:
java.io.IOException

expandFiles

public static void expandFiles(PluginIOContext p,
                               java.lang.String[] includes,
                               java.lang.String[] excludes,
                               java.lang.String[] zipIncludes,
                               boolean overwrite)
                        throws java.io.IOException
Throws:
java.io.IOException

getFile

public static java.io.File getFile(java.io.File base,
                                   java.lang.String... paths)

getRelativePath

public static java.lang.String getRelativePath(java.io.File base,
                                               java.io.File file)

expandFile

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

getLines

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

getLinesAsFiles

public static java.io.File[] getLinesAsFiles(java.io.File src)
                                      throws java.io.IOException
Parameters:
src - the source file to read
Returns:
the files instanciate from lines of the source file.
Throws:
java.io.IOException - if any pb while reading file


Copyright © 2009-2010 CodeLutin. All Rights Reserved.