org.alfresco.maven.plugin.amp.packaging
Class AbstractAmpPackagingTask

java.lang.Object
  extended by org.alfresco.maven.plugin.amp.packaging.AbstractAmpPackagingTask
All Implemented Interfaces:
AmpPackagingTask
Direct Known Subclasses:
AmpProjectPackagingTask, ArtifactsPackagingTask, ClassesPackagingTask, OverlayPackagingTask

public abstract class AbstractAmpPackagingTask
extends Object
implements AmpPackagingTask

Author:
Stephane Nicoll

Field Summary
static String[] DEFAULT_INCLUDES
           
static String META_INF_PATH
           
 
Constructor Summary
AbstractAmpPackagingTask()
           
 
Method Summary
protected  boolean copyFile(AmpPackagingContext context, File source, File destination, String targetFilename, boolean onlyIfModified)
          Copy file from source to destination.
protected  void copyFile(String sourceId, AmpPackagingContext context, File file, String targetFilename)
          Copy the specified file if the target location has not yet already been used.
protected  void copyFiles(String sourceId, AmpPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet)
          Copies the files if possible as is.
protected  void copyFiles(String sourceId, AmpPackagingContext context, File sourceBaseDir, PathSet sourceFilesSet, String targetPrefix)
          Copies the files if possible with an optional target prefix.
protected  boolean copyFilteredFile(String sourceId, AmpPackagingContext context, File file, String targetFilename)
          Copy the specified file if the target location has not yet already been used and filter its content with the configureed filter properties.
protected  void doUnpack(AmpPackagingContext context, File file, File unpackDirectory)
          Unpacks the specified file to the specified directory.
protected  String getArtifactFinalName(AmpPackagingContext context, org.apache.maven.artifact.Artifact artifact)
          Returns the final name of the specified artifact.
protected  PathSet getFilesToIncludes(File baseDir, String[] includes, String[] excludes)
          Returns the file to copy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.alfresco.maven.plugin.amp.packaging.AmpPackagingTask
performPackaging
 

Field Detail

DEFAULT_INCLUDES

public static final String[] DEFAULT_INCLUDES

META_INF_PATH

public static final String META_INF_PATH
See Also:
Constant Field Values
Constructor Detail

AbstractAmpPackagingTask

public AbstractAmpPackagingTask()
Method Detail

copyFiles

protected void copyFiles(String sourceId,
                         AmpPackagingContext context,
                         File sourceBaseDir,
                         PathSet sourceFilesSet,
                         String targetPrefix)
                  throws IOException
Copies the files if possible with an optional target prefix.

Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method makes sure to update the list of protected files which gives the list of files that have already been copied.

If the structure of the source directory is not the same as the root of the webapp, use the targetPrefix parameter to specify in which particular directory the files should be copied. Use null to copy the files with the same structure

Parameters:
sourceId - the source id
context - the context to use
sourceBaseDir - the base directory from which the sourceFilesSet will be copied
sourceFilesSet - the files to be copied
targetPrefix - the prefix to add to the target file name
Throws:
IOException - if an error occured while copying the files

copyFiles

protected void copyFiles(String sourceId,
                         AmpPackagingContext context,
                         File sourceBaseDir,
                         PathSet sourceFilesSet)
                  throws IOException
Copies the files if possible as is.

Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method makes sure to update the list of protected files which gives the list of files that have already been copied.

Parameters:
sourceId - the source id
context - the context to use
sourceBaseDir - the base directory from which the sourceFilesSet will be copied
sourceFilesSet - the files to be copied
Throws:
IOException - if an error occured while copying the files

copyFile

protected void copyFile(String sourceId,
                        AmpPackagingContext context,
                        File file,
                        String targetFilename)
                 throws IOException
Copy the specified file if the target location has not yet already been used.

The targetFileName is the relative path according to the root of the generated web application.

Parameters:
sourceId - the source id
context - the context to use
file - the file to copy
targetFilename - the relative path according to the root of the webapp
Throws:
IOException - if an error occured while copying

copyFilteredFile

protected boolean copyFilteredFile(String sourceId,
                                   AmpPackagingContext context,
                                   File file,
                                   String targetFilename)
                            throws IOException,
                                   org.apache.maven.plugin.MojoExecutionException
Copy the specified file if the target location has not yet already been used and filter its content with the configureed filter properties.

The targetFileName is the relative path according to the root of the generated web application.

Parameters:
sourceId - the source id
context - the context to use
file - the file to copy
targetFilename - the relative path according to the root of the webapp
Returns:
true if the file has been copied, false otherwise
Throws:
IOException - if an error occured while copying
org.apache.maven.plugin.MojoExecutionException - if an error occured while retrieving the filter properties

doUnpack

protected void doUnpack(AmpPackagingContext context,
                        File file,
                        File unpackDirectory)
                 throws org.apache.maven.plugin.MojoExecutionException
Unpacks the specified file to the specified directory.

Parameters:
context - the packaging context
file - the file to unpack
unpackDirectory - the directory to use for th unpacked file
Throws:
org.apache.maven.plugin.MojoExecutionException - if an error occured while unpacking the file

copyFile

protected boolean copyFile(AmpPackagingContext context,
                           File source,
                           File destination,
                           String targetFilename,
                           boolean onlyIfModified)
                    throws IOException
Copy file from source to destination. The directories up to destination will be created if they don't already exist. if the onlyIfModified flag is false, destination will be overwritten if it already exists. If the flag is true destination will be overwritten if it's not up to date.

Parameters:
context - the packaging context
source - an existing non-directory File to copy bytes from
destination - a non-directory File to write bytes to (possibly overwriting).
targetFilename - the relative path of the file from the webapp root directory
onlyIfModified - if true, copy the file only if the source has changed, always copy otherwise
Returns:
true if the file has been copied/updated, false otherwise
Throws:
IOException - if source does not exist, destination cannot be written to, or an IO error occurs during copying

getFilesToIncludes

protected PathSet getFilesToIncludes(File baseDir,
                                     String[] includes,
                                     String[] excludes)
Returns the file to copy. If the includes are null or empty, the default includes are used.

Parameters:
baseDir - the base directory to start from
includes - the includes
excludes - the excludes
Returns:
the files to copy

getArtifactFinalName

protected String getArtifactFinalName(AmpPackagingContext context,
                                      org.apache.maven.artifact.Artifact artifact)
Returns the final name of the specified artifact.

If the outputFileNameMapping is set, it is used, otherwise the standard naming scheme is used.

Parameters:
context - the packaging context
artifact - the artifact
Returns:
the converted filename of the artifact


Copyright © 2009 Alfresco. All Rights Reserved.